Skip to content

Commit d7fbf9b

Browse files
[9.2] [Background search] Restore unsaved dashboards (#240067) (#241419)
# Backport This will backport the following commits from `main` to `9.2`: - [[Background search] Restore unsaved dashboards (#240067)](#240067) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Alejandro García Parrondo","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-10-31T09:35:46Z","message":"[Background search] Restore unsaved dashboards (#240067)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/227311\n\nRight now if we create a background search of an unsaved dashboard it\ndoesn't store the panels/references in the saved object, that menas that\nwe can't really restore it. With this we store them even if the\ndashboard isn't saved but I don't have any context on why it wasn't done\nlike this before so happy to get input on it.\n\n---\n\n#### Background an unsaved dashboard and just open it again\n\nBefore\n\n\nhttps://github.com/user-attachments/assets/fd282c28-53ea-49dc-b58b-1441e25dfbb1\n\nAfter\n\n\nhttps://github.com/user-attachments/assets/d39fbef0-d9b2-4763-bd10-1db98b4fc667\n\n---\n\n#### Background an unsaved dashboard, remove it and open it again\n\nBefore\n\n\nhttps://github.com/user-attachments/assets/9c1ba24d-a55f-4176-a409-5070d282110d\n\n\nAfter\n\n\nhttps://github.com/user-attachments/assets/7d0a4e3e-e213-40f4-9c41-50783a08b2df\n\n---\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [x] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n- [x] Review the [backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand apply applicable `backport:*` labels.","sha":"968633561559bfb774bd6e38ffd4c56c859317b8","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Project:AsyncSearch","Team:DataDiscovery","Feature:Search Sessions","backport:version","v9.3.0","v9.2.1"],"title":"[Background search] Restore unsaved dashboards","number":240067,"url":"https://github.com/elastic/kibana/pull/240067","mergeCommit":{"message":"[Background search] Restore unsaved dashboards (#240067)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/227311\n\nRight now if we create a background search of an unsaved dashboard it\ndoesn't store the panels/references in the saved object, that menas that\nwe can't really restore it. With this we store them even if the\ndashboard isn't saved but I don't have any context on why it wasn't done\nlike this before so happy to get input on it.\n\n---\n\n#### Background an unsaved dashboard and just open it again\n\nBefore\n\n\nhttps://github.com/user-attachments/assets/fd282c28-53ea-49dc-b58b-1441e25dfbb1\n\nAfter\n\n\nhttps://github.com/user-attachments/assets/d39fbef0-d9b2-4763-bd10-1db98b4fc667\n\n---\n\n#### Background an unsaved dashboard, remove it and open it again\n\nBefore\n\n\nhttps://github.com/user-attachments/assets/9c1ba24d-a55f-4176-a409-5070d282110d\n\n\nAfter\n\n\nhttps://github.com/user-attachments/assets/7d0a4e3e-e213-40f4-9c41-50783a08b2df\n\n---\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [x] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n- [x] Review the [backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand apply applicable `backport:*` labels.","sha":"968633561559bfb774bd6e38ffd4c56c859317b8"}},"sourceBranch":"main","suggestedTargetBranches":["9.2"],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/240067","number":240067,"mergeCommit":{"message":"[Background search] Restore unsaved dashboards (#240067)\n\n## Summary\n\nCloses https://github.com/elastic/kibana/issues/227311\n\nRight now if we create a background search of an unsaved dashboard it\ndoesn't store the panels/references in the saved object, that menas that\nwe can't really restore it. With this we store them even if the\ndashboard isn't saved but I don't have any context on why it wasn't done\nlike this before so happy to get input on it.\n\n---\n\n#### Background an unsaved dashboard and just open it again\n\nBefore\n\n\nhttps://github.com/user-attachments/assets/fd282c28-53ea-49dc-b58b-1441e25dfbb1\n\nAfter\n\n\nhttps://github.com/user-attachments/assets/d39fbef0-d9b2-4763-bd10-1db98b4fc667\n\n---\n\n#### Background an unsaved dashboard, remove it and open it again\n\nBefore\n\n\nhttps://github.com/user-attachments/assets/9c1ba24d-a55f-4176-a409-5070d282110d\n\n\nAfter\n\n\nhttps://github.com/user-attachments/assets/7d0a4e3e-e213-40f4-9c41-50783a08b2df\n\n---\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [x] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n- [x] Review the [backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand apply applicable `backport:*` labels.","sha":"968633561559bfb774bd6e38ffd4c56c859317b8"}},{"branch":"9.2","label":"v9.2.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Alejandro García Parrondo <[email protected]>
1 parent 1c9eb06 commit d7fbf9b

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)