1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-23 00:22:19 +01:00

feat: sort feature strategies (#4218)

This commit is contained in:
Mateusz Kwasniewski 2023-07-11 13:58:14 +02:00 committed by GitHub
parent 469727bb19
commit 2e9bf76717
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -77,6 +77,7 @@ export default class FeatureToggleClientStore
'fs.disabled as strategy_disabled',
'fs.parameters as parameters',
'fs.constraints as constraints',
'fs.sort_order as sort_order',
'segments.id as segment_id',
'segments.constraints as segment_constraints',
] as (string | Raw<any>)[];
@ -208,7 +209,17 @@ export default class FeatureToggleClientStore
// strip away unwanted properties
const cleanedFeatures = features.map(({ strategies, ...rest }) => ({
...rest,
strategies: strategies?.map(({ id, title, ...strategy }) => ({
strategies: strategies
?.sort((strategy1, strategy2) => {
if (
typeof strategy1.sortOrder === 'number' &&
typeof strategy2.sortOrder === 'number'
) {
return strategy1.sortOrder - strategy2.sortOrder;
}
return 0;
})
.map(({ id, title, sortOrder, ...strategy }) => ({
...strategy,
...(isPlayground && title ? { title } : {}),
@ -229,6 +240,7 @@ export default class FeatureToggleClientStore
title: row.strategy_title,
constraints: row.constraints || [],
parameters: mapValues(row.parameters || {}, ensureStringValue),
sortOrder: row.sort_order,
};
}