Skip to content

Conversation

@jughosta
Copy link
Contributor

@jughosta jughosta commented Sep 12, 2025

Summary

This PR extends the Discover locator with a new param tabId (and tabLabel). Passing new value to it will signal to open the search in a new Discover tab.

Was a persisted Discover Session (A) open when a search session was triggered? Was user previously viewing a persisted Discover session (B) in Discover Outcome after opening a search session link from Stack Management
no no non-persisted Discover session
no yes non-persisted Discover session (previous tabs cleared)
yes no the persisted Discover session A (previous tabs cleared)
yes yes (A discover session Id is the same as B) the persisted Discover session A
yes yes (A discover session Id is different from B) the persisted Discover session A (previous tabs cleared)

Let me know if it's too complex or you have ideas on how to append to a persisted session tabs without reseting previous tabs.

The main problem comes from the fact that it also depends from where you saved a search session: it might include the notion of savedSearchId and it might not => this result in getting either /view/<saved search id>?searchSessionId=<id> route or /?searchSessionId=<id>. And Discover reacts to saved search id value in URL.

From the other side tabs gets cleared if ids don't match

const openTabs =
persistedDiscoverSession?.id === storedTabsState.discoverSessionId
? storedTabsState.openTabs.map((tab) => toTabState(tab, defaultTabState))
: persistedTabs ?? [];
(non-persisted Discover session means no id).

Additionally, this PR adds openInNewTab redux action. I think we should use it from Background Search flyout as it would append to tabs without the mentioned problems.

Checklist

  • Unit or functional tests were updated or added to match the most common scenarios
  • 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.

@jughosta jughosta self-assigned this Sep 12, 2025
@jughosta jughosta added release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting Project:AsyncSearch Background search, partial results, async search services. 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 Sep 12, 2025
if (searchSessionId) {
newDefaultTab.dataRequestParams = {
...newDefaultTab.dataRequestParams,
searchSessionId,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would still need additional handling to sync it to the search session manager.

@jughosta jughosta requested a review from Copilot September 15, 2025 12:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR extends the Discover locator to support opening searches in new tabs by adding tabId and tabLabel parameters. When tabId is set to "new", it signals to create a new Discover tab with the specified configuration.

Key changes:

  • Added NEW_TAB_ID constant and tab-related parameters to the locator interface
  • Implemented logic to handle new tab creation via URL parameters
  • Added openInNewTab Redux action for programmatic tab creation
  • Updated search session management to optionally open restored sessions in new tabs

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/platform/plugins/shared/discover/common/constants.ts Added NEW_TAB_ID constant and updated TABS_STATE_URL_KEY
src/platform/plugins/shared/discover/common/app_locator.ts Extended locator interface with tabId and tabLabel parameters
src/platform/plugins/shared/discover/common/app_locator_get_location.ts Added URL state handling for tab parameters
src/platform/plugins/shared/discover/public/application/main/state_management/tabs_storage_manager.ts Implemented new tab creation logic and URL state management
src/platform/plugins/shared/discover/public/application/main/state_management/redux/actions/tabs.ts Added openInNewTab action and updated tab restoration logic
src/platform/plugins/shared/discover/public/application/main/state_management/redux/index.ts Exported new openInNewTab action
src/platform/plugins/shared/discover/public/application/main/state_management/redux/internal_state.test.ts Added test coverage for the new tab functionality
src/platform/plugins/shared/discover/public/application/main/state_management/hooks/use_state_managers.ts Updated comments to reflect correct URL parameter name
src/platform/plugins/shared/discover/public/application/main/components/top_nav/app_menu_actions/get_share.tsx Added TODO comment for future tab ID integration
src/platform/plugins/shared/discover/common/app_locator.test.ts Added test cases for new tab functionality
src/platform/plugins/shared/data/public/search/session/sessions_mgmt/components/table/utils/map_to_ui_session.ts Added support for opening search sessions in new tabs
src/platform/plugins/shared/data/public/search/session/sessions_mgmt/components/table/table.tsx Added feature flag check for new tab functionality

@jughosta jughosta marked this pull request as ready for review September 15, 2025 16:37
@jughosta jughosta requested review from a team as code owners September 15, 2025 16:37
@elasticmachine
Copy link
Contributor

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

);
const enableOpeningInNewTab = useMemo(
() =>
core.featureFlags.getBooleanValue(BACKGROUND_SEARCH_FEATURE_FLAG_KEY, false) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: do we need to check both feature flags for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AlexGPlay Good question! How would you recommend to change it?

Copy link
Contributor

Choose a reason for hiding this comment

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

i was thinking that maybe the tabs one is enough since it's the feature this is truly targeting, wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 1f6aa3d

Copy link
Contributor

@AlexGPlay AlexGPlay left a comment

Choose a reason for hiding this comment

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

tested from a bgs perspective and lgtm 🚀

Copy link
Contributor

@dej611 dej611 left a comment

Choose a reason for hiding this comment

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

@elastic/kibana-visualizations code review 👍

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.

Code changes LGTM, also tested locally and it seems to work as expected! Left some minor feedback, but nothing blocking.

Thanks for adding the expected outcome matrix to the summary, it helped a lot with testing. I agree it would be best to use the Redux action for restoring background searches within the flyout (not sure it'll make it for 9.2 though).

The expected outcomes are fairly complex, but I'm not sure what else you could have done here either given the current background search implementation. We'll at least have the unsaved changes modal and recently closed tabs to limit the impact for 9.2.

We should continue discussing this either async or in the office hours this Thursday, but I think we're good to merge the current implementation for now. If we figure out a way to resolve the conflicts better, IMO it could be treated as a fix and backported to 9.2 post FF.

refreshInterval,
};

// TODO: for a persisted saved search, add the current tab ID to the params
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably worth creating an issue for this one if we don't do it in this PR, since we should do it for 9.2. Could be a good smaller task for one of the newer team members.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created #235320

);
});

it('should append a new tab to the tabs list', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding a unit test here! Would have liked to add more of these initially if I wasn't rushing through so much of it early on 🙂

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

Thanks for the reviews, @davismcphee and @AlexGPlay!
Updated the code.

);
const enableOpeningInNewTab = useMemo(
() =>
core.featureFlags.getBooleanValue(BACKGROUND_SEARCH_FEATURE_FLAG_KEY, false) &&
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 1f6aa3d

refreshInterval,
};

// TODO: for a persisted saved search, add the current tab ID to the params
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created #235320

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #96 / Cloud Security Posture Test adding Cloud Security Posture Integrations CSPM AWS CIS_AWS Organization Manual Direct Access CIS_AWS Organization Manual Direct Access Workflow

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.1MB 1.1MB +941.0B

Page load bundle

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

id before after diff
data 421.5KB 421.7KB +180.0B
discover 23.3KB 23.3KB +19.0B
total +199.0B
Unknown metric groups

API count

id before after diff
discover 209 210 +1

History

cc @jughosta

@jughosta jughosta merged commit f3495de into elastic:main Sep 17, 2025
12 checks passed
@jughosta jughosta deleted the 230829-locator-new-tab branch September 17, 2025 13:55
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Sep 24, 2025
… tab (elastic#234912)

- Closes elastic#230829

## Summary

This PR extends the Discover locator with a new param `tabId` (and
`tabLabel`). Passing `new` value to it will signal to open the search in
a new Discover tab.

| Was a persisted Discover Session (A) open when a search session was
triggered? | Was user previously viewing a persisted Discover session
(B) in Discover | Outcome after opening a search session link from Stack
Management |
| ------------- | ------------- | ------------- |
| no  | no | non-persisted Discover session |
| no  | yes  | non-persisted Discover session (previous tabs cleared) |
| yes | no | the persisted Discover session A (previous tabs cleared) |
| yes | yes (A discover session Id is the same as B) | the persisted
Discover session A |
| yes | yes (A discover session Id is different from B) | the persisted
Discover session A (previous tabs cleared) |

Let me know if it's too complex or you have ideas on how to append to a
persisted session tabs without reseting previous tabs.

The main problem comes from the fact that it also depends from where you
saved a search session: it might include the notion of `savedSearchId`
and it might not => this result in getting either `/view/<saved search
id>?searchSessionId=<id>` route or `/?searchSessionId=<id>`. And
Discover reacts to saved search id value in URL.

From the other side tabs gets cleared if ids don't match
https://github.com/elastic/kibana/blob/17f697055f699438ca84eae3c0230a54d4ad8170/src/platform/plugins/shared/discover/public/application/main/state_management/tabs_storage_manager.ts#L393-L396
(non-persisted Discover session means no id).

Additionally, this PR adds `openInNewTab` redux action. I think we
should use it from Background Search flyout as it would append to tabs
without the mentioned problems.

### 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] 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: Copilot <[email protected]>
niros1 pushed a commit that referenced this pull request Sep 30, 2025
… tab (#234912)

- Closes #230829

## Summary

This PR extends the Discover locator with a new param `tabId` (and
`tabLabel`). Passing `new` value to it will signal to open the search in
a new Discover tab.

| Was a persisted Discover Session (A) open when a search session was
triggered? | Was user previously viewing a persisted Discover session
(B) in Discover | Outcome after opening a search session link from Stack
Management |
| ------------- | ------------- | ------------- |
| no  | no | non-persisted Discover session |
| no  | yes  | non-persisted Discover session (previous tabs cleared) |
| yes | no | the persisted Discover session A (previous tabs cleared) |
| yes | yes (A discover session Id is the same as B) | the persisted
Discover session A |
| yes | yes (A discover session Id is different from B) | the persisted
Discover session A (previous tabs cleared) |

Let me know if it's too complex or you have ideas on how to append to a
persisted session tabs without reseting previous tabs.

The main problem comes from the fact that it also depends from where you
saved a search session: it might include the notion of `savedSearchId`
and it might not => this result in getting either `/view/<saved search
id>?searchSessionId=<id>` route or `/?searchSessionId=<id>`. And
Discover reacts to saved search id value in URL.

From the other side tabs gets cleared if ids don't match
https://github.com/elastic/kibana/blob/17f697055f699438ca84eae3c0230a54d4ad8170/src/platform/plugins/shared/discover/public/application/main/state_management/tabs_storage_manager.ts#L393-L396
(non-persisted Discover session means no id).

Additionally, this PR adds `openInNewTab` redux action. I think we
should use it from Background Search flyout as it would append to tabs
without the mentioned problems.

### 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] 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: Copilot <[email protected]>
rylnd pushed a commit to rylnd/kibana that referenced this pull request Oct 17, 2025
… tab (elastic#234912)

- Closes elastic#230829

## Summary

This PR extends the Discover locator with a new param `tabId` (and
`tabLabel`). Passing `new` value to it will signal to open the search in
a new Discover tab.

| Was a persisted Discover Session (A) open when a search session was
triggered? | Was user previously viewing a persisted Discover session
(B) in Discover | Outcome after opening a search session link from Stack
Management |
| ------------- | ------------- | ------------- |
| no  | no | non-persisted Discover session |
| no  | yes  | non-persisted Discover session (previous tabs cleared) |
| yes | no | the persisted Discover session A (previous tabs cleared) |
| yes | yes (A discover session Id is the same as B) | the persisted
Discover session A |
| yes | yes (A discover session Id is different from B) | the persisted
Discover session A (previous tabs cleared) |

Let me know if it's too complex or you have ideas on how to append to a
persisted session tabs without reseting previous tabs.

The main problem comes from the fact that it also depends from where you
saved a search session: it might include the notion of `savedSearchId`
and it might not => this result in getting either `/view/<saved search
id>?searchSessionId=<id>` route or `/?searchSessionId=<id>`. And
Discover reacts to saved search id value in URL.

From the other side tabs gets cleared if ids don't match
https://github.com/elastic/kibana/blob/17f697055f699438ca84eae3c0230a54d4ad8170/src/platform/plugins/shared/discover/public/application/main/state_management/tabs_storage_manager.ts#L393-L396
(non-persisted Discover session means no id).

Additionally, this PR adds `openInNewTab` redux action. I think we
should use it from Background Search flyout as it would append to tabs
without the mentioned problems.

### 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] 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: Copilot <[email protected]>
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:AsyncSearch Background search, partial results, async search services. 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.

[Discover Tabs] Extend the discover locator to allow opening in a new tab

6 participants