mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-24 01:18:01 +02:00
fix: Remove lastSeenAt from useCollaborateData.tsx staleness check (#4461)
Remove the lastSeenAt property when checking for stale data --------- Signed-off-by: andreas-unleash <andreas@getunleash.ai>
This commit is contained in:
parent
c1314a8ee8
commit
46314d2772
@ -1,8 +1,10 @@
|
|||||||
import { IFeatureToggle } from 'interfaces/featureToggle';
|
import { IFeatureToggle } from 'interfaces/featureToggle';
|
||||||
|
import { deepOmit, DeepOmit } from '../../../utils/deepOmit';
|
||||||
|
|
||||||
export const comparisonModerator = (data: IFeatureToggle) => {
|
export const comparisonModerator = (
|
||||||
|
data: IFeatureToggle
|
||||||
|
): DeepOmit<IFeatureToggle, keyof IFeatureToggle> => {
|
||||||
const tempData = { ...data };
|
const tempData = { ...data };
|
||||||
delete tempData.lastSeenAt;
|
|
||||||
|
|
||||||
return tempData;
|
return deepOmit(tempData, 'lastSeenAt');
|
||||||
};
|
};
|
||||||
|
49
frontend/src/utils/deepOmit.test.ts
Normal file
49
frontend/src/utils/deepOmit.test.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import { deepOmit } from './deepOmit';
|
||||||
|
|
||||||
|
test('should omit all instances of a given field', () => {
|
||||||
|
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')).toEqual({
|
||||||
|
color: 'blue',
|
||||||
|
children: {
|
||||||
|
color: 'blue',
|
||||||
|
children: {
|
||||||
|
color: 'blue',
|
||||||
|
children: {
|
||||||
|
color: 'blue',
|
||||||
|
children: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(deepOmit(input, 'color')).toEqual({
|
||||||
|
name: 'some-name',
|
||||||
|
children: {
|
||||||
|
name: 'some-name',
|
||||||
|
children: {
|
||||||
|
name: 'some-name',
|
||||||
|
children: {
|
||||||
|
name: 'some-name',
|
||||||
|
children: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
23
frontend/src/utils/deepOmit.ts
Normal file
23
frontend/src/utils/deepOmit.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
export type DeepOmit<T, K extends keyof any> = T extends Record<string, any>
|
||||||
|
? { [P in Exclude<keyof T, K>]: DeepOmit<T[P], K> }
|
||||||
|
: T;
|
||||||
|
|
||||||
|
export function deepOmit<T, K extends keyof any>(
|
||||||
|
obj: T,
|
||||||
|
keyToOmit: K
|
||||||
|
): DeepOmit<T, K> {
|
||||||
|
if (Array.isArray(obj)) {
|
||||||
|
return obj.map(item =>
|
||||||
|
deepOmit(item, keyToOmit)
|
||||||
|
) 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result as DeepOmit<T, K>;
|
||||||
|
}
|
||||||
|
return obj as DeepOmit<T, K>;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user