Skip to content

Commit 9686335

Browse files
authored
[Background search] Restore unsaved dashboards (#240067)
## Summary Closes #227311 Right now if we create a background search of an unsaved dashboard it doesn't store the panels/references in the saved object, that menas that we can't really restore it. With this we store them even if the dashboard isn't saved but I don't have any context on why it wasn't done like this before so happy to get input on it. --- #### Background an unsaved dashboard and just open it again Before https://github.com/user-attachments/assets/fd282c28-53ea-49dc-b58b-1441e25dfbb1 After https://github.com/user-attachments/assets/d39fbef0-d9b2-4763-bd10-1db98b4fc667 --- #### Background an unsaved dashboard, remove it and open it again Before https://github.com/user-attachments/assets/9c1ba24d-a55f-4176-a409-5070d282110d After https://github.com/user-attachments/assets/7d0a4e3e-e213-40f4-9c41-50783a08b2df --- ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [x] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels.
1 parent 736ad8e commit 9686335

File tree

3 files changed

+129
-6
lines changed

3 files changed

+129
-6
lines changed

src/platform/plugins/shared/dashboard/public/dashboard_app/url/search_sessions_integration.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,11 @@ function getLocatorParams({
7878
shouldRestoreSearchSession: boolean;
7979
}): DashboardLocatorParams {
8080
const savedObjectId = dashboardApi.savedObjectId$.value;
81-
const panels = savedObjectId
82-
? (dashboardInternalApi.serializeLayout() as Pick<
83-
DashboardLocatorParams,
84-
'panels' | 'references'
85-
>)
86-
: undefined;
81+
82+
const panels = dashboardInternalApi.serializeLayout() as Pick<
83+
DashboardLocatorParams,
84+
'panels' | 'references'
85+
>;
8786

8887
const { controlGroupInput, controlGroupReferences } = dashboardInternalApi.serializeControls();
8988

x-pack/platform/test/search_sessions_integration/tests/apps/dashboard/async_search/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ export default function ({ loadTestFile, getService, getPageObjects }: FtrProvid
3838
loadTestFile(require.resolve('./save_search_session'));
3939
loadTestFile(require.resolve('./save_search_session_relative_time'));
4040
loadTestFile(require.resolve('./sessions_in_space'));
41+
loadTestFile(require.resolve('./unsaved_dashboard'));
4142
});
4243
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import expect from '@kbn/expect';
9+
import type { FtrProviderContext } from '../../../../ftr_provider_context';
10+
11+
export default function ({ getService, getPageObjects }: FtrProviderContext) {
12+
const testSubjects = getService('testSubjects');
13+
const log = getService('log');
14+
const searchSessions = getService('searchSessions');
15+
const kibanaServer = getService('kibanaServer');
16+
const retry = getService('retry');
17+
const monacoEditor = getService('monacoEditor');
18+
19+
const { common, home, timePicker, header, discover, dashboard, searchSessionsManagement } =
20+
getPageObjects([
21+
'common',
22+
'timePicker',
23+
'header',
24+
'home',
25+
'discover',
26+
'dashboard',
27+
'dashboardControls',
28+
'searchSessionsManagement',
29+
]);
30+
31+
async function addFromLibrary() {
32+
await testSubjects.click('dashboardAddTopNavButton');
33+
await testSubjects.click('dashboardAddFromLibraryButton');
34+
await testSubjects.setValue('savedObjectFinderSearchInput', 'Unsaved dashboard slow query');
35+
await testSubjects.click('savedObjectTitleUnsaved-dashboard-slow-query');
36+
}
37+
38+
async function openBackgroundSearchWhenReady() {
39+
await retry.waitFor('the background search to be completed', async () => {
40+
const _list = await searchSessionsManagement.getList();
41+
return _list[0].status === 'complete';
42+
});
43+
44+
const list = await searchSessionsManagement.getList();
45+
await list[0].view();
46+
}
47+
48+
describe('saves a search session for unsaved dashboard', () => {
49+
describe('with a discover session', () => {
50+
// Add the sample dataset
51+
before(async () => {
52+
await kibanaServer.uiSettings.replace({
53+
enableESQL: true,
54+
});
55+
56+
await common.navigateToUrl('home', '/tutorial_directory/sampleData', {
57+
useActualUrl: true,
58+
});
59+
await retry.try(async () => {
60+
await home.addSampleDataSet('flights');
61+
const isInstalled = await home.isSampleDataSetInstalled('flights');
62+
expect(isInstalled).to.be(true);
63+
});
64+
log.debug('Sample data installed');
65+
});
66+
67+
// Save a slow query to a discover session
68+
before(async () => {
69+
await common.navigateToApp('discover');
70+
await header.waitUntilLoadingHasFinished();
71+
72+
await timePicker.setCommonlyUsedTime('This_week');
73+
await discover.selectTextBaseLang();
74+
await monacoEditor.setCodeEditorValue(
75+
'FROM kibana_sample_data_flights | LIMIT 1 | WHERE DELAY(1500ms)'
76+
);
77+
await testSubjects.clickWhenNotDisabledWithoutRetry('querySubmitButton');
78+
await discover.waitUntilSearchingHasFinished();
79+
await discover.saveSearch('Unsaved dashboard slow query');
80+
});
81+
82+
afterEach(async () => {
83+
await common.navigateToApp('dashboard');
84+
await testSubjects.click('discard-unsaved-New-Dashboard');
85+
await testSubjects.click('confirmModalConfirmButton');
86+
});
87+
88+
it('should be restored when opening from the background search', async () => {
89+
await common.navigateToApp('dashboard');
90+
await dashboard.clickCreateDashboardPrompt();
91+
92+
await addFromLibrary();
93+
await searchSessions.save({ isSubmitButton: true });
94+
await dashboard.waitForRenderComplete();
95+
96+
await searchSessions.openFlyoutFromToast();
97+
await openBackgroundSearchWhenReady();
98+
99+
await dashboard.verifyNoRenderErrors();
100+
});
101+
102+
describe('when the dashboard is also discarded', async () => {
103+
it('should still restore the session', async () => {
104+
await common.navigateToApp('dashboard');
105+
await dashboard.clickCreateDashboardPrompt();
106+
107+
await addFromLibrary();
108+
await searchSessions.save({ isSubmitButton: true });
109+
await dashboard.waitForRenderComplete();
110+
111+
await common.navigateToApp('dashboard');
112+
await testSubjects.click('discard-unsaved-New-Dashboard');
113+
await testSubjects.click('confirmModalConfirmButton');
114+
115+
await searchSessionsManagement.goTo();
116+
await openBackgroundSearchWhenReady();
117+
118+
await dashboard.verifyNoRenderErrors();
119+
});
120+
});
121+
});
122+
});
123+
}

0 commit comments

Comments
 (0)