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

Do not toggle plot section when clicking a link #2632

Merged
merged 2 commits into from
Oct 19, 2022
Merged
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
26 changes: 26 additions & 0 deletions webview/src/plots/components/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,32 @@ describe('App', () => {
})
})

it('should not toggle the checkpoint plots section if a link is clicked', () => {
renderAppWithOptionalData({
checkpoint: checkpointPlotsFixture
})

const checkpointsTooltipToggle = screen.getAllByTestId(
'info-tooltip-toggle'
)[2]
fireEvent.mouseEnter(checkpointsTooltipToggle, {
bubbles: true,
cancelable: true
})

const tooltip = screen.getByTestId('tooltip-checkpoint-plots')
const tooltipLink = within(tooltip).getByRole('link')
fireEvent.click(tooltipLink, {
bubbles: true,
cancelable: true
})

expect(mockPostMessage).not.toHaveBeenCalledWith({
payload: { [Section.CHECKPOINT_PLOTS]: true },
type: MessageFromWebviewType.TOGGLE_PLOTS_SECTION
})
})

it('should not toggle the checkpoint plots section when its header is clicked and the content of its tooltip is selected', async () => {
renderAppWithOptionalData({
checkpoint: checkpointPlotsFixture
Expand Down
6 changes: 5 additions & 1 deletion webview/src/plots/components/PlotsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
Lines
} from '../../shared/components/icons'
import { isSelecting } from '../../util/strings'
import { EventTargetWithNodeName } from '../../util/objects'

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

const toggleSection = (e: MouseEvent) => {
e.preventDefault()
if (!isSelecting([title, SectionDescription[sectionKey].props.children])) {
if (
!isSelecting([title, SectionDescription[sectionKey].props.children]) &&
!['A', 'BUTTON'].includes((e.target as EventTargetWithNodeName).nodeName)
) {
sendMessage({
payload: {
[sectionKey]: !sectionCollapsed
Expand Down
4 changes: 4 additions & 0 deletions webview/src/util/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ export type Obj = { [key: string]: Any }

export const keepReferenceIfEqual = (old: BaseType, recent: BaseType) =>
isEqual(old, recent) ? old : recent

export interface EventTargetWithNodeName extends EventTarget {
nodeName: string
}