mirror of
https://github.com/outline/outline.git
synced 2026-11-27 07:58:51 +03:00
* Fix issue #8026: Prevent multiple context menus from being open simultaneously - Created useCoordinatedMenuState hook that wraps Reakit's useMenuState - Enhanced MenuProvider with menu registry and coordination logic - Expanded MenuProvider scope to wrap entire application - Updated key menu components to use coordinated menu state: - DocumentMenu - Template (SubMenu) - FilterOptions - AccountMenu - CollectionMenu - Ensures only one context menu can be open at a time - Maintains existing Reakit integration and component structure * Update all imports, add lint rule * Update to named export * fix: Sidebar still needs separate MenuProvider to track isOpen within * fix: Cannot directly open a menu with another open --------- Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com> Co-authored-by: Tom Moor <tom@getoutline.com>
69 lines
1.8 KiB
TypeScript
69 lines
1.8 KiB
TypeScript
import { observer } from "mobx-react";
|
|
import * as React from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { MenuButton } from "reakit/Menu";
|
|
import ContextMenu from "~/components/ContextMenu";
|
|
import Template from "~/components/ContextMenu/Template";
|
|
import {
|
|
navigateToWorkspaceSettings,
|
|
logout,
|
|
} from "~/actions/definitions/navigation";
|
|
import {
|
|
createTeam,
|
|
switchTeamsList,
|
|
desktopLoginTeam,
|
|
} from "~/actions/definitions/teams";
|
|
import useActionContext from "~/hooks/useActionContext";
|
|
import { useMenuState } from "~/hooks/useMenuState";
|
|
import usePrevious from "~/hooks/usePrevious";
|
|
import useStores from "~/hooks/useStores";
|
|
import separator from "~/menus/separator";
|
|
|
|
type Props = {
|
|
children?: React.ReactNode;
|
|
};
|
|
|
|
const TeamMenu: React.FC = ({ children }: Props) => {
|
|
const menu = useMenuState({
|
|
unstable_offset: [4, -4],
|
|
placement: "bottom-start",
|
|
modal: true,
|
|
});
|
|
const stores = useStores();
|
|
const { theme } = stores.ui;
|
|
const previousTheme = usePrevious(theme);
|
|
const { t } = useTranslation();
|
|
const context = useActionContext({ isContextMenu: true });
|
|
|
|
React.useEffect(() => {
|
|
if (theme !== previousTheme) {
|
|
menu.hide();
|
|
}
|
|
}, [menu, theme, previousTheme]);
|
|
|
|
// NOTE: it's useful to memoize on the team id and session because the action
|
|
// menu is not cached at all.
|
|
const actions = React.useMemo(
|
|
() => [
|
|
...switchTeamsList(context),
|
|
createTeam,
|
|
desktopLoginTeam,
|
|
separator(),
|
|
navigateToWorkspaceSettings,
|
|
logout,
|
|
],
|
|
[context]
|
|
);
|
|
|
|
return (
|
|
<>
|
|
<MenuButton {...menu}>{children}</MenuButton>
|
|
<ContextMenu {...menu} aria-label={t("Account")}>
|
|
<Template {...menu} items={undefined} actions={actions} />
|
|
</ContextMenu>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default observer(TeamMenu);
|