Skip to content

Commit

Permalink
Add graph to saved object relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecote committed Dec 14, 2018
1 parent de44006 commit b0b9333
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions x-pack/plugins/graph/public/services/saved_workspace.js
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { clone, assign } from 'lodash';
import { uiModules } from 'ui/modules';
import { SavedObjectProvider } from 'ui/courier';

Expand All @@ -20,6 +21,8 @@ export function SavedWorkspaceProvider(Private) {
type: SavedWorkspace.type,
mapping: SavedWorkspace.mapping,
searchSource: SavedWorkspace.searchsource,
extractReferences: SavedWorkspace.extractReferences,
injectReferences: SavedWorkspace.injectReferences,

// if this is null/undefined then the SavedObject will be assigned the defaults
id: id,
Expand Down Expand Up @@ -57,6 +60,27 @@ export function SavedWorkspaceProvider(Private) {
};

SavedWorkspace.searchsource = false;

SavedWorkspace.extractReferences = (source) => {
const references = clone(source.references) || {};
// For some reason, wsState comes in stringified 2x
const state = JSON.parse(JSON.parse(source.wsState));
references.indexPattern = state.indexPattern;
state.indexPatternReference = 'indexPattern';
delete state.indexPattern;
return assign({}, source, {
references,
wsState: JSON.stringify(JSON.stringify(state))
});
};

SavedWorkspace.injectReferences = function (references) {
const state = JSON.parse(this.wsState);
state.indexPattern = references[state.indexPatternReference];
delete state.indexPatternReference;
this.wsState = JSON.stringify(state);
};

return SavedWorkspace;
}

Expand Down

0 comments on commit b0b9333

Please sign in to comment.