diff --git a/.changeset/chart-table-edited-order-by.md b/.changeset/chart-table-edited-order-by.md new file mode 100644 index 0000000000..e1072d8094 --- /dev/null +++ b/.changeset/chart-table-edited-order-by.md @@ -0,0 +1,5 @@ +--- +'@hyperdx/app': patch +--- + +fix: run an edited Order By on a chart table instead of the last column header sort diff --git a/packages/app/src/__tests__/utils.test.ts b/packages/app/src/__tests__/utils.test.ts index 42fceb36d9..c92427366a 100644 --- a/packages/app/src/__tests__/utils.test.ts +++ b/packages/app/src/__tests__/utils.test.ts @@ -6,7 +6,6 @@ import { TLogSource, TSource, } from '@hyperdx/common-utils/dist/types'; -import { SortingState } from '@tanstack/react-table'; import { act, renderHook } from '@testing-library/react'; import { MetricsDataType, NumberFormat } from '@/types'; @@ -29,10 +28,8 @@ import { mapKeyBy, mergePath, orderByAfterRemovingSelectItem, - orderByStringToSortingState, parseTimestampToMs, resolveConditionalColor, - sortingStateToOrderByString, stripTrailingSlash, useQueryHistory, withMapKeyAlias, @@ -1209,99 +1206,6 @@ describe('useQueryHistory', () => { }); }); -describe('sortingStateToOrderByString', () => { - it('returns undefined for null input', () => { - expect(sortingStateToOrderByString(null)).toBeUndefined(); - }); - - it('returns undefined for empty array', () => { - const sortingState: SortingState = []; - expect(sortingStateToOrderByString(sortingState)).toBeUndefined(); - }); - - it('converts sorting state with desc: false to ASC order', () => { - const sortingState: SortingState = [{ id: 'timestamp', desc: false }]; - expect(sortingStateToOrderByString(sortingState)).toBe('timestamp ASC'); - }); - - it('converts sorting state with desc: true to DESC order', () => { - const sortingState: SortingState = [{ id: 'timestamp', desc: true }]; - expect(sortingStateToOrderByString(sortingState)).toBe('timestamp DESC'); - }); - - it('handles column names with special characters', () => { - const sortingState: SortingState = [{ id: 'user_count', desc: false }]; - expect(sortingStateToOrderByString(sortingState)).toBe('user_count ASC'); - }); -}); - -describe('orderByStringToSortingState', () => { - it('returns undefined for undefined input', () => { - expect(orderByStringToSortingState(undefined)).toBeUndefined(); - }); - - it('returns undefined for empty string', () => { - expect(orderByStringToSortingState('')).toBeUndefined(); - }); - - it('converts "column ASC" to sorting state with desc: false', () => { - const result = orderByStringToSortingState('timestamp ASC'); - expect(result).toEqual([{ id: 'timestamp', desc: false }]); - }); - - it('converts "column DESC" to sorting state with desc: true', () => { - const result = orderByStringToSortingState('timestamp DESC'); - expect(result).toEqual([{ id: 'timestamp', desc: true }]); - }); - - it('handles case insensitive direction keywords', () => { - expect(orderByStringToSortingState('col asc')).toEqual([ - { id: 'col', desc: false }, - ]); - expect(orderByStringToSortingState('col Asc')).toEqual([ - { id: 'col', desc: false }, - ]); - expect(orderByStringToSortingState('col desc')).toEqual([ - { id: 'col', desc: true }, - ]); - expect(orderByStringToSortingState('col Desc')).toEqual([ - { id: 'col', desc: true }, - ]); - expect(orderByStringToSortingState('col DESC')).toEqual([ - { id: 'col', desc: true }, - ]); - }); - - it('returns undefined for invalid format without direction', () => { - expect(orderByStringToSortingState('timestamp')).toBeUndefined(); - }); - - it('returns undefined for invalid format with wrong number of parts', () => { - expect(orderByStringToSortingState('col name ASC')).toBeUndefined(); - }); - - it('returns undefined for invalid direction keyword', () => { - expect(orderByStringToSortingState('col INVALID')).toBeUndefined(); - }); - - it('handles column names with underscores', () => { - const result = orderByStringToSortingState('user_count DESC'); - expect(result).toEqual([{ id: 'user_count', desc: true }]); - }); - - it('handles column names with numbers', () => { - const result = orderByStringToSortingState('col123 ASC'); - expect(result).toEqual([{ id: 'col123', desc: false }]); - }); - - it('round-trips correctly with sortingStateToOrderByString', () => { - const originalSort: SortingState = [{ id: 'service_name', desc: true }]; - const orderByString = sortingStateToOrderByString(originalSort); - const roundTripSort = orderByStringToSortingState(orderByString); - expect(roundTripSort).toEqual(originalSort); - }); -}); - describe('mapKeyBy', () => { it('returns a map', () => { const result = mapKeyBy([{ id: 'a' }, { id: 'b' }], 'id'); diff --git a/packages/app/src/components/DBEditTimeChartForm/ChartPreviewPanel.tsx b/packages/app/src/components/DBEditTimeChartForm/ChartPreviewPanel.tsx index a061b8811a..737d3cc26e 100644 --- a/packages/app/src/components/DBEditTimeChartForm/ChartPreviewPanel.tsx +++ b/packages/app/src/components/DBEditTimeChartForm/ChartPreviewPanel.tsx @@ -48,16 +48,14 @@ import { isSingleExpression, useSource, } from '@/source'; -import { - orderByStringToSortingState, - sortingStateToOrderByString, -} from '@/utils'; import { QueryPreviewAccordion } from './QueryPreviewAccordion'; import { buildRenderedPromqlExpression, buildSampleEventsConfig, isQueryReady, + orderByToTableSortState, + tableSortStateToOrderBy, tabQueriesData, } from './utils'; @@ -228,7 +226,7 @@ export function ChartPreviewPanel({ const onTableSortingChange = useCallback( (sortState: SortingState | null) => { - setValue('orderBy', sortingStateToOrderByString(sortState) ?? ''); + setValue('orderBy', tableSortStateToOrderBy(sortState)); onSubmit(); }, [setValue, onSubmit], @@ -240,8 +238,8 @@ export function ChartPreviewPanel({ isBuilderChartConfig(queriedConfig) && queriedConfig.orderBy && typeof queriedConfig.orderBy === 'string' - ? orderByStringToSortingState(queriedConfig.orderBy) - : undefined, + ? orderByToTableSortState(queriedConfig.orderBy) + : [], [queriedConfig], ); diff --git a/packages/app/src/components/DBEditTimeChartForm/__tests__/utils.test.ts b/packages/app/src/components/DBEditTimeChartForm/__tests__/utils.test.ts index 6635957e58..4493e5466a 100644 --- a/packages/app/src/components/DBEditTimeChartForm/__tests__/utils.test.ts +++ b/packages/app/src/components/DBEditTimeChartForm/__tests__/utils.test.ts @@ -21,9 +21,11 @@ import { displayTypeToActiveTab, getPreviewBlockingFilters, isQueryReady, + orderByToTableSortState, resolvePreviewVariables, resolveTilePreviewFilters, seriesToFilters, + tableSortStateToOrderBy, tabQueriesData, TABS_WITH_GENERATED_SQL, withBroadcastFilters, @@ -1353,3 +1355,49 @@ describe('buildGroupByConnectionProps', () => { expect(result).toEqual({ tableConnection }); }); }); + +describe('table sort state <-> Order By', () => { + it.each([ + ['"duration min" ASC', { id: '"duration min"', desc: false }], + [ + 'round(Duration / 1e6, 2) DESC', + { id: 'round(Duration / 1e6, 2)', desc: true }, + ], + ['Duration desc', { id: 'Duration', desc: true }], + [ + '(TimestampTime, Timestamp) DESC', + { id: '(TimestampTime, Timestamp)', desc: true }, + ], + ['"a, b" ASC', { id: '"a, b"', desc: false }], + [ + "arrayElement(Attributes, 'k') DESC", + { id: "arrayElement(Attributes, 'k')", desc: true }, + ], + ])('parses %s and serializes it back', (orderBy, expected) => { + const sort = orderByToTableSortState(orderBy); + expect(sort).toEqual([expected]); + expect(tableSortStateToOrderBy(sort)).toBe( + orderBy.replace(/desc$/, 'DESC'), + ); + }); + + it.each([ + '', + ' ', + 'Duration', + '(TimestampTime, Timestamp)', + 'Duration DESC NULLS LAST', + 'Timestamp DESC, ServiceName ASC', + 'TimestampTime ASC, Timestamp DESC', + ])( + 'returns an empty sort for an Order By that is not a single key with a trailing direction (%p)', + orderBy => { + expect(orderByToTableSortState(orderBy)).toEqual([]); + }, + ); + + it('serializes an empty or null sort as an empty Order By', () => { + expect(tableSortStateToOrderBy([])).toBe(''); + expect(tableSortStateToOrderBy(null)).toBe(''); + }); +}); diff --git a/packages/app/src/components/DBEditTimeChartForm/utils.ts b/packages/app/src/components/DBEditTimeChartForm/utils.ts index 4ee56423ed..06891aa779 100644 --- a/packages/app/src/components/DBEditTimeChartForm/utils.ts +++ b/packages/app/src/components/DBEditTimeChartForm/utils.ts @@ -7,7 +7,10 @@ import { displayTypeSupportsReducer, getQueriedPromqlSeries, } from '@hyperdx/common-utils/dist/core/promql'; -import { isTimeSeriesDisplayType } from '@hyperdx/common-utils/dist/core/utils'; +import { + isTimeSeriesDisplayType, + splitAndTrimWithBracket, +} from '@hyperdx/common-utils/dist/core/utils'; import { configConsumesBroadcastFilters, getBlockingRequiredFilters, @@ -44,6 +47,7 @@ import { validateAlertScheduleOffsetMinutes, } from '@hyperdx/common-utils/dist/types'; import { filterReferencedVariables } from '@hyperdx/common-utils/dist/variables'; +import type { SortingState } from '@tanstack/react-table'; import { convertToCategoricalChartConfig, @@ -66,6 +70,7 @@ import { extendDateRangeToInterval, intervalToGranularity, } from '@/utils/alerts'; +import { parseAsSortingStateString } from '@/utils/queryParsers'; export const isQueryReady = ( queriedConfig: ChartConfigWithDateRange | undefined, @@ -610,3 +615,22 @@ export function buildGroupByConnectionProps({ ? { tableConnections: connections, intersectFields: true } : { tableConnection }; } + +/** + * Sort state for the preview table's headers. An Order By that doesn't parse + * (no trailing direction, trailing modifiers, empty, more than one key) yields + * `[]` rather than `undefined`, so DBTableChart doesn't fall back to a stale + * header sort and the typed Order By is queried as written. + */ +export function orderByToTableSortState(orderBy: string): SortingState { + // The parser would read `a DESC, b ASC` as one key with the last direction, + // and pagination takes its time direction from that, not from `a DESC`. + if (splitAndTrimWithBracket(orderBy).length > 1) return []; + const sort = parseAsSortingStateString.parse(orderBy); + return sort ? [sort] : []; +} + +export function tableSortStateToOrderBy(sort: SortingState | null): string { + const first = sort?.at(0); + return first ? parseAsSortingStateString.serialize(first) : ''; +} diff --git a/packages/app/src/components/DBTableChart.tsx b/packages/app/src/components/DBTableChart.tsx index 028a6cae13..d2e9fa4226 100644 --- a/packages/app/src/components/DBTableChart.tsx +++ b/packages/app/src/components/DBTableChart.tsx @@ -76,6 +76,18 @@ export default function DBTableChart({ }) { const [sort, setSort] = useState([]); + // A header sort only overrides the Order By it was clicked against. Clear it + // when the config's own Order By changes (e.g. the tile was edited), so it + // can't come back if the Order By is later changed back. + const configOrderByKey = JSON.stringify( + isBuilderChartConfig(config) ? (config.orderBy ?? null) : null, + ); + const [sortOrderByKey, setSortOrderByKey] = useState(configOrderByKey); + if (sortOrderByKey !== configOrderByKey) { + setSortOrderByKey(configOrderByKey); + setSort([]); + } + const { data: source } = useSource({ id: config.source, }); diff --git a/packages/app/src/components/__tests__/DBTableChart.test.tsx b/packages/app/src/components/__tests__/DBTableChart.test.tsx index 06ebdba068..304659972a 100644 --- a/packages/app/src/components/__tests__/DBTableChart.test.tsx +++ b/packages/app/src/components/__tests__/DBTableChart.test.tsx @@ -1,4 +1,6 @@ import React from 'react'; +import { isBuilderChartConfig } from '@hyperdx/common-utils/dist/guards'; +import { act } from '@testing-library/react'; import DateRangeIndicator from '@/components/charts/DateRangeIndicator'; import DBTableChart from '@/components/DBTableChart'; @@ -617,6 +619,73 @@ describe('DBTableChart', () => { }); }); + describe('header sort without a controlled sort prop', () => { + const queriedOrderBy = () => { + const config = jest.mocked(useOffsetPaginatedQuery).mock.calls.at(-1)![0]; + return isBuilderChartConfig(config) ? config.orderBy : undefined; + }; + const clickHeaderSort = () => + act(() => { + jest + .mocked(Table) + .mock.calls.at(-1)![0] + .onSortingChange?.([{ id: 'ServiceName', desc: false }]); + }); + const headerSortOrderBy = [ + { valueExpression: 'ServiceName', ordering: 'ASC' }, + ]; + + it('overrides the config Order By while it is unchanged', () => { + const config = { ...baseTestConfig, orderBy: 'Duration DESC' }; + const { rerender } = renderWithMantine(); + clickHeaderSort(); + expect(queriedOrderBy()).toEqual(headerSortOrderBy); + + rerender( + + + , + ); + expect(queriedOrderBy()).toEqual(headerSortOrderBy); + }); + + it('is dropped when the config Order By changes', () => { + const { rerender } = renderWithMantine( + , + ); + clickHeaderSort(); + + rerender( + + + , + ); + expect(queriedOrderBy()).toBe('ServiceName DESC'); + }); + + it('stays dropped when the config Order By changes back', () => { + const { rerender } = renderWithMantine( + , + ); + clickHeaderSort(); + + for (const orderBy of ['ServiceName DESC', 'Duration DESC']) { + rerender( + + + , + ); + } + expect(queriedOrderBy()).toBe('Duration DESC'); + }); + }); + it('does not render DateRangeIndicator when MV optimization has no optimized date range', () => { // Mock useMVOptimizationExplanation to return data without an optimized config jest.mocked(useMVOptimizationExplanation).mockReturnValue({ diff --git a/packages/app/src/utils.ts b/packages/app/src/utils.ts index a5f2b7f747..37391f5180 100644 --- a/packages/app/src/utils.ts +++ b/packages/app/src/utils.ts @@ -22,7 +22,6 @@ import { TMetricSource, TSource, } from '@hyperdx/common-utils/dist/types'; -import { SortingState } from '@tanstack/react-table'; import { MetricsDataType, NumberFormat } from './types'; @@ -1459,50 +1458,6 @@ export const stripTrailingSlash = (url: string | undefined | null): string => { return url.endsWith('/') ? url.slice(0, -1) : url; }; -/** - * Converts the given SortingState into a SQL Order By string - * Note, only the first element of the SortingState is used. Returns - * undefined if the input is null or empty. - * - * Output format: " " - * */ -export const sortingStateToOrderByString = ( - sort: SortingState | null, -): string | undefined => { - const firstSort = sort?.at(0); - return firstSort - ? `${firstSort.id} ${firstSort.desc ? 'DESC' : 'ASC'}` - : undefined; -}; - -/** - * Converts the given SQL Order By string into a SortingState. - * - * Expects format matching the output of sortingStateToOrderByString - * (" "). Returns undefined if the input is invalid. - */ -export const orderByStringToSortingState = ( - orderBy: string | undefined, -): SortingState | undefined => { - if (!orderBy) { - return undefined; - } - - const orderByParts = orderBy.split(' '); - const endsWithDirection = orderBy.toLowerCase().match(/ (asc|desc)$/i); - - if (orderByParts.length !== 2 || !endsWithDirection) { - return undefined; - } - - return [ - { - id: orderByParts[0].trim(), - desc: orderByParts[1].trim().toUpperCase() === 'DESC', - }, - ]; -}; - export const mapKeyBy = (array: T[], key: keyof T) => { const map = new Map(); diff --git a/packages/app/tests/e2e/features/chart-explorer.spec.ts b/packages/app/tests/e2e/features/chart-explorer.spec.ts index acb05b582c..28444748bb 100644 --- a/packages/app/tests/e2e/features/chart-explorer.spec.ts +++ b/packages/app/tests/e2e/features/chart-explorer.spec.ts @@ -159,6 +159,77 @@ test.describe('Chart Explorer Functionality', { tag: ['@charts'] }, () => { }); }); + test('should query an edited Order By instead of the last header sort on a table', async () => { + const { chartEditor } = chartExplorerPage; + let headerSortValues: string[] = []; + let headerSortDesc = false; + + await test.step('Query a table grouped by ServiceName', async () => { + await expect(chartExplorerPage.form).toBeVisible(); + await chartExplorerPage.page.waitForLoadState('networkidle'); + await chartEditor.setChartType(DisplayType.Table); + await chartEditor.setGroupBy('ServiceName'); + await chartEditor.runQuery(false); + await expect( + chartExplorerPage.getTableSortButton('ServiceName'), + ).toBeVisible({ timeout: 15000 }); + }); + + await test.step('Sort by clicking the ServiceName header', async () => { + await chartExplorerPage.getTableSortButton('ServiceName').click(); + await expect + .poll(() => chartExplorerPage.getOrderByText(), { timeout: 10000 }) + .toMatch(/^ServiceName (ASC|DESC)$/); + headerSortDesc = (await chartExplorerPage.getOrderByText()).endsWith( + 'DESC', + ); + await expect(chartExplorerPage.getTableSortIndicators()).toHaveCount(1); + + await expect + .poll( + async () => + (await chartExplorerPage.getTableColumnValues('ServiceName')) + .length, + { timeout: 10000 }, + ) + .toBeGreaterThan(1); + headerSortValues = + await chartExplorerPage.getTableColumnValues('ServiceName'); + }); + + await test.step('Edit the Order By to the opposite direction with a trailing modifier', async () => { + // "NULLS LAST" has no trailing ASC/DESC, so the table can't show it as a + // header sort; it must still be queried as typed. + await chartEditor.setOrderBy( + `ServiceName ${headerSortDesc ? 'ASC' : 'DESC'} NULLS LAST`, + ); + await chartEditor.runQuery(false); + + await expect + .poll(() => chartExplorerPage.getTableColumnValues('ServiceName'), { + timeout: 10000, + }) + .toEqual([...headerSortValues].reverse()); + await expect(chartExplorerPage.getTableSortIndicators()).toHaveCount(0); + }); + + await test.step('Clear the Order By and verify the header sort is not restored', async () => { + await chartEditor.setOrderBy(''); + await chartEditor.runQuery(false); + + await expect + .poll( + async () => + (await chartExplorerPage.getTableColumnValues('ServiceName')) + .length, + { timeout: 10000 }, + ) + .toBeGreaterThan(1); + await expect(chartExplorerPage.getTableSortIndicators()).toHaveCount(0); + expect(await chartExplorerPage.getOrderByText()).toBe(''); + }); + }); + test('should apply a custom ORDER BY on a categorical pie chart', async () => { let ascendingLabels: string[] = []; let descendingLabels: string[] = []; diff --git a/packages/app/tests/e2e/features/dashboard-table-sort.spec.ts b/packages/app/tests/e2e/features/dashboard-table-sort.spec.ts new file mode 100644 index 0000000000..3780929d40 --- /dev/null +++ b/packages/app/tests/e2e/features/dashboard-table-sort.spec.ts @@ -0,0 +1,79 @@ +import { DisplayType } from '@hyperdx/common-utils/dist/types'; + +import { DashboardPage } from '../page-objects/DashboardPage'; +import { expect, test } from '../utils/base-test'; +import { DEFAULT_LOGS_SOURCE_NAME } from '../utils/constants'; + +test.describe( + 'Dashboard table tile sorting', + { tag: ['@dashboard', '@full-stack'] }, + () => { + let dashboardPage: DashboardPage; + + test.beforeEach(async ({ page }) => { + test.setTimeout(60000); + dashboardPage = new DashboardPage(page); + await dashboardPage.goto(); + await dashboardPage.createNewDashboard(); + }); + + test('should run an edited Order By instead of the last header sort', async () => { + const ts = Date.now(); + let headerSortValues: string[] = []; + + await test.step('Add a table tile grouped by ServiceName', async () => { + await dashboardPage.addTile(); + await dashboardPage.chartEditor.waitForDataToLoad(); + await dashboardPage.chartEditor.setChartType(DisplayType.Table); + await dashboardPage.chartEditor.setChartName(`E2E Table Sort ${ts}`); + await dashboardPage.chartEditor.selectSource(DEFAULT_LOGS_SOURCE_NAME); + await dashboardPage.chartEditor.setGroupBy('ServiceName'); + await dashboardPage.chartEditor.runQuery(false); + await dashboardPage.saveTile(); + await dashboardPage.waitForTableTileRows(0); + }); + + await test.step('Sort the tile by clicking the ServiceName header', async () => { + await dashboardPage.getTileSortButton(0, 'ServiceName').click(); + await expect( + dashboardPage.getTile(0).getByTestId('raw-log-table-sort-indicator'), + ).toHaveCount(1); + await expect + .poll( + async () => + (await dashboardPage.getTileColumnValues(0, 'ServiceName')) + .length, + { timeout: 10000 }, + ) + .toBeGreaterThan(1); + headerSortValues = await dashboardPage.getTileColumnValues( + 0, + 'ServiceName', + ); + }); + + await test.step('Edit the tile to order by the opposite direction', async () => { + const headerSortAsc = + JSON.stringify(headerSortValues) === + JSON.stringify([...headerSortValues].sort()); + await dashboardPage.editTile(0); + await expect(dashboardPage.chartEditor.nameInput).toBeVisible(); + await dashboardPage.chartEditor.setOrderBy( + `ServiceName ${headerSortAsc ? 'DESC' : 'ASC'}`, + ); + await dashboardPage.saveTile(); + }); + + await test.step('Verify the tile runs the edited Order By', async () => { + await expect + .poll(() => dashboardPage.getTileColumnValues(0, 'ServiceName'), { + timeout: 10000, + }) + .toEqual([...headerSortValues].reverse()); + await expect( + dashboardPage.getTile(0).getByTestId('raw-log-table-sort-indicator'), + ).toHaveCount(0); + }); + }); + }, +); diff --git a/packages/app/tests/e2e/page-objects/ChartExplorerPage.ts b/packages/app/tests/e2e/page-objects/ChartExplorerPage.ts index 2c7d4de75d..cb2dc2cb92 100644 --- a/packages/app/tests/e2e/page-objects/ChartExplorerPage.ts +++ b/packages/app/tests/e2e/page-objects/ChartExplorerPage.ts @@ -84,6 +84,41 @@ export class ChartExplorerPage { return titles.filter(t => t.length > 0); } + /** The sort button in the header of the results table column `name`. */ + getTableSortButton(name: string) { + return this.page + .getByTestId('raw-log-table-sort-button') + .filter({ hasText: name }); + } + + /** Header sort arrows shown in the results table. */ + getTableSortIndicators() { + return this.page.getByTestId('raw-log-table-sort-indicator'); + } + + /** The text of the chart editor's ORDER BY input, excluding its placeholder. */ + async getOrderByText(): Promise { + const content = this.page + .getByTestId('order-by-input') + .locator('.cm-content'); + // CodeMirror renders the placeholder only when the editor is empty. + if ((await content.locator('.cm-placeholder').count()) > 0) return ''; + return ((await content.textContent()) ?? '').trim(); + } + + /** Cell values of results table column `name`, top to bottom. */ + async getTableColumnValues(name: string): Promise { + const headers = ( + await this.page.locator('table thead th').allTextContents() + ).map(h => h.trim()); + const index = headers.findIndex(h => h === name); + if (index === -1) return []; + const cells = this.page.locator( + `table tbody tr[data-index] td:nth-child(${index + 1})`, + ); + return (await cells.allTextContents()).map(c => c.trim()); + } + // Getters for assertions get form() { diff --git a/packages/app/tests/e2e/page-objects/DashboardPage.ts b/packages/app/tests/e2e/page-objects/DashboardPage.ts index f1e25b1066..80510db06e 100644 --- a/packages/app/tests/e2e/page-objects/DashboardPage.ts +++ b/packages/app/tests/e2e/page-objects/DashboardPage.ts @@ -2131,6 +2131,30 @@ export class DashboardPage { .waitFor({ state: 'visible', timeout: 15000 }); } + /** The sort button in the header of column `name` in a table tile. */ + getTileSortButton(tileIndex: number, name: string) { + return this.getTile(tileIndex) + .getByTestId('raw-log-table-sort-button') + .filter({ hasText: name }); + } + + /** Cell values of column `name` in a table tile, top to bottom. */ + async getTileColumnValues( + tileIndex: number, + name: string, + ): Promise { + const table = this.getTile(tileIndex).locator('table').first(); + const headers = (await table.locator('thead th').allTextContents()).map(h => + h.trim(), + ); + const index = headers.findIndex(h => h === name); + if (index === -1) return []; + const cells = table.locator( + `tbody tr[data-index] td:nth-child(${index + 1})`, + ); + return (await cells.allTextContents()).map(c => c.trim()); + } + /** * Get the `title` attribute of a cell (by column index) in the first row of * a table tile. The title mirrors the cell's stringified value, useful