From 9618d514e155358153d3d3f07e8e1662c84bd59c Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 17 Dec 2022 21:50:50 -0500 Subject: [PATCH] fix: Switch workspace unreliable --- app/actions/definitions/teams.tsx | 43 ++++++++++++++++--------------- app/menus/OrganizationMenu.tsx | 6 +++-- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/app/actions/definitions/teams.tsx b/app/actions/definitions/teams.tsx index fcb8c9d85..b9334e421 100644 --- a/app/actions/definitions/teams.tsx +++ b/app/actions/definitions/teams.tsx @@ -6,31 +6,32 @@ import RootStore from "~/stores/RootStore"; import TeamNew from "~/scenes/TeamNew"; import TeamLogo from "~/components/TeamLogo"; import { createAction } from "~/actions"; +import { ActionContext } from "~/types"; import { TeamSection } from "../sections"; export const createTeamsList = ({ stores }: { stores: RootStore }) => { return ( - stores.auth.availableTeams?.map((session) => - createAction({ - name: session.name, - section: TeamSection, - keywords: "change switch workspace organization team", - icon: () => ( - - ), - visible: ({ currentTeamId }) => currentTeamId !== session.id, - perform: () => (window.location.href = session.url), - }) - ) ?? [] + stores.auth.availableTeams?.map((session) => ({ + id: `switch-${session.id}`, + name: session.name, + section: TeamSection, + keywords: "change switch workspace organization team", + icon: () => ( + + ), + visible: ({ currentTeamId }: ActionContext) => + currentTeamId !== session.id, + perform: () => (window.location.href = session.url), + })) ?? [] ); }; diff --git a/app/menus/OrganizationMenu.tsx b/app/menus/OrganizationMenu.tsx index 2c1d11578..06beb149f 100644 --- a/app/menus/OrganizationMenu.tsx +++ b/app/menus/OrganizationMenu.tsx @@ -6,6 +6,7 @@ import ContextMenu from "~/components/ContextMenu"; import Template from "~/components/ContextMenu/Template"; import { navigateToSettings, logout } from "~/actions/definitions/navigation"; import { createTeam, createTeamsList } from "~/actions/definitions/teams"; +import useActionContext from "~/hooks/useActionContext"; import usePrevious from "~/hooks/usePrevious"; import useStores from "~/hooks/useStores"; import separator from "~/menus/separator"; @@ -20,6 +21,7 @@ const OrganizationMenu: React.FC = ({ children }) => { const { theme } = stores.ui; const previousTheme = usePrevious(theme); const { t } = useTranslation(); + const context = useActionContext({ isContextMenu: true }); React.useEffect(() => { if (theme !== previousTheme) { @@ -31,13 +33,13 @@ const OrganizationMenu: React.FC = ({ children }) => { // menu is not cached at all. const actions = React.useMemo(() => { return [ - ...createTeamsList({ stores }), + ...createTeamsList(context), createTeam, separator(), navigateToSettings, logout, ]; - }, [stores]); + }, [context]); return ( <>