Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lens] Allow detaching from global time range #125563

Merged
merged 9 commits into from
Feb 21, 2022

Conversation

flash1293
Copy link
Contributor

@flash1293 flash1293 commented Feb 14, 2022

Fixes #123219
Fixes #118851

Kapture 2022-02-14 at 19 07 51

This PR adds the ability to not filter the field used for a date histogram by the global time range. As it's not possible to use the "auto" interval in this case (because it calculates the interval based on the selected time range), this option is only available as part of the "custom interval" part of the config UI.

Screenshot 2022-02-14 at 19 11 07

It's not possible to use this setting if the selected field of the date histogram operation is the default time field of the current data view because this filter is always applied (even if there is no date histogram).

The most important change on the xy chart is to read the time range from the data table column meta data instead of relying on data.timeRange - this is anyway necessary to get rid of lens multi table. The time range used for the data of a date histogram column is encoded in the column and returned via search.aggs.getDateHistogramMetaDataByDatatableColumn. This PR switches from data.timeRange to column meta data in all the places to determine the x domain.

Also, previously all charts would set the timeFieldName on the click and brush event handlers to the field of the column that got clicked. This caused the filter action to always update the global time range instead of creating a filter, but now that's not the right behavior anymore (as a date histogram column can be detached from the global time range). This PR fixes this by checking whether the clicked column is bound to a time range - if yes, the timeFieldName is set to the field of the column, otherwise it stays empty. As this logic is the same for all visualizations, it can be done at the root (on embeddable and editor side)

The logs data set is bad for testing this because while there are multiple time fields, they all contain the same dates.

In the ecommerce data set there's products.created_on and order_date which are the targeted use case:
Screenshot 2022-02-14 at 19 20 19

"Last 7 days" is selected in the top right (filtering by the default time field which is order_date), but the date histogram is done on the created_on field which is not filtered by the selected time range.

This switch is making Lens behave like Visualize in the context of applying filters based on the currently selected time range.

@flash1293 flash1293 added release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure Feature:Lens backport:skip This commit does not require backporting v8.2.0 labels Feb 14, 2022
@flash1293
Copy link
Contributor Author

@elasticmachine merge upstream

@flash1293 flash1293 marked this pull request as ready for review February 15, 2022 18:58
@flash1293 flash1293 requested a review from a team as a code owner February 15, 2022 18:58
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-vis-editors @elastic/kibana-vis-editors-external (Team:VisEditors)

@flash1293
Copy link
Contributor Author

@elasticmachine merge upstream

@stratoula
Copy link
Contributor

@elasticmachine merge upstream

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

This works great and I can't find any regression. On the contrary, this is a great enhancement 💯

@kibana-ci
Copy link
Collaborator

💚 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
expressionHeatmap 15.9KB 15.7KB -259.0B
lens 1.1MB 1.1MB +1.6KB
total +1.3KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@stratoula stratoula merged commit 1f60b7b into elastic:main Feb 21, 2022
academo pushed a commit to academo/kibana that referenced this pull request Feb 22, 2022
* allow detaching from global time range

* add test

* fix time field recognition

* fix tests

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
lucasfcosta pushed a commit to lucasfcosta/kibana that referenced this pull request Mar 2, 2022
* allow detaching from global time range

* add test

* fix time field recognition

* fix tests

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
academo added a commit that referenced this pull request Mar 3, 2022
* WIP

* WIP2

* Use new cases context hooks to open and close the flyout

* Update timelines to use new hooks

* CLose flyout on create success

* Add back sucess toast

* Move code to a dedicated component

* Add CasesContext to observability

* Remove dependency

* Small refactor

* Use observabilityAppId instead of observabilityFeatureId for buttons

* Add CasesContext to timetable

* Fix detection engine test cases

* Fix broken tests

* Fix broken tests

* Rename hook

* Add test cases for cases context ui

* Add test for new hook

* Remove state from the provider context

* Remove basevalue

* apply suggested renaming

* Add usecallback

* Add reducer types, fix test type, remove redundant check

* Accept attachments as a prop for the cases select modal

* Expose useCasesAddToExistingCase hook, reducer code and global component

* use the new hook to open the select cases modasl

* Fix tests and types

* Add tests for cases global components

* [Fleet] showing agent policy creation error message on UI (#125931)

* showing agent policy creation error message on UI

* mapping the error instead of showing from the backend

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* [ResponseOps] Adds tooltip to time window selector in ES query rule flyout (#125764)

* [Lens] Allow detaching from global time range (#125563)

* allow detaching from global time range

* add test

* fix time field recognition

* fix tests

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* [Fleet] refactor auto upgrade package policies logic (#125909)

* refactor upgrade package policies

* fixed tests

* code cleanup

* review improvements

* added api test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* skip flaky suite (#126027)

* Remove deprecated api (#125524)

* [Fleet] Remove deprecated kibana APIs - License

* Remove basePath from FleetApp

* Replace AsyncPlugin with Plugin

* Get fieldFormats from fieldFormats plugin rather than data plugin

* Fix ts errors

* Attempt fixing wrong type

* Move licenseService to FleetStartDeps

* Fix types and mocks

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* Upgrade `markdown-it` dependency (`10.0.0` → `12.3.2`). (#125526)

* skipping failing tests (#126039)

* remove unused deprecated code and use field format plugin directly for data view field editor (#126029)

* [data views] Improve preview pane (#126013)

* fix preview pane

* fix preview pane

* one less span tag

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* [Alerting] Provide services to set context for recovered alerts (#124972)

* Rename alert instance to alert and add create fn to alert factory

* Rename alert instance to alert and add create fn to alert factory

* Fixing types

* Fixing types

* Adding flag for rule types to opt into setting recovery context

* Only showing context in action variable menu if flag set to true

* Adding recovery functions to createAlertFactory

* Setting recovery in index threshold and fixing types

* Fixing lint issues and some refactoring

* Cleanup

* Functional tests for index threshold rule recovery context

* Return array of recovered alerts instead of record

* Fixing types

* Fixing types

* Cleanup

* Handling nulls and more tests

* Updating developer docs

* Making getRecoveryAlerts non-optional

* Setting unknown in index threshold recovery value

* PR feedback

* Adding a test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* [Discover] Re-introduce saved_searches test (#126059)

* [Archive Migration]  index pattern without timefield (#125870)

* kbn_archive date_nanos

* kbn_archive date_nanos in context and discover

* kbn_archiver more date_nanos tests

* split out kbnArchiver for index_pattern_without_timefield

* remove date_nanos files from a different PR

* update another test for usage of the same archives

* set default index pattern for test

* remove duplicate const kibanaServer

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* delete unused es_archive visualize_embedding (#126001)

* delete unused es_archive

* remove other unused es_archive

* more unused es_archives

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* Bump packages (#126119)

* url-parse 1.5.3 -> 1.5.9
* follow-redirects 1.y.z -> 1.14.9

* Add tests for all cases selector and attachments

* Add tests for use add to existing case hook

* First version of the cases timeline actions

* export add alert to new case button from cases plugin

* Make Cases ECS compatible with timelines and security_solution

* Delete new case button

* Add helpers

* Use the cases hook directly for add to new case

* Remov unused dependencies

* Rename callbacks, remove timelines calls

* Fixing tests for the dropdown

* Fix broken test

* mocking cases for tests

* Fix detectiosn tests

* Observability now uses the new cases hooks

* Wrap events viewer into cases context

* Open the create case flyout if create case was selected in the modal

* Fix cases mocks for security_solution

* Update tests

* Add tests for use cases toast

* Improve cases mock

* delete security mock

* replace tests mocks for cases

* fix import mock

* Do not require onRowClick

* Show the toast inside the modal

* show the toast inside the flyout

* remove toast logic from the consumer plugin

* fix typescript types

* Rename type

* Fix broken test

* Fix file name and broken test

* Use internal navigation hook

* Update hook dependencies

* Move useCaseToast

* Fix mock paths

* fix eslint

* Add test cases for the toast content

* Add cases context to the overview page

Co-authored-by: Julia Bardi <90178898+juliaElastic@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: István Zoltán Szabó <szabosteve@gmail.com>
Co-authored-by: Joe Reuter <johannes.reuter@elastic.co>
Co-authored-by: Tiago Costa <tiago.costa@elastic.co>
Co-authored-by: Cristina Amico <criamico@users.noreply.github.com>
Co-authored-by: Aleh Zasypkin <aleh.zasypkin@elastic.co>
Co-authored-by: Gloria Hornero <gloria.hornero@elastic.co>
Co-authored-by: Matthew Kime <matt@mattki.me>
Co-authored-by: Ying Mao <ying.mao@elastic.co>
Co-authored-by: Maja Grubic <maja.grubic@elastic.co>
Co-authored-by: Lee Drengenberg <lee.drengenberg@elastic.co>
Co-authored-by: Joe Portner <5295965+jportner@users.noreply.github.com>
lucasfcosta pushed a commit to lucasfcosta/kibana that referenced this pull request Mar 8, 2022
…#126265)

* WIP

* WIP2

* Use new cases context hooks to open and close the flyout

* Update timelines to use new hooks

* CLose flyout on create success

* Add back sucess toast

* Move code to a dedicated component

* Add CasesContext to observability

* Remove dependency

* Small refactor

* Use observabilityAppId instead of observabilityFeatureId for buttons

* Add CasesContext to timetable

* Fix detection engine test cases

* Fix broken tests

* Fix broken tests

* Rename hook

* Add test cases for cases context ui

* Add test for new hook

* Remove state from the provider context

* Remove basevalue

* apply suggested renaming

* Add usecallback

* Add reducer types, fix test type, remove redundant check

* Accept attachments as a prop for the cases select modal

* Expose useCasesAddToExistingCase hook, reducer code and global component

* use the new hook to open the select cases modasl

* Fix tests and types

* Add tests for cases global components

* [Fleet] showing agent policy creation error message on UI (elastic#125931)

* showing agent policy creation error message on UI

* mapping the error instead of showing from the backend

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* [ResponseOps] Adds tooltip to time window selector in ES query rule flyout (elastic#125764)

* [Lens] Allow detaching from global time range (elastic#125563)

* allow detaching from global time range

* add test

* fix time field recognition

* fix tests

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* [Fleet] refactor auto upgrade package policies logic (elastic#125909)

* refactor upgrade package policies

* fixed tests

* code cleanup

* review improvements

* added api test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* skip flaky suite (elastic#126027)

* Remove deprecated api (elastic#125524)

* [Fleet] Remove deprecated kibana APIs - License

* Remove basePath from FleetApp

* Replace AsyncPlugin with Plugin

* Get fieldFormats from fieldFormats plugin rather than data plugin

* Fix ts errors

* Attempt fixing wrong type

* Move licenseService to FleetStartDeps

* Fix types and mocks

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* Upgrade `markdown-it` dependency (`10.0.0` → `12.3.2`). (elastic#125526)

* skipping failing tests (elastic#126039)

* remove unused deprecated code and use field format plugin directly for data view field editor (elastic#126029)

* [data views] Improve preview pane (elastic#126013)

* fix preview pane

* fix preview pane

* one less span tag

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* [Alerting] Provide services to set context for recovered alerts (elastic#124972)

* Rename alert instance to alert and add create fn to alert factory

* Rename alert instance to alert and add create fn to alert factory

* Fixing types

* Fixing types

* Adding flag for rule types to opt into setting recovery context

* Only showing context in action variable menu if flag set to true

* Adding recovery functions to createAlertFactory

* Setting recovery in index threshold and fixing types

* Fixing lint issues and some refactoring

* Cleanup

* Functional tests for index threshold rule recovery context

* Return array of recovered alerts instead of record

* Fixing types

* Fixing types

* Cleanup

* Handling nulls and more tests

* Updating developer docs

* Making getRecoveryAlerts non-optional

* Setting unknown in index threshold recovery value

* PR feedback

* Adding a test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* [Discover] Re-introduce saved_searches test (elastic#126059)

* [Archive Migration]  index pattern without timefield (elastic#125870)

* kbn_archive date_nanos

* kbn_archive date_nanos in context and discover

* kbn_archiver more date_nanos tests

* split out kbnArchiver for index_pattern_without_timefield

* remove date_nanos files from a different PR

* update another test for usage of the same archives

* set default index pattern for test

* remove duplicate const kibanaServer

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* delete unused es_archive visualize_embedding (elastic#126001)

* delete unused es_archive

* remove other unused es_archive

* more unused es_archives

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* Bump packages (elastic#126119)

* url-parse 1.5.3 -> 1.5.9
* follow-redirects 1.y.z -> 1.14.9

* Add tests for all cases selector and attachments

* Add tests for use add to existing case hook

* First version of the cases timeline actions

* export add alert to new case button from cases plugin

* Make Cases ECS compatible with timelines and security_solution

* Delete new case button

* Add helpers

* Use the cases hook directly for add to new case

* Remov unused dependencies

* Rename callbacks, remove timelines calls

* Fixing tests for the dropdown

* Fix broken test

* mocking cases for tests

* Fix detectiosn tests

* Observability now uses the new cases hooks

* Wrap events viewer into cases context

* Open the create case flyout if create case was selected in the modal

* Fix cases mocks for security_solution

* Update tests

* Add tests for use cases toast

* Improve cases mock

* delete security mock

* replace tests mocks for cases

* fix import mock

* Do not require onRowClick

* Show the toast inside the modal

* show the toast inside the flyout

* remove toast logic from the consumer plugin

* fix typescript types

* Rename type

* Fix broken test

* Fix file name and broken test

* Use internal navigation hook

* Update hook dependencies

* Move useCaseToast

* Fix mock paths

* fix eslint

* Add test cases for the toast content

* Add cases context to the overview page

Co-authored-by: Julia Bardi <90178898+juliaElastic@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: István Zoltán Szabó <szabosteve@gmail.com>
Co-authored-by: Joe Reuter <johannes.reuter@elastic.co>
Co-authored-by: Tiago Costa <tiago.costa@elastic.co>
Co-authored-by: Cristina Amico <criamico@users.noreply.github.com>
Co-authored-by: Aleh Zasypkin <aleh.zasypkin@elastic.co>
Co-authored-by: Gloria Hornero <gloria.hornero@elastic.co>
Co-authored-by: Matthew Kime <matt@mattki.me>
Co-authored-by: Ying Mao <ying.mao@elastic.co>
Co-authored-by: Maja Grubic <maja.grubic@elastic.co>
Co-authored-by: Lee Drengenberg <lee.drengenberg@elastic.co>
Co-authored-by: Joe Portner <5295965+jportner@users.noreply.github.com>
lucasfcosta pushed a commit to lucasfcosta/kibana that referenced this pull request Mar 8, 2022
…#126265)

* WIP

* WIP2

* Use new cases context hooks to open and close the flyout

* Update timelines to use new hooks

* CLose flyout on create success

* Add back sucess toast

* Move code to a dedicated component

* Add CasesContext to observability

* Remove dependency

* Small refactor

* Use observabilityAppId instead of observabilityFeatureId for buttons

* Add CasesContext to timetable

* Fix detection engine test cases

* Fix broken tests

* Fix broken tests

* Rename hook

* Add test cases for cases context ui

* Add test for new hook

* Remove state from the provider context

* Remove basevalue

* apply suggested renaming

* Add usecallback

* Add reducer types, fix test type, remove redundant check

* Accept attachments as a prop for the cases select modal

* Expose useCasesAddToExistingCase hook, reducer code and global component

* use the new hook to open the select cases modasl

* Fix tests and types

* Add tests for cases global components

* [Fleet] showing agent policy creation error message on UI (elastic#125931)

* showing agent policy creation error message on UI

* mapping the error instead of showing from the backend

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* [ResponseOps] Adds tooltip to time window selector in ES query rule flyout (elastic#125764)

* [Lens] Allow detaching from global time range (elastic#125563)

* allow detaching from global time range

* add test

* fix time field recognition

* fix tests

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* [Fleet] refactor auto upgrade package policies logic (elastic#125909)

* refactor upgrade package policies

* fixed tests

* code cleanup

* review improvements

* added api test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* skip flaky suite (elastic#126027)

* Remove deprecated api (elastic#125524)

* [Fleet] Remove deprecated kibana APIs - License

* Remove basePath from FleetApp

* Replace AsyncPlugin with Plugin

* Get fieldFormats from fieldFormats plugin rather than data plugin

* Fix ts errors

* Attempt fixing wrong type

* Move licenseService to FleetStartDeps

* Fix types and mocks

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* Upgrade `markdown-it` dependency (`10.0.0` → `12.3.2`). (elastic#125526)

* skipping failing tests (elastic#126039)

* remove unused deprecated code and use field format plugin directly for data view field editor (elastic#126029)

* [data views] Improve preview pane (elastic#126013)

* fix preview pane

* fix preview pane

* one less span tag

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* [Alerting] Provide services to set context for recovered alerts (elastic#124972)

* Rename alert instance to alert and add create fn to alert factory

* Rename alert instance to alert and add create fn to alert factory

* Fixing types

* Fixing types

* Adding flag for rule types to opt into setting recovery context

* Only showing context in action variable menu if flag set to true

* Adding recovery functions to createAlertFactory

* Setting recovery in index threshold and fixing types

* Fixing lint issues and some refactoring

* Cleanup

* Functional tests for index threshold rule recovery context

* Return array of recovered alerts instead of record

* Fixing types

* Fixing types

* Cleanup

* Handling nulls and more tests

* Updating developer docs

* Making getRecoveryAlerts non-optional

* Setting unknown in index threshold recovery value

* PR feedback

* Adding a test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* [Discover] Re-introduce saved_searches test (elastic#126059)

* [Archive Migration]  index pattern without timefield (elastic#125870)

* kbn_archive date_nanos

* kbn_archive date_nanos in context and discover

* kbn_archiver more date_nanos tests

* split out kbnArchiver for index_pattern_without_timefield

* remove date_nanos files from a different PR

* update another test for usage of the same archives

* set default index pattern for test

* remove duplicate const kibanaServer

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* delete unused es_archive visualize_embedding (elastic#126001)

* delete unused es_archive

* remove other unused es_archive

* more unused es_archives

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* Bump packages (elastic#126119)

* url-parse 1.5.3 -> 1.5.9
* follow-redirects 1.y.z -> 1.14.9

* Add tests for all cases selector and attachments

* Add tests for use add to existing case hook

* First version of the cases timeline actions

* export add alert to new case button from cases plugin

* Make Cases ECS compatible with timelines and security_solution

* Delete new case button

* Add helpers

* Use the cases hook directly for add to new case

* Remov unused dependencies

* Rename callbacks, remove timelines calls

* Fixing tests for the dropdown

* Fix broken test

* mocking cases for tests

* Fix detectiosn tests

* Observability now uses the new cases hooks

* Wrap events viewer into cases context

* Open the create case flyout if create case was selected in the modal

* Fix cases mocks for security_solution

* Update tests

* Add tests for use cases toast

* Improve cases mock

* delete security mock

* replace tests mocks for cases

* fix import mock

* Do not require onRowClick

* Show the toast inside the modal

* show the toast inside the flyout

* remove toast logic from the consumer plugin

* fix typescript types

* Rename type

* Fix broken test

* Fix file name and broken test

* Use internal navigation hook

* Update hook dependencies

* Move useCaseToast

* Fix mock paths

* fix eslint

* Add test cases for the toast content

* Add cases context to the overview page

Co-authored-by: Julia Bardi <90178898+juliaElastic@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: István Zoltán Szabó <szabosteve@gmail.com>
Co-authored-by: Joe Reuter <johannes.reuter@elastic.co>
Co-authored-by: Tiago Costa <tiago.costa@elastic.co>
Co-authored-by: Cristina Amico <criamico@users.noreply.github.com>
Co-authored-by: Aleh Zasypkin <aleh.zasypkin@elastic.co>
Co-authored-by: Gloria Hornero <gloria.hornero@elastic.co>
Co-authored-by: Matthew Kime <matt@mattki.me>
Co-authored-by: Ying Mao <ying.mao@elastic.co>
Co-authored-by: Maja Grubic <maja.grubic@elastic.co>
Co-authored-by: Lee Drengenberg <lee.drengenberg@elastic.co>
Co-authored-by: Joe Portner <5295965+jportner@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 commit does not require backporting Feature:Lens release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.2.0
Projects
None yet
5 participants