Skip to content

Commit

Permalink
feat(annotations): fix annotations tooltip (#1383)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
megansmith-box and mergify[bot] authored May 14, 2021
1 parent b6dd0da commit 87e36b3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,11 @@ export type Props = React.PropsWithChildren<{
function AnnotationsTargetedTooltip({ children, isEnabled = false }: Props): JSX.Element | null {
const { experiences } = React.useContext(ExperiencesContext);
const { setIsForced } = React.useContext(ControlsLayerContext);
const [shouldTargetAnnotationsTooltip, setShouldTargetAnnotationsTooltip] = React.useState(true);
const [wasClosedByUser, setWasClosedByUser] = React.useState(false);

const shouldTarget = !!(
isEnabled &&
experiences &&
experiences.tooltipFlowAnnotationsExperience &&
experiences.tooltipFlowAnnotationsExperience.canShow
);

if (!shouldTarget) {
return <>{children}</>;
}

return (
<TargetedClickThroughTooltip
className="bp-AnnotationsTooltip"
shouldTarget={shouldTargetAnnotationsTooltip}
shouldTarget={isEnabled}
showCloseButton
text={
<div>
Expand All @@ -47,16 +34,10 @@ function AnnotationsTargetedTooltip({ children, isEnabled = false }: Props): JSX
},
onComplete: (): void => {
experiences.tooltipFlowAnnotationsExperience.onComplete();
setShouldTargetAnnotationsTooltip(false);
setIsForced(false);
},
onShow: (): void => {
experiences.tooltipFlowAnnotationsExperience.onShow();

if (wasClosedByUser) {
return;
}

setWasClosedByUser(true);
setIsForced(true);
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ describe('AnnotationsControls', () => {
};

beforeEach(() => {
let found = false; // we want to find the first use of useEffect
jest.spyOn(React, 'useEffect').mockImplementation(cb => {
unmount = cb() as () => void; // Enzyme unmount helper does not currently invoke useEffect cleanup
if (!found) {
found = true;
unmount = cb() as () => void; // Enzyme unmount helper does not currently invoke useEffect cleanup
}
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('AnnotationsTargetedTooltip', () => {
});

expect(wrapper.children().text()).toBe('Child');
expect(wrapper.children().prop('shouldTarget')).toBe(undefined);
expect(wrapper.children().prop('shouldTarget')).toBe(false);
});
});
});

0 comments on commit 87e36b3

Please sign in to comment.