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

Commit 0b50e02

Browse files
authored
Merge pull request #11508 from matrix-org/germain-gg/notifications-labs
Move notifications bell back in labs
2 parents dce42d3 + d5d4b52 commit 0b50e02

File tree

10 files changed

+61
-43
lines changed

10 files changed

+61
-43
lines changed

cypress/e2e/right-panel/notification-panel.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ describe("NotificationPanel", () => {
3838
});
3939

4040
it("should render empty state", () => {
41+
cy.enableLabsFeature("feature_notifications");
4142
cy.viewRoomByName(ROOM_NAME);
4243
cy.findByRole("button", { name: "Notifications" }).click();
4344

cypress/e2e/room/room-header.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ describe("Room Header", () => {
3636
});
3737

3838
it("should render default buttons properly", () => {
39+
cy.enableLabsFeature("feature_notifications");
3940
cy.createRoom({ name: "Test Room" }).viewRoomByName("Test Room");
4041

4142
cy.get(".mx_LegacyRoomHeader").within(() => {
@@ -79,6 +80,7 @@ describe("Room Header", () => {
7980
});
8081

8182
it("should render a very long room name without collapsing the buttons", () => {
83+
cy.enableLabsFeature("feature_notifications");
8284
const LONG_ROOM_NAME =
8385
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore " +
8486
"et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut " +
@@ -109,6 +111,7 @@ describe("Room Header", () => {
109111
});
110112

111113
it("should have buttons highlighted by being clicked", () => {
114+
cy.enableLabsFeature("feature_notifications");
112115
cy.createRoom({ name: "Test Room" }).viewRoomByName("Test Room");
113116

114117
cy.get(".mx_LegacyRoomHeader").within(() => {
@@ -142,6 +145,7 @@ describe("Room Header", () => {
142145
};
143146

144147
it("should render buttons for room options, beta pill, invite, chat, and room info", () => {
148+
cy.enableLabsFeature("feature_notifications");
145149
createVideoRoom();
146150

147151
cy.get(".mx_LegacyRoomHeader").within(() => {

src/components/views/right_panel/HeaderButtons.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import RightPanelStore from "../../../stores/right-panel/RightPanelStore";
2525
import { RightPanelPhases } from "../../../stores/right-panel/RightPanelStorePhases";
2626
import { UPDATE_EVENT } from "../../../stores/AsyncStore";
2727
import { NotificationColor } from "../../../stores/notifications/NotificationColor";
28+
import SettingsStore from "../../../settings/SettingsStore";
2829

2930
export enum HeaderKind {
3031
Room = "room",
@@ -35,13 +36,15 @@ interface IState {
3536
phase: RightPanelPhases | null;
3637
threadNotificationColor: NotificationColor;
3738
globalNotificationColor: NotificationColor;
39+
notificationsEnabled?: boolean;
3840
}
3941

4042
interface IProps {}
4143

4244
export default abstract class HeaderButtons<P = {}> extends React.Component<IProps & P, IState> {
4345
private unmounted = false;
4446
private dispatcherRef?: string = undefined;
47+
private readonly watcherRef: string;
4548

4649
public constructor(props: IProps & P, kind: HeaderKind) {
4750
super(props);
@@ -52,7 +55,11 @@ export default abstract class HeaderButtons<P = {}> extends React.Component<IPro
5255
phase: rps.currentCard.phase,
5356
threadNotificationColor: NotificationColor.None,
5457
globalNotificationColor: NotificationColor.None,
58+
notificationsEnabled: SettingsStore.getValue("feature_notifications"),
5559
};
60+
this.watcherRef = SettingsStore.watchSetting("feature_notifications", null, (...[, , , value]) =>
61+
this.setState({ notificationsEnabled: value }),
62+
);
5663
}
5764

5865
public componentDidMount(): void {
@@ -63,6 +70,7 @@ export default abstract class HeaderButtons<P = {}> extends React.Component<IPro
6370
this.unmounted = true;
6471
RightPanelStore.instance.off(UPDATE_EVENT, this.onRightPanelStoreUpdate);
6572
if (this.dispatcherRef) dis.unregister(this.dispatcherRef);
73+
if (this.watcherRef) SettingsStore.unwatchSetting(this.watcherRef);
6674
}
6775

6876
public isPhase(phases: string | string[]): boolean {

src/components/views/right_panel/LegacyRoomHeaderButtons.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -282,21 +282,23 @@ export default class LegacyRoomHeaderButtons extends HeaderButtons<IProps> {
282282
<UnreadIndicator color={this.state.threadNotificationColor} />
283283
</HeaderButton>,
284284
);
285-
rightPanelPhaseButtons.set(
286-
RightPanelPhases.NotificationPanel,
287-
<HeaderButton
288-
key="notifsButton"
289-
name="notifsButton"
290-
title={_t("Notifications")}
291-
isHighlighted={this.isPhase(RightPanelPhases.NotificationPanel)}
292-
onClick={this.onNotificationsClicked}
293-
isUnread={this.globalNotificationState.color === NotificationColor.Red}
294-
>
295-
{this.globalNotificationState.color === NotificationColor.Red ? (
296-
<UnreadIndicator color={this.globalNotificationState.color} />
297-
) : null}
298-
</HeaderButton>,
299-
);
285+
if (this.state.notificationsEnabled) {
286+
rightPanelPhaseButtons.set(
287+
RightPanelPhases.NotificationPanel,
288+
<HeaderButton
289+
key="notifsButton"
290+
name="notifsButton"
291+
title={_t("Notifications")}
292+
isHighlighted={this.isPhase(RightPanelPhases.NotificationPanel)}
293+
onClick={this.onNotificationsClicked}
294+
isUnread={this.globalNotificationState.color === NotificationColor.Red}
295+
>
296+
{this.globalNotificationState.color === NotificationColor.Red ? (
297+
<UnreadIndicator color={this.globalNotificationState.color} />
298+
) : null}
299+
</HeaderButton>,
300+
);
301+
}
300302
rightPanelPhaseButtons.set(
301303
RightPanelPhases.RoomSummary,
302304
<HeaderButton

src/components/views/rooms/RoomHeader.tsx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ export default function RoomHeader({ room }: { room: Room }): JSX.Element {
100100
}, [room, directRoomsList]);
101101
const e2eStatus = useEncryptionStatus(client, room);
102102

103+
const notificationsEnabled = useFeatureEnabled("feature_notifications");
104+
103105
return (
104106
<Flex
105107
as="header"
@@ -202,18 +204,20 @@ export default function RoomHeader({ room }: { room: Room }): JSX.Element {
202204
<ThreadsIcon />
203205
</IconButton>
204206
</Tooltip>
205-
<Tooltip label={_t("Notifications")}>
206-
<IconButton
207-
indicator={notificationColorToIndicator(globalNotificationState.color)}
208-
onClick={(evt) => {
209-
evt.stopPropagation();
210-
RightPanelStore.instance.showOrHidePanel(RightPanelPhases.NotificationPanel);
211-
}}
212-
title={_t("Notifications")}
213-
>
214-
<NotificationsIcon />
215-
</IconButton>
216-
</Tooltip>
207+
{notificationsEnabled && (
208+
<Tooltip label={_t("Notifications")}>
209+
<IconButton
210+
indicator={notificationColorToIndicator(globalNotificationState.color)}
211+
onClick={(evt) => {
212+
evt.stopPropagation();
213+
RightPanelStore.instance.showOrHidePanel(RightPanelPhases.NotificationPanel);
214+
}}
215+
title={_t("Notifications")}
216+
>
217+
<NotificationsIcon />
218+
</IconButton>
219+
</Tooltip>
220+
)}
217221
</Flex>
218222
{!isDirectMessage && (
219223
<BodyText

src/i18n/strings/en_EN.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,9 @@
11611161
"rust_crypto": "Rust cryptography implementation",
11621162
"hidebold": "Hide notification dot (only display counters badges)",
11631163
"ask_to_join": "Enable ask to join",
1164-
"new_room_decoration_ui": "New room header & details interface",
1164+
"new_room_decoration_ui": "Under active development, new room header & details interface",
1165+
"notifications": "Enable the notifications panel in the room header",
1166+
"unrealiable_e2e": "Unreliable in encrypted rooms",
11651167
"beta_feature": "This is a beta feature",
11661168
"click_for_info": "Click for more info",
11671169
"leave_beta_reload": "Leaving the beta will reload %(brand)s.",

src/settings/Settings.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,14 @@ export const SETTINGS: { [setting: string]: ISetting } = {
547547
default: false,
548548
controller: new ReloadOnChangeController(),
549549
},
550+
"feature_notifications": {
551+
isFeature: true,
552+
labsGroup: LabGroup.Messaging,
553+
displayName: _td("labs|notifications"),
554+
description: _td("labs|unrealiable_e2e"),
555+
supportedLevels: LEVELS_FEATURE,
556+
default: false,
557+
},
550558
"useCompactLayout": {
551559
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS,
552560
displayName: _td("Use a more compact 'Modern' layout"),

test/components/views/right_panel/__snapshots__/LegacyRoomHeaderButtons-test.tsx.snap

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ exports[`LegacyRoomHeaderButtons-test.tsx should render 1`] = `
1717
role="button"
1818
tabindex="0"
1919
/>
20-
<div
21-
aria-current="false"
22-
aria-label="Notifications"
23-
class="mx_AccessibleButton mx_LegacyRoomHeader_button mx_RightPanel_notifsButton"
24-
role="button"
25-
tabindex="0"
26-
/>
2720
<div
2821
aria-current="false"
2922
aria-label="Room info"

test/components/views/rooms/RoomHeader-test.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ describe("RoomHeader", () => {
200200
});
201201

202202
it("opens the notifications panel", async () => {
203+
jest.spyOn(SettingsStore, "getValue").mockImplementation((name: string) => {
204+
if (name === "feature_notifications") return true;
205+
});
206+
203207
const { container } = render(
204208
<RoomHeader room={room} />,
205209
withClientContextRenderOptions(MatrixClientPeg.get()!),

test/components/views/rooms/__snapshots__/RoomHeader-test.tsx.snap

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,6 @@ exports[`RoomHeader does not show the face pile for DMs 1`] = `
6060
>
6161
<div />
6262
</button>
63-
<button
64-
class="_icon-button_1segd_17"
65-
data-state="closed"
66-
style="--cpd-icon-button-size: 32px;"
67-
title="Notifications"
68-
>
69-
<div />
70-
</button>
7163
</nav>
7264
</header>
7365
</DocumentFragment>

0 commit comments

Comments
 (0)