From 2f2067e434000fd4531f270b36b3b8fa6a781b6e Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 1 Aug 2023 16:26:14 +0100 Subject: [PATCH] Fix home/all rooms context menu in space panel (#11350) * Fix home/all rooms context menu in space panel * Fix tests --- .../views/context_menus/SpaceContextMenu.tsx | 11 ++++++----- src/components/views/spaces/SpaceTreeLevel.tsx | 2 +- .../views/context_menus/SpaceContextMenu-test.tsx | 2 ++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/views/context_menus/SpaceContextMenu.tsx b/src/components/views/context_menus/SpaceContextMenu.tsx index bdc25916e9f..6dff155415a 100644 --- a/src/components/views/context_menus/SpaceContextMenu.tsx +++ b/src/components/views/context_menus/SpaceContextMenu.tsx @@ -43,13 +43,17 @@ import PosthogTrackers from "../../../PosthogTrackers"; import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload"; interface IProps extends IContextMenuProps { - space: Room; + space?: Room; hideHeader?: boolean; } const SpaceContextMenu: React.FC = ({ space, hideHeader, onFinished, ...props }) => { const cli = useContext(MatrixClientContext); - const userId = cli.getUserId()!; + const userId = cli.getSafeUserId(); + const videoRoomsEnabled = useFeatureEnabled("feature_video_rooms"); + const elementCallVideoRoomsEnabled = useFeatureEnabled("feature_element_call_video_rooms"); + + if (!space) return null; let inviteOption: JSX.Element | null = null; if (space.getJoinRule() === "public" || space.canInvite(userId)) { @@ -135,9 +139,6 @@ const SpaceContextMenu: React.FC = ({ space, hideHeader, onFinished, ... ); } - const videoRoomsEnabled = useFeatureEnabled("feature_video_rooms"); - const elementCallVideoRoomsEnabled = useFeatureEnabled("feature_element_call_video_rooms"); - const hasPermissionToAddSpaceChild = space.currentState.maySendStateEvent(EventType.SpaceChild, userId); const canAddRooms = hasPermissionToAddSpaceChild && shouldShowComponent(UIComponent.CreateRooms); const canAddVideoRooms = canAddRooms && videoRoomsEnabled; diff --git a/src/components/views/spaces/SpaceTreeLevel.tsx b/src/components/views/spaces/SpaceTreeLevel.tsx index 9f66a290b99..926b9048da9 100644 --- a/src/components/views/spaces/SpaceTreeLevel.tsx +++ b/src/components/views/spaces/SpaceTreeLevel.tsx @@ -121,7 +121,7 @@ export const SpaceButton: React.FC = ({ } let contextMenu: JSX.Element | undefined; - if (space && menuDisplayed && handle.current && ContextMenuComponent) { + if (menuDisplayed && handle.current && ContextMenuComponent) { contextMenu = ( ", () => { const mockClient = { getUserId: jest.fn().mockReturnValue(userId), + getSafeUserId: jest.fn().mockReturnValue(userId), } as unknown as Mocked; const makeMockSpace = (props = {}) => @@ -86,6 +87,7 @@ describe("", () => { beforeEach(() => { jest.resetAllMocks(); mockClient.getUserId.mockReturnValue(userId); + mockClient.getSafeUserId.mockReturnValue(userId); }); it("renders menu correctly", () => {