Skip to content

Commit

Permalink
1644 - Hide "Create space"-button on top level
Browse files Browse the repository at this point in the history
  • Loading branch information
eiksta committed Jun 7, 2024
1 parent 3342aa5 commit ae15e5d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/components/structures/SpaceRoomView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { useStateArray } from "../../hooks/useStateArray";
import { _t } from "../../languageHandler";
import PosthogTrackers from "../../PosthogTrackers";
import { inviteMultipleToRoom, showRoomInviteDialog } from "../../RoomInvite";
import { UIComponent } from "../../settings/UIFeature";
import { UIComponent , UIFeature } from "../../settings/UIFeature";
import { UPDATE_EVENT } from "../../stores/AsyncStore";
import RightPanelStore from "../../stores/right-panel/RightPanelStore";
import { RightPanelPhases } from "../../stores/right-panel/RightPanelStorePhases";
Expand Down Expand Up @@ -74,6 +74,7 @@ import MainSplit from "./MainSplit";
import RightPanel from "./RightPanel";
import SpaceHierarchy, { showRoom } from "./SpaceHierarchy";
import { RoomPermalinkCreator } from "../../utils/permalinks/Permalinks";
import SettingsStore from "../../settings/SettingsStore";

interface IProps {
space: Room;
Expand Down Expand Up @@ -173,7 +174,7 @@ const SpaceLandingAddButton: React.FC<{ space: Room }> = ({ space }) => {
showAddExistingRooms(space);
}}
/>
{canCreateSpace && (
{canCreateSpace && SettingsStore.getValue(UIFeature.ShowCreateSpaceButton) && (
<IconizedContextMenuOption
label={_t("room_list|add_space_label")}
iconClassName="mx_RoomList_iconPlus"
Expand Down
13 changes: 10 additions & 3 deletions src/components/views/spaces/SpacePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import { ActionPayload } from "../../../dispatcher/payloads";
import { Action } from "../../../dispatcher/actions";
import { NotificationState } from "../../../stores/notifications/NotificationState";
import { shouldShowComponent } from "../../../customisations/helpers/UIComponents";
import { UIComponent } from "../../../settings/UIFeature";
import { UIComponent, UIFeature } from "../../../settings/UIFeature";
import { ThreadsActivityCentre } from "./threads-activity-centre/";
import AccessibleButton from "../elements/AccessibleButton";
import { KeyboardShortcut } from "../settings/KeyboardShortcut";
Expand Down Expand Up @@ -344,8 +344,15 @@ const InnerSpacePanel = React.memo<IInnerSpacePanelProps>(
</Draggable>
))}
{children}
{shouldShowComponent(UIComponent.CreateSpaces) && (
<CreateSpaceButton isPanelCollapsed={isPanelCollapsed} setPanelCollapsed={setPanelCollapsed} />
{SettingsStore.getValue(UIFeature.ShowCreateSpaceButton) && (
<>
{shouldShowComponent(UIComponent.CreateSpaces) && (
<CreateSpaceButton
isPanelCollapsed={isPanelCollapsed}
setPanelCollapsed={setPanelCollapsed}
/>
)}
</>
)}
</IndicatorScrollbar>
);
Expand Down
4 changes: 4 additions & 0 deletions src/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,10 @@ export const SETTINGS: { [setting: string]: ISetting } = {
supportedLevels: LEVELS_UI_FEATURE,
default: true,
},
[UIFeature.ShowCreateSpaceButton]: {
supportedLevels: LEVELS_UI_FEATURE,
default: true,
},

// Electron-specific settings, they are stored by Electron and set/read over an IPC.
// We store them over there are they are necessary to know before the renderer process launches.
Expand Down
1 change: 1 addition & 0 deletions src/settings/UIFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const enum UIFeature {
RoomHistorySettings = "UIFeature.roomHistorySettings",
TimelineEnableRelativeDates = "UIFeature.timelineEnableRelativeDates",
BulkUnverifiedSessionsReminder = "UIFeature.BulkUnverifiedSessionsReminder",
ShowCreateSpaceButton = "UIFeature.showCreateSpaceButton",
}

export enum UIComponent {
Expand Down
20 changes: 19 additions & 1 deletion test/components/views/spaces/SpacePanel-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { MatrixClient, Room } from "matrix-js-sdk/src/matrix";
import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
import { MetaSpace, SpaceKey } from "../../../../src/stores/spaces";
import { shouldShowComponent } from "../../../../src/customisations/helpers/UIComponents";
import { UIComponent } from "../../../../src/settings/UIFeature";
import { UIComponent, UIFeature } from "../../../../src/settings/UIFeature";
import { mkStubRoom, wrapInMatrixClientContext, wrapInSdkContext } from "../../../test-utils";
import { SdkContextClass } from "../../../../src/contexts/SDKContext";
import SpaceStore from "../../../../src/stores/spaces/SpaceStore";
Expand Down Expand Up @@ -177,6 +177,24 @@ describe("<SpacePanel />", () => {
fireEvent.click(screen.getByTestId("create-space-button"));
screen.getByTestId("create-space-button");
});
it("renders create space button when UIFeature is true", () => {
jest.spyOn(SettingsStore, "getValue").mockImplementation((name) => {
if (name === UIFeature.ShowCreateSpaceButton) return true;
return true;
});
mocked(shouldShowComponent).mockReturnValue(true);
render(<SpacePanel />);
expect(screen.queryByTestId("create-space-button")).not.toBeNull();
});
it("does not render create space button when UIFeature is false", () => {
jest.spyOn(SettingsStore, "getValue").mockImplementation((name) => {
if (name === UIFeature.ShowCreateSpaceButton) return false;
return true;
});
mocked(shouldShowComponent).mockReturnValue(true);
render(<SpacePanel />);
expect(screen.queryByTestId("create-space-button")).toBeNull();
});
});

it("should allow rearranging via drag and drop", async () => {
Expand Down

0 comments on commit ae15e5d

Please sign in to comment.