[Enhancement] Sort datasets alphabetically in dataset pickers#12267
[Enhancement] Sort datasets alphabetically in dataset pickers#12267Maosaic wants to merge 1 commit into
Conversation
Sort datasets alphabetically in the Explore (DatasetSelect) and Discover (DatasetSelector) pickers, which previously rendered datasets in the order returned by the saved-objects query. - Explore dropdown: sort options by displayed label (displayName || title) - Explore "View datasets" modal: sort the list by displayName || title - Discover dropdown: sort the "Index patterns" group by full label (dataSource.title::name); the "Recently selected" group keeps recency order All comparisons are case-insensitive (localeCompare, sensitivity: 'base'). Adds a test asserting the View datasets modal renders rows alphabetically. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Joey Liu <jiyili@amazon.com>
| ); | ||
| if (sort) { | ||
| datasetOptions.sort((a, b) => | ||
| a.label.localeCompare(b.label, undefined, { sensitivity: 'base' }) |
There was a problem hiding this comment.
Inconsistent sort key between the two pickers. Here in buildDatasetOptions the sort is on a.label, which is ${dataSource.title}::${displayLabel} when a data source is present — so datasets get ordered by data-source prefix first, then display name. By contrast, ViewDatasetsModal (in dataset_select.tsx) sorts purely on displayName || title.
The PR title says "by display name," so this divergence is a little surprising. Two questions:
- Is the data-source-prefix-first ordering here intentional (i.e., group by cluster)?
- If the goal is true display-name ordering in both places, consider sorting on
displayName || titlerather than the prefixedlabel.
Either way is fine — just want the behavior to be deliberate and consistent across both pickers (and ideally noted in the description).
There was a problem hiding this comment.
Good catch, and thanks for the detailed read. The divergence is intentional:
- Yes, the data-source-prefix-first ordering in Discover is deliberate. Discover's option
labelis the prefixed string (dataSource.title::name), so sorting onlabelgroups datasets by cluster, then by name — which is the intended grouping for Discover's multi-cluster list. - Explore is different by design: it renders the data source in a subtitle rather than the label, so its label (and sort key) is just
displayName || title. That's whyViewDatasetsModaland the Explore dropdown sort purely on the display name.
So the two pickers sort on different keys because their labels are constructed differently. I've updated the PR description to spell this out explicitly so the behavior is documented and unambiguous. Let me know if you'd prefer both pickers to use pure display-name ordering instead — happy to switch Discover to sort on displayName || title if cross-picker consistency is preferred over cluster grouping.
Description
The dataset pickers in both the Explore (
DatasetSelect) and Discover (DatasetSelector) plugins previously rendered datasets in whatever order the saved-objectsfindquery returned them (nosortFieldis passed, so effectively backend/relevance order — not alphabetical). This makes datasets hard to scan as the list grows.This PR sorts datasets alphabetically across all three surfaces. All comparisons are case-insensitive (
localeComparewithsensitivity: 'base').Sort keys (intentionally differ per picker)
The two pickers sort on different keys by design, because their option labels are constructed differently:
displayName || title. Explore renders the data source in a subtitle, not in the label, so the sort key is just the name. (The modal sorts a copy so thedatasetsprop isn't mutated.)dataSource.title::name, and we sort on that full label. The effect is that datasets are grouped by data source first, then by name — the intended grouping for Discover's multi-cluster list. The Recently selected group intentionally keeps its recency order (only the Index patterns group is sorted).In short: Explore orders purely by display name; Discover orders by data-source-prefixed label (cluster-grouped). This divergence is deliberate and matches how each picker presents the data source.
Issues Resolved
N/A
Testing
yarn test:jest src/plugins/data/public/ui/dataset_select/dataset_select.test.tsx— 29 passed, 1 skipped.yarn test:jest src/plugins/data/public/ui/dataset_selector/dataset_selector.test.tsx— 3 passed.Check List
--signoff🤖 Generated with Claude Code