Skip to content

[LensEmbeddable] Add "Open in lens" in the same tab#217528

Merged
mariairiartef merged 22 commits intoelastic:mainfrom
mariairiartef:poc/204155
May 26, 2025
Merged

[LensEmbeddable] Add "Open in lens" in the same tab#217528
mariairiartef merged 22 commits intoelastic:mainfrom
mariairiartef:poc/204155

Conversation

@mariairiartef
Copy link
Contributor

@mariairiartef mariairiartef commented Apr 8, 2025

Summary

Closes #204155

Adds support for the following behaviors:

  1. Clicking "Open in Lens" opens the Lens editor in the same tab.
  2. Using Command (or Ctrl if is not an apple device) + Click opens the Lens editor in a new tab.

Note

This is a temporary workaround until a more comprehensive solution, which requires additional effort, is implemented.

Details

The goal is that by clicking on the "Open in Lens" button, the Lens editor is opened in the current tab, and by Command + Clicking, the Lens editor is opened in a separate tab. Currently, the approach uses the navigateToPrefilledEditor method, exposed by the Lens plugin, which is called upon execution of the action.

Initially, the idea was to use the shortUrl service to generate a share URL. This service generates an Elasticsearch object, which can be excessive since the requirement doesn’t imply generating a URL that can be shared.

With the current approach, the data is persisted because it is in the session storage. That is why when we click on the button and it opens in a new tab, you can see the data. However, if you copy the same URL to another tab, nothing appears because there’s no data.

If we want to add an href by specifying the getHref method to the action (as suggested here, it won’t work as you cannot persist the data when you click on a link.

To maintain the requested behavior, we update the openInNewTab parameter that is passed to the Lens navigateToPrefilledEditor method to be true when it is a modified event or false when it is not.

Checklist

  • Unit or functional tests were updated or added to match the most common scenarios
  • 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
@mariairiartef mariairiartef self-assigned this Apr 9, 2025
@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

🟠 Some tests failed. - kibana-flaky-test-suite-runner#8197

[❌] x-pack/test/functional/apps/infra/config.ts: 1/25 tests passed.

see run history

@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

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

[✅] x-pack/test/functional/apps/infra/config.ts: 25/25 tests passed.

see run history

@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

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

[✅] x-pack/test/functional/apps/infra/config.ts: 50/50 tests passed.

see run history

@mariairiartef
Copy link
Contributor Author

mariairiartef commented Apr 22, 2025

I've been looking for a suitable place to test the behavior where clicking "Open in Lens" opens the Lens editor in the same tab, and using Command (or Ctrl if is not an apple device) + Click opens the Lens editor in a new tab. However, I'm unsure about the best location for this test.

I found a functional test that checks the visibility of the button, but it was skipped. They were unable to fix it in #197861 and I was trying to see the problem.

I assume that the expected behavior should be tested in an e2e test. I found this file where it could potentially be added.

@mariairiartef mariairiartef changed the title Add "Open in lens" in the same tab Apr 22, 2025
@mariairiartef mariairiartef added papercut Small "burr" in the product that we should fix. and removed papercut Small "burr" in the product that we should fix. labels Apr 22, 2025
@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

🟠 Some tests failed. - kibana-flaky-test-suite-runner#8203

[❌] x-pack/test/functional/apps/infra/config.ts: 99/100 tests passed.

see run history

@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

🟠 Some tests failed. - kibana-flaky-test-suite-runner#8206

[❌] x-pack/test/functional/apps/infra/config.ts: 49/75 tests passed.

see run history

Comment on lines +139 to +140
const menuElement = await testSubjects.find('presentationPanelContextMenuItems');
await menuElement.moveMouseTo();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tried to move away the mouse from the chart so the chart tooltip does not appear

@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

🟠 Some tests failed. - kibana-flaky-test-suite-runner#8208

[❌] x-pack/test/functional/apps/infra/config.ts: 24/50 tests passed.

see run history

@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

🟠 Some tests failed. - kibana-flaky-test-suite-runner#8210

[❌] x-pack/test/functional/apps/infra/config.ts: 24/50 tests passed.

see run history

@mariairiartef mariairiartef marked this pull request as ready for review April 23, 2025 15:50
@mariairiartef mariairiartef requested a review from a team April 23, 2025 15:50
@mariairiartef mariairiartef requested a review from a team as a code owner April 23, 2025 15:50
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-visualizations (Team:Visualizations)

Comment on lines +504 to +508
const mockMouseEvent = new MouseEvent('click') as unknown as React.MouseEvent;
// We need to make sure that the current target is a HTMLAnchorElement
Object.defineProperty(mockMouseEvent, 'currentTarget', {
value: document.createElement('a'),
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

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

@mariairiartef mariairiartef enabled auto-merge (squash) May 26, 2025 15:00
@mariairiartef mariairiartef merged commit ca1d622 into elastic:main May 26, 2025
10 checks passed
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

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
infra 1.1MB 1.1MB +181.0B

Page load bundle

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

id before after diff
uiActions 21.9KB 21.9KB +13.0B
Unknown metric groups

API count

id before after diff
uiActions 161 162 +1

History

cc @mariairiartef

@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label May 27, 2025
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 217528 locally
cc: @mariairiartef

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 217528 locally
cc: @mariairiartef

@mariairiartef mariairiartef added backport:version Backport to applied version labels and removed backport missing Added to PRs automatically when the are determined to be missing a backport. backport:version Backport to applied version labels labels May 29, 2025
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.19

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

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.19 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 217528

Questions ?

Please refer to the Backport tool documentation

akowalska622 pushed a commit to akowalska622/kibana that referenced this pull request May 29, 2025
## Summary

Closes elastic#204155

Adds support for the following behaviors:

1. Clicking "Open in Lens" opens the Lens editor in the same tab.
2. Using Command (or Ctrl if is not an apple device) + Click opens the
Lens editor in a new tab.

> [!NOTE]
> This is a temporary workaround until a more comprehensive solution,
which requires additional effort, is implemented.

### Details

The goal is that by clicking on the "Open in Lens" button, the Lens
editor is opened in the current tab, and by Command + Clicking, the Lens
editor is opened in a separate tab. Currently, the approach uses the
`navigateToPrefilledEditor` method, exposed by the Lens plugin, which is
called upon execution of the action.

Initially, the idea was to use the shortUrl service to generate a share
URL. This service generates an Elasticsearch object, which can be
excessive since the requirement doesn’t imply generating a URL that can
be shared.

With the current approach, the data is persisted because it is in the
session storage. That is why when we click on the button and it opens in
a new tab, you can see the data. However, if you copy the same URL to
another tab, nothing appears because there’s no data.

If we want to add an href by specifying the `getHref` method to the
action (as suggested
[here](elastic#204155 (comment)),
it won’t work as you cannot persist the data when you click on a link.

To maintain the requested behavior, we update the openInNewTab parameter
that is passed to the Lens `navigateToPrefilledEditor` method to be true
when it is a modified event or false when it is not.

## Checklist

- [ ] [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
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) 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](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
@markov00
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.19

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

Questions ?

Please refer to the Backport tool documentation

markov00 pushed a commit to markov00/kibana that referenced this pull request May 30, 2025
## Summary

Closes elastic#204155

Adds support for the following behaviors:

1. Clicking "Open in Lens" opens the Lens editor in the same tab.
2. Using Command (or Ctrl if is not an apple device) + Click opens the
Lens editor in a new tab.

> [!NOTE]
> This is a temporary workaround until a more comprehensive solution,
which requires additional effort, is implemented.

### Details

The goal is that by clicking on the "Open in Lens" button, the Lens
editor is opened in the current tab, and by Command + Clicking, the Lens
editor is opened in a separate tab. Currently, the approach uses the
`navigateToPrefilledEditor` method, exposed by the Lens plugin, which is
called upon execution of the action.

Initially, the idea was to use the shortUrl service to generate a share
URL. This service generates an Elasticsearch object, which can be
excessive since the requirement doesn’t imply generating a URL that can
be shared.

With the current approach, the data is persisted because it is in the
session storage. That is why when we click on the button and it opens in
a new tab, you can see the data. However, if you copy the same URL to
another tab, nothing appears because there’s no data.

If we want to add an href by specifying the `getHref` method to the
action (as suggested
[here](elastic#204155 (comment)),
it won’t work as you cannot persist the data when you click on a link.

To maintain the requested behavior, we update the openInNewTab parameter
that is passed to the Lens `navigateToPrefilledEditor` method to be true
when it is a modified event or false when it is not.

## Checklist

- [ ] [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
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) 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](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

(cherry picked from commit ca1d622)

# Conflicts:
#	x-pack/test/functional/apps/infra/hosts_view.ts
#	x-pack/test/functional/page_objects/infra_hosts_view.ts
@mariairiartef
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.19

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

Questions ?

Please refer to the Backport tool documentation

@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @mariairiartef

@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label May 30, 2025
@kibanamachine
Copy link
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.
cc: @mariairiartef

mariairiartef added a commit that referenced this pull request Jun 2, 2025
…222022)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[LensEmbeddable] Add "Open in lens" in the same tab
(#217528)](#217528)

<!--- Backport version: 10.0.0 -->

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

<!--BACKPORT [{"author":{"name":"Maria
Iriarte","email":"106958839+mariairiartef@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-05-26T16:25:56Z","message":"[LensEmbeddable]
Add \"Open in lens\" in the same tab (#217528)\n\n## Summary\n\nCloses
https://github.com/elastic/kibana/issues/204155\n\nAdds support for the
following behaviors:\n\n1. Clicking \"Open in Lens\" opens the Lens
editor in the same tab.\n2. Using Command (or Ctrl if is not an apple
device) + Click opens the\nLens editor in a new tab.\n\n> [!NOTE]\n>
This is a temporary workaround until a more comprehensive
solution,\nwhich requires additional effort, is implemented.\n\n###
Details\n\nThe goal is that by clicking on the \"Open in Lens\" button,
the Lens\neditor is opened in the current tab, and by Command +
Clicking, the Lens\neditor is opened in a separate tab. Currently, the
approach uses the\n`navigateToPrefilledEditor` method, exposed by the
Lens plugin, which is\ncalled upon execution of the
action.\n\nInitially, the idea was to use the shortUrl service to
generate a share\nURL. This service generates an Elasticsearch object,
which can be\nexcessive since the requirement doesn’t imply generating a
URL that can\nbe shared.\n\nWith the current approach, the data is
persisted because it is in the\nsession storage. That is why when we
click on the button and it opens in\na new tab, you can see the data.
However, if you copy the same URL to\nanother tab, nothing appears
because there’s no data.\n\nIf we want to add an href by specifying the
`getHref` method to the\naction (as
suggested\n[here](https://github.com/elastic/kibana/issues/204155#issuecomment-2578218129),\nit
won’t work as you cannot persist the data when you click on a
link.\n\nTo maintain the requested behavior, we update the openInNewTab
parameter\nthat is passed to the Lens `navigateToPrefilledEditor` method
to be true\nwhen it is a modified event or false when it is not.\n\n##
Checklist\n\n- [ ] [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- [ ] [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)","sha":"ca1d622ed0501b937490d56e16a7cf33c61cab09","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","Team:Visualizations","Feature:Lens","backport:version","v9.1.0","v8.19.0"],"title":"[LensEmbeddable]
Add \"Open in lens\" in the same
tab","number":217528,"url":"https://github.com/elastic/kibana/pull/217528","mergeCommit":{"message":"[LensEmbeddable]
Add \"Open in lens\" in the same tab (#217528)\n\n## Summary\n\nCloses
https://github.com/elastic/kibana/issues/204155\n\nAdds support for the
following behaviors:\n\n1. Clicking \"Open in Lens\" opens the Lens
editor in the same tab.\n2. Using Command (or Ctrl if is not an apple
device) + Click opens the\nLens editor in a new tab.\n\n> [!NOTE]\n>
This is a temporary workaround until a more comprehensive
solution,\nwhich requires additional effort, is implemented.\n\n###
Details\n\nThe goal is that by clicking on the \"Open in Lens\" button,
the Lens\neditor is opened in the current tab, and by Command +
Clicking, the Lens\neditor is opened in a separate tab. Currently, the
approach uses the\n`navigateToPrefilledEditor` method, exposed by the
Lens plugin, which is\ncalled upon execution of the
action.\n\nInitially, the idea was to use the shortUrl service to
generate a share\nURL. This service generates an Elasticsearch object,
which can be\nexcessive since the requirement doesn’t imply generating a
URL that can\nbe shared.\n\nWith the current approach, the data is
persisted because it is in the\nsession storage. That is why when we
click on the button and it opens in\na new tab, you can see the data.
However, if you copy the same URL to\nanother tab, nothing appears
because there’s no data.\n\nIf we want to add an href by specifying the
`getHref` method to the\naction (as
suggested\n[here](https://github.com/elastic/kibana/issues/204155#issuecomment-2578218129),\nit
won’t work as you cannot persist the data when you click on a
link.\n\nTo maintain the requested behavior, we update the openInNewTab
parameter\nthat is passed to the Lens `navigateToPrefilledEditor` method
to be true\nwhen it is a modified event or false when it is not.\n\n##
Checklist\n\n- [ ] [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- [ ] [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)","sha":"ca1d622ed0501b937490d56e16a7cf33c61cab09"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/217528","number":217528,"mergeCommit":{"message":"[LensEmbeddable]
Add \"Open in lens\" in the same tab (#217528)\n\n## Summary\n\nCloses
https://github.com/elastic/kibana/issues/204155\n\nAdds support for the
following behaviors:\n\n1. Clicking \"Open in Lens\" opens the Lens
editor in the same tab.\n2. Using Command (or Ctrl if is not an apple
device) + Click opens the\nLens editor in a new tab.\n\n> [!NOTE]\n>
This is a temporary workaround until a more comprehensive
solution,\nwhich requires additional effort, is implemented.\n\n###
Details\n\nThe goal is that by clicking on the \"Open in Lens\" button,
the Lens\neditor is opened in the current tab, and by Command +
Clicking, the Lens\neditor is opened in a separate tab. Currently, the
approach uses the\n`navigateToPrefilledEditor` method, exposed by the
Lens plugin, which is\ncalled upon execution of the
action.\n\nInitially, the idea was to use the shortUrl service to
generate a share\nURL. This service generates an Elasticsearch object,
which can be\nexcessive since the requirement doesn’t imply generating a
URL that can\nbe shared.\n\nWith the current approach, the data is
persisted because it is in the\nsession storage. That is why when we
click on the button and it opens in\na new tab, you can see the data.
However, if you copy the same URL to\nanother tab, nothing appears
because there’s no data.\n\nIf we want to add an href by specifying the
`getHref` method to the\naction (as
suggested\n[here](https://github.com/elastic/kibana/issues/204155#issuecomment-2578218129),\nit
won’t work as you cannot persist the data when you click on a
link.\n\nTo maintain the requested behavior, we update the openInNewTab
parameter\nthat is passed to the Lens `navigateToPrefilledEditor` method
to be true\nwhen it is a modified event or false when it is not.\n\n##
Checklist\n\n- [ ] [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- [ ] [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)","sha":"ca1d622ed0501b937490d56e16a7cf33c61cab09"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Jun 2, 2025
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 Feature:Lens release_note:enhancement Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// v8.19.0 v9.1.0

7 participants