Skip to content

[Discover] Add support for restorable state for doc viewer flyout tabs#249030

Merged
akowalska622 merged 25 commits intoelastic:mainfrom
akowalska622:discover-support-restorable-state-for-doc-viewer
Jan 20, 2026
Merged

[Discover] Add support for restorable state for doc viewer flyout tabs#249030
akowalska622 merged 25 commits intoelastic:mainfrom
akowalska622:discover-support-restorable-state-for-doc-viewer

Conversation

@akowalska622
Copy link
Contributor

@akowalska622 akowalska622 commented Jan 14, 2026

Summary

Resolves: #248564

This pull request introduces state persistence and restoration capabilities for the DocViewer in Discover. It enables each doc viewer tab to save and restore its own state, and wires this state handling through the Redux store and all relevant components. This improves user experience by maintaining tab-specific state across navigation and document changes.

It's also prepared to save and restore any other state, apart from doc viewer tab state and gives profiles possibility to register components with restorable state.

It prepares us to specifically save Table and JSON tabs as per:
[Discover] [Unified Doc Viewer] Support restorable state in the Table doc viewer tab #248567
[Discover] [Unified Doc Viewer] Support restorable state in the JSON doc viewer tab #248568

Here you can find an example how to use it as a consumer.

Video of an example usage:

Screen.Recording.2026-01-16.at.13.12.12.mov

Acceptance criteria

  • Doc viewer tab state is stored within Discover's state management, scoped per tab.
  • Doc viewer tab state is restored when switching between Discover tabs with open flyouts.
  • Doc viewer tab state is cleared when the flyout is closed or the expanded document changes.
  • Discover profiles are able to register doc viewer tabs with restorable state.
  • (Optional) Discover profiles can pass initialTabState to their doc viewer tabs when calling the setExpandedDoc extension point action

Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

  • 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.

Identify risks

Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging.

@akowalska622 akowalska622 self-assigned this Jan 14, 2026
@akowalska622 akowalska622 added release_note:enhancement Feature:Discover Discover Application 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// Feature:UnifiedDocViewer Issues relating to the unified doc viewer component Project:OneDiscover Enrich Discover with contextual awareness Feature:DiscoverTabs Tabs feature within Discover labels Jan 14, 2026
Copy link
Contributor

@davismcphee davismcphee left a comment

Choose a reason for hiding this comment

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

Changes are looking good! Left some initial feedback.

Copy link
Contributor

@davismcphee davismcphee left a comment

Choose a reason for hiding this comment

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

Thanks for the updates, looks great! Once we fix the conflicts from #248203 and add some tests, this looks ready to ship to me 🚀

@akowalska622 akowalska622 marked this pull request as ready for review January 17, 2026 13:12
@akowalska622 akowalska622 requested a review from a team as a code owner January 17, 2026 13:12
@elasticmachine
Copy link
Contributor

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

Copy link
Contributor

@davismcphee davismcphee left a comment

Choose a reason for hiding this comment

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

Latest changes look great!

Just one final ask: could you please update an example profile to use the restorable state functionality and add FTR tests for it here?

It would also probably be helpful to add some inline documentation about how consumers can use the restorable functionality to the type definition (or add it to the Unified Doc Viewer readme and link from here):

/**
* Supports customizing the behaviour of the Discover document
* viewer flyout, such as the flyout title and available tabs
* @param params The doc viewer extension parameters
* @returns The doc viewer extension
*/
getDocViewer: (params: DocViewerExtensionParams) => DocViewerExtension;

@akowalska622
Copy link
Contributor Author

could you please update an example profile to use the restorable state functionality

Ah this sounds like much better solution than my dedicated branch for example 😅 On it!

@akowalska622
Copy link
Contributor Author

Thanks @davismcphee! All asks addressed. I've created a new dedicated component for a doc viewer tab with restorable state in example profile, so the original custom tab is kept leaner. When I initially added it there, I felt that too much is going on there and maybe it's worth keeping it separated, but I'm open for changes!

Comment on lines -17 to -18
* The trace waterfall does not show in components since it's an Embeddable and we're not mocking everything out.
* The "(X% of trace)" component is never rendered because we are not fetching parent span data.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This gets auto adjusted on save in VSC

Copy link
Contributor

Choose a reason for hiding this comment

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

VSC knew it was wrong 🙂

Copy link
Contributor

@davismcphee davismcphee left a comment

Choose a reason for hiding this comment

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

Excellent work on this, you're now officially our resident doc viewer expert! I'm gonna trigger a flaky test run against the new tests to be sure, but assuming that passes, this LGTM 🚀

Copy link
Contributor

Choose a reason for hiding this comment

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

Wonderful documentation, thank you!

Comment on lines -17 to -18
* The trace waterfall does not show in components since it's an Embeddable and we're not mocking everything out.
* The "(X% of trace)" component is never rendered because we are not fetching parent span data.
Copy link
Contributor

Choose a reason for hiding this comment

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

VSC knew it was wrong 🙂

@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

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

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

see run history

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #36 / Data Views Verify data view is created once user reach the findings page - default space

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
discover 1982 1983 +1

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/unified-doc-viewer 24 28 +4

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.4MB 1.4MB -2.5KB
unifiedDocViewer 372.0KB 372.6KB +548.0B
total -2.0KB

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
@kbn/unified-doc-viewer 3 4 +1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
discover 25.4KB 25.4KB +36.0B
Unknown metric groups

API count

id before after diff
@kbn/unified-doc-viewer 26 31 +5

async chunk count

id before after diff
discover 41 42 +1

History

cc @akowalska622

@akowalska622 akowalska622 merged commit 817a1b3 into elastic:main Jan 20, 2026
16 checks passed
dennis-tismenko pushed a commit to dennis-tismenko/kibana that referenced this pull request Jan 22, 2026
elastic#249030)

## Summary

Resolves: elastic#248564

This pull request introduces state persistence and restoration
capabilities for the DocViewer in Discover. It enables each doc viewer
tab to save and restore its own state, and wires this state handling
through the Redux store and all relevant components. This improves user
experience by maintaining tab-specific state across navigation and
document changes.

It's also prepared to save and restore any other state, apart from doc
viewer tab state and gives profiles possibility to register components
with restorable state.

It prepares us to specifically save `Table` and `JSON` tabs as per:
[[Discover] [Unified Doc Viewer] Support restorable state in the Table
doc viewer tab elastic#248567](elastic#248567)
[[Discover] [Unified Doc Viewer] Support restorable state in the JSON
doc viewer tab elastic#248568](elastic#248568)


[Here](akowalska622@a82b54f)
you can find an example how to use it as a consumer.

Video of an example usage:


https://github.com/user-attachments/assets/2caaaaa9-cbc0-48bb-9fe0-d9723efb3b57



### Acceptance criteria
- [x] Doc viewer tab state is stored within Discover's state management,
scoped per tab.
- [x] Doc viewer tab state is restored when switching between Discover
tabs with open flyouts.
- [x] Doc viewer tab state is cleared when the flyout is closed or the
expanded document changes.
- [x] Discover profiles are able to register doc viewer tabs with
restorable state.
- [x] (Optional) Discover profiles can pass `initialTabState` to their
doc viewer tabs when calling the `setExpandedDoc` extension point action

### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [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
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] 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](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [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)
- [ ] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.

### Identify risks

Does this PR introduce any risks? For example, consider risks like hard
to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified
risk. Invite stakeholders and evaluate how to proceed before merging.

- [ ] [See some risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
- [ ] ...

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Davis McPhee <davismcphee@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting Feature:Discover Discover Application Feature:DiscoverTabs Tabs feature within Discover Feature:UnifiedDocViewer Issues relating to the unified doc viewer component Project:OneDiscover Enrich Discover with contextual awareness release_note:enhancement Team:DataDiscovery Discover, search (data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. t// v9.4.0

4 participants