FlatObjectMetadataMaps and non FP style refactor (#13590)
# Introduction - Retrieveing flat-object-metadata-maps for input transpilation, we decided not to introduce map merge for remaining validation operation for the moment - Refactored the field metadata service v2 to sequentially optimistically render on each iteration
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { StringPropertyKeys } from '@/utils/trim-and-remove-duplicated-whitespaces-from-object-string-properties';
|
||||
import { isDefined } from '@/utils/validation';
|
||||
|
||||
export const fromArrayToValuesByKeyRecord = <T extends object>({
|
||||
array,
|
||||
key,
|
||||
}: {
|
||||
array: T[];
|
||||
key: StringPropertyKeys<T>;
|
||||
}) => {
|
||||
return array.reduce<Record<string, T[]>>((acc, value) => {
|
||||
const computedKey = value[key] as string;
|
||||
const occurrence = acc[computedKey];
|
||||
|
||||
if (isDefined(occurrence)) {
|
||||
return {
|
||||
...acc,
|
||||
[computedKey]: [...occurrence, value],
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
...acc,
|
||||
[computedKey]: [value],
|
||||
};
|
||||
}, {});
|
||||
};
|
||||
Reference in New Issue
Block a user