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', | ||||
|     'built_in', | ||||
|     'deprecated', | ||||
|     'display_name', | ||||
| ]; | ||||
| const TABLE = 'strategies'; | ||||
| 
 | ||||
| @ -20,6 +21,7 @@ export interface IStrategy { | ||||
|     description: string; | ||||
|     parameters: object; | ||||
|     deprecated: boolean; | ||||
|     displayName: string; | ||||
| } | ||||
| 
 | ||||
| export interface IEditableStrategy { | ||||
| @ -41,6 +43,7 @@ interface IStrategyRow { | ||||
|     description: string; | ||||
|     parameters: object; | ||||
|     deprecated: boolean; | ||||
|     display_name: string; | ||||
| } | ||||
| export default class StrategyStore { | ||||
|     private db: Knex; | ||||
| @ -56,6 +59,7 @@ export default class StrategyStore { | ||||
|         const rows = await this.db | ||||
|             .select(STRATEGY_COLUMNS) | ||||
|             .from(TABLE) | ||||
|             .orderBy('sort_order', 'asc') | ||||
|             .orderBy('name', 'asc'); | ||||
| 
 | ||||
|         return rows.map(this.rowToStrategy); | ||||
| @ -66,7 +70,9 @@ export default class StrategyStore { | ||||
|             .select(STRATEGY_COLUMNS) | ||||
|             .from(TABLE) | ||||
|             .where({ built_in: 0 }) // eslint-disable-line
 | ||||
|             .orderBy('sort_order', 'asc') | ||||
|             .orderBy('name', 'asc'); | ||||
| 
 | ||||
|         return rows.map(this.rowToEditableStrategy); | ||||
|     } | ||||
| 
 | ||||
| @ -83,6 +89,7 @@ export default class StrategyStore { | ||||
|             throw new NotFoundError('No strategy found'); | ||||
|         } | ||||
|         return { | ||||
|             displayName: row.display_name, | ||||
|             name: row.name, | ||||
|             editable: row.built_in !== 1, | ||||
|             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