Skip to content

Commit a501e6b

Browse files
authored
Check if element clicked is link to skip the toggle of the section (#2632)
1 parent 5a382de commit a501e6b

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

webview/src/plots/components/App.test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,32 @@ describe('App', () => {
428428
})
429429
})
430430

431+
it('should not toggle the checkpoint plots section if a link is clicked', () => {
432+
renderAppWithOptionalData({
433+
checkpoint: checkpointPlotsFixture
434+
})
435+
436+
const checkpointsTooltipToggle = screen.getAllByTestId(
437+
'info-tooltip-toggle'
438+
)[2]
439+
fireEvent.mouseEnter(checkpointsTooltipToggle, {
440+
bubbles: true,
441+
cancelable: true
442+
})
443+
444+
const tooltip = screen.getByTestId('tooltip-checkpoint-plots')
445+
const tooltipLink = within(tooltip).getByRole('link')
446+
fireEvent.click(tooltipLink, {
447+
bubbles: true,
448+
cancelable: true
449+
})
450+
451+
expect(mockPostMessage).not.toHaveBeenCalledWith({
452+
payload: { [Section.CHECKPOINT_PLOTS]: true },
453+
type: MessageFromWebviewType.TOGGLE_PLOTS_SECTION
454+
})
455+
})
456+
431457
it('should not toggle the checkpoint plots section when its header is clicked and the content of its tooltip is selected', async () => {
432458
renderAppWithOptionalData({
433459
checkpoint: checkpointPlotsFixture

webview/src/plots/components/PlotsContainer.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
Lines
1919
} from '../../shared/components/icons'
2020
import { isSelecting } from '../../util/strings'
21+
import { EventTargetWithNodeName } from '../../util/objects'
2122

2223
export interface CommonPlotsContainerProps {
2324
onResize: (size: PlotSize) => void
@@ -139,7 +140,10 @@ export const PlotsContainer: React.FC<PlotsContainerProps> = ({
139140

140141
const toggleSection = (e: MouseEvent) => {
141142
e.preventDefault()
142-
if (!isSelecting([title, SectionDescription[sectionKey].props.children])) {
143+
if (
144+
!isSelecting([title, SectionDescription[sectionKey].props.children]) &&
145+
!['A', 'BUTTON'].includes((e.target as EventTargetWithNodeName).nodeName)
146+
) {
143147
sendMessage({
144148
payload: {
145149
[sectionKey]: !sectionCollapsed

webview/src/util/objects.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ export type Obj = { [key: string]: Any }
1515

1616
export const keepReferenceIfEqual = (old: BaseType, recent: BaseType) =>
1717
isEqual(old, recent) ? old : recent
18+
19+
export interface EventTargetWithNodeName extends EventTarget {
20+
nodeName: string
21+
}

0 commit comments

Comments
 (0)