Files
outline/app/menus/ApiKeyMenu.tsx
codegen-sh[bot]andTom Moor d559afe2ce fix: Prevent multiple context menus from being open simultaneously (#9298)
* 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>
2025-05-24 19:20:00 -04:00

46 lines
1.3 KiB
TypeScript

import { observer } from "mobx-react";
import { useCallback } from "react";
import { useTranslation } from "react-i18next";
import ApiKey from "~/models/ApiKey";
import ApiKeyRevokeDialog from "~/scenes/Settings/components/ApiKeyRevokeDialog";
import ContextMenu from "~/components/ContextMenu";
import MenuItem from "~/components/ContextMenu/MenuItem";
import OverflowMenuButton from "~/components/ContextMenu/OverflowMenuButton";
import { useMenuState } from "~/hooks/useMenuState";
import useStores from "~/hooks/useStores";
type Props = {
/** The apiKey to associate with the menu */
apiKey: ApiKey;
};
function ApiKeyMenu({ apiKey }: Props) {
const menu = useMenuState({
modal: true,
});
const { dialogs } = useStores();
const { t } = useTranslation();
const handleRevoke = useCallback(() => {
dialogs.openModal({
title: t("Revoke token"),
content: (
<ApiKeyRevokeDialog onSubmit={dialogs.closeAllModals} apiKey={apiKey} />
),
});
}, [t, dialogs, apiKey]);
return (
<>
<OverflowMenuButton aria-label={t("Show menu")} {...menu} />
<ContextMenu {...menu}>
<MenuItem {...menu} onClick={handleRevoke} dangerous>
{t("Revoke")}
</MenuItem>
</ContextMenu>
</>
);
}
export default observer(ApiKeyMenu);