diff --git a/.changeset/fix-row-details-id-where.md b/.changeset/fix-row-details-id-where.md new file mode 100644 index 0000000000..8d339eb024 --- /dev/null +++ b/.changeset/fix-row-details-id-where.md @@ -0,0 +1,5 @@ +--- +'@hyperdx/app': patch +--- + +Fix expanding a row on tables with a string `id` column: row details now keep the internal WHERE-clause id instead of being overwritten by the raw column value (#3370) diff --git a/packages/app/src/components/DBRowTable.tsx b/packages/app/src/components/DBRowTable.tsx index 29c5016588..6e5885b4a8 100644 --- a/packages/app/src/components/DBRowTable.tsx +++ b/packages/app/src/components/DBRowTable.tsx @@ -1363,10 +1363,10 @@ export const RawLogTable = memo( canOpenSidePanel={canOpenSidePanel} > {renderRowDetails?.({ + ...row.original, id: rowId, aliasWith: row.original[INTERNAL_ROW_FIELDS.ALIAS_WITH], - ...row.original, })} )} diff --git a/packages/app/src/components/__tests__/DBRowTable.test.tsx b/packages/app/src/components/__tests__/DBRowTable.test.tsx index c4cf31d189..61730b121e 100644 --- a/packages/app/src/components/__tests__/DBRowTable.test.tsx +++ b/packages/app/src/components/__tests__/DBRowTable.test.tsx @@ -11,7 +11,7 @@ import { useConfigWithAdditionalSelect, } from '@/components/DBRowTable'; import * as useChartConfigModule from '@/hooks/useChartConfig'; -import { RowWhereResult } from '@/hooks/useRowWhere'; +import { RowWhereResult, WithClause } from '@/hooks/useRowWhere'; import { RowClickAction, UserPreferences } from '@/useUserPreferences'; const mockSetQueryState = jest.fn(); @@ -392,6 +392,41 @@ describe('RawLogTable', () => { expect(mockSetQueryState).toHaveBeenCalledWith('rowWhere', ROW_ID); }); + // A table with its own `id` column must not overwrite the WHERE clause the + // expanded row queries with (#3370). + it('passes the row where clause to row details when the row has an id column', async () => { + const aliasWith: WithClause[] = [ + { + name: 'body', + sql: { sql: 'Body', params: {} }, + isSubquery: false, + }, + ]; + const renderRowDetails = jest.fn(() =>
row details
); + + renderTable( + ({ where: ROW_ID, aliasWith })} + renderRowDetails={renderRowDetails} + onRowDetailsClick={() => {}} + />, + 'expand', + ); + + await userEvent.click( + await screen.findByRole('button', { name: 'Expand log row' }), + ); + + await screen.findByTestId(`expanded-row-${ROW_ID}`); + expect(renderRowDetails).toHaveBeenLastCalledWith( + expect.objectContaining({ id: ROW_ID, aliasWith, col1: 'value1' }), + ); + }); + it('collapses an expanded row when its body is clicked again', async () => { renderTable( {}} />,