Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give table cells their own component directory #1517

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions webview/src/experiments/components/cell/Cell.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Experiment } from 'dvc/src/experiments/webview/contract'
import React from 'react'
import { Cell } from 'react-table'
import { CellTooltip } from './CellTooltip'
import { CopyButton } from '../copyButton/CopyButton'
import Tooltip, {
CELL_TOOLTIP_DELAY
} from '../../../shared/components/tooltip/Tooltip'
import { formatFloat } from '../../util/numberFormatting'
import styles from '../table/styles.module.scss'

const UndefinedCell = (
<div className={styles.innerCell}>
<span className={styles.cellContents}>. . .</span>
</div>
)

export const CellComponent: React.FC<
Cell<Experiment, string | number>
> = cell => {
const { value } = cell
if (value === undefined) {
return UndefinedCell
}

const stringValue = String(value)

const displayValue =
typeof value === 'number' && !Number.isInteger(value)
? formatFloat(value as number)
: stringValue

return (
<Tooltip
content={<CellTooltip cell={cell} />}
placement="bottom"
arrow={true}
delay={[CELL_TOOLTIP_DELAY, 0]}
>
<div className={styles.innerCell}>
<CopyButton value={stringValue} />
<span className={styles.cellContents}>{displayValue}</span>
</div>
</Tooltip>
)
}
22 changes: 22 additions & 0 deletions webview/src/experiments/components/cell/CellTooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react'
import { Cell } from 'react-table'
import { Experiment } from 'dvc/src/experiments/webview/contract'

const groupLabels: Record<string, string> = {
metrics: 'Metric',
params: 'Parameter'
}

export const CellTooltip: React.FC<{
cell: Cell<Experiment, string | number>
}> = ({ cell }) => {
const {
column: { group },
value
} = cell
return (
<>
{groupLabels[group as string]}: {value}
</>
)
}
68 changes: 3 additions & 65 deletions webview/src/experiments/util/buildDynamicColumns.tsx
Original file line number Diff line number Diff line change
@@ -1,72 +1,10 @@
import React from 'react'
import get from 'lodash/get'
import {
Column,
Accessor,
ColumnGroup,
ColumnInstance,
Cell
} from 'react-table'
import { Column, Accessor, ColumnGroup, ColumnInstance } from 'react-table'
import { Experiment, MetricOrParam } from 'dvc/src/experiments/webview/contract'
import { formatFloat } from './numberFormatting'
import Tooltip, {
CELL_TOOLTIP_DELAY
} from '../../shared/components/tooltip/Tooltip'
import styles from '../components/table/styles.module.scss'
import { CopyButton } from '../components/copyButton/CopyButton'
import { OverflowHoverTooltip } from '../components/overflowHoverTooltip/OverflowHoverTooltip'
const UndefinedCell = (
<div className={styles.innerCell}>
<span className={styles.cellContents}>. . .</span>
</div>
)

const groupLabels: Record<string, string> = {
metrics: 'Metric',
params: 'Parameter'
}

const CellTooltip: React.FC<{
cell: Cell<Experiment, string | number>
}> = ({ cell }) => {
const {
column: { group },
value
} = cell
return (
<>
{groupLabels[group as string]}: {value}
</>
)
}

const Cell: React.FC<Cell<Experiment, string | number>> = cell => {
const { value } = cell
if (value === undefined) {
return UndefinedCell
}

const stringValue = String(value)

const displayValue =
typeof value === 'number' && !Number.isInteger(value)
? formatFloat(value as number)
: stringValue

return (
<Tooltip
content={<CellTooltip cell={cell} />}
placement="bottom"
arrow={true}
delay={[CELL_TOOLTIP_DELAY, 0]}
>
<div className={styles.innerCell}>
<CopyButton value={stringValue} />
<span className={styles.cellContents}>{displayValue}</span>
</div>
</Tooltip>
)
}
import { CellComponent } from '../components/cell/Cell'

const Header: React.FC<{ column: Column<Experiment> }> = ({
column: { name }
Expand Down Expand Up @@ -96,7 +34,7 @@ const buildDynamicColumns = (
const childColumns = buildDynamicColumns(properties, path)

const column: ColumnGroup<Experiment> | Column<Experiment> = {
Cell,
Cell: CellComponent,
Header,
accessor: pathArray && buildAccessor(pathArray),
columns: childColumns.length > 0 ? childColumns : undefined,
Expand Down