From 071c9ce3957781d7ca5597ef5e1ead18ace8b828 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 13 Mar 2023 12:35:57 +1300 Subject: [PATCH 1/5] add poll history tab to room settings --- .../views/dialogs/_RoomSettingsDialog.pcss | 4 ++ .../views/dialogs/RoomSettingsDialog.tsx | 14 ++++++ .../settings/tabs/room/PollHistoryTab.tsx | 46 +++++++++++++++++++ src/i18n/strings/en_EN.json | 1 + 4 files changed, 65 insertions(+) create mode 100644 src/components/views/settings/tabs/room/PollHistoryTab.tsx diff --git a/res/css/views/dialogs/_RoomSettingsDialog.pcss b/res/css/views/dialogs/_RoomSettingsDialog.pcss index 143cb6fa3c7..f57f6361932 100644 --- a/res/css/views/dialogs/_RoomSettingsDialog.pcss +++ b/res/css/views/dialogs/_RoomSettingsDialog.pcss @@ -42,6 +42,10 @@ limitations under the License. mask-image: url("$(res)/img/feather-customised/bridge.svg"); } +.mx_RoomSettingsDialog_pollsIcon::before { + mask-image: url("$(res)/img/element-icons/room/composer/poll.svg"); +} + .mx_RoomSettingsDialog_warningIcon::before { mask-image: url("$(res)/img/element-icons/room/settings/advanced.svg"); } diff --git a/src/components/views/dialogs/RoomSettingsDialog.tsx b/src/components/views/dialogs/RoomSettingsDialog.tsx index d1ddc62683e..049a71bd4e9 100644 --- a/src/components/views/dialogs/RoomSettingsDialog.tsx +++ b/src/components/views/dialogs/RoomSettingsDialog.tsx @@ -35,6 +35,7 @@ import { Action } from "../../../dispatcher/actions"; import { VoipRoomSettingsTab } from "../settings/tabs/room/VoipRoomSettingsTab"; import { ActionPayload } from "../../../dispatcher/payloads"; import { NonEmptyArray } from "../../../@types/common"; +import { PollHistoryTab } from "../settings/tabs/room/PollHistoryTab"; export const ROOM_GENERAL_TAB = "ROOM_GENERAL_TAB"; export const ROOM_VOIP_TAB = "ROOM_VOIP_TAB"; @@ -43,6 +44,7 @@ export const ROOM_ROLES_TAB = "ROOM_ROLES_TAB"; export const ROOM_NOTIFICATIONS_TAB = "ROOM_NOTIFICATIONS_TAB"; export const ROOM_BRIDGES_TAB = "ROOM_BRIDGES_TAB"; export const ROOM_ADVANCED_TAB = "ROOM_ADVANCED_TAB"; +export const ROOM_POLL_HISTORY_TAB = "ROOM_POLL_HISTORY_TAB"; interface IProps { roomId: string; @@ -162,6 +164,18 @@ export default class RoomSettingsDialog extends React.Component ); } + if (SettingsStore.getValue("feature_poll_history")) { + tabs.push( + new Tab( + ROOM_POLL_HISTORY_TAB, + _td("Poll history"), + "mx_RoomSettingsDialog_pollsIcon", + this.props.onFinished(true)} />, + "RoomSettingsPollHistory", + ), + ); + } + if (SettingsStore.getValue(UIFeature.AdvancedSettings)) { tabs.push( new Tab( diff --git a/src/components/views/settings/tabs/room/PollHistoryTab.tsx b/src/components/views/settings/tabs/room/PollHistoryTab.tsx new file mode 100644 index 00000000000..c1866d3b0df --- /dev/null +++ b/src/components/views/settings/tabs/room/PollHistoryTab.tsx @@ -0,0 +1,46 @@ +/* +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 React, { useContext } from "react"; + +import MatrixClientContext from "../../../../../contexts/MatrixClientContext"; +import { PollHistory } from "../../../polls/pollHistory/PollHistory"; +import { RoomPermalinkCreator } from "../../../../../utils/permalinks/Permalinks"; + +interface IProps { + roomId: string; + onFinished: () => void; +} + +export const PollHistoryTab: React.FC = ({ roomId, onFinished }) => { + const matrixClient = useContext(MatrixClientContext); + const room = matrixClient.getRoom(roomId); + if (!room) { + return null; + } + const permalinkCreator = new RoomPermalinkCreator(room, roomId); + + return ( +
+ +
+ ); +}; diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 7fd40936e99..121520a05e9 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -2957,6 +2957,7 @@ "Send report": "Send report", "Report Content to Your Homeserver Administrator": "Report Content to Your Homeserver Administrator", "Reporting this message will send its unique 'event ID' to the administrator of your homeserver. If messages in this room are encrypted, your homeserver administrator will not be able to read the message text or view any files or images.": "Reporting this message will send its unique 'event ID' to the administrator of your homeserver. If messages in this room are encrypted, your homeserver administrator will not be able to read the message text or view any files or images.", + "Poll history": "Poll history", "Room Settings - %(roomName)s": "Room Settings - %(roomName)s", "Failed to upgrade room": "Failed to upgrade room", "The room upgrade could not be completed": "The room upgrade could not be completed", From a498e96a354b31a053cb48cc6ca2920faeabb9f0 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 13 Mar 2023 14:34:49 +1300 Subject: [PATCH 2/5] test poll history in room settings --- .../views/dialogs/RoomSettingsDialog-test.tsx | 111 +++++++++++++++ .../RoomSettingsDialog-test.tsx.snap | 129 ++++++++++++++++++ 2 files changed, 240 insertions(+) create mode 100644 test/components/views/dialogs/RoomSettingsDialog-test.tsx create mode 100644 test/components/views/dialogs/__snapshots__/RoomSettingsDialog-test.tsx.snap diff --git a/test/components/views/dialogs/RoomSettingsDialog-test.tsx b/test/components/views/dialogs/RoomSettingsDialog-test.tsx new file mode 100644 index 00000000000..eefc8b23a8e --- /dev/null +++ b/test/components/views/dialogs/RoomSettingsDialog-test.tsx @@ -0,0 +1,111 @@ +/* +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 React from "react"; +import { fireEvent, render, screen } from "@testing-library/react"; +import { Room, Visibility } from "matrix-js-sdk/src/matrix"; + +import { getMockClientWithEventEmitter, mockClientMethodsUser } from "../../../test-utils"; +import RoomSettingsDialog from "../../../../src/components/views/dialogs/RoomSettingsDialog"; +import MatrixClientContext from "../../../../src/contexts/MatrixClientContext"; +import SettingsStore from "../../../../src/settings/SettingsStore"; +import { UIFeature } from "../../../../src/settings/UIFeature"; + +describe("", () => { + const userId = "@alice:server.org"; + const mockClient = getMockClientWithEventEmitter({ + ...mockClientMethodsUser(userId), + isRoomEncrypted: jest.fn().mockReturnValue(false), + getRoom: jest.fn(), + getDomain: jest.fn().mockReturnValue("server.org"), + getLocalAliases: jest.fn().mockResolvedValue({ aliases: [] }), + getRoomDirectoryVisibility: jest.fn().mockResolvedValue({ visibility: Visibility.Private }), + getOrCreateFilter: jest.fn(), + }); + + const roomId = "!room:server.org"; + const room = new Room(roomId, mockClient, userId); + + jest.spyOn(SettingsStore, "getValue"); + + beforeEach(() => { + jest.clearAllMocks(); + + mockClient.getRoom.mockReturnValue(room); + + jest.spyOn(SettingsStore, "getValue").mockReset().mockReturnValue(false); + }); + + const getComponent = (onFinished = jest.fn()) => + render(, { + wrapper: ({ children }) => ( + {children} + ), + }); + + describe("Settings tabs", () => { + it("renders default tabs correctly", () => { + const { container } = getComponent(); + expect(container.querySelectorAll(".mx_TabbedView_tabLabel")).toMatchSnapshot(); + }); + + it("renders voip settings tab when enabled", () => { + jest.spyOn(SettingsStore, "getValue").mockImplementation( + (settingName) => settingName === "feature_group_calls", + ); + getComponent(); + expect(screen.getByTestId("settings-tab-ROOM_VOIP_TAB")).toBeInTheDocument(); + }); + + it("renders bridges settings tab when enabled", () => { + jest.spyOn(SettingsStore, "getValue").mockImplementation( + (settingName) => settingName === "feature_bridge_state", + ); + getComponent(); + expect(screen.getByTestId("settings-tab-ROOM_BRIDGES_TAB")).toBeInTheDocument(); + }); + + it("renders advanced settings tab when enabled", () => { + jest.spyOn(SettingsStore, "getValue").mockImplementation( + (settingName) => settingName === UIFeature.AdvancedSettings, + ); + getComponent(); + expect(screen.getByTestId("settings-tab-ROOM_ADVANCED_TAB")).toBeInTheDocument(); + }); + }); + + describe("poll history", () => { + beforeEach(() => { + jest.spyOn(SettingsStore, "getValue").mockImplementation( + (settingName) => settingName === "feature_poll_history", + ); + + mockClient.getOrCreateFilter.mockResolvedValue("filterId"); + }); + it("renders poll history tab", () => { + getComponent(); + expect(screen.getByTestId("settings-tab-ROOM_POLL_HISTORY_TAB")).toBeInTheDocument(); + }); + + it("displays poll history when tab clicked", () => { + const { container } = getComponent(); + + fireEvent.click(screen.getByText("Poll history")); + + expect(container.querySelector(".mx_SettingsTab")).toMatchSnapshot(); + }); + }); +}); diff --git a/test/components/views/dialogs/__snapshots__/RoomSettingsDialog-test.tsx.snap b/test/components/views/dialogs/__snapshots__/RoomSettingsDialog-test.tsx.snap new file mode 100644 index 00000000000..0ddd22f419c --- /dev/null +++ b/test/components/views/dialogs/__snapshots__/RoomSettingsDialog-test.tsx.snap @@ -0,0 +1,129 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` Settings tabs renders default tabs correctly 1`] = ` +NodeList [ +
+ + + General + +
, +
+ + + Security & Privacy + +
, +
+ + + Roles & Permissions + +
, +
+ + + Notifications + +
, +] +`; + +exports[` poll history displays poll history when tab clicked 1`] = ` +
+
+

+ Polls history +

+
+
+ + +
+
+
+
+
+ Loading polls +
+
+
+
+`; From 575b09e7b9892ab220dd67c58208104ee92400de Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 13 Mar 2023 15:06:10 +1300 Subject: [PATCH 3/5] remove posthog tracking for poll his --- src/components/views/dialogs/RoomSettingsDialog.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/views/dialogs/RoomSettingsDialog.tsx b/src/components/views/dialogs/RoomSettingsDialog.tsx index 049a71bd4e9..eb4b5b8bf2d 100644 --- a/src/components/views/dialogs/RoomSettingsDialog.tsx +++ b/src/components/views/dialogs/RoomSettingsDialog.tsx @@ -171,7 +171,6 @@ export default class RoomSettingsDialog extends React.Component _td("Poll history"), "mx_RoomSettingsDialog_pollsIcon", this.props.onFinished(true)} />, - "RoomSettingsPollHistory", ), ); } From 3e8c937ca648f28c2c4740603211a0711186c876 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 13 Mar 2023 15:14:01 +1300 Subject: [PATCH 4/5] remove labs flag for poll history --- cypress/e2e/polls/pollHistory.spec.ts | 2 -- .../views/dialogs/RoomSettingsDialog.tsx | 18 ++++++++---------- .../views/right_panel/RoomSummaryCard.tsx | 4 +--- src/i18n/strings/en_EN.json | 3 +-- src/settings/Settings.tsx | 8 -------- .../views/dialogs/RoomSettingsDialog-test.tsx | 4 ---- .../RoomSettingsDialog-test.tsx.snap | 15 +++++++++++++++ .../views/right_panel/RoomSummaryCard-test.tsx | 4 +--- .../RoomSummaryCard-test.tsx.snap | 7 +++++++ 9 files changed, 33 insertions(+), 32 deletions(-) diff --git a/cypress/e2e/polls/pollHistory.spec.ts b/cypress/e2e/polls/pollHistory.spec.ts index 2b9a0b67344..4ead781b078 100644 --- a/cypress/e2e/polls/pollHistory.spec.ts +++ b/cypress/e2e/polls/pollHistory.spec.ts @@ -88,8 +88,6 @@ describe("Poll history", () => { cy.startHomeserver("default").then((data) => { homeserver = data; - cy.enableLabsFeature("feature_poll_history"); - cy.initTestUser(homeserver, "Tom"); }); }); diff --git a/src/components/views/dialogs/RoomSettingsDialog.tsx b/src/components/views/dialogs/RoomSettingsDialog.tsx index eb4b5b8bf2d..8c5de0b579e 100644 --- a/src/components/views/dialogs/RoomSettingsDialog.tsx +++ b/src/components/views/dialogs/RoomSettingsDialog.tsx @@ -164,16 +164,14 @@ export default class RoomSettingsDialog extends React.Component ); } - if (SettingsStore.getValue("feature_poll_history")) { - tabs.push( - new Tab( - ROOM_POLL_HISTORY_TAB, - _td("Poll history"), - "mx_RoomSettingsDialog_pollsIcon", - this.props.onFinished(true)} />, - ), - ); - } + tabs.push( + new Tab( + ROOM_POLL_HISTORY_TAB, + _td("Poll history"), + "mx_RoomSettingsDialog_pollsIcon", + this.props.onFinished(true)} />, + ), + ); if (SettingsStore.getValue(UIFeature.AdvancedSettings)) { tabs.push( diff --git a/src/components/views/right_panel/RoomSummaryCard.tsx b/src/components/views/right_panel/RoomSummaryCard.tsx index 84df7891d54..5cb8770c96e 100644 --- a/src/components/views/right_panel/RoomSummaryCard.tsx +++ b/src/components/views/right_panel/RoomSummaryCard.tsx @@ -327,8 +327,6 @@ const RoomSummaryCard: React.FC = ({ room, permalinkCreator, onClose }) const pinningEnabled = useFeatureEnabled("feature_pinning"); const pinCount = usePinnedEvents(pinningEnabled ? room : undefined)?.length; - const isPollHistoryEnabled = useFeatureEnabled("feature_poll_history"); - return ( @@ -341,7 +339,7 @@ const RoomSummaryCard: React.FC = ({ room, permalinkCreator, onClose }) {_t("Files")} )} - {!isVideoRoom && isPollHistoryEnabled && ( + {!isVideoRoom && ( diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 121520a05e9..074b1863de2 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -958,8 +958,6 @@ "Use new room breadcrumbs": "Use new room breadcrumbs", "Right panel stays open": "Right panel stays open", "Defaults to room member list.": "Defaults to room member list.", - "Polls history": "Polls history", - "View a list of polls in a room. (Under active development)": "View a list of polls in a room. (Under active development)", "Jump to date (adds /jumptodate and jump to date headers)": "Jump to date (adds /jumptodate and jump to date headers)", "Send read receipts": "Send read receipts", "Sliding Sync mode": "Sliding Sync mode", @@ -2231,6 +2229,7 @@ "Not encrypted": "Not encrypted", "About": "About", "Files": "Files", + "Polls history": "Polls history", "Pinned": "Pinned", "Export chat": "Export chat", "Share room": "Share room", diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx index b8d69f6c262..69bb3748812 100644 --- a/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx @@ -359,14 +359,6 @@ export const SETTINGS: { [setting: string]: ISetting } = { description: _td("Defaults to room member list."), default: false, }, - "feature_poll_history": { - isFeature: true, - labsGroup: LabGroup.Rooms, - supportedLevels: LEVELS_FEATURE, - displayName: _td("Polls history"), - description: _td("View a list of polls in a room. (Under active development)"), - default: false, - }, "feature_jump_to_date": { isFeature: true, labsGroup: LabGroup.Messaging, diff --git a/test/components/views/dialogs/RoomSettingsDialog-test.tsx b/test/components/views/dialogs/RoomSettingsDialog-test.tsx index eefc8b23a8e..5a4356cb334 100644 --- a/test/components/views/dialogs/RoomSettingsDialog-test.tsx +++ b/test/components/views/dialogs/RoomSettingsDialog-test.tsx @@ -89,10 +89,6 @@ describe("", () => { describe("poll history", () => { beforeEach(() => { - jest.spyOn(SettingsStore, "getValue").mockImplementation( - (settingName) => settingName === "feature_poll_history", - ); - mockClient.getOrCreateFilter.mockResolvedValue("filterId"); }); it("renders poll history tab", () => { diff --git a/test/components/views/dialogs/__snapshots__/RoomSettingsDialog-test.tsx.snap b/test/components/views/dialogs/__snapshots__/RoomSettingsDialog-test.tsx.snap index 0ddd22f419c..32553e4a89d 100644 --- a/test/components/views/dialogs/__snapshots__/RoomSettingsDialog-test.tsx.snap +++ b/test/components/views/dialogs/__snapshots__/RoomSettingsDialog-test.tsx.snap @@ -62,6 +62,21 @@ NodeList [ Notifications
, +
+ + + Poll history + +
, ] `; diff --git a/test/components/views/right_panel/RoomSummaryCard-test.tsx b/test/components/views/right_panel/RoomSummaryCard-test.tsx index 393a8e9b45e..c6783bcfe47 100644 --- a/test/components/views/right_panel/RoomSummaryCard-test.tsx +++ b/test/components/views/right_panel/RoomSummaryCard-test.tsx @@ -134,15 +134,13 @@ describe("", () => { }); describe("poll history", () => { - it("renders poll history option when feature is enabled", () => { - featureEnabledSpy.mockImplementation((feature) => feature === "feature_poll_history"); + it("renders poll history option", () => { const { getByText } = getComponent(); expect(getByText("Polls history")).toBeInTheDocument(); }); it("opens poll history dialog on button click", () => { - featureEnabledSpy.mockImplementation((feature) => feature === "feature_poll_history"); const { getByText } = getComponent(); fireEvent.click(getByText("Polls history")); diff --git a/test/components/views/right_panel/__snapshots__/RoomSummaryCard-test.tsx.snap b/test/components/views/right_panel/__snapshots__/RoomSummaryCard-test.tsx.snap index 5aca1d6c389..6128ecdd73a 100644 --- a/test/components/views/right_panel/__snapshots__/RoomSummaryCard-test.tsx.snap +++ b/test/components/views/right_panel/__snapshots__/RoomSummaryCard-test.tsx.snap @@ -83,6 +83,13 @@ exports[` renders the room summary 1`] = ` > Files +
+ Polls history +
Date: Tue, 14 Mar 2023 14:14:46 +1300 Subject: [PATCH 5/5] i18n --- src/i18n/strings/en_EN.json | 1 - 1 file changed, 1 deletion(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 932b96b11b6..fd2fbd24fb8 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -2957,7 +2957,6 @@ "Send report": "Send report", "Report Content to Your Homeserver Administrator": "Report Content to Your Homeserver Administrator", "Reporting this message will send its unique 'event ID' to the administrator of your homeserver. If messages in this room are encrypted, your homeserver administrator will not be able to read the message text or view any files or images.": "Reporting this message will send its unique 'event ID' to the administrator of your homeserver. If messages in this room are encrypted, your homeserver administrator will not be able to read the message text or view any files or images.", - "Poll history": "Poll history", "Room Settings - %(roomName)s": "Room Settings - %(roomName)s", "Failed to upgrade room": "Failed to upgrade room", "The room upgrade could not be completed": "The room upgrade could not be completed",