-
Notifications
You must be signed in to change notification settings - Fork 17.6k
feat(chart): add server-side column sorting for table and drill-detail views #40907
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1305,6 +1305,18 @@ export default function TableChart<D extends DataRecord = DataRecord>( | |
| } | ||
| }} | ||
| role="columnheader button" | ||
| // Expose sort state to assistive technology. Only | ||
| // sortable headers advertise aria-sort; the value tracks the | ||
| // ascending/descending/none cycle rendered by <SortIcon>. | ||
| aria-sort={ | ||
| col.canSort | ||
| ? col.isSorted | ||
| ? col.isSortedDesc | ||
| ? 'descending' | ||
| : 'ascending' | ||
| : 'none' | ||
| : undefined | ||
| } | ||
| onClick={onClick} | ||
| data-column-name={col.id} | ||
| {...(allowRearrangeColumns && { | ||
|
|
@@ -1524,10 +1536,13 @@ export default function TableChart<D extends DataRecord = DataRecord>( | |
| const modifiedOwnState = { | ||
| ...serverPaginationData, | ||
| sortBy, | ||
| // Changing the sort re-queries the full dataset, so the | ||
| // previous page offset is meaningless — return to the first page. | ||
| currentPage: 0, | ||
| }; | ||
| updateTableOwnState(setDataMask, modifiedOwnState); | ||
| }, | ||
| [serverPagination, serverPaginationData, setDataMask], | ||
| [serverPaginationData, setDataMask], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The callback dependency list is incomplete: it reads Severity Level: Major
|
||
| ); | ||
|
|
||
| const handleSearch = (searchText: string) => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,13 +128,18 @@ const buildQuery: BuildQuery<TableChartFormData> = ( | |
|
|
||
| if (queryMode === QueryMode.Aggregate) { | ||
| metrics = metrics || []; | ||
| // override orderby with timeseries metric when in aggregation mode | ||
| if (sortByMetric) { | ||
| orderby = [[sortByMetric, !orderDesc]]; | ||
| } else if (metrics?.length > 0) { | ||
| // default to ordering by first metric in descending order | ||
| // when no "sort by" metric is set (regardless if "SORT DESC" is set to true) | ||
| orderby = [[metrics[0], false]]; | ||
| // Fall back to a metric-based default sort only when no explicit orderby | ||
| // was supplied (e.g. a column sort from the "View as table" results pane). | ||
| // An explicit orderby from form data takes precedence. | ||
| if (orderby.length === 0) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing test coverage for orderby logic
The new Code Review Run #0a5875 Should Bito avoid suggestions like this for future reviews? (Manage Rules)
|
||
| // override orderby with timeseries metric when in aggregation mode | ||
| if (sortByMetric) { | ||
| orderby = [[sortByMetric, !orderDesc]]; | ||
| } else if (metrics?.length > 0) { | ||
| // default to ordering by first metric in descending order | ||
| // when no "sort by" metric is set (regardless if "SORT DESC" is set to true) | ||
| orderby = [[metrics[0], false]]; | ||
| } | ||
| } | ||
| // add postprocessing for percent metrics only when in aggregation mode | ||
| type PercentMetricCalculationMode = 'row_limit' | 'all_records'; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,4 +59,12 @@ export interface TableProps<RecordType> { | |
| usePagination?: boolean; | ||
|
|
||
| striped?: boolean; | ||
|
|
||
| /** | ||
| * Called when the sort state changes, with it translated to a query | ||
| * `orderby` (`[[columnId, isAscending]]`) so the consumer can re-request | ||
| * server-sorted data. Only the primary sort column is included, matching the | ||
| * chart data API's single-column sort constraint. | ||
| */ | ||
|
Comment on lines
+63
to
+68
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doc/impl mismatch on multi-column sort
Update the JSDoc for Code Review Run #0a5875 Should Bito avoid suggestions like this for future reviews? (Manage Rules)
Comment on lines
+63
to
+68
|
||
| onServerSort?: (orderby: [string, boolean][]) => void; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new guard
if (orderby.length === 0)correctly prevents overriding explicit orderby from form data. However, no test covers this scenario — existing tests usebasicFormDatawithout explicit orderby. Add a test withorderby: [['state', true]]alongsidesortByMetricto verify the explicit orderby is preserved.Code Review Run #0a5875
Should Bito avoid suggestions like this for future reviews? (Manage Rules)