Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rm/1955 hierarchy ux 1 #51

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions src/components/views/context_menus/SpaceContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import SettingsStore from "../../../settings/SettingsStore";
import { useFeatureEnabled } from "../../../hooks/useSettings";
import { Action } from "../../../dispatcher/actions";
import { shouldShowComponent } from "../../../customisations/helpers/UIComponents";
import { UIComponent } from "../../../settings/UIFeature";
import { UIComponent, UIFeature } from "../../../settings/UIFeature";
import PosthogTrackers from "../../../PosthogTrackers";
import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload";

Expand Down Expand Up @@ -193,7 +193,7 @@ const SpaceContextMenu: React.FC<IProps> = ({ space, hideHeader, onFinished, ...
<BetaPill />
</IconizedContextMenuOption>
)}
{canAddSubSpaces && (
{SettingsStore.getValue(UIFeature.AddSubSpace) && canAddSubSpaces && (
<IconizedContextMenuOption
data-testid="new-subspace-option"
iconClassName="mx_SpacePanel_iconPlus"
Expand Down
5 changes: 3 additions & 2 deletions src/components/views/rooms/RoomListHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { useEventEmitterState, useTypedEventEmitter, useTypedEventEmitterState }
import { useFeatureEnabled } from "../../../hooks/useSettings";
import { _t } from "../../../languageHandler";
import PosthogTrackers from "../../../PosthogTrackers";
import { UIComponent } from "../../../settings/UIFeature";
import { UIComponent, UIFeature } from "../../../settings/UIFeature";
import {
getMetaSpaceName,
MetaSpace,
Expand Down Expand Up @@ -59,6 +59,7 @@ import IconizedContextMenu, {
import SpaceContextMenu from "../context_menus/SpaceContextMenu";
import InlineSpinner from "../elements/InlineSpinner";
import { HomeButtonContextMenu } from "../spaces/SpacePanel";
import SettingsStore from "../../../settings/SettingsStore";

const contextMenuBelow = (elementRect: DOMRect): MenuProps => {
// align the context menu's icons with the icon which opened the context menu
Expand Down Expand Up @@ -269,7 +270,7 @@ const RoomListHeader: React.FC<IProps> = ({ onVisibilityChange }) => {
disabled={!canAddSubRooms}
title={!canAddSubRooms ? _t("spaces|error_no_permission_add_room") : undefined}
/>
{canCreateSpaces && (
{SettingsStore.getValue(UIFeature.AddSpace) && canCreateSpaces && (
<IconizedContextMenuOption
label={_t("room_list|add_space_label")}
iconClassName="mx_RoomListHeader_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 @@ -72,7 +72,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 @@ -349,8 +349,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
12 changes: 12 additions & 0 deletions src/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,18 @@ export const SETTINGS: { [setting: string]: ISetting } = {
supportedLevels: LEVELS_UI_FEATURE,
default: true,
},
[UIFeature.ShowCreateSpaceButton]: {
supportedLevels: LEVELS_UI_FEATURE,
default: true,
},
[UIFeature.AddSubSpace]: {
supportedLevels: LEVELS_UI_FEATURE,
default: true,
},
[UIFeature.AddSpace]: {
supportedLevels: LEVELS_UI_FEATURE,
default: true,
},
[UIFeature.ShowStickersButtonSetting]: {
supportedLevels: LEVELS_UI_FEATURE,
default: true,
Expand Down
3 changes: 3 additions & 0 deletions src/settings/UIFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export const enum UIFeature {
RoomHistorySettings = "UIFeature.roomHistorySettings",
TimelineEnableRelativeDates = "UIFeature.timelineEnableRelativeDates",
BulkUnverifiedSessionsReminder = "UIFeature.BulkUnverifiedSessionsReminder",
ShowCreateSpaceButton = "UIFeature.showCreateSpaceButton",
AddSubSpace = "UIFeature.addSubSpace",
AddSpace = "UIFeature.addSpace",
ShowStickersButtonSetting = "UIFeature.showStickersButtonSetting",
InsertTrailingColonSetting = "UIFeature.insertTrailingColonSetting",
ShowJoinLeavesSetting = "UIFeature.showJoinLeavesSetting",
Expand Down
40 changes: 39 additions & 1 deletion test/components/views/context_menus/SpaceContextMenu-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import {
} from "../../../../src/utils/space";
import { leaveSpace } from "../../../../src/utils/leave-behaviour";
import { shouldShowComponent } from "../../../../src/customisations/helpers/UIComponents";
import { UIComponent } from "../../../../src/settings/UIFeature";
import { UIComponent, UIFeature } from "../../../../src/settings/UIFeature";
import SettingsStore from "../../../../src/settings/SettingsStore";

jest.mock("../../../../src/customisations/helpers/UIComponents", () => ({
shouldShowComponent: jest.fn(),
Expand Down Expand Up @@ -223,4 +224,41 @@ describe("<SpaceContextMenu />", () => {
expect(onFinished).toHaveBeenCalled();
});
});

describe("UIFeature.AddSubSpace feature flag", () => {
const space = makeMockSpace();

beforeEach(() => {
// set space to allow adding children to space
mocked(space.currentState.maySendStateEvent).mockReturnValue(true);
mocked(shouldShowComponent).mockReturnValue(true);
jest.clearAllMocks();
});

it("UIFeature.AddSubSpace = true: renders create space button when UIFeature is true", () => {
jest.spyOn(SettingsStore, "getValue").mockImplementation((name) => {
if (name === UIFeature.AddSubSpace) return true;
else return "default";
});
renderComponent({ space });

screen.debug();

expect(screen.getByTestId("add-to-space-header")).toBeInTheDocument();
expect(screen.getByTestId("new-room-option")).toBeInTheDocument();
expect(screen.queryByTestId("new-subspace-option")).toBeInTheDocument();
});

it("UIFeature.AddSubSpace = false: does not render create space button when UIFeature is false", () => {
jest.spyOn(SettingsStore, "getValue").mockImplementation((name) => {
if (name === UIFeature.AddSubSpace) return false;
else return "default";
});
renderComponent({ space });

expect(screen.getByTestId("add-to-space-header")).toBeInTheDocument();
expect(screen.getByTestId("new-room-option")).toBeInTheDocument();
expect(screen.queryByTestId("new-subspace-option")).not.toBeInTheDocument();
});
});
});
28 changes: 27 additions & 1 deletion test/components/views/rooms/RoomListHeader-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { MatrixClientPeg } from "../../../../src/MatrixClientPeg";
import SettingsStore from "../../../../src/settings/SettingsStore";
import { SettingLevel } from "../../../../src/settings/SettingLevel";
import { shouldShowComponent } from "../../../../src/customisations/helpers/UIComponents";
import { UIComponent } from "../../../../src/settings/UIFeature";
import { UIComponent, UIFeature } from "../../../../src/settings/UIFeature";

const RoomListHeader = testUtils.wrapInMatrixClientContext(_RoomListHeader);

Expand Down Expand Up @@ -285,4 +285,30 @@ describe("RoomListHeader", () => {
checkIsDisabled(items[3]);
});
});

describe("UIFeature.AddSpace", () => {
it("UIFeature.AddSpace = true: renders Add Space when user has permission to add spaces", async () => {
jest.spyOn(SettingsStore, "getValue").mockImplementation((name) => {
if (name === UIFeature.AddSpace) return true;
else return "default";
});

const testSpace = setupSpace(client);
await setupPlusMenu(client, testSpace);

expect(screen.getByText("Add space")).toBeInTheDocument();
});

it("UIFeature.AddSpace = false: does not render Add Space when user has permission to add spaces", async () => {
jest.spyOn(SettingsStore, "getValue").mockImplementation((name) => {
if (name === UIFeature.AddSpace) return false;
else return "default";
});

const testSpace = setupSpace(client);
await setupPlusMenu(client, testSpace);

expect(screen.queryByText("Add space")).not.toBeInTheDocument();
});
});
});
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 @@ -26,7 +26,7 @@ import {
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 @@ -182,6 +182,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
Loading