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

Update RoomSummaryCard navigation links #11812

Merged
merged 31 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
97e5c74
Update RoomSummaryCard navigation links
Oct 31, 2023
a4edf58
Fix tests
Oct 31, 2023
684da23
remove unneeded test
Oct 31, 2023
08d2cd8
Merge branch 'develop' into germain-gg/summary-card-links
Nov 10, 2023
427ed16
"@vector-im/compound-web": "0.8.0"
Nov 10, 2023
c7079f3
Merge branch 'kerry/bump-cw' into germain-gg/summary-card-links
Nov 10, 2023
711ef2f
Merge branch 'develop' into germain-gg/summary-card-links
Nov 14, 2023
222156c
Fix: search button no transition on hover
Nov 14, 2023
f93762a
Fix: disabled invite option is not reflected in UI
Nov 14, 2023
4173b1e
Merge pull request #11867 from matrix-org/kerry/summary-card-links
Nov 14, 2023
ab6d71b
test canInviteTo
Nov 14, 2023
2f473ba
update snapshots for CW 0.8.1
Nov 14, 2023
2ecb139
Merge pull request #11868 from matrix-org/kerry/summary-card-links
Nov 14, 2023
173b62d
unit test inviteToRoom
Nov 14, 2023
0026789
unit test tagRoom
Nov 14, 2023
adafbbc
add member link to roomsummarycard when using legacy room header
Nov 14, 2023
a3be1e1
Merge branch 'develop' into kerry/summary-card-links
Nov 14, 2023
d3064c7
Merge branch 'develop' into germain-gg/summary-card-links
Nov 14, 2023
bca684c
use onChange instead of onClick for ToggleMenuItem favourite room
Nov 15, 2023
49cd1f5
update selectors in cypress tests
Nov 15, 2023
6f65375
Merge branch 'germain-gg/summary-card-links' into kerry/summary-card-…
Nov 15, 2023
0e5b1e6
Merge pull request #11883 from matrix-org/kerry/summary-card-links
Nov 15, 2023
72da2cd
always show people menu item
Nov 15, 2023
8bca205
always show people menu item
Nov 15, 2023
8bee956
Merge branch 'develop' into germain-gg/summary-card-links
Nov 15, 2023
55a346b
add hover style to close button
Nov 15, 2023
1a2efe7
add padding around room name
Nov 15, 2023
012e00f
Merge pull request #11886 from matrix-org/kerry/summary-card-links
Nov 15, 2023
d0bd00e
Merge branch 'develop' into germain-gg/summary-card-links
Nov 16, 2023
18955a0
prettier
Nov 16, 2023
d30ec58
Merge branch 'develop' into germain-gg/summary-card-links
Nov 16, 2023
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
"@sentry/browser": "^7.0.0",
"@sentry/tracing": "^7.0.0",
"@testing-library/react-hooks": "^8.0.1",
"@vector-im/compound-design-tokens": "^0.0.6",
"@vector-im/compound-web": "0.5.4",
"@vector-im/compound-design-tokens": "0.0.7",
"@vector-im/compound-web": "0.6.3",
"@zxcvbn-ts/core": "^3.0.4",
"@zxcvbn-ts/language-common": "^3.0.4",
"@zxcvbn-ts/language-en": "^3.0.2",
Expand Down
54 changes: 0 additions & 54 deletions res/css/views/right_panel/_RoomSummaryCard.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,6 @@ limitations under the License.
}
}

.mx_RoomSummaryCard_aboutGroup {
.mx_RoomSummaryCard_Button {
padding-left: 44px;

&::before {
content: "";
position: absolute;
top: 8px;
left: 10px;
height: 24px;
width: 24px;
mask-repeat: no-repeat;
mask-position: center;
background-color: $icon-button-color;
}
}
}

.mx_RoomSummaryCard_appsGroup {
.mx_RoomSummaryCard_Button {
/* this button is special so we have to override some of the original styling */
Expand Down Expand Up @@ -259,42 +241,6 @@ limitations under the License.
cursor: pointer;
}

.mx_RoomSummaryCard_icon_people::before {
mask-image: url("$(res)/img/element-icons/room/members.svg");
}

.mx_RoomSummaryCard_icon_files::before {
mask-image: url("$(res)/img/element-icons/room/files.svg");
}

.mx_RoomSummaryCard_icon_pins::before {
mask-image: url("$(res)/img/element-icons/room/pin-upright.svg");
}

.mx_RoomSummaryCard_icon_threads::before {
mask-image: url("$(res)/img/element-icons/message/thread.svg");
}

.mx_RoomSummaryCard_icon_share::before {
mask-image: url("$(res)/img/element-icons/room/share.svg");
}

.mx_RoomSummaryCard_icon_settings::before {
mask-image: url("$(res)/img/element-icons/settings.svg");
}

.mx_RoomSummaryCard_icon_export::before {
mask-image: url("$(res)/img/element-icons/export.svg");
}

.mx_RoomSummaryCard_icon_poll::before {
mask-image: url("$(res)/img/element-icons/room/composer/poll.svg");
}

.mx_RoomSummaryCard_icon_search::before {
mask-image: url("$(res)/img/element-icons/room/search-inset.svg");
}

.mx_RoomSummaryCard_searchBtn {
background: var(--cpd-color-bg-canvas-default);
color: var(--cpd-color-icon-primary);
Expand Down
13 changes: 2 additions & 11 deletions src/components/views/context_menus/RoomContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ limitations under the License.

import React, { useContext } from "react";
import { Room } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger";

import { IProps as IContextMenuProps } from "../../structures/ContextMenu";
import IconizedContextMenu, {
Expand All @@ -30,7 +29,6 @@ import { ButtonEvent } from "../elements/AccessibleButton";
import { DefaultTagID, TagID } from "../../../stores/room-list/models";
import RoomListStore, { LISTS_UPDATE_EVENT } from "../../../stores/room-list/RoomListStore";
import dis from "../../../dispatcher/dispatcher";
import RoomListActions from "../../../actions/RoomListActions";
import { EchoChamber } from "../../../stores/local-echo/EchoChamber";
import { RoomNotifState } from "../../../RoomNotifs";
import Modal from "../../../Modal";
Expand All @@ -52,6 +50,7 @@ import { SdkContextClass } from "../../../contexts/SDKContext";
import { shouldShowComponent } from "../../../customisations/helpers/UIComponents";
import { UIComponent } from "../../../settings/UIFeature";
import { DeveloperToolsOption } from "./DeveloperToolsOption";
import { tagRoom } from "../../../utils/room/tagRoom";

interface IProps extends IContextMenuProps {
room: Room;
Expand Down Expand Up @@ -333,15 +332,7 @@ const RoomContextMenu: React.FC<IProps> = ({ room, onFinished, ...props }) => {
ev.preventDefault();
ev.stopPropagation();

if (tagId === DefaultTagID.Favourite || tagId === DefaultTagID.LowPriority) {
const inverseTag = tagId === DefaultTagID.Favourite ? DefaultTagID.LowPriority : DefaultTagID.Favourite;
const isApplied = RoomListStore.instance.getTagsForRoom(room).includes(tagId);
const removeTag = isApplied ? tagId : inverseTag;
const addTag = isApplied ? null : tagId;
dis.dispatch(RoomListActions.tagRoom(cli, room, removeTag, addTag, 0));
} else {
logger.warn(`Unexpected tag ${tagId} applied to ${room.roomId}`);
}
tagRoom(room, tagId);

const action = getKeyBindingsManager().getAccessibilityAction(ev as React.KeyboardEvent);
switch (action) {
Expand Down
139 changes: 75 additions & 64 deletions src/components/views/right_panel/RoomSummaryCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,29 @@ limitations under the License.
import React, { useCallback, useContext, useEffect, useMemo, useState } from "react";
import classNames from "classnames";
import { Room } from "matrix-js-sdk/src/matrix";
import { Tooltip } from "@vector-im/compound-web";
import { MenuItem, Tooltip, Separator, ToggleMenuItem, Text } from "@vector-im/compound-web";
import { Icon as SearchIcon } from "@vector-im/compound-design-tokens/icons/search.svg";
import { Icon as FavouriteIcon } from "@vector-im/compound-design-tokens/icons/favourite-off.svg";
import { Icon as UserAddIcon } from "@vector-im/compound-design-tokens/icons/user-add.svg";
import { Icon as LinkIcon } from "@vector-im/compound-design-tokens/icons/link.svg";
import { Icon as SettingsIcon } from "@vector-im/compound-design-tokens/icons/settings.svg";
import { Icon as ExportArchiveIcon } from "@vector-im/compound-design-tokens/icons/export-archive.svg";
import { Icon as LeaveIcon } from "@vector-im/compound-design-tokens/icons/leave.svg";
import { Icon as FilesIcon } from "@vector-im/compound-design-tokens/icons/files.svg";
import { Icon as PollsIcon } from "@vector-im/compound-design-tokens/icons/polls.svg";
import { Icon as PinIcon } from "@vector-im/compound-design-tokens/icons/pin-off.svg";

import MatrixClientContext from "../../../contexts/MatrixClientContext";
import { useIsEncrypted } from "../../../hooks/useIsEncrypted";
import BaseCard, { Group } from "./BaseCard";
import { _t } from "../../../languageHandler";
import RoomAvatar from "../avatars/RoomAvatar";
import AccessibleButton, { ButtonEvent, IAccessibleButtonProps } from "../elements/AccessibleButton";
import AccessibleButton, { ButtonEvent } from "../elements/AccessibleButton";
import defaultDispatcher from "../../../dispatcher/dispatcher";
import { RightPanelPhases } from "../../../stores/right-panel/RightPanelStorePhases";
import Modal from "../../../Modal";
import ShareDialog from "../dialogs/ShareDialog";
import { useEventEmitter } from "../../../hooks/useEventEmitter";
import { useEventEmitter, useEventEmitterState } from "../../../hooks/useEventEmitter";
import WidgetUtils from "../../../utils/WidgetUtils";
import { IntegrationManagers } from "../../../integrations/IntegrationManagers";
import SettingsStore from "../../../settings/SettingsStore";
Expand All @@ -44,7 +53,6 @@ import RoomContext from "../../../contexts/RoomContext";
import { UIComponent, UIFeature } from "../../../settings/UIFeature";
import { ChevronFace, ContextMenuTooltipButton, useContextMenu } from "../../structures/ContextMenu";
import { WidgetContextMenu } from "../context_menus/WidgetContextMenu";
import { useRoomMemberCount } from "../../../hooks/useRoomMembers";
import { useFeatureEnabled } from "../../../hooks/useSettings";
import { usePinnedEvents } from "./PinnedMessagesCard";
import { Container, MAX_PINNED, WidgetLayoutStore } from "../../../stores/widgets/WidgetLayoutStore";
Expand All @@ -56,6 +64,11 @@ import PosthogTrackers from "../../../PosthogTrackers";
import { shouldShowComponent } from "../../../customisations/helpers/UIComponents";
import { PollHistoryDialog } from "../dialogs/PollHistoryDialog";
import { Flex } from "../../utils/Flex";
import RoomListStore, { LISTS_UPDATE_EVENT } from "../../../stores/room-list/RoomListStore";
import { DefaultTagID } from "../../../stores/room-list/models";
import { tagRoom } from "../../../utils/room/tagRoom";
import { canInviteTo } from "../../../utils/room/canInviteTo";
import { inviteToRoom } from "../../../utils/room/inviteToRoom";

interface IProps {
room: Room;
Expand All @@ -68,23 +81,6 @@ interface IAppsSectionProps {
room: Room;
}

interface IButtonProps extends IAccessibleButtonProps {
className: string;
onClick(ev: ButtonEvent): void;
}

const Button: React.FC<IButtonProps> = ({ children, className, onClick, ...props }) => {
return (
<AccessibleButton
{...props}
className={classNames("mx_BaseCard_Button mx_RoomSummaryCard_Button", className)}
onClick={onClick}
>
{children}
</AccessibleButton>
);
};

export const useWidgets = (room: Room): IApp[] => {
const [apps, setApps] = useState<IApp[]>(() => WidgetStore.instance.getApps(room.roomId));

Expand Down Expand Up @@ -258,11 +254,6 @@ const AppsSection: React.FC<IAppsSectionProps> = ({ room }) => {
);
};

const onRoomMembersClick = (ev: ButtonEvent): void => {
RightPanelStore.instance.pushCard({ phase: RightPanelPhases.RoomMemberList }, true);
PosthogTrackers.trackInteraction("WebRightPanelRoomInfoPeopleButton", ev);
};

const onRoomFilesClick = (): void => {
RightPanelStore.instance.pushCard({ phase: RightPanelPhases.FilePanel }, true);
};
Expand Down Expand Up @@ -299,6 +290,13 @@ const RoomSummaryCard: React.FC<IProps> = ({ room, permalinkCreator, onClose, on
});
};

const onLeaveRoomClick = (): void => {
defaultDispatcher.dispatch({
action: "leave_room",
room_id: room.roomId,
});
};

const isRoomEncrypted = useIsEncrypted(cli, room);
const roomContext = useContext(RoomContext);
const e2eStatus = roomContext.e2eStatus;
Expand Down Expand Up @@ -335,10 +333,14 @@ const RoomSummaryCard: React.FC<IProps> = ({ room, permalinkCreator, onClose, on
</header>
);

const memberCount = useRoomMemberCount(room);
const pinningEnabled = useFeatureEnabled("feature_pinning");
const pinCount = usePinnedEvents(pinningEnabled ? room : undefined)?.length;

const roomTags = useEventEmitterState(RoomListStore.instance, LISTS_UPDATE_EVENT, () =>
RoomListStore.instance.getTagsForRoom(room),
);
const isFavorite = roomTags.includes(DefaultTagID.Favourite);

return (
<BaseCard header={null} className="mx_RoomSummaryCard" onClose={onClose}>
<Flex
Expand Down Expand Up @@ -369,43 +371,52 @@ const RoomSummaryCard: React.FC<IProps> = ({ room, permalinkCreator, onClose, on
</Flex>

{header}
<Group title={_t("common|about")} className="mx_RoomSummaryCard_aboutGroup">
<Button className="mx_RoomSummaryCard_icon_people" onClick={onRoomMembersClick}>
{_t("common|people")}
<span className="mx_BaseCard_Button_sublabel">{memberCount}</span>
</Button>
{!isVideoRoom && (
<Button className="mx_RoomSummaryCard_icon_files" onClick={onRoomFilesClick}>
{_t("right_panel|files_button")}
</Button>
)}
{!isVideoRoom && (
<Button className="mx_RoomSummaryCard_icon_poll" onClick={onRoomPollHistoryClick}>
{_t("right_panel|polls_button")}
</Button>
)}
{pinningEnabled && !isVideoRoom && (
<Button className="mx_RoomSummaryCard_icon_pins" onClick={onRoomPinsClick}>
{_t("right_panel|pinned_messages_button")}
{pinCount > 0 && <span className="mx_BaseCard_Button_sublabel">{pinCount}</span>}
</Button>
)}
{!isVideoRoom && (
<Button className="mx_RoomSummaryCard_icon_export" onClick={onRoomExportClick}>
{_t("right_panel|export_chat_button")}
</Button>
)}
<Button
data-testid="shareRoomButton"
className="mx_RoomSummaryCard_icon_share"
onClick={onShareRoomClick}
>
{_t("right_panel|share_button")}
</Button>
<Button className="mx_RoomSummaryCard_icon_settings" onClick={onRoomSettingsClick}>
{_t("right_panel|settings_button")}
</Button>
</Group>

<Separator />

<ToggleMenuItem
Icon={FavouriteIcon}
label={_t("room|context_menu|favourite")}
checked={isFavorite}
onClick={() => tagRoom(room, DefaultTagID.Favourite)}
/>
<MenuItem
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The disabled state is not reflected in the UI. It still looks like, that you can click the item:

image

Peek 2023-11-01 09-57

Tested in Matrix-HQ

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2023-11-14 at 16 02 26

Fixed in compound 0.8.1

Icon={UserAddIcon}
label={_t("action|invite")}
disabled={!canInviteTo(room)}
onClick={() => inviteToRoom(room)}
/>
<MenuItem Icon={LinkIcon} label={_t("action|copy_link")} onClick={onShareRoomClick} />
<MenuItem Icon={SettingsIcon} label={_t("common|settings")} onClick={onRoomSettingsClick} />

{!isVideoRoom && (
<>
<Separator />

<MenuItem Icon={FilesIcon} label={_t("right_panel|files_button")} onClick={onRoomFilesClick} />
<MenuItem
Icon={PollsIcon}
label={_t("right_panel|polls_button")}
onClick={onRoomPollHistoryClick}
/>
{pinningEnabled && (
<MenuItem
Icon={PinIcon}
label={_t("right_panel|pinned_messages_button")}
onClick={onRoomPinsClick}
>
<Text as="span" size="sm">
{pinCount}
</Text>
</MenuItem>
)}
<MenuItem Icon={ExportArchiveIcon} label={_t("export_chat|title")} onClick={onRoomExportClick} />
</>
)}

<Separator />

<MenuItem Icon={LeaveIcon} kind="critical" label={_t("action|leave_room")} onClick={onLeaveRoomClick} />

{SettingsStore.getValue(UIFeature.Widgets) &&
!isVideoRoom &&
Expand Down
3 changes: 0 additions & 3 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@
"spaceinvaders_message": "sends space invaders"
},
"common": {
"about": "About",
"access_token": "Access Token",
"accessibility": "Accessibility",
"advanced": "Advanced",
Expand Down Expand Up @@ -1852,8 +1851,6 @@
"room_summary_card": {
"title": "Room info"
},
"settings_button": "Room settings",
"share_button": "Share room",
"thread_list": {
"context_menu_label": "Thread options"
},
Expand Down
33 changes: 33 additions & 0 deletions src/utils/room/canInviteTo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright 2023 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { JoinRule, Room } from "matrix-js-sdk/src/matrix";

import { shouldShowComponent } from "../../customisations/helpers/UIComponents";
import { UIComponent } from "../../settings/UIFeature";

/**
* Can a user invite new members to the room
* @param room
* @returns whether the user can invite new members to the room
*/
export function canInviteTo(room: Room): boolean {
const client = room.client;
const canInvite =
!!room?.canInvite(client.getSafeUserId()) || !!(room?.isSpaceRoom() && room.getJoinRule() === JoinRule.Public);

return canInvite && room?.getMyMembership() === "join" && shouldShowComponent(UIComponent.InviteUsers);
}
Loading
Loading