Tempo: Fix sorting for nested tables (#87214)

This commit is contained in:
Fabrizio 2024-05-06 10:41:47 +02:00 committed by GitHub
parent 57038e8dfa
commit f99d4ee92d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 4 deletions

View File

@ -254,7 +254,9 @@ export const RowsList = (props: RowsListProps) => {
<ExpandedRow <ExpandedRow
nestedData={nestedDataField} nestedData={nestedDataField}
tableStyles={tableStyles} tableStyles={tableStyles}
rowIndex={index} // Using `row.index` ensures that we pick the correct row from the original data frame even when rows in
// the table are sorted, since `row.index` does not change when sorting.
rowIndex={row.index}
width={width} width={width}
cellHeight={cellHeight} cellHeight={cellHeight}
/> />
@ -298,7 +300,7 @@ export const RowsList = (props: RowsListProps) => {
const indexForPagination = rowIndexForPagination(index); const indexForPagination = rowIndexForPagination(index);
const row = rows[indexForPagination]; const row = rows[indexForPagination];
if (tableState.expanded[row.id] && nestedDataField) { if (tableState.expanded[row.id] && nestedDataField) {
return getExpandedRowHeight(nestedDataField, index, tableStyles); return getExpandedRowHeight(nestedDataField, row.index, tableStyles);
} }
return tableStyles.rowHeight; return tableStyles.rowHeight;

View File

@ -597,7 +597,7 @@ describe('Table', () => {
describe('when mounted with nested data', () => { describe('when mounted with nested data', () => {
beforeEach(() => { beforeEach(() => {
const nestedFrame = (idx: number) => const createNestedFrame = (idx: number) =>
applyOverrides( applyOverrides(
toDataFrame({ toDataFrame({
name: `nested_frame${idx}`, name: `nested_frame${idx}`,
@ -626,7 +626,10 @@ describe('Table', () => {
{ {
name: 'nested', name: 'nested',
type: FieldType.nestedFrames, type: FieldType.nestedFrames,
values: [[nestedFrame(0), nestedFrame(1)]], values: [
[createNestedFrame(0), createNestedFrame(1)],
[createNestedFrame(2), createNestedFrame(3)],
],
config: {}, config: {},
}, },
], ],