Skip to content

Commit

Permalink
[Discover] fix using the data grid full screen mode causes the top na…
Browse files Browse the repository at this point in the history
…v buttons to disappear (elastic#176324)

## Summary

fix elastic#172716

The header_action_menu didn't reset the state correctly when it was
unmounted. This caused an state bug when remounting and as the result
elastic#172716 the action menu didn't
render
  • Loading branch information
Dosant authored and fkanout committed Mar 4, 2024
1 parent 82f7b61 commit f20c680
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,24 @@ describe('HeaderActionMenu', () => {
expect(unmounts.FOO).toHaveBeenCalledTimes(1);
expect(unmounts.BAR).not.toHaveBeenCalled();
});

it('calls mount point `unmount` when unmounts', () => {
const TestComponent = () => {
const mounter = useHeaderActionMenuMounter(menuMount$);
return <HeaderActionMenu mounter={mounter} />;
};
component = mount(<TestComponent />);

act(() => {
menuMount$.next(createMountPoint('FOO'));
});
refresh();

expect(Object.keys(unmounts)).toEqual(['FOO']);
expect(unmounts.FOO).not.toHaveBeenCalled();

component.unmount();

expect(unmounts.FOO).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ export const HeaderActionMenu: FC<HeaderActionMenuProps> = ({ mounter }) => {
const unmountRef = useRef<UnmountCallback | null>(null);

useLayoutEffect(() => {
if (unmountRef.current) {
unmountRef.current();
unmountRef.current = null;
}

if (mounter.mount && elementRef.current) {
try {
unmountRef.current = mounter.mount(elementRef.current);
Expand All @@ -53,6 +48,12 @@ export const HeaderActionMenu: FC<HeaderActionMenuProps> = ({ mounter }) => {
console.error(e);
}
}
return () => {
if (unmountRef.current) {
unmountRef.current();
unmountRef.current = null;
}
};
}, [mounter]);

return <div data-test-subj="headerAppActionMenu" ref={elementRef} />;
Expand Down

0 comments on commit f20c680

Please sign in to comment.