Skip to content

[Discover] Fix legacy sort saved search stored in dashboard saved objects#137488

Merged
kertal merged 23 commits into
elastic:mainfrom
kertal:discover-refactor-sort-functions
Aug 23, 2022
Merged

[Discover] Fix legacy sort saved search stored in dashboard saved objects#137488
kertal merged 23 commits into
elastic:mainfrom
kertal:discover-refactor-sort-functions

Conversation

@kertal
Copy link
Copy Markdown
Member

@kertal kertal commented Jul 28, 2022

Summary

This PR fixes the handling of legacy sort URL stored in Dashboards. Those URLs are automatically migrated on the fly like it works in main Discover.

It contains a refactoring migrating sort functions from public/components/doc_table/utils to public/utils, away from classic table, since it was already shared among different parts of our plugin.
Those functions now are also used in a better way in our embeddable code, centralizing handling of the sort property of state and its usage in data fetching. This change fixes the bug.

Fixes #81559

Testing

  • Create a dashboard with a single saved search
  • Goto Saved Objects, export this dashboard, related objects are not needed
  • Edit the dashboard locally, search for sort, it could look like this.
    "sort\":[[\"taxful_total_price\",\"asc\"],[\"order_date\",\"desc\"]],
    Legacy sort wasn't an array of arrays, but a single array containing the property to sort by, and the direction, so it needs to be changed like this
    "sort\":[\"taxful_total_price\",\"asc\"],
  • Save the change and upload it again
  • Now it should be sorted by this single field correctly

Checklist

@kertal kertal self-assigned this Jul 29, 2022
@kertal kertal added Feature:Discover Discover Application Team:DataDiscovery Discover, search (data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. t// release_note:fix backport:skip This PR does not require backporting labels Jul 29, 2022
@kertal kertal marked this pull request as ready for review July 29, 2022 13:35
@kertal kertal requested a review from a team as a code owner July 29, 2022 13:35
@elasticmachine
Copy link
Copy Markdown
Contributor

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

@kertal kertal changed the title [Discover] Refactor sort functionality [Discover] Fix legacy sort saved search URLs in Discover Jul 29, 2022
@kertal
Copy link
Copy Markdown
Member Author

kertal commented Aug 1, 2022

@elasticmachine merge upstream

Copy link
Copy Markdown
Contributor

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

Nice refactoring! 🙂
Left some questions.

Comment thread src/plugins/discover/public/types.ts Outdated
Comment thread src/plugins/discover/public/utils/get_sort.ts Outdated
Comment thread src/plugins/discover/public/embeddable/saved_search_embeddable.tsx Outdated
@kertal
Copy link
Copy Markdown
Member Author

kertal commented Aug 8, 2022

@elasticmachine merge upstream

@kertal kertal requested a review from jughosta August 8, 2022 05:53
@kertal kertal changed the title [Discover] Fix legacy sort saved search URLs in Discover [Discover] Fix legacy sort saved search stored in dashboard saved objects Aug 8, 2022
this.services.core.uiSettings
).columns;
searchProps.sort = this.getSort(
this.input.sort || this.savedSearch.sort,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for fixing this case!

I noticed one weird thing when a saved search configuration on Dashboard has legacy format for a column "sort":["extension","desc"]. It replaces the current sorting setting when trying to add another sort criteria on Dashboard (on Discover pages it works as expected)

Aug-08-2022 10-39-45
Aug-08-2022 10-41-54

Is it something we can improve?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

definitely! another good catch 🎣 ! thx!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this is interesting, because it worked for me locally ... maybe you could export the dashboard saved object and send it to me so I could reproduce? many thx!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

thx for the saved object! So the problem here is that extension is a field that's not sortable, extension.keyword is sortable. when changing the sort, this field is removed from sorting (sorted out 😃). Since the sorting state of the UI can only be changed with manually tweaking the saved search, I think we're safe here. However there might be a potential follow up taking care of the behavior in Discover, which seems to work differently in this case.

@kertal kertal requested a review from jughosta August 10, 2022 15:03
@kertal
Copy link
Copy Markdown
Member Author

kertal commented Aug 11, 2022

@elasticmachine merge upstream

Copy link
Copy Markdown
Contributor

@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 fixing this old issue and for the refactoring! LGTM 👍

@jughosta
Copy link
Copy Markdown
Contributor

We merge it after #138388, right?

@kertal
Copy link
Copy Markdown
Member Author

kertal commented Aug 22, 2022

@elasticmachine merge upstream

@kibana-ci
Copy link
Copy Markdown

💚 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
discover 462.7KB 462.3KB -434.0B

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
discover 5 4 -1

History

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

cc @kertal

@kertal kertal merged commit 1a213bd into elastic:main Aug 23, 2022
Mpdreamz pushed a commit to Mpdreamz/kibana that referenced this pull request Sep 6, 2022
patrykkopycinski pushed a commit to patrykkopycinski/kibana that referenced this pull request May 6, 2026
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 release_note:fix Team:DataDiscovery Discover, search (data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. t// v8.5.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Saved search sort order is ignored for embeddable config with 1-dimensional sort array

5 participants