Skip to content

Commit c60913f

Browse files
authored
Clean up table file structure (#3706)
* Clean up table file structure * Reduce complexity * Fix bad merge
1 parent ee0450f commit c60913f

27 files changed

+222
-235
lines changed

webview/src/experiments/components/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
updateRows,
2727
updateSelectedForPlotsCount,
2828
updateSorts
29-
} from './table/tableDataSlice'
29+
} from '../state/tableDataSlice'
3030
import { useVsCodeMessaging } from '../../shared/hooks/useVsCodeMessaging'
3131

3232
export const App: React.FC<Record<string, unknown>> = () => {

webview/src/experiments/components/Experiments.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import styles from './table/styles.module.scss'
2727
import { AddColumns, Welcome } from './GetStarted'
2828
import { RowSelectionProvider } from './table/RowSelectionContext'
2929
import { CellValue } from './table/content/Cell'
30-
import { CellSecondaryName } from './table/CellSecondaryName'
30+
import { CellSecondaryName } from './table/body/CellSecondaryName'
3131
import { AddStage } from './AddStage'
3232
import { buildColumns, columnHelper } from '../util/buildColumns'
3333
import { sendMessage } from '../../shared/vscode'

webview/src/experiments/components/table/Indicators.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import React, { MouseEventHandler, ReactElement, ReactNode } from 'react'
22
import { useSelector } from 'react-redux'
33
import styles from './styles.module.scss'
4-
import { CellHintTooltip } from './CellHintTooltip'
5-
import { focusFiltersTree, focusSortsTree, openPlotsWebview } from './messages'
4+
import { CellHintTooltip } from './body/CellHintTooltip'
5+
import {
6+
focusFiltersTree,
7+
focusSortsTree,
8+
openPlotsWebview
9+
} from '../../util/messages'
610
import { Icon } from '../../../shared/components/Icon'
711
import {
812
Filter,

webview/src/experiments/components/table/RowSelectionContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { createContext, useState } from 'react'
2-
import { RowProp } from './interfaces'
2+
import { RowProp } from '../../util/interfaces'
33

44
export interface RowSelectionContextValue {
55
selectedRows: Record<string, RowProp | undefined>

webview/src/experiments/components/table/Table.tsx

Lines changed: 9 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
1-
import React, {
2-
useRef,
3-
useState,
4-
CSSProperties,
5-
useContext,
6-
useCallback
7-
} from 'react'
8-
import { useSelector } from 'react-redux'
1+
import React, { useRef, useState, CSSProperties, useContext } from 'react'
92
import { ColumnOrderState } from '@tanstack/react-table'
103
import cx from 'classnames'
114
import styles from './styles.module.scss'
125
import { TableHead } from './header/TableHead'
13-
import { InstanceProp, RowProp } from './interfaces'
146
import { RowSelectionContext } from './RowSelectionContext'
15-
import { TableBody } from './TableBody'
167
import { Indicators } from './Indicators'
178
import { CommitsAndBranchesNavigation } from './commitsAndBranches/CommitsAndBranchesNavigation'
18-
import { ExperimentsState } from '../../store'
9+
import { TableContent } from './body/TableContent'
10+
import { InstanceProp } from '../../util/interfaces'
1911

2012
interface TableProps extends InstanceProp {
2113
onColumnOrderChange: (order: ColumnOrderState) => void
@@ -25,51 +17,12 @@ export const Table: React.FC<TableProps> = ({
2517
instance,
2618
onColumnOrderChange
2719
}) => {
28-
const { rows, flatRows } = instance.getRowModel()
29-
30-
const hasCheckpoints = useSelector(
31-
(state: ExperimentsState) => state.tableData.hasCheckpoints
32-
)
33-
const hasRunningExperiment = useSelector(
34-
(state: ExperimentsState) => state.tableData.hasRunningExperiment
35-
)
36-
37-
const { clearSelectedRows, batchSelection, lastSelectedRow } =
38-
useContext(RowSelectionContext)
20+
const { clearSelectedRows } = useContext(RowSelectionContext)
3921
const [expColumnNeedsShadow, setExpColumnNeedsShadow] = useState(false)
4022
const [tableHeadHeight, setTableHeadHeight] = useState(55)
4123

4224
const tableRef = useRef<HTMLTableElement>(null)
4325

44-
const batchRowSelection = useCallback(
45-
({ row: { id } }: RowProp) => {
46-
const lastSelectedRowId = lastSelectedRow?.row.id ?? ''
47-
const lastIndex =
48-
flatRows.findIndex(flatRow => flatRow.id === lastSelectedRowId) || 1
49-
const selectedIndex =
50-
flatRows.findIndex(flatRow => flatRow.id === id) || 1
51-
const rangeStart = Math.min(lastIndex, selectedIndex)
52-
const rangeEnd = Math.max(lastIndex, selectedIndex)
53-
54-
const collapsedIds = flatRows
55-
.filter(flatRow => !flatRow.getIsExpanded())
56-
.map(flatRow => flatRow.id)
57-
58-
const batch = flatRows
59-
.slice(rangeStart, rangeEnd + 1)
60-
.filter(
61-
flatRow =>
62-
!collapsedIds.some(collapsedId =>
63-
flatRow.id.startsWith(`${collapsedId}.`)
64-
)
65-
)
66-
.map(row => ({ row }))
67-
68-
batchSelection?.(batch)
69-
},
70-
[flatRows, batchSelection, lastSelectedRow]
71-
)
72-
7326
return (
7427
<div
7528
className={styles.tableContainer}
@@ -95,18 +48,11 @@ export const Table: React.FC<TableProps> = ({
9548
setTableHeadHeight={setTableHeadHeight}
9649
onOrderChange={onColumnOrderChange}
9750
/>
98-
{rows.map(row => (
99-
<TableBody
100-
tableHeaderHeight={tableHeadHeight}
101-
root={tableRef.current}
102-
row={row}
103-
instance={instance}
104-
key={row.id}
105-
hasRunningExperiment={hasRunningExperiment}
106-
projectHasCheckpoints={hasCheckpoints}
107-
batchRowSelection={batchRowSelection}
108-
/>
109-
))}
51+
<TableContent
52+
instance={instance}
53+
tableRef={tableRef}
54+
tableHeadHeight={tableHeadHeight}
55+
/>
11056
</table>
11157
<CommitsAndBranchesNavigation />
11258
<Indicators />

webview/src/experiments/components/table/Cell.tsx renamed to webview/src/experiments/components/table/body/Cell.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { flexRender } from '@tanstack/react-table'
22
import React, { ReactNode } from 'react'
33
import cx from 'classnames'
4-
import styles from './styles.module.scss'
5-
import { CellProp, RowProp } from './interfaces'
64
import { CellRowActionsProps, CellRowActions } from './CellRowActions'
7-
import { CellValue, isValueWithChanges } from './content/Cell'
8-
import { clickAndEnterProps } from '../../../util/props'
9-
import { ErrorTooltip } from '../../../shared/components/tooltip/ErrorTooltip'
5+
import styles from '../styles.module.scss'
6+
import { CellValue, isValueWithChanges } from '../content/Cell'
7+
import { CellProp, RowProp } from '../../../util/interfaces'
8+
import { clickAndEnterProps } from '../../../../util/props'
9+
import { ErrorTooltip } from '../../../../shared/components/tooltip/ErrorTooltip'
1010

1111
const cellHasChanges = (cellValue: CellValue) =>
1212
isValueWithChanges(cellValue) ? cellValue.changes : false

webview/src/experiments/components/table/CellHintTooltip.tsx renamed to webview/src/experiments/components/table/body/CellHintTooltip.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { ReactNode, ReactElement } from 'react'
22
import { TippyProps } from '@tippyjs/react'
3-
import styles from './styles.module.scss'
3+
import styles from '../styles.module.scss'
44
import Tooltip, {
55
NORMAL_TOOLTIP_DELAY
6-
} from '../../../shared/components/tooltip/Tooltip'
6+
} from '../../../../shared/components/tooltip/Tooltip'
77

88
export type CellHintTooltipProps = {
99
tooltipContent: ReactNode

webview/src/experiments/components/table/CellRowActions.tsx renamed to webview/src/experiments/components/table/body/CellRowActions.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import {
44
ExperimentStatus,
55
isQueued
66
} from 'dvc/src/experiments/webview/contract'
7-
import { Indicator } from './Indicators'
8-
import { addStarredFilter, openPlotsWebview } from './messages'
9-
import styles from './styles.module.scss'
107
import { CellHintTooltip } from './CellHintTooltip'
11-
import { clickAndEnterProps } from '../../../util/props'
12-
import { Clock, StarFull, StarEmpty } from '../../../shared/components/icons'
8+
import { Indicator } from '../Indicators'
9+
import { addStarredFilter, openPlotsWebview } from '../../../util/messages'
10+
import styles from '../styles.module.scss'
11+
import { clickAndEnterProps } from '../../../../util/props'
12+
import { Clock, StarFull, StarEmpty } from '../../../../shared/components/icons'
1313

1414
export type CellRowActionsProps = {
1515
bulletColor?: string

webview/src/experiments/components/table/CellSecondaryName.tsx renamed to webview/src/experiments/components/table/body/CellSecondaryName.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react'
22
import { VSCodeTag } from '@vscode/webview-ui-toolkit/react'
33
import { CommitData } from 'dvc/src/experiments/webview/contract'
4-
import styles from './styles.module.scss'
5-
import Tooltip from '../../../shared/components/tooltip/Tooltip'
6-
import { Icon } from '../../../shared/components/Icon'
7-
import { GitCommit } from '../../../shared/components/icons'
4+
import styles from '../styles.module.scss'
5+
import Tooltip from '../../../../shared/components/tooltip/Tooltip'
6+
import { Icon } from '../../../../shared/components/Icon'
7+
import { GitCommit } from '../../../../shared/components/icons'
88

99
export const CellSecondaryName: React.FC<{
1010
displayName: string

webview/src/experiments/components/table/ExperimentGroup.tsx renamed to webview/src/experiments/components/table/body/ExperimentGroup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import { BatchSelectionProp } from './Row'
3-
import { RowProp } from './interfaces'
43
import { NestedRow } from './NestedRow'
4+
import { RowProp } from '../../../util/interfaces'
55

66
export const ExperimentGroup: React.FC<RowProp & BatchSelectionProp> = ({
77
row,

0 commit comments

Comments
 (0)