1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01: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:
andreas-unleash 2023-08-10 16:13:24 +03:00 committed by GitHub
parent c1314a8ee8
commit 46314d2772
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 77 additions and 3 deletions

View File

@ -1,8 +1,10 @@
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 };
delete tempData.lastSeenAt;
return tempData;
return deepOmit(tempData, 'lastSeenAt');
};

View 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: {},
},
},
},
});
});

View 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>;
}