Skip to content

[Discover] Restore Unified Search UI state on tab change (query, time range)#227298

Merged
jughosta merged 26 commits intoelastic:mainfrom
jughosta:218509-restore-search-state
Jul 22, 2025
Merged

[Discover] Restore Unified Search UI state on tab change (query, time range)#227298
jughosta merged 26 commits intoelastic:mainfrom
jughosta:218509-restore-search-state

Conversation

@jughosta
Copy link
Copy Markdown
Contributor

@jughosta jughosta commented Jul 9, 2025

Summary

This PR introduces a way to keep track of the unsubmitted changes in UnifiedSearch component (query, dateRangeFrom and dateRangeTo) and restores when when switching tabs in Discover. It does not use @kbn/restorable-state because src/platform/plugins/shared/unified_search/public/search_bar/search_bar.tsx is a class component which would require a lot of refactoring otherwise. Instead, the PR introduces draft and onDraftChange optional props for UnifiedSearch. They allow to mount a search bar with a prefilled query state and it will be visually rendered as "dirty" (with "Update" button).

  • unsubmitted KQL query and unsubmitted time range
  • unsubmitted ES|QL query and unsubmitted time range

Saving uiState.searchDraft per tab will allow us to address other issues too jughosta#19.

Testing

To enable tabs in Discover, run localStorage.setItem('discoverExperimental:tabs', 'true') in browser Console.

Checklist

@jughosta jughosta self-assigned this Jul 9, 2025
@jughosta jughosta 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// Project:OneDiscover Enrich Discover with contextual awareness labels Jul 9, 2025
@elasticmachine

This comment was marked as outdated.

@kibanamachine
Copy link
Copy Markdown
Contributor

Flaky Test Runner Stats

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

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

see run history

@jughosta jughosta changed the title [Discover] Restore Unified Search UI state on tab change [Discover] Restore Unified Search UI state on tab change (query, time range) Jul 16, 2025
@jughosta jughosta marked this pull request as ready for review July 16, 2025 08:45
@jughosta jughosta requested a review from a team as a code owner July 16, 2025 08:45
@jughosta jughosta requested review from a team as code owners July 16, 2025 08:45
@elasticmachine
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Member

@pheyos pheyos left a comment

Choose a reason for hiding this comment

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

src/platform/test/functional/page_objects/unified_tabs.ts changes LGTM

Copy link
Copy Markdown
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.

Works great, thanks for addressing it! Left some comments and questions, but nothing blocking.

@elasticmachine
Copy link
Copy Markdown
Contributor

elasticmachine commented Jul 20, 2025

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #18 / QueryBarTopRowTopRow draft Should call onDraftChange with empty draft when in normal state
  • [job] [logs] Jest Tests #18 / QueryBarTopRowTopRow draft Should call onDraftChange with empty draft when in normal state

Metrics [docs]

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
unifiedSearch 113 117 +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.1MB 1.1MB +406.0B
unifiedSearch 338.9KB 339.3KB +497.0B
total +903.0B

Page load bundle

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

id before after diff
unifiedSearch 22.2KB 22.2KB +44.0B
Unknown metric groups

API count

id before after diff
unifiedSearch 151 155 +4

History

cc @jughosta

Copy link
Copy Markdown
Contributor Author

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

@davismcphee Thanks for the review! I addressed your suggestions.

Copy link
Copy Markdown
Contributor

@ThomThomson ThomThomson left a comment

Choose a reason for hiding this comment

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

Changes LGTM! We don't have enough unified search knowledge on the team to determine if this is the ideal way to solve this, but the code looks pretty straightforward, so approving to unblock!

Copy link
Copy Markdown
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, much simpler now 👍 Approving again since the latest changes LGTM.

@jughosta jughosta merged commit ec951bd into elastic:main Jul 22, 2025
12 checks passed
Bluefinger pushed a commit to Bluefinger/kibana that referenced this pull request Jul 22, 2025
… range) (elastic#227298)

- Addresses elastic#218509

## Summary

This PR introduces a way to keep track of the unsubmitted changes in
UnifiedSearch component (`query`, `dateRangeFrom` and `dateRangeTo`) and
restores when when switching tabs in Discover. It does not use
`@kbn/restorable-state` because
`src/platform/plugins/shared/unified_search/public/search_bar/search_bar.tsx`
is a class component which would require a lot of refactoring otherwise.
Instead, the PR introduces `draft` and `onDraftChange` optional props
for UnifiedSearch. They allow to mount a search bar with a prefilled
query state and it will be visually rendered as "dirty" (with "Update"
button).

- [x] unsubmitted KQL query and unsubmitted time range
- [x] unsubmitted ES|QL query and unsubmitted time range

Saving `uiState.searchDraft` per tab will allow us to address other
issues too jughosta#19.

### Testing

To enable tabs in Discover, run
`localStorage.setItem('discoverExperimental:tabs', 'true')` in browser
Console.

### Checklist

- [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
- [x] [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)
- [x] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
maxcold pushed a commit that referenced this pull request Jul 22, 2025
… range) (#227298)

- Addresses #218509

## Summary

This PR introduces a way to keep track of the unsubmitted changes in
UnifiedSearch component (`query`, `dateRangeFrom` and `dateRangeTo`) and
restores when when switching tabs in Discover. It does not use
`@kbn/restorable-state` because
`src/platform/plugins/shared/unified_search/public/search_bar/search_bar.tsx`
is a class component which would require a lot of refactoring otherwise.
Instead, the PR introduces `draft` and `onDraftChange` optional props
for UnifiedSearch. They allow to mount a search bar with a prefilled
query state and it will be visually rendered as "dirty" (with "Update"
button).

- [x] unsubmitted KQL query and unsubmitted time range
- [x] unsubmitted ES|QL query and unsubmitted time range

Saving `uiState.searchDraft` per tab will allow us to address other
issues too jughosta#19.

### Testing

To enable tabs in Discover, run
`localStorage.setItem('discoverExperimental:tabs', 'true')` in browser
Console.

### Checklist

- [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
- [x] [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)
- [x] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
kdelemme pushed a commit to kdelemme/kibana that referenced this pull request Jul 23, 2025
… range) (elastic#227298)

- Addresses elastic#218509

## Summary

This PR introduces a way to keep track of the unsubmitted changes in
UnifiedSearch component (`query`, `dateRangeFrom` and `dateRangeTo`) and
restores when when switching tabs in Discover. It does not use
`@kbn/restorable-state` because
`src/platform/plugins/shared/unified_search/public/search_bar/search_bar.tsx`
is a class component which would require a lot of refactoring otherwise.
Instead, the PR introduces `draft` and `onDraftChange` optional props
for UnifiedSearch. They allow to mount a search bar with a prefilled
query state and it will be visually rendered as "dirty" (with "Update"
button).

- [x] unsubmitted KQL query and unsubmitted time range
- [x] unsubmitted ES|QL query and unsubmitted time range

Saving `uiState.searchDraft` per tab will allow us to address other
issues too jughosta#19.

### Testing

To enable tabs in Discover, run
`localStorage.setItem('discoverExperimental:tabs', 'true')` in browser
Console.

### Checklist

- [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
- [x] [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)
- [x] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
kertal pushed a commit to kertal/kibana that referenced this pull request Jul 25, 2025
… range) (elastic#227298)

- Addresses elastic#218509

## Summary

This PR introduces a way to keep track of the unsubmitted changes in
UnifiedSearch component (`query`, `dateRangeFrom` and `dateRangeTo`) and
restores when when switching tabs in Discover. It does not use
`@kbn/restorable-state` because
`src/platform/plugins/shared/unified_search/public/search_bar/search_bar.tsx`
is a class component which would require a lot of refactoring otherwise.
Instead, the PR introduces `draft` and `onDraftChange` optional props
for UnifiedSearch. They allow to mount a search bar with a prefilled
query state and it will be visually rendered as "dirty" (with "Update"
button).

- [x] unsubmitted KQL query and unsubmitted time range
- [x] unsubmitted ES|QL query and unsubmitted time range

Saving `uiState.searchDraft` per tab will allow us to address other
issues too jughosta#19.

### Testing

To enable tabs in Discover, run
`localStorage.setItem('discoverExperimental:tabs', 'true')` in browser
Console.

### Checklist

- [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
- [x] [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)
- [x] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
crespocarlos pushed a commit to crespocarlos/kibana that referenced this pull request Jul 25, 2025
… range) (elastic#227298)

- Addresses elastic#218509

## Summary

This PR introduces a way to keep track of the unsubmitted changes in
UnifiedSearch component (`query`, `dateRangeFrom` and `dateRangeTo`) and
restores when when switching tabs in Discover. It does not use
`@kbn/restorable-state` because
`src/platform/plugins/shared/unified_search/public/search_bar/search_bar.tsx`
is a class component which would require a lot of refactoring otherwise.
Instead, the PR introduces `draft` and `onDraftChange` optional props
for UnifiedSearch. They allow to mount a search bar with a prefilled
query state and it will be visually rendered as "dirty" (with "Update"
button).

- [x] unsubmitted KQL query and unsubmitted time range
- [x] unsubmitted ES|QL query and unsubmitted time range

Saving `uiState.searchDraft` per tab will allow us to address other
issues too jughosta#19.

### Testing

To enable tabs in Discover, run
`localStorage.setItem('discoverExperimental:tabs', 'true')` in browser
Console.

### Checklist

- [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
- [x] [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)
- [x] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.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 Project:OneDiscover Enrich Discover with contextual awareness 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.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants