Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 0e0be08

Browse files
robintownestellecommentmcalingheeweeman1337
authored
Remove "Add Space" button from RoomListHeader when user cannot create spaces (#9129)
* Remove Add Space button in RoomListHeader when user cannot createSpaces * Reuse the same booleans as SpaceContextMenu * Code review fixes * Fix test for standard case * Refactor tests and add more * Test the PlusMenu, where the bug originally was * Add tests for plus menu * Refactor tests * add type in functions and use DMRoomMap#setShared * use of wrapInMatrixClientContext * Trigger CI * Ignore enzyme deprecation in RoomListHeader-test.tsx Co-authored-by: Estelle Comment <[email protected]> Co-authored-by: mcalinghee <[email protected]> Co-authored-by: Michael Weimann <[email protected]>
1 parent ed3350c commit 0e0be08

File tree

2 files changed

+255
-67
lines changed

2 files changed

+255
-67
lines changed

src/components/views/rooms/RoomListHeader.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,19 @@ const RoomListHeader = ({ onVisibilityChange }: IProps) => {
146146
}
147147
}, [onVisibilityChange]);
148148

149-
const canAddRooms = activeSpace?.currentState?.maySendStateEvent(EventType.SpaceChild, cli.getUserId());
150-
151-
const canCreateRooms = shouldShowComponent(UIComponent.CreateRooms);
152149
const canExploreRooms = shouldShowComponent(UIComponent.ExploreRooms);
150+
const canCreateRooms = shouldShowComponent(UIComponent.CreateRooms);
151+
const canCreateSpaces = shouldShowComponent(UIComponent.CreateSpaces);
152+
153+
const hasPermissionToAddSpaceChild =
154+
activeSpace?.currentState?.maySendStateEvent(EventType.SpaceChild, cli.getUserId());
155+
const canAddSubRooms = hasPermissionToAddSpaceChild && canCreateRooms;
156+
const canAddSubSpaces = hasPermissionToAddSpaceChild && canCreateSpaces;
153157

154158
// If the user can't do anything on the plus menu, don't show it. This aims to target the
155159
// plus menu shown on the Home tab primarily: the user has options to use the menu for
156160
// communities and spaces, but is at risk of no options on the Home tab.
157-
const canShowPlusMenu = canCreateRooms || canExploreRooms || activeSpace;
161+
const canShowPlusMenu = canCreateRooms || canExploreRooms || canCreateSpaces || activeSpace;
158162

159163
let contextMenu: JSX.Element;
160164
if (mainMenuDisplayed && mainMenuHandle.current) {
@@ -249,10 +253,10 @@ const RoomListHeader = ({ onVisibilityChange }: IProps) => {
249253
showAddExistingRooms(activeSpace);
250254
closePlusMenu();
251255
}}
252-
disabled={!canAddRooms}
253-
tooltip={!canAddRooms && _t("You do not have permissions to add rooms to this space")}
256+
disabled={!canAddSubRooms}
257+
tooltip={!canAddSubRooms && _t("You do not have permissions to add rooms to this space")}
254258
/>
255-
<IconizedContextMenuOption
259+
{ canCreateSpaces && <IconizedContextMenuOption
256260
label={_t("Add space")}
257261
iconClassName="mx_RoomListHeader_iconPlus"
258262
onClick={(e) => {
@@ -261,11 +265,12 @@ const RoomListHeader = ({ onVisibilityChange }: IProps) => {
261265
showCreateNewSubspace(activeSpace);
262266
closePlusMenu();
263267
}}
264-
disabled={!canAddRooms}
265-
tooltip={!canAddRooms && _t("You do not have permissions to add spaces to this space")}
268+
disabled={!canAddSubSpaces}
269+
tooltip={!canAddSubSpaces && _t("You do not have permissions to add spaces to this space")}
266270
>
267271
<BetaPill />
268272
</IconizedContextMenuOption>
273+
}
269274
</IconizedContextMenuOptionList>
270275
</IconizedContextMenu>;
271276
} else if (plusMenuDisplayed) {

0 commit comments

Comments
 (0)