Skip to content

Commit

Permalink
Fix experiments table move to start functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Sep 27, 2023
1 parent 07856b2 commit 48d4561
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
25 changes: 25 additions & 0 deletions webview/src/experiments/components/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { vsCodeApi } from '../../shared/api'
import {
commonColumnFields,
expectHeaders,
getHeaders,
tableData as sortingTableDataFixture
} from '../../test/sort'
import {
Expand Down Expand Up @@ -164,6 +165,30 @@ describe('App', () => {
await expectHeaders(['A', 'C', 'D', 'B'])
})

it('should be able to move columns to the start', async () => {
renderTable({
...sortingTableDataFixture,
columnOrder: ['id', 'Created', 'params:A', 'params:B', 'params:C']
})

await expectHeaders(['A', 'B', 'C'])

const moveBCtoStart = ['id', 'params:B', 'params:C', 'Created', 'params:A']

setTableData({
...sortingTableDataFixture,
columnOrder: moveBCtoStart
})

expect(await getHeaders()).toStrictEqual([
'Experiment',
'B',
'C',
'Created',
'A'
])
})

describe('Row expansion', () => {
const experimentLabel = '4fb124a'

Expand Down
10 changes: 8 additions & 2 deletions webview/src/experiments/components/Experiments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
Row as TableRow,
getCoreRowModel,
getExpandedRowModel,
ColumnSizingState
ColumnSizingState,
ColumnOrderState
} from '@tanstack/react-table'
import { Table } from './table/Table'
import styles from './table/styles.module.scss'
Expand Down Expand Up @@ -64,7 +65,8 @@ export const ExperimentsTable: React.FC = () => {
const [columns, setColumns] = useState(buildColumns(columnData))
const [columnSizing, setColumnSizing] =
useState<ColumnSizingState>(columnWidths)
const [columnOrder, setColumnOrder] = useState(columnOrderData)
const [columnOrder, setColumnOrder] =
useState<ColumnOrderState>(columnOrderData)
const resizeTimeout = useRef(0)

useEffect(() => {
Expand All @@ -75,6 +77,10 @@ export const ExperimentsTable: React.FC = () => {
setColumns(buildColumns(columnData))
}, [columnData])

useEffect(() => {
setColumnOrder(columnOrderData)
}, [columnOrderData])

const getRowId = useCallback(
(experiment: Commit, relativeIndex: number, parent?: TableRow<Commit>) =>
parent ? [parent.id, experiment.id].join('.') : String(relativeIndex),
Expand Down

0 comments on commit 48d4561

Please sign in to comment.