Skip to content

Commit

Permalink
refactor: update to cloneDeep
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Wang <wonglam@amazon.com>
  • Loading branch information
wanglam committed Sep 12, 2023
1 parent f4b0873 commit 1cd52d1
Showing 1 changed file with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import { SavedObject } from 'opensearch-dashboards/server';
import { cloneDeep } from 'lodash';

const generateIdWithPrefix = (id: string, prefix?: string) => {
return [...(prefix ? [prefix] : []), id].join('_');
Expand All @@ -13,9 +14,6 @@ export const appendDataSourceId = (id: string) => {
return (dataSourceId?: string) => generateIdWithPrefix(id, dataSourceId);
};

const cloneSavedObjectsList = (savedObjectList: SavedObject[]) =>
JSON.parse(JSON.stringify(savedObjectList));

const overrideSavedObjectId = (savedObject: SavedObject, idGenerator: (id: string) => string) => {
savedObject.id = idGenerator(savedObject.id);
// update reference
Expand Down Expand Up @@ -62,7 +60,7 @@ export const getDataSourceIntegratedSavedObjects = (
dataSourceId?: string,
dataSourceTitle?: string
): SavedObject[] => {
savedObjectList = cloneSavedObjectsList(savedObjectList);
savedObjectList = cloneDeep(savedObjectList);
if (dataSourceId) {
const idGeneratorWithDataSource = (id: string) => generateIdWithPrefix(id, dataSourceId);
return savedObjectList.map((savedObject) => {
Expand Down Expand Up @@ -107,7 +105,7 @@ export const getWorkspaceIntegratedSavedObjects = (
savedObjectList: SavedObject[],
workspaceId?: string
) => {
savedObjectList = cloneSavedObjectsList(savedObjectList);
savedObjectList = cloneDeep(savedObjectList);
const generateWithWorkspaceId = (id: string) => appendWorkspaceId(id)(workspaceId);

savedObjectList.forEach((savedObject) => {
Expand Down

0 comments on commit 1cd52d1

Please sign in to comment.