diff --git a/src/plugins/visualize/public/application/utils/use/use_saved_vis_instance.ts b/src/plugins/visualize/public/application/utils/use/use_saved_vis_instance.ts index 6e5b3a012aabd..3b431286d2569 100644 --- a/src/plugins/visualize/public/application/utils/use/use_saved_vis_instance.ts +++ b/src/plugins/visualize/public/application/utils/use/use_saved_vis_instance.ts @@ -101,7 +101,8 @@ export const useSavedVisInstance = ( ? stateTransferService.getAppNameFromId(originatingApp) : undefined; const redirectToOrigin = originatingApp ? () => navigateToApp(originatingApp) : undefined; - const byValueCreateMode = dashboard.dashboardFeatureFlagConfig.allowByValueEmbeddables; + const byValueCreateMode = + Boolean(originatingApp) && dashboard.dashboardFeatureFlagConfig.allowByValueEmbeddables; if (savedVis.id) { chrome.setBreadcrumbs( diff --git a/x-pack/test/functional/page_objects/lens_page.ts b/x-pack/test/functional/page_objects/lens_page.ts index 13ff6a64f8936..dc19de47bbb41 100644 --- a/x-pack/test/functional/page_objects/lens_page.ts +++ b/x-pack/test/functional/page_objects/lens_page.ts @@ -270,7 +270,13 @@ export function LensPageProvider({ getService, getPageObjects }: FtrProviderCont /** * Save the current Lens visualization. */ - async save(title: string, saveAsNew?: boolean, redirectToOrigin?: boolean) { + async save( + title: string, + saveAsNew?: boolean, + redirectToOrigin?: boolean, + addToDashboard?: boolean, + dashboardId?: boolean + ) { await PageObjects.header.waitUntilLoadingHasFinished(); await testSubjects.click('lnsApp_saveButton'); await testSubjects.setValue('savedObjectTitle', title); @@ -287,6 +293,22 @@ export function LensPageProvider({ getService, getPageObjects }: FtrProviderCont await testSubjects.setEuiSwitch('returnToOriginModeSwitch', state); } + const dashboardSelectorExists = await testSubjects.exists('add-to-dashboard-options'); + if (dashboardSelectorExists) { + const dashboardSelector = await testSubjects.find('add-to-dashboard-options'); + let optionSelector = 'add-to-library-option'; + if (addToDashboard) { + optionSelector = dashboardId ? 'existing-dashboard-option' : 'new-dashboard-option'; + } + log.debug('dashboard selector exists, choosing option:', optionSelector); + const label = await dashboardSelector.findByCssSelector(`label[for="${optionSelector}"]`); + await label.click(); + + if (dashboardId) { + // TODO - selecting an existing dashboard + } + } + await testSubjects.click('confirmSaveSavedObjectButton'); await retry.waitForWithTimeout('Save modal to disappear', 1000, () => testSubjects diff --git a/x-pack/test/saved_object_tagging/functional/tests/visualize_integration.ts b/x-pack/test/saved_object_tagging/functional/tests/visualize_integration.ts index 834c3083071df..3353078ae0ffa 100644 --- a/x-pack/test/saved_object_tagging/functional/tests/visualize_integration.ts +++ b/x-pack/test/saved_object_tagging/functional/tests/visualize_integration.ts @@ -95,6 +95,13 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { await PageObjects.visualize.ensureSavePanelOpen(); await testSubjects.setValue('savedObjectTitle', 'My new markdown viz'); + + const dashboardSelector = await testSubjects.find('add-to-dashboard-options'); + const label = await dashboardSelector.findByCssSelector( + `label[for="add-to-library-option"]` + ); + await label.click(); + await selectSavedObjectTags('tag-1'); await testSubjects.click('confirmSaveSavedObjectButton'); @@ -120,6 +127,12 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { await PageObjects.visualize.ensureSavePanelOpen(); await testSubjects.setValue('savedObjectTitle', 'vis-with-new-tag'); + const dashboardSelector = await testSubjects.find('add-to-dashboard-options'); + const label = await dashboardSelector.findByCssSelector( + `label[for="add-to-library-option"]` + ); + await label.click(); + await testSubjects.click('savedObjectTagSelector'); await testSubjects.click(`tagSelectorOption-action__create`);