mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	Fix/strategies sort order (#798)
* feat: add sort order field to strageies * feat: update strategy display name and description Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com>
This commit is contained in:
		
							parent
							
								
									4b10356325
								
							
						
					
					
						commit
						7776f3c940
					
				| @ -11,6 +11,7 @@ const STRATEGY_COLUMNS = [ | |||||||
|     'parameters', |     'parameters', | ||||||
|     'built_in', |     'built_in', | ||||||
|     'deprecated', |     'deprecated', | ||||||
|  |     'display_name', | ||||||
| ]; | ]; | ||||||
| const TABLE = 'strategies'; | const TABLE = 'strategies'; | ||||||
| 
 | 
 | ||||||
| @ -20,6 +21,7 @@ export interface IStrategy { | |||||||
|     description: string; |     description: string; | ||||||
|     parameters: object; |     parameters: object; | ||||||
|     deprecated: boolean; |     deprecated: boolean; | ||||||
|  |     displayName: string; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export interface IEditableStrategy { | export interface IEditableStrategy { | ||||||
| @ -41,6 +43,7 @@ interface IStrategyRow { | |||||||
|     description: string; |     description: string; | ||||||
|     parameters: object; |     parameters: object; | ||||||
|     deprecated: boolean; |     deprecated: boolean; | ||||||
|  |     display_name: string; | ||||||
| } | } | ||||||
| export default class StrategyStore { | export default class StrategyStore { | ||||||
|     private db: Knex; |     private db: Knex; | ||||||
| @ -56,6 +59,7 @@ export default class StrategyStore { | |||||||
|         const rows = await this.db |         const rows = await this.db | ||||||
|             .select(STRATEGY_COLUMNS) |             .select(STRATEGY_COLUMNS) | ||||||
|             .from(TABLE) |             .from(TABLE) | ||||||
|  |             .orderBy('sort_order', 'asc') | ||||||
|             .orderBy('name', 'asc'); |             .orderBy('name', 'asc'); | ||||||
| 
 | 
 | ||||||
|         return rows.map(this.rowToStrategy); |         return rows.map(this.rowToStrategy); | ||||||
| @ -66,7 +70,9 @@ export default class StrategyStore { | |||||||
|             .select(STRATEGY_COLUMNS) |             .select(STRATEGY_COLUMNS) | ||||||
|             .from(TABLE) |             .from(TABLE) | ||||||
|             .where({ built_in: 0 }) // eslint-disable-line
 |             .where({ built_in: 0 }) // eslint-disable-line
 | ||||||
|  |             .orderBy('sort_order', 'asc') | ||||||
|             .orderBy('name', 'asc'); |             .orderBy('name', 'asc'); | ||||||
|  | 
 | ||||||
|         return rows.map(this.rowToEditableStrategy); |         return rows.map(this.rowToEditableStrategy); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -83,6 +89,7 @@ export default class StrategyStore { | |||||||
|             throw new NotFoundError('No strategy found'); |             throw new NotFoundError('No strategy found'); | ||||||
|         } |         } | ||||||
|         return { |         return { | ||||||
|  |             displayName: row.display_name, | ||||||
|             name: row.name, |             name: row.name, | ||||||
|             editable: row.built_in !== 1, |             editable: row.built_in !== 1, | ||||||
|             description: row.description, |             description: row.description, | ||||||
|  | |||||||
| @ -0,0 +1,19 @@ | |||||||
|  | 'use strict'; | ||||||
|  | 
 | ||||||
|  | exports.up = function(db, cb) { | ||||||
|  |     db.runSql( | ||||||
|  |         ` | ||||||
|  |     ALTER TABLE strategies ADD COLUMN sort_order integer DEFAULT 9999; | ||||||
|  |     UPDATE strategies SET sort_order = 0 WHERE name = 'default'; | ||||||
|  |     UPDATE strategies SET sort_order = 1 WHERE name = 'flexibleRollout'; | ||||||
|  |     UPDATE strategies SET sort_order = 2 WHERE name = 'userWithId'; | ||||||
|  |     UPDATE strategies SET sort_order = 3 WHERE name = 'remoteAddress'; | ||||||
|  |     UPDATE strategies SET sort_order = 4 WHERE name = 'applicationHostname'; | ||||||
|  |   `,
 | ||||||
|  |         cb, | ||||||
|  |     ); | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | exports.down = function(db, cb) { | ||||||
|  |     db.runSql(`ALTER TABLE strategies REMOVE COLUMN sort_order;`, cb); | ||||||
|  | }; | ||||||
| @ -0,0 +1,19 @@ | |||||||
|  | 'use strict'; | ||||||
|  | 
 | ||||||
|  | exports.up = function(db, cb) { | ||||||
|  |     db.runSql( | ||||||
|  |         ` | ||||||
|  |     ALTER TABLE strategies ADD COLUMN display_name text; | ||||||
|  |     UPDATE strategies SET display_name = 'Standard', description = 'The standard strategy is strictly on / off for your entire userbase.' WHERE name = 'default'; | ||||||
|  |     UPDATE strategies SET display_name = 'Gradual rollout', description = 'Roll out to a percentage of your userbase, and ensure that the experience is the same for the user on each visit.' WHERE name = 'flexibleRollout'; | ||||||
|  |     UPDATE strategies SET display_name = 'UserIDs', description = 'Enable the feature for a specific set of userIds.' WHERE name = 'userWithId'; | ||||||
|  |     UPDATE strategies SET display_name = 'IPs', description = 'Enable the feature for a specific set of IP addresses.' WHERE name = 'remoteAddress'; | ||||||
|  |     UPDATE strategies SET display_name = 'Hosts', description = 'Enable the feature for a specific set of hostnames.' WHERE name = 'applicationHostname'; | ||||||
|  |   `,
 | ||||||
|  |         cb, | ||||||
|  |     ); | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | exports.down = function(db, cb) { | ||||||
|  |     db.runSql(`ALTER TABLE strategies DROP COLUMN display_name;`, cb); | ||||||
|  | }; | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user