Skip to content

Commit

Permalink
refactor the generate id logic
Browse files Browse the repository at this point in the history
Signed-off-by: yujin-emma <yujin.emma.work@gmail.com>
  • Loading branch information
yujin-emma committed Feb 6, 2024
1 parent 54d2ebb commit 8b1a3f4
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/core/server/saved_objects/import/regenerate_ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,13 @@ import { SavedObject } from '../types';
* @param objects The saved objects to generate new IDs for.
*/
export const regenerateIds = (objects: SavedObject[], dataSourceId: string | undefined) => {
const importIdMap = objects
.filter((object) => object.type !== 'data-source')
.reduce((acc, object) => {
if (dataSourceId) {
return acc.set(`${object.type}:${object.id}`, {
id: `${dataSourceId}_${uuidv4()}`,
const importIdMap = objects.reduce((acc, object) => {
return object.type === 'data-source'
? acc
: acc.set(`${object.type}:${object.id}`, {
id: dataSourceId ? `${dataSourceId}_${uuidv4()}` : uuidv4(),
omitOriginId: true,
});
}
return acc.set(`${object.type}:${object.id}`, { id: uuidv4(), omitOriginId: true });
}, new Map<string, { id: string; omitOriginId?: boolean }>());
}, new Map<string, { id: string; omitOriginId?: boolean }>());
return importIdMap;
};

0 comments on commit 8b1a3f4

Please sign in to comment.