Skip to content

Commit

Permalink
[Discover] Fix issue where workspace switches to uninitialized briefl…
Browse files Browse the repository at this point in the history
…y when saving as copy in Graph
  • Loading branch information
davismcphee committed Sep 21, 2022
1 parent 0061025 commit e6cc955
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ export const WorkspaceLayoutComponent = ({
const search = useLocation().search;
const urlQuery = new URLSearchParams(search).get('query');

const isInitialized = Boolean(workspaceInitialized || savedWorkspace.id);
// savedWorkspace.id gets set to null while saving a copy of an existing
// workspace, so we need to check for savedWorkspace.isSaving as well
const isInitialized = Boolean(
workspaceInitialized || savedWorkspace.id || savedWorkspace.isSaving
);

const selectSelected = useCallback((node: WorkspaceNode) => {
selectedNode.current = node;
Expand Down
28 changes: 15 additions & 13 deletions x-pack/plugins/graph/public/helpers/saved_workspace_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,6 @@ export async function saveSavedWorkspace(
overlays: OverlayStart;
}
) {
// Save the original id in case the save fails.
const originalId = savedObject.id;
// Read https://github.com/elastic/kibana/issues/9056 and
// https://github.com/elastic/kibana/issues/9012 for some background into why this copyOnSave variable
// exists.
// The goal is to move towards a better rename flow, but since our users have been conditioned
// to expect a 'save as' flow during a rename, we are keeping the logic the same until a better
// UI/UX can be worked out.
if (savedObject.copyOnSave) {
delete savedObject.id;
}

let attributes: SavedObjectAttributes = {};

forOwn(mapping, (fieldType, fieldName) => {
Expand All @@ -191,14 +179,28 @@ export async function saveSavedWorkspace(
throw new Error('References not returned from extractReferences');
}

// Save the original id in case the save fails.
const originalId = savedObject.id;

try {
// Read https://github.com/elastic/kibana/issues/9056 and
// https://github.com/elastic/kibana/issues/9012 for some background into why this copyOnSave variable
// exists.
// The goal is to move towards a better rename flow, but since our users have been conditioned
// to expect a 'save as' flow during a rename, we are keeping the logic the same until a better
// UI/UX can be worked out.
if (savedObject.copyOnSave) {
delete savedObject.id;
}

savedObject.isSaving = true;

await checkForDuplicateTitle(
savedObject as any,
isTitleDuplicateConfirmed,
onTitleDuplicate,
services
);
savedObject.isSaving = true;

const createOpt = {
id: savedObject.id,
Expand Down

0 comments on commit e6cc955

Please sign in to comment.