Skip to content

Commit 238c2e7

Browse files
[8.19] [Discover][Query Bar] Enable "Save Query" button after making changes in the save query menu (#229053) (#229909)
# Backport This will backport the following commits from `main` to `8.19`: - [[Discover][Query Bar] Enable "Save Query" button after making changes in the save query menu (#229053)](#229053) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Miłosz Radzyński","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-07-30T07:16:45Z","message":"[Discover][Query Bar] Enable \"Save Query\" button after making changes in the save query menu (#229053)\n\n## Summary\n\nThis PR fixes an issue where the `Save Query` button was disabled after\nmaking changes (e.g., adding filters) in the query menu. Currently, a\nuser is unable to click `Save Query` if they previously saved the query\nwith the `Include filters` field unchecked and then added new filters.\n\nThe problem occurred because we compare the filter state in the\nuseEffect hook. However, if the user saved the query without the\n`Include filters` option, the in-memory object lacked the\n`attributes.filters` property entirely. This prevented the comparison\nfrom executing correctly and resulted in the logical test always\nreturning `false`.\n\nTo fix the issue, I removed the `savedQuery?.attributes.filters &&`\ncondition, and provided `[]` as a fallback value for\n`savedQuery?.attributes.filters` if the filters were not defined.\n\nResolves: #210948\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] Any text added follows [EUI's writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\nsentence case text and includes [i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n- [ ]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials\n- [x] [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- [ ] If a plugin configuration key changed, check if it needs to be\nallowlisted in the cloud and added to the [docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n- [ ] This was checked for breaking HTTP API changes, and any breaking\nchanges have been approved by the breaking-change committee. The\n`release_note:breaking` label should be applied in these situations.\n- [x] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed\n- [ ] 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.\n\n### Identify risks\n\nDoes this PR introduce any risks? For example, consider risks like hard\nto test bugs, performance regression, potential of data loss.\n\nDescribe the risk, its severity, and mitigation for each identified\nrisk. Invite stakeholders and evaluate how to proceed before merging.\n\n- [ ] [See some risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n- [ ] ...","sha":"43c1ea7e41bcd8a54af55c14a41287f6ca2911aa","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:DataDiscovery","backport:version","v8.19.0","v9.2.0","v9.0.5","v9.1.1","v8.18.5"],"title":"[Discover][Query Bar] Enable \"Save Query\" button after making changes in the save query menu","number":229053,"url":"https://github.com/elastic/kibana/pull/229053","mergeCommit":{"message":"[Discover][Query Bar] Enable \"Save Query\" button after making changes in the save query menu (#229053)\n\n## Summary\n\nThis PR fixes an issue where the `Save Query` button was disabled after\nmaking changes (e.g., adding filters) in the query menu. Currently, a\nuser is unable to click `Save Query` if they previously saved the query\nwith the `Include filters` field unchecked and then added new filters.\n\nThe problem occurred because we compare the filter state in the\nuseEffect hook. However, if the user saved the query without the\n`Include filters` option, the in-memory object lacked the\n`attributes.filters` property entirely. This prevented the comparison\nfrom executing correctly and resulted in the logical test always\nreturning `false`.\n\nTo fix the issue, I removed the `savedQuery?.attributes.filters &&`\ncondition, and provided `[]` as a fallback value for\n`savedQuery?.attributes.filters` if the filters were not defined.\n\nResolves: #210948\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] Any text added follows [EUI's writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\nsentence case text and includes [i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n- [ ]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials\n- [x] [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- [ ] If a plugin configuration key changed, check if it needs to be\nallowlisted in the cloud and added to the [docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n- [ ] This was checked for breaking HTTP API changes, and any breaking\nchanges have been approved by the breaking-change committee. The\n`release_note:breaking` label should be applied in these situations.\n- [x] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed\n- [ ] 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.\n\n### Identify risks\n\nDoes this PR introduce any risks? For example, consider risks like hard\nto test bugs, performance regression, potential of data loss.\n\nDescribe the risk, its severity, and mitigation for each identified\nrisk. Invite stakeholders and evaluate how to proceed before merging.\n\n- [ ] [See some risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n- [ ] ...","sha":"43c1ea7e41bcd8a54af55c14a41287f6ca2911aa"}},"sourceBranch":"main","suggestedTargetBranches":["8.19","9.0","9.1","8.18"],"targetPullRequestStates":[{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/229053","number":229053,"mergeCommit":{"message":"[Discover][Query Bar] Enable \"Save Query\" button after making changes in the save query menu (#229053)\n\n## Summary\n\nThis PR fixes an issue where the `Save Query` button was disabled after\nmaking changes (e.g., adding filters) in the query menu. Currently, a\nuser is unable to click `Save Query` if they previously saved the query\nwith the `Include filters` field unchecked and then added new filters.\n\nThe problem occurred because we compare the filter state in the\nuseEffect hook. However, if the user saved the query without the\n`Include filters` option, the in-memory object lacked the\n`attributes.filters` property entirely. This prevented the comparison\nfrom executing correctly and resulted in the logical test always\nreturning `false`.\n\nTo fix the issue, I removed the `savedQuery?.attributes.filters &&`\ncondition, and provided `[]` as a fallback value for\n`savedQuery?.attributes.filters` if the filters were not defined.\n\nResolves: #210948\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] Any text added follows [EUI's writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\nsentence case text and includes [i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n- [ ]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials\n- [x] [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- [ ] If a plugin configuration key changed, check if it needs to be\nallowlisted in the cloud and added to the [docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n- [ ] This was checked for breaking HTTP API changes, and any breaking\nchanges have been approved by the breaking-change committee. The\n`release_note:breaking` label should be applied in these situations.\n- [x] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed\n- [ ] 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.\n\n### Identify risks\n\nDoes this PR introduce any risks? For example, consider risks like hard\nto test bugs, performance regression, potential of data loss.\n\nDescribe the risk, its severity, and mitigation for each identified\nrisk. Invite stakeholders and evaluate how to proceed before merging.\n\n- [ ] [See some risk\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\n- [ ] ...","sha":"43c1ea7e41bcd8a54af55c14a41287f6ca2911aa"}},{"branch":"9.0","label":"v9.0.5","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.1","label":"v9.1.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.5","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Miłosz Radzyński <[email protected]>
1 parent af009dd commit 238c2e7

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/platform/plugins/shared/unified_search/public/query_string_input/query_bar_menu_panels.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,10 @@ export function useQueryBarMenuPanels({
255255

256256
useEffect(() => {
257257
if (savedQuery) {
258-
const filtersHaveChanged = Boolean(
259-
savedQuery?.attributes.filters &&
260-
!compareFilters(filters ?? [], savedQuery.attributes.filters, COMPARE_ALL_OPTIONS)
258+
const filtersHaveChanged = !compareFilters(
259+
filters ?? [],
260+
savedQuery.attributes.filters ?? [],
261+
COMPARE_ALL_OPTIONS
261262
);
262263

263264
const timeFilterHasChanged = Boolean(

src/platform/test/functional/apps/discover/ccs_compatibility/_saved_queries.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,37 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
270270
await queryBar.switchQueryLanguage('lucene');
271271
expect(await queryBar.getQueryString()).to.eql('');
272272
});
273+
274+
it('checks if the "Save query" button becomes enabled after adding filters, even when the query was saved with "Include filters" unchecked', async () => {
275+
await queryBar.setQuery('response:200');
276+
await queryBar.submitQuery();
277+
await savedQueryManagementComponent.saveNewQuery('filterExcluded', '', false, false);
278+
await savedQueryManagementComponent.savedQueryExistOrFail('filterExcluded');
279+
await savedQueryManagementComponent.closeSavedQueryManagementComponent();
280+
await savedQueryManagementComponent.openSavedQueryManagementComponent();
281+
let isSaveButtonDisabled = await testSubjects.getAttribute(
282+
'saved-query-management-save-button',
283+
'disabled'
284+
);
285+
expect(isSaveButtonDisabled).to.equal(
286+
'true',
287+
'Save button should be disabled directly after saving a query'
288+
);
289+
await filterBar.addFilter({ field: '@message', operation: 'exists' });
290+
await savedQueryManagementComponent.openSavedQueryManagementComponent();
291+
isSaveButtonDisabled = await testSubjects.getAttribute(
292+
'saved-query-management-save-button',
293+
'disabled'
294+
);
295+
expect(isSaveButtonDisabled).to.equal(
296+
null,
297+
'Save button should be enabled after adding a filter'
298+
);
299+
const updateQueryButtonExists = await testSubjects.exists(
300+
'saved-query-management-save-changes-button'
301+
);
302+
expect(updateQueryButtonExists).to.equal(true, 'Update query button does not exist');
303+
});
273304
});
274305
});
275306
}

0 commit comments

Comments
 (0)