Skip to content

Commit 1626546

Browse files
authored
Update table hints (#2413)
* Have table indicators hints to have same styles as other cell hints * make tooltipContent optional in Indicator and JustCounter components
1 parent 4431285 commit 1626546

File tree

4 files changed

+45
-46
lines changed

4 files changed

+45
-46
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ export const FirstCell: React.FC<
7272
<IndicatorWithJustTheCounter
7373
aria-label={'Sub-rows selected for plots'}
7474
count={plotSelections}
75-
tooltipContent={''}
7675
/>
7776
{queued && <Clock />}
7877
</span>

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
import React, { ReactNode, ReactElement } from 'react'
2+
import { TippyProps } from '@tippyjs/react'
23
import styles from './styles.module.scss'
34
import Tooltip, {
45
CELL_TOOLTIP_DELAY
56
} from '../../../shared/components/tooltip/Tooltip'
67

7-
export const CellHintTooltip: React.FC<{
8+
export type CellHintTooltipProps = {
89
tooltipContent: ReactNode
910
children: ReactElement
10-
}> = ({ tooltipContent, children }) => {
11+
}
12+
13+
export const CellHintTooltip: React.FC<CellHintTooltipProps & TippyProps> = ({
14+
tooltipContent,
15+
children,
16+
delay = [CELL_TOOLTIP_DELAY, 0]
17+
}) => {
1118
return (
1219
<Tooltip
1320
content={<span className={styles.cellHintTooltip}>{tooltipContent}</span>}
1421
placement="bottom-start"
1522
offset={[0, -2]}
16-
delay={[CELL_TOOLTIP_DELAY, 0]}
23+
delay={delay}
1724
>
1825
{children}
1926
</Tooltip>

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ export const CellRowAction: React.FC<CellRowActionProps> = ({
4545
className={cx(styles.rowActions, hidden && styles.hidden)}
4646
data-testid={testId}
4747
>
48-
<Indicator tooltipContent="" count={count}>
49-
{children}
50-
</Indicator>
48+
<Indicator count={count}>{children}</Indicator>
5149
</div>
5250
</CellHintTooltip>
5351
)

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

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,20 @@
1-
import React, { MouseEventHandler, ReactNode } from 'react'
1+
import React, { MouseEventHandler, ReactElement, ReactNode } from 'react'
22
import { useSelector } from 'react-redux'
33
import cx from 'classnames'
44
import { MessageFromWebviewType } from 'dvc/src/webview/contract'
55
import { FilteredCounts } from 'dvc/src/experiments/model/filterBy/collect'
6-
import { TippyProps } from '@tippyjs/react'
76
import styles from './styles.module.scss'
7+
import { CellHintTooltip } from './CellHintTooltip'
88
import { Icon } from '../../../shared/components/Icon'
99
import {
1010
Filter,
1111
GraphScatter,
1212
SortPrecedence
1313
} from '../../../shared/components/icons'
1414
import { sendMessage } from '../../../shared/vscode'
15-
import Tooltip from '../../../shared/components/tooltip/Tooltip'
1615
import { pluralize } from '../../../util/strings'
1716
import { ExperimentsState } from '../../store'
1817

19-
export type IndicatorTooltipProps = Pick<TippyProps, 'children'> & {
20-
tooltipContent: ReactNode
21-
}
22-
23-
export const IndicatorTooltip: React.FC<IndicatorTooltipProps> = ({
24-
children,
25-
tooltipContent
26-
}) => {
27-
const wrapperRef = React.useRef<HTMLDivElement>(null)
28-
return (
29-
<Tooltip
30-
placement="bottom-start"
31-
disabled={!tooltipContent}
32-
content={tooltipContent}
33-
ref={wrapperRef}
34-
>
35-
{children}
36-
</Tooltip>
37-
)
38-
}
39-
4018
export type CounterBadgeProps = {
4119
count?: number
4220
}
@@ -59,12 +37,13 @@ export const Indicator = ({
5937
'aria-label': ariaLabel,
6038
tooltipContent,
6139
onClick
62-
}: IndicatorTooltipProps &
63-
CounterBadgeProps & {
64-
'aria-label'?: string
65-
onClick?: MouseEventHandler
66-
}) => (
67-
<IndicatorTooltip tooltipContent={tooltipContent}>
40+
}: CounterBadgeProps & {
41+
'aria-label'?: string
42+
onClick?: MouseEventHandler
43+
tooltipContent?: ReactNode
44+
children: ReactElement
45+
}) => {
46+
const content = (
6847
<button
6948
className={cx(styles.indicatorIcon, count && styles.indicatorWithCount)}
7049
aria-label={ariaLabel}
@@ -73,23 +52,39 @@ export const Indicator = ({
7352
{children}
7453
<CounterBadge count={count} />
7554
</button>
76-
</IndicatorTooltip>
77-
)
55+
)
56+
57+
return tooltipContent ? (
58+
<CellHintTooltip tooltipContent={tooltipContent} delay={[0, 0]}>
59+
{content}
60+
</CellHintTooltip>
61+
) : (
62+
content
63+
)
64+
}
7865

7966
export const IndicatorWithJustTheCounter = ({
8067
count,
8168
'aria-label': ariaLabel,
8269
tooltipContent
83-
}: CounterBadgeProps &
84-
IndicatorTooltipProps & {
85-
'aria-label'?: string
86-
}) => (
87-
<IndicatorTooltip tooltipContent={tooltipContent}>
70+
}: CounterBadgeProps & {
71+
'aria-label'?: string
72+
tooltipContent?: ReactNode
73+
}) => {
74+
const children = (
8875
<span aria-label={ariaLabel}>
8976
<CounterBadge count={count} />
9077
</span>
91-
</IndicatorTooltip>
92-
)
78+
)
79+
80+
return tooltipContent ? (
81+
<CellHintTooltip tooltipContent={tooltipContent}>
82+
{children}
83+
</CellHintTooltip>
84+
) : (
85+
children
86+
)
87+
}
9388

9489
const focusFiltersTree = () =>
9590
sendMessage({ type: MessageFromWebviewType.FOCUS_FILTERS_TREE })

0 commit comments

Comments
 (0)