Skip to content

Commit b0342d0

Browse files
authored
Update cell hint styles and context menu position (#2384)
* make cell hint text smaller * add hint to first cell bullet * take off cell indicator tooltips * have context menu appear based off of cursor position
1 parent cab6542 commit b0342d0

File tree

7 files changed

+59
-42
lines changed

7 files changed

+59
-42
lines changed

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { IndicatorWithJustTheCounter } from './Indicators'
55
import styles from './styles.module.scss'
66
import { CellProp, RowProp } from './interfaces'
77
import { CellRowActionsProps, CellRowActions } from './CellRowActions'
8+
import { CellHintTooltip } from './CellHintTooltip'
89
import { clickAndEnterProps } from '../../../util/props'
910
import { Clock } from '../../../shared/components/icons'
10-
import { pluralize } from '../../../util/strings'
1111
import { cellHasChanges } from '../../util/buildDynamicColumns'
1212

1313
const RowExpansionButton: React.FC<RowProp> = ({ row }) =>
@@ -63,21 +63,20 @@ export const FirstCell: React.FC<
6363
<div className={styles.innerCell}>
6464
<CellRowActions {...rowActionsProps} />
6565
<RowExpansionButton row={row} />
66-
<span
67-
className={styles.bullet}
68-
style={{ color: bulletColor }}
69-
{...clickAndEnterProps(toggleExperiment)}
70-
>
71-
<IndicatorWithJustTheCounter
72-
aria-label={'Sub-rows selected for plots'}
73-
count={plotSelections}
74-
tooltipContent={`${plotSelections} ${pluralize(
75-
'sub-row',
76-
plotSelections
77-
)} selected for plots.`}
78-
/>
79-
{queued && <Clock />}
80-
</span>
66+
<CellHintTooltip tooltipContent={bulletColor ? 'Unplot' : 'Plot'}>
67+
<span
68+
className={styles.bullet}
69+
style={{ color: bulletColor }}
70+
{...clickAndEnterProps(toggleExperiment)}
71+
>
72+
<IndicatorWithJustTheCounter
73+
aria-label={'Sub-rows selected for plots'}
74+
count={plotSelections}
75+
tooltipContent={''}
76+
/>
77+
{queued && <Clock />}
78+
</span>
79+
</CellHintTooltip>
8180
{isPlaceholder ? null : (
8281
<ErrorTooltip error={error}>
8382
<div
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React, { ReactNode, ReactElement } from 'react'
2+
import styles from './styles.module.scss'
3+
import Tooltip, {
4+
CELL_TOOLTIP_DELAY
5+
} from '../../../shared/components/tooltip/Tooltip'
6+
7+
export const CellHintTooltip: React.FC<{
8+
tooltipContent: ReactNode
9+
children: ReactElement
10+
}> = ({ tooltipContent, children }) => {
11+
return (
12+
<Tooltip
13+
content={<span className={styles.cellHintTooltip}>{tooltipContent}</span>}
14+
placement="bottom-start"
15+
offset={[0, -2]}
16+
delay={[CELL_TOOLTIP_DELAY, 0]}
17+
>
18+
{children}
19+
</Tooltip>
20+
)
21+
}

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

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@ import cx from 'classnames'
33
import { VSCodeCheckbox } from '@vscode/webview-ui-toolkit/react'
44
import { Indicator } from './Indicators'
55
import styles from './styles.module.scss'
6+
import { CellHintTooltip } from './CellHintTooltip'
67
import { clickAndEnterProps } from '../../../util/props'
78
import { StarFull, StarEmpty } from '../../../shared/components/icons'
8-
import { pluralize } from '../../../util/strings'
9-
import Tooltip, {
10-
CELL_TOOLTIP_DELAY
11-
} from '../../../shared/components/tooltip/Tooltip'
129

1310
export type CellRowActionsProps = {
1411
isRowSelected: boolean
@@ -26,7 +23,6 @@ export type CellRowActionsProps = {
2623
export type CellRowActionProps = {
2724
showSubRowStates: boolean
2825
subRowsAffected: number
29-
actionAppliedLabel: string
3026
children: React.ReactElement
3127
hidden?: boolean
3228
testId?: string
@@ -36,7 +32,6 @@ export type CellRowActionProps = {
3632
export const CellRowAction: React.FC<CellRowActionProps> = ({
3733
showSubRowStates,
3834
subRowsAffected,
39-
actionAppliedLabel,
4035
children,
4136
hidden,
4237
testId,
@@ -45,26 +40,16 @@ export const CellRowAction: React.FC<CellRowActionProps> = ({
4540
const count = (showSubRowStates && subRowsAffected) || 0
4641

4742
return (
48-
<Tooltip
49-
content={tooltipContent}
50-
placement="bottom-end"
51-
delay={[CELL_TOOLTIP_DELAY, 0]}
52-
>
43+
<CellHintTooltip tooltipContent={tooltipContent}>
5344
<div
5445
className={cx(styles.rowActions, hidden && styles.hidden)}
5546
data-testid={testId}
5647
>
57-
<Indicator
58-
count={count}
59-
tooltipContent={
60-
count &&
61-
`${count} ${pluralize('sub-row', count)} ${actionAppliedLabel}.`
62-
}
63-
>
48+
<Indicator tooltipContent="" count={count}>
6449
{children}
6550
</Indicator>
6651
</div>
67-
</Tooltip>
52+
</CellHintTooltip>
6853
)
6954
}
7055

@@ -81,7 +66,6 @@ export const CellRowActions: React.FC<CellRowActionsProps> = ({
8166
<CellRowAction
8267
showSubRowStates={showSubRowStates}
8368
subRowsAffected={selections}
84-
actionAppliedLabel={'selected'}
8569
testId={'row-action-checkbox'}
8670
tooltipContent={isRowSelected ? 'Unselect' : 'Select'}
8771
>
@@ -93,9 +77,8 @@ export const CellRowActions: React.FC<CellRowActionsProps> = ({
9377
<CellRowAction
9478
showSubRowStates={showSubRowStates}
9579
subRowsAffected={stars}
96-
actionAppliedLabel={'starred'}
9780
testId={'row-action-star'}
98-
tooltipContent={starred ? 'Remove Star' : 'Add Star'}
81+
tooltipContent={starred ? 'Star' : 'Unstar'}
9982
>
10083
<div
10184
className={styles.starSwitch}

webview/src/experiments/components/table/styles.module.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,10 @@ $workspace-row-edge-margin: $edge-padding - $cell-padding;
613613
}
614614
}
615615

616+
.cellHintTooltip {
617+
font-size: 0.65rem;
618+
}
619+
616620
.webviewHeader {
617621
display: flex;
618622
justify-content: space-between;

webview/src/shared/components/contextMenu/ContextMenu.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const ContextMenu: React.FC<ContextMenuProps> = ({
5656
<Tooltip
5757
trigger={trigger}
5858
delay={[100, 200]}
59-
placement={'right-start'}
59+
placement={'bottom-start'}
6060
interactive
6161
isContextMenu={true}
6262
onTrigger={positionContextMenuAndDisableEvents}
@@ -66,6 +66,8 @@ export const ContextMenu: React.FC<ContextMenuProps> = ({
6666
onShow={onShow}
6767
disabled={!content || disabled}
6868
appendTo={'parent'}
69+
followCursor={'initial'}
70+
offset={[0, 0]}
6971
>
7072
{children}
7173
</Tooltip>

webview/src/shared/components/tooltip/Tooltip.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { forwardRef, Ref } from 'react'
2+
import { followCursor } from 'tippy.js'
23
import Tippy, { TippyProps } from '@tippyjs/react'
34
import styles from './styles.module.scss'
45
import 'tippy.js/dist/tippy.css'
@@ -49,7 +50,9 @@ const TooltipRenderFunction: React.ForwardRefRenderFunction<
4950
onTrigger,
5051
appendTo,
5152
isContextMenu = false,
52-
animation = false
53+
animation = false,
54+
followCursor: followCursorVal,
55+
offset
5356
},
5457
ref
5558
) => (
@@ -78,7 +81,9 @@ const TooltipRenderFunction: React.ForwardRefRenderFunction<
7881
onShow={onShow}
7982
onHide={onHide}
8083
ref={ref as Ref<Element>}
81-
plugins={[hideOnEsc]}
84+
followCursor={followCursorVal}
85+
plugins={[hideOnEsc, followCursor]}
86+
offset={offset}
8287
>
8388
{children}
8489
</Tippy>

webview/src/stories/Table.stories.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,12 @@ const contextMenuPlay = async ({
154154
canvasElement: HTMLElement
155155
}) => {
156156
const experiment = await within(canvasElement).findByText('[exp-e7a67]')
157+
const clientRect = experiment.getBoundingClientRect()
157158
userEvent.click(experiment, {
158159
bubbles: true,
159-
button: 2
160+
button: 2,
161+
clientX: clientRect.left,
162+
clientY: clientRect.top
160163
})
161164
}
162165

0 commit comments

Comments
 (0)