From fdf324a9f5f3c46052d2b16b14eb321bf0a85eb3 Mon Sep 17 00:00:00 2001 From: Jari Bakken Date: Mon, 10 Nov 2014 16:21:22 +0100 Subject: [PATCH] Add features.description to db and ui --- lib/featureDb.js | 15 ++++++++++++--- .../20141110144153-add-description-to-features.js | 2 ++ .../sql/002-add-description-to-features.down.sql | 1 + .../sql/002-add-description-to-features.up.sql | 1 + public/js/components/feature/Feature.jsx | 10 +++++++--- 5 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 migrations/20141110144153-add-description-to-features.js create mode 100644 migrations/sql/002-add-description-to-features.down.sql create mode 100644 migrations/sql/002-add-description-to-features.up.sql diff --git a/lib/featureDb.js b/lib/featureDb.js index b64eca33bb..abd20f4b78 100644 --- a/lib/featureDb.js +++ b/lib/featureDb.js @@ -5,9 +5,11 @@ var eventStore = require('./eventStore'), dbPool = require('./dbPool'); eventStore.on(eventType.featureCreated, function (event) { - var sql = 'INSERT INTO features(name, enabled, strategy_name, parameters) VALUES ($1, $2, $3, $4)'; + var sql = 'INSERT INTO features(name, description, enabled, strategy_name, parameters) ' + + 'VALUES ($1, $2, $3, $4, $5)'; var params = [ event.data.name, + event.data.description, event.data.enabled ? 1 : 0, event.data.strategy, event.data.parameters @@ -34,6 +36,10 @@ eventStore.on(eventType.featureUpdated, function (event) { sql = 'UPDATE features SET strategy_name = $1 WHERE name=$2'; params = [event.data.value, event.data.name]; break; + case 'description': + sql = 'UPDATE features SET description = $1 WHERE name=$2'; + params = [event.data.value, event.data.name]; + break; case 'parameters': sql = 'UPDATE features SET parameters = $1 WHERE name=$2'; params = [event.data.value, event.data.name]; @@ -57,7 +63,8 @@ eventStore.on(eventType.featureUpdated, function (event) { ); function getFeatures() { - var sql = 'SELECT name, enabled, strategy_name as strategy, parameters FROM features ORDER BY created_at DESC'; + var sql = 'SELECT name, description, enabled, strategy_name as strategy, parameters ' + + 'FROM features ORDER BY created_at DESC'; return new Promise(function (resolve, reject) { dbPool.query(sql, function(err, res) { if(err) {reject(err);} @@ -67,7 +74,8 @@ function getFeatures() { } function getFeature(name) { - var sql = 'SELECT name, enabled, strategy_name as strategy, parameters FROM features WHERE name=$1'; + var sql = 'SELECT name, description, enabled, strategy_name as strategy, parameters ' + + 'FROM features WHERE name=$1'; return new Promise(function (resolve, reject) { dbPool.query(sql, [name], function(err, res) { @@ -85,6 +93,7 @@ function getFeature(name) { function mapToToggle(row) { return { name: row.name, + description: row.description, enabled: row.enabled > 0, strategy: row.strategy, parameters: row.parameters diff --git a/migrations/20141110144153-add-description-to-features.js b/migrations/20141110144153-add-description-to-features.js new file mode 100644 index 0000000000..7ff1b2734a --- /dev/null +++ b/migrations/20141110144153-add-description-to-features.js @@ -0,0 +1,2 @@ +module.exports = require('../lib/migrationRunner').create('002-add-description-to-features'); + diff --git a/migrations/sql/002-add-description-to-features.down.sql b/migrations/sql/002-add-description-to-features.down.sql new file mode 100644 index 0000000000..95bc6040d0 --- /dev/null +++ b/migrations/sql/002-add-description-to-features.down.sql @@ -0,0 +1 @@ +ALTER TABLE features DROP COLUMN "description"; diff --git a/migrations/sql/002-add-description-to-features.up.sql b/migrations/sql/002-add-description-to-features.up.sql new file mode 100644 index 0000000000..d4057d6ff7 --- /dev/null +++ b/migrations/sql/002-add-description-to-features.up.sql @@ -0,0 +1 @@ +ALTER TABLE features ADD "description" text; diff --git a/public/js/components/feature/Feature.jsx b/public/js/components/feature/Feature.jsx index 0c6129c368..823b03debd 100644 --- a/public/js/components/feature/Feature.jsx +++ b/public/js/components/feature/Feature.jsx @@ -12,15 +12,19 @@ var Feature = React.createClass({ render: function() { return (
-
+
-
+
{this.props.feature.name}
-
+
+ {this.props.feature.description || '\u00a0'} +
+ +
{this.props.feature.strategy}