mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-05 17:53:12 +02:00
feat: cleanup
This commit is contained in:
parent
2b46a21f21
commit
af23c0df39
@ -13,7 +13,7 @@ export const sortStrategiesByFeature = <
|
|||||||
strategies: ExistingStrategy[],
|
strategies: ExistingStrategy[],
|
||||||
changeRequestStrategies: (UpdatedStrategy | NewStrategy)[],
|
changeRequestStrategies: (UpdatedStrategy | NewStrategy)[],
|
||||||
): (ExistingStrategy | UpdatedStrategy | NewStrategy)[] => {
|
): (ExistingStrategy | UpdatedStrategy | NewStrategy)[] => {
|
||||||
const collected = [...strategies, ...changeRequestStrategies].reduce(
|
const strategiesByFlag = [...strategies, ...changeRequestStrategies].reduce(
|
||||||
(acc, strategy) => {
|
(acc, strategy) => {
|
||||||
if (!strategy.featureName) {
|
if (!strategy.featureName) {
|
||||||
// this shouldn't ever happen here, but because the
|
// this shouldn't ever happen here, but because the
|
||||||
@ -39,19 +39,17 @@ export const sortStrategiesByFeature = <
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const flags: [
|
const flagToStrategiesList = Object.entries(strategiesByFlag);
|
||||||
string,
|
|
||||||
(ExistingStrategy | UpdatedStrategy | NewStrategy)[],
|
|
||||||
][] = Object.entries(collected);
|
|
||||||
|
|
||||||
flags.sort(([flagA], [flagB]) => {
|
flagToStrategiesList.sort(([flagA], [flagB]) => {
|
||||||
return flagA.localeCompare(flagB);
|
return flagA.localeCompare(flagB);
|
||||||
});
|
});
|
||||||
|
|
||||||
return flags.flatMap(([_, strategies]) => {
|
return flagToStrategiesList.flatMap(([_, strategies]) => {
|
||||||
const isExistingStrategy = (
|
const isExistingStrategy = (
|
||||||
strategy: ExistingStrategy | UpdatedStrategy | NewStrategy,
|
strategy: ExistingStrategy | UpdatedStrategy | NewStrategy,
|
||||||
): strategy is ExistingStrategy | UpdatedStrategy => 'id' in strategy;
|
): strategy is ExistingStrategy | UpdatedStrategy => 'id' in strategy;
|
||||||
|
|
||||||
const isChangeRequest = (
|
const isChangeRequest = (
|
||||||
strategy: ExistingStrategy | UpdatedStrategy | NewStrategy,
|
strategy: ExistingStrategy | UpdatedStrategy | NewStrategy,
|
||||||
): strategy is UpdatedStrategy | NewStrategy =>
|
): strategy is UpdatedStrategy | NewStrategy =>
|
||||||
@ -92,20 +90,3 @@ export const sortStrategiesByFeature = <
|
|||||||
return strategies;
|
return strategies;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const sortAndFlattenStrategies = <
|
|
||||||
T extends { id: string; featureName?: string },
|
|
||||||
U extends {
|
|
||||||
id?: string;
|
|
||||||
featureName: string;
|
|
||||||
changeRequest: { id: number };
|
|
||||||
},
|
|
||||||
>(
|
|
||||||
strategies: T[],
|
|
||||||
changeRequestStrategies: U[],
|
|
||||||
): (T | U)[] => {
|
|
||||||
const sorted = sortStrategiesByFeature(strategies, changeRequestStrategies);
|
|
||||||
|
|
||||||
// flatten list of
|
|
||||||
return Object.values(sorted).flat();
|
|
||||||
};
|
|
||||||
|
Loading…
Reference in New Issue
Block a user