Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Dec 9, 2020
1 parent 55667df commit 74989ee
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions x-pack/plugins/graph/public/services/persistence/deserialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand All @@ -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;
Expand Down

0 comments on commit 74989ee

Please sign in to comment.