Fix home/all rooms context menu in space panel (#11350)

* Fix home/all rooms context menu in space panel

* Fix tests
pull/28217/head
Michael Telatynski 2023-08-01 16:26:14 +01:00 committed by GitHub
parent 5d9f5ccf0b
commit 2f2067e434
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 6 deletions

View File

@ -43,13 +43,17 @@ import PosthogTrackers from "../../../PosthogTrackers";
import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload"; import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload";
interface IProps extends IContextMenuProps { interface IProps extends IContextMenuProps {
space: Room; space?: Room;
hideHeader?: boolean; hideHeader?: boolean;
} }
const SpaceContextMenu: React.FC<IProps> = ({ space, hideHeader, onFinished, ...props }) => { const SpaceContextMenu: React.FC<IProps> = ({ space, hideHeader, onFinished, ...props }) => {
const cli = useContext(MatrixClientContext); 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; let inviteOption: JSX.Element | null = null;
if (space.getJoinRule() === "public" || space.canInvite(userId)) { if (space.getJoinRule() === "public" || space.canInvite(userId)) {
@ -135,9 +139,6 @@ const SpaceContextMenu: React.FC<IProps> = ({ 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 hasPermissionToAddSpaceChild = space.currentState.maySendStateEvent(EventType.SpaceChild, userId);
const canAddRooms = hasPermissionToAddSpaceChild && shouldShowComponent(UIComponent.CreateRooms); const canAddRooms = hasPermissionToAddSpaceChild && shouldShowComponent(UIComponent.CreateRooms);
const canAddVideoRooms = canAddRooms && videoRoomsEnabled; const canAddVideoRooms = canAddRooms && videoRoomsEnabled;

View File

@ -121,7 +121,7 @@ export const SpaceButton: React.FC<IButtonProps> = ({
} }
let contextMenu: JSX.Element | undefined; let contextMenu: JSX.Element | undefined;
if (space && menuDisplayed && handle.current && ContextMenuComponent) { if (menuDisplayed && handle.current && ContextMenuComponent) {
contextMenu = ( contextMenu = (
<ContextMenuComponent <ContextMenuComponent
{...toRightOf(handle.current.getBoundingClientRect(), 0)} {...toRightOf(handle.current.getBoundingClientRect(), 0)}

View File

@ -56,6 +56,7 @@ describe("<SpaceContextMenu />", () => {
const mockClient = { const mockClient = {
getUserId: jest.fn().mockReturnValue(userId), getUserId: jest.fn().mockReturnValue(userId),
getSafeUserId: jest.fn().mockReturnValue(userId),
} as unknown as Mocked<MatrixClient>; } as unknown as Mocked<MatrixClient>;
const makeMockSpace = (props = {}) => const makeMockSpace = (props = {}) =>
@ -86,6 +87,7 @@ describe("<SpaceContextMenu />", () => {
beforeEach(() => { beforeEach(() => {
jest.resetAllMocks(); jest.resetAllMocks();
mockClient.getUserId.mockReturnValue(userId); mockClient.getUserId.mockReturnValue(userId);
mockClient.getSafeUserId.mockReturnValue(userId);
}); });
it("renders menu correctly", () => { it("renders menu correctly", () => {