Skip to content

[Discover] Reset layout on profile change#265174

Merged
davismcphee merged 14 commits into
elastic:mainfrom
davismcphee:discover-reset-layout-on-profile-change
Apr 28, 2026
Merged

[Discover] Reset layout on profile change#265174
davismcphee merged 14 commits into
elastic:mainfrom
davismcphee:discover-reset-layout-on-profile-change

Conversation

@davismcphee
Copy link
Copy Markdown
Contributor

@davismcphee davismcphee commented Apr 23, 2026

Summary

This PR fixes the layout carry-over that happens when Discover switches between profiles. Currently when resolving the metrics profile first and then switching to logs, the collapsed table state from metrics leaks into logs even though logs doesn't define that as a profile default:

Now Discover treats initial profile resolution differently from later profile switches. On profile change, Discover restores saved state for that profile when it exists, otherwise it resets layout state back to the shared local storage values before applying profile defaults. This keeps metrics defaults intact while preventing logs from inheriting the table layout when switching from metrics.

The PR also moves layout local storage helpers to @kbn/discover-utils, simplifies how panel toggle actions are wired into unified histogram, and adds test coverage for the new layout reset behaviour.

Testing notes

Setup:

  • Ingest some logs and metrics, e.g. with node scripts/synthtrace logs_and_metrics.ts.
  • Create a new o11y space in Kibana.
  • Use a clean local storage (e.g. private window).

The table should shown in this case (same as before):

  1. Start with FROM logs-* (by refreshing the page once you run that query)
  2. TS metrics-*
  3. FROM logs-*

The table should now also be shown in this case (new to this PR):

  1. Start with TS metrics-* (by refreshing the page once you run that query)
  2. FROM logs-*

Resolves #266092.

Checklist

  • Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support
  • Documentation was added for features that require explanation or tutorials
  • Unit or functional tests were updated or added to match the most common scenarios
  • If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the docker list
  • This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The release_note:breaking label should be applied in these situations.
  • Flaky Test Runner was used on any tests changed
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines
  • Review the backport guidelines and apply applicable backport:* labels.

@davismcphee davismcphee self-assigned this Apr 23, 2026
@davismcphee davismcphee added release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting Team:DataDiscovery Discover, search (data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. t// labels Apr 23, 2026
@davismcphee
Copy link
Copy Markdown
Contributor Author

/ci

@elasticmachine
Copy link
Copy Markdown
Contributor

elasticmachine commented Apr 23, 2026

💔 Build Failed

Failed CI Steps

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
discover 1.9MB 1.9MB +579.0B

History

cc @davismcphee

@davismcphee
Copy link
Copy Markdown
Contributor Author

/ci

@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented Apr 27, 2026

Catch flakiness early (recommended)

Recommended before merge: run the flaky test runner against this PR to catch flakiness early.

A new beforeEach hook clearing browser local storage was added to the histogram test suite, changing the state each test starts with.

Trigger a run with the Flaky Test Runner UI or post this comment on the PR:

/flaky ftrConfig:src/platform/test/functional/apps/discover/group1/config.ts:30

Share feedback in the #appex-qa channel.

Posted via Macroscope — Flaky Test Runner nudge

@davismcphee davismcphee force-pushed the discover-reset-layout-on-profile-change branch from 4fff6de to a264467 Compare April 27, 2026 23:40
@davismcphee davismcphee added backport:version Backport to applied version labels v9.4.0 v9.5.0 and removed backport:skip This PR does not require backporting labels Apr 27, 2026
@davismcphee
Copy link
Copy Markdown
Contributor Author

/ci

@davismcphee
Copy link
Copy Markdown
Contributor Author

/flaky ftrConfig:src/platform/test/functional/apps/discover/group1/config.ts:30

@kibanamachine
Copy link
Copy Markdown
Contributor

Flaky Test Runner

✅ Build triggered - kibana-flaky-test-suite-runner#11957

  • src/platform/test/functional/apps/discover/group1/config.ts x30

@kibanamachine
Copy link
Copy Markdown
Contributor

Flaky Test Runner Stats

🎉 All tests passed! - kibana-flaky-test-suite-runner#11957

[✅] src/platform/test/functional/apps/discover/group1/config.ts: 30/30 tests passed.

see run history

@davismcphee davismcphee marked this pull request as ready for review April 28, 2026 13:39
@davismcphee davismcphee requested review from a team as code owners April 28, 2026 13:39
@elastic elastic deleted a comment from infra-vault-gh-plugin-prod Bot Apr 28, 2026
@infra-vault-gh-plugin-prod
Copy link
Copy Markdown

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

Copy link
Copy Markdown
Contributor

@jughosta jughosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested the mentioned cases and they LGTM 👍

{chartVisible && (
<>
<section
ref={(element) => (chartRef.current.element = element)}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we lost the logic of returning the focus to the chart.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just double checked again in main to be sure, but looks like it's been dead code for a long time now (likely since we added renderCustomChartToggleActions in #171638). We could consider making it work again with our current approach, but I guess it hasn't been missed so far at least.

Comment on lines +415 to +416
hideChart: getChartHidden(services.storage, 'discover'),
hideTable: getTableHidden(services.storage, 'discover'),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if in the URL the states were different?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't run on init (!isFirstResolution) so it'll use URL state there, only on fetch when switching profiles to one that hasn't been resolved previously. So I think we're good here, but please let me know if I misunderstood.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining!

@kibanamachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #124 / Dashboard dashboard in space Storing search sessions in space Saves and restores a session

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
alertingVTwo 918 919 +1
apm 2165 2166 +1
cloudSecurityPosture 767 768 +1
datasetQuality 1077 1076 -1
dataVisualizer 876 877 +1
discover 2021 2020 -1
esql 990 991 +1
esqlDataGrid 436 437 +1
eventAnnotationListing 702 703 +1
fleet 2111 2112 +1
infra 1867 1868 +1
lens 1739 1740 +1
logsShared 448 449 +1
ml 4231 4232 +1
observability 1746 1747 +1
observabilityLogsExplorer 252 253 +1
osquery 756 757 +1
queryActivity 256 257 +1
searchPlayground 568 569 +1
securitySolution 9366 9367 +1
slo 1337 1338 +1
streamsApp 1839 1840 +1
triggersActionsUi 1402 1403 +1
unifiedDocViewer 912 913 +1
workflowsManagement 1598 1599 +1
total +21

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/discover-utils 354 378 +24
@kbn/unified-histogram 83 68 -15
total +9

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
datasetQuality 524.0KB 524.0KB +2.0B
discover 1.9MB 1.9MB -448.0B
total -446.0B
Unknown metric groups

API count

id before after diff
@kbn/discover-utils 443 475 +32
@kbn/unified-histogram 128 107 -21
total +11

History

cc @davismcphee

@davismcphee davismcphee merged commit 09769b0 into elastic:main Apr 28, 2026
17 checks passed
@davismcphee davismcphee deleted the discover-reset-layout-on-profile-change branch April 28, 2026 21:27
@kibanamachine
Copy link
Copy Markdown
Contributor

Starting backport for target branches: 9.4

https://github.com/elastic/kibana/actions/runs/25078582140

@kibanamachine
Copy link
Copy Markdown
Contributor

💔 All backports failed

Status Branch Result
9.4 Backport failed because of merge conflicts

You might need to backport the following PRs to 9.4:
- [Search] [Inference Endpoints] Small UI improvements to Add/Edit endpoint flyout (#262143)
- Move all i18n inline (#262363)

Manual backport

To create the backport manually run:

node scripts/backport --pr 265174

Questions ?

Please refer to the Backport tool documentation

@davismcphee
Copy link
Copy Markdown
Contributor Author

💚 All backports created successfully

Status Branch Result
9.4

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

davismcphee added a commit that referenced this pull request Apr 29, 2026
# Backport

This will backport the following commits from `main` to `9.4`:
- [[Discover] Reset layout on profile change
(#265174)](#265174)

<!--- Backport version: 11.0.2 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Davis
McPhee","email":"davis.mcphee@elastic.co"},"sourceCommit":{"committedDate":"2026-04-28T21:27:08Z","message":"[Discover]
Reset layout on profile change (#265174)\n\n## Summary\n\nThis PR fixes
the layout carry-over that happens when Discover switches\nbetween
profiles. Currently when resolving the metrics profile first and\nthen
switching to logs, the collapsed table state from metrics leaks\ninto
logs even though logs doesn't define that as a profile
default:\n<img\nsrc=\"https://github.com/user-attachments/assets/80a7280c-f2df-4580-83fe-c9c7fd0d769f\"\n/>\n\nNow
Discover treats initial profile resolution differently from
later\nprofile switches. On profile change, Discover restores saved
state for\nthat profile when it exists, otherwise it resets layout state
back to\nthe shared local storage values before applying profile
defaults. This\nkeeps metrics defaults intact while preventing logs from
inheriting the\ntable layout when switching from metrics.\n\nThe PR also
moves layout local storage helpers to `@kbn/discover-utils`,\nsimplifies
how panel toggle actions are wired into unified histogram,\nand adds
test coverage for the new layout reset behaviour.\n\n### Testing
notes\n\nSetup:\n- Ingest some logs and metrics, e.g. with `node
scripts/synthtrace\nlogs_and_metrics.ts`.\n- Create a new o11y space in
Kibana.\n- Use a clean local storage (e.g. private window).\n\nThe table
should shown in this case (same as before):\n1. Start with `FROM logs-*`
(by refreshing the page once you run that\nquery)\n2. `TS metrics-*`\n3.
`FROM logs-*`\n\nThe table should now also be shown in this case (new to
this PR):\n1. Start with `TS metrics-*` (by refreshing the page once you
run that\nquery)\n2. `FROM logs-*`\n\nResolves #266092.\n\n###
Checklist\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-
[x] 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- [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.\n\n---------\n\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"09769b0ba1f9e46e84dedbb7e89b2a0bd0984a81","branchLabelMapping":{"^v9.5.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:DataDiscovery","backport:version","v9.4.0","v9.5.0"],"title":"[Discover]
Reset layout on profile
change","number":265174,"url":"https://github.com/elastic/kibana/pull/265174","mergeCommit":{"message":"[Discover]
Reset layout on profile change (#265174)\n\n## Summary\n\nThis PR fixes
the layout carry-over that happens when Discover switches\nbetween
profiles. Currently when resolving the metrics profile first and\nthen
switching to logs, the collapsed table state from metrics leaks\ninto
logs even though logs doesn't define that as a profile
default:\n<img\nsrc=\"https://github.com/user-attachments/assets/80a7280c-f2df-4580-83fe-c9c7fd0d769f\"\n/>\n\nNow
Discover treats initial profile resolution differently from
later\nprofile switches. On profile change, Discover restores saved
state for\nthat profile when it exists, otherwise it resets layout state
back to\nthe shared local storage values before applying profile
defaults. This\nkeeps metrics defaults intact while preventing logs from
inheriting the\ntable layout when switching from metrics.\n\nThe PR also
moves layout local storage helpers to `@kbn/discover-utils`,\nsimplifies
how panel toggle actions are wired into unified histogram,\nand adds
test coverage for the new layout reset behaviour.\n\n### Testing
notes\n\nSetup:\n- Ingest some logs and metrics, e.g. with `node
scripts/synthtrace\nlogs_and_metrics.ts`.\n- Create a new o11y space in
Kibana.\n- Use a clean local storage (e.g. private window).\n\nThe table
should shown in this case (same as before):\n1. Start with `FROM logs-*`
(by refreshing the page once you run that\nquery)\n2. `TS metrics-*`\n3.
`FROM logs-*`\n\nThe table should now also be shown in this case (new to
this PR):\n1. Start with `TS metrics-*` (by refreshing the page once you
run that\nquery)\n2. `FROM logs-*`\n\nResolves #266092.\n\n###
Checklist\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-
[x] 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- [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.\n\n---------\n\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"09769b0ba1f9e46e84dedbb7e89b2a0bd0984a81"}},"sourceBranch":"main","suggestedTargetBranches":["9.4"],"targetPullRequestStates":[{"branch":"9.4","label":"v9.4.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.5.0","branchLabelMappingKey":"^v9.5.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/265174","number":265174,"mergeCommit":{"message":"[Discover]
Reset layout on profile change (#265174)\n\n## Summary\n\nThis PR fixes
the layout carry-over that happens when Discover switches\nbetween
profiles. Currently when resolving the metrics profile first and\nthen
switching to logs, the collapsed table state from metrics leaks\ninto
logs even though logs doesn't define that as a profile
default:\n<img\nsrc=\"https://github.com/user-attachments/assets/80a7280c-f2df-4580-83fe-c9c7fd0d769f\"\n/>\n\nNow
Discover treats initial profile resolution differently from
later\nprofile switches. On profile change, Discover restores saved
state for\nthat profile when it exists, otherwise it resets layout state
back to\nthe shared local storage values before applying profile
defaults. This\nkeeps metrics defaults intact while preventing logs from
inheriting the\ntable layout when switching from metrics.\n\nThe PR also
moves layout local storage helpers to `@kbn/discover-utils`,\nsimplifies
how panel toggle actions are wired into unified histogram,\nand adds
test coverage for the new layout reset behaviour.\n\n### Testing
notes\n\nSetup:\n- Ingest some logs and metrics, e.g. with `node
scripts/synthtrace\nlogs_and_metrics.ts`.\n- Create a new o11y space in
Kibana.\n- Use a clean local storage (e.g. private window).\n\nThe table
should shown in this case (same as before):\n1. Start with `FROM logs-*`
(by refreshing the page once you run that\nquery)\n2. `TS metrics-*`\n3.
`FROM logs-*`\n\nThe table should now also be shown in this case (new to
this PR):\n1. Start with `TS metrics-*` (by refreshing the page once you
run that\nquery)\n2. `FROM logs-*`\n\nResolves #266092.\n\n###
Checklist\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-
[x] 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- [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.\n\n---------\n\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"09769b0ba1f9e46e84dedbb7e89b2a0bd0984a81"}}]}]
BACKPORT-->

Co-authored-by: Lukas Olson <lukas@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover, search (data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. t// v9.4.0 v9.5.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Discover] Improve default layout handling when switching between Discover profiles

5 participants