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
nestedData={nestedDataField}
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}
cellHeight={cellHeight}
/>
@ -298,7 +300,7 @@ export const RowsList = (props: RowsListProps) => {
const indexForPagination = rowIndexForPagination(index);
const row = rows[indexForPagination];
if (tableState.expanded[row.id] && nestedDataField) {
return getExpandedRowHeight(nestedDataField, index, tableStyles);
return getExpandedRowHeight(nestedDataField, row.index, tableStyles);
}
return tableStyles.rowHeight;

View File

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