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:
parent
469727bb19
commit
2e9bf76717
@ -77,6 +77,7 @@ export default class FeatureToggleClientStore
|
|||||||
'fs.disabled as strategy_disabled',
|
'fs.disabled as strategy_disabled',
|
||||||
'fs.parameters as parameters',
|
'fs.parameters as parameters',
|
||||||
'fs.constraints as constraints',
|
'fs.constraints as constraints',
|
||||||
|
'fs.sort_order as sort_order',
|
||||||
'segments.id as segment_id',
|
'segments.id as segment_id',
|
||||||
'segments.constraints as segment_constraints',
|
'segments.constraints as segment_constraints',
|
||||||
] as (string | Raw<any>)[];
|
] as (string | Raw<any>)[];
|
||||||
@ -208,15 +209,25 @@ export default class FeatureToggleClientStore
|
|||||||
// strip away unwanted properties
|
// strip away unwanted properties
|
||||||
const cleanedFeatures = features.map(({ strategies, ...rest }) => ({
|
const cleanedFeatures = features.map(({ strategies, ...rest }) => ({
|
||||||
...rest,
|
...rest,
|
||||||
strategies: strategies?.map(({ id, title, ...strategy }) => ({
|
strategies: strategies
|
||||||
...strategy,
|
?.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 } : {}),
|
...(isPlayground && title ? { title } : {}),
|
||||||
|
|
||||||
// We should not send strategy IDs from the client API,
|
// We should not send strategy IDs from the client API,
|
||||||
// as this breaks old versions of the Go SDK (at least).
|
// as this breaks old versions of the Go SDK (at least).
|
||||||
...(isAdmin || isPlayground ? { id } : {}),
|
...(isAdmin || isPlayground ? { id } : {}),
|
||||||
})),
|
})),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return cleanedFeatures;
|
return cleanedFeatures;
|
||||||
@ -229,6 +240,7 @@ export default class FeatureToggleClientStore
|
|||||||
title: row.strategy_title,
|
title: row.strategy_title,
|
||||||
constraints: row.constraints || [],
|
constraints: row.constraints || [],
|
||||||
parameters: mapValues(row.parameters || {}, ensureStringValue),
|
parameters: mapValues(row.parameters || {}, ensureStringValue),
|
||||||
|
sortOrder: row.sort_order,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user