diff --git a/frontend/src/component/feature/FeatureStrategy/featureStrategy.utils.ts b/frontend/src/component/feature/FeatureStrategy/featureStrategy.utils.ts index 2ef39aae51..344f0d37fb 100644 --- a/frontend/src/component/feature/FeatureStrategy/featureStrategy.utils.ts +++ b/frontend/src/component/feature/FeatureStrategy/featureStrategy.utils.ts @@ -6,5 +6,5 @@ export const comparisonModerator = ( ): DeepOmit => { const tempData = { ...data }; - return deepOmit(tempData, 'lastSeenAt'); + return deepOmit(tempData, 'lastSeenAt', 'yes', 'no'); }; diff --git a/frontend/src/utils/deepOmit.test.ts b/frontend/src/utils/deepOmit.test.ts index 7dfceb8e1c..4ea04ce909 100644 --- a/frontend/src/utils/deepOmit.test.ts +++ b/frontend/src/utils/deepOmit.test.ts @@ -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: {}, + }, + }, + }, + }); +}); diff --git a/frontend/src/utils/deepOmit.ts b/frontend/src/utils/deepOmit.ts index 5c8bc74881..2519e19413 100644 --- a/frontend/src/utils/deepOmit.ts +++ b/frontend/src/utils/deepOmit.ts @@ -4,17 +4,22 @@ export type DeepOmit = T extends Record export function deepOmit( obj: T, - keyToOmit: K, + ...keysToOmit: K[] ): DeepOmit { + const omitSet = new Set(keysToOmit); + if (Array.isArray(obj)) { return obj.map((item) => - deepOmit(item, keyToOmit), + deepOmit(item, ...keysToOmit), ) as unknown as DeepOmit; } else if (typeof obj === 'object' && obj !== null) { const result: Partial> = {}; for (const [key, value] of Object.entries(obj)) { - if (key !== keyToOmit) { - result[key as Exclude] = deepOmit(value, keyToOmit); + if (!omitSet.has(key as K)) { + result[key as Exclude] = deepOmit( + value, + ...keysToOmit, + ); } } return result as DeepOmit;