mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-28 00:06:53 +01:00
fix: omit yes no from stale data comparison (#7052)
This commit is contained in:
parent
5b8c63f748
commit
668cb81384
@ -6,5 +6,5 @@ export const comparisonModerator = (
|
||||
): DeepOmit<IFeatureToggle, keyof IFeatureToggle> => {
|
||||
const tempData = { ...data };
|
||||
|
||||
return deepOmit(tempData, 'lastSeenAt');
|
||||
return deepOmit(tempData, 'lastSeenAt', 'yes', 'no');
|
||||
};
|
||||
|
@ -47,3 +47,33 @@ test('should omit all instances of a given field', () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test('should omit all instances of multiple fields', () => {
|
||||
const input = {
|
||||
name: 'some-name',
|
||||
color: 'blue',
|
||||
children: {
|
||||
name: 'some-name',
|
||||
color: 'blue',
|
||||
children: {
|
||||
name: 'some-name',
|
||||
color: 'blue',
|
||||
children: {
|
||||
name: 'some-name',
|
||||
color: 'blue',
|
||||
children: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
expect(deepOmit(input, 'name', 'color')).toEqual({
|
||||
children: {
|
||||
children: {
|
||||
children: {
|
||||
children: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
@ -4,17 +4,22 @@ export type DeepOmit<T, K extends keyof any> = T extends Record<string, any>
|
||||
|
||||
export function deepOmit<T, K extends keyof any>(
|
||||
obj: T,
|
||||
keyToOmit: K,
|
||||
...keysToOmit: K[]
|
||||
): DeepOmit<T, K> {
|
||||
const omitSet = new Set(keysToOmit);
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map((item) =>
|
||||
deepOmit(item, keyToOmit),
|
||||
deepOmit(item, ...keysToOmit),
|
||||
) as unknown as DeepOmit<T, K>;
|
||||
} else if (typeof obj === 'object' && obj !== null) {
|
||||
const result: Partial<DeepOmit<T, K>> = {};
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
if (key !== keyToOmit) {
|
||||
result[key as Exclude<keyof T, K>] = deepOmit(value, keyToOmit);
|
||||
if (!omitSet.has(key as K)) {
|
||||
result[key as Exclude<keyof T, K>] = deepOmit(
|
||||
value,
|
||||
...keysToOmit,
|
||||
);
|
||||
}
|
||||
}
|
||||
return result as DeepOmit<T, K>;
|
||||
|
Loading…
Reference in New Issue
Block a user