From 74989eec5db8113cc2c504c7af193ea34b4064c1 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Wed, 9 Dec 2020 14:33:43 +0100 Subject: [PATCH] code review --- .../graph/public/services/persistence/deserialize.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/graph/public/services/persistence/deserialize.ts b/x-pack/plugins/graph/public/services/persistence/deserialize.ts index 063348691f817..a25e4b7e5e3dc 100644 --- a/x-pack/plugins/graph/public/services/persistence/deserialize.ts +++ b/x-pack/plugins/graph/public/services/persistence/deserialize.ts @@ -61,7 +61,13 @@ function deserializeUrlTemplate({ return template; } -// returns the id of the index pattern, lookup is done in app.js +/** + * Migrates `savedWorkspace` to use the id instead of the title of the referenced index pattern. + * Returns a status indicating successful migration or failure to look up the index pattern by title. + * If the workspace is migrated already, a success status is returned as well. + * @param savedWorkspace The workspace saved object to migrate. The migration will happen in-place and mutate the passed in object + * @param indexPatterns All index patterns existing in the current space + */ export function migrateLegacyIndexPatternRef( savedWorkspace: GraphWorkspaceSavedObject, indexPatterns: IndexPatternSavedObject[] @@ -70,13 +76,13 @@ export function migrateLegacyIndexPatternRef( if (!legacyIndexPatternRef) { return { success: true }; } - const serializedWorkspaceState: SerializedWorkspaceState = JSON.parse(savedWorkspace.wsState); const indexPatternId = indexPatterns.find( (pattern) => pattern.attributes.title === legacyIndexPatternRef )?.id; if (!indexPatternId) { return { success: false, missingIndexPattern: legacyIndexPatternRef }; } + const serializedWorkspaceState: SerializedWorkspaceState = JSON.parse(savedWorkspace.wsState); serializedWorkspaceState.indexPattern = indexPatternId!; savedWorkspace.wsState = JSON.stringify(serializedWorkspaceState); delete savedWorkspace.legacyIndexPatternRef;