From 44a9aa620e286484bc101943b53033589a60f5e4 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 15 Aug 2024 14:17:24 +0100 Subject: [PATCH 1/2] Add a config option to control the default widget container height --- src/IConfigOptions.ts | 1 + src/SlidingSyncManager.ts | 2 +- src/components/views/rooms/AppsDrawer.tsx | 3 +- .../views/rooms/AppsDrawer-test.tsx | 84 +++++++++++++++++++ 4 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 test/components/views/rooms/AppsDrawer-test.tsx diff --git a/src/IConfigOptions.ts b/src/IConfigOptions.ts index 69c83499651..c305b17ca50 100644 --- a/src/IConfigOptions.ts +++ b/src/IConfigOptions.ts @@ -98,6 +98,7 @@ export interface IConfigOptions { integrations_ui_url?: string; integrations_rest_url?: string; integrations_widgets_urls?: string[]; + default_widget_container_height?: number; // height in pixels show_labs_settings: boolean; features?: Record; // diff --git a/src/SlidingSyncManager.ts b/src/SlidingSyncManager.ts index 4885ffa8dc5..a3bfb14de90 100644 --- a/src/SlidingSyncManager.ts +++ b/src/SlidingSyncManager.ts @@ -383,7 +383,7 @@ export class SlidingSyncManager { public async nativeSlidingSyncSupport(client: MatrixClient): Promise { // Per https://github.com/matrix-org/matrix-spec-proposals/pull/3575/files#r1589542561 // `client` can be undefined/null in tests for some reason. - const support = await client?.doesServerSupportUnstableFeature("org.matrix.msc3575"); + const support = await client?.doesServerSupportUnstableFeature("org.matrix.simplified_msc3575"); if (support) { logger.log("nativeSlidingSyncSupport: sliding sync advertised as unstable"); } diff --git a/src/components/views/rooms/AppsDrawer.tsx b/src/components/views/rooms/AppsDrawer.tsx index 2247edce045..6da77499fa8 100644 --- a/src/components/views/rooms/AppsDrawer.tsx +++ b/src/components/views/rooms/AppsDrawer.tsx @@ -35,6 +35,7 @@ import { clamp, percentageOf, percentageWithin } from "../../../utils/numbers"; import UIStore from "../../../stores/UIStore"; import { ActionPayload } from "../../../dispatcher/payloads"; import Spinner from "../elements/Spinner"; +import SdkConfig from "../../../SdkConfig"; interface IProps { userId: string; @@ -335,7 +336,7 @@ const PersistentVResizer: React.FC = ({ defaultHeight = clamp(defaultHeight, 0, 100); defaultHeight = percentageWithin(defaultHeight / 100, minHeight, maxHeight); } else { - defaultHeight = 280; + defaultHeight = SdkConfig.get().default_widget_container_height ?? 280; } return ( diff --git a/test/components/views/rooms/AppsDrawer-test.tsx b/test/components/views/rooms/AppsDrawer-test.tsx new file mode 100644 index 00000000000..3da0f0560f0 --- /dev/null +++ b/test/components/views/rooms/AppsDrawer-test.tsx @@ -0,0 +1,84 @@ +/* +Copyright 2024 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 { MatrixClient, PendingEventOrdering, Room } from "matrix-js-sdk/src/matrix"; +import { render } from "@testing-library/react"; + +import { stubClient } from "../../../test-utils"; +import AppsDrawer from "../../../../src/components/views/rooms/AppsDrawer"; +import SdkConfig from "../../../../src/SdkConfig"; +import ResizeNotifier from "../../../../src/utils/ResizeNotifier"; +import { WidgetLayoutStore } from "../../../../src/stores/widgets/WidgetLayoutStore"; +import MatrixClientContext from "../../../../src/contexts/MatrixClientContext"; + +const ROOM_ID = "!room:id"; + +describe("AppsDrawer", () => { + let client: MatrixClient; + let room: Room; + let dummyResizeNotifier: ResizeNotifier; + + beforeEach(async () => { + client = stubClient(); + room = new Room(ROOM_ID, client, client.getUserId()!, { + pendingEventOrdering: PendingEventOrdering.Detached, + }); + dummyResizeNotifier = new ResizeNotifier(); + }); + + afterEach(() => { + jest.restoreAllMocks(); + }); + + it("honours default_widget_container_height", () => { + jest.spyOn(SdkConfig, "get").mockImplementation((key) => { + if (!key) { + return { + default_widget_container_height: 500, + }; + } + }); + jest.spyOn(WidgetLayoutStore.instance, "getContainerWidgets").mockImplementation((room, container) => { + if (container === "top") { + return [ + { + id: "testwidget", + creatorUserId: client.getUserId()!, + type: "test", + url: "https://nowhere.dummy/notawidget", + }, + ]; + } + return []; + }); + + const { container } = render( + , + { + wrapper: ({ ...rest }) => , + }, + ); + + const appsDrawerResizer = container.getElementsByClassName("mx_AppsDrawer_resizer")[0] as HTMLElement; + expect(appsDrawerResizer.style.height).toBe("500px"); + }); +}); From b4cad81ad08a5719238c145e92233e5365415bea Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 15 Aug 2024 14:39:11 +0100 Subject: [PATCH 2/2] Oops: need to remember to git checkout --- src/SlidingSyncManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SlidingSyncManager.ts b/src/SlidingSyncManager.ts index a3bfb14de90..4885ffa8dc5 100644 --- a/src/SlidingSyncManager.ts +++ b/src/SlidingSyncManager.ts @@ -383,7 +383,7 @@ export class SlidingSyncManager { public async nativeSlidingSyncSupport(client: MatrixClient): Promise { // Per https://github.com/matrix-org/matrix-spec-proposals/pull/3575/files#r1589542561 // `client` can be undefined/null in tests for some reason. - const support = await client?.doesServerSupportUnstableFeature("org.matrix.simplified_msc3575"); + const support = await client?.doesServerSupportUnstableFeature("org.matrix.msc3575"); if (support) { logger.log("nativeSlidingSyncSupport: sliding sync advertised as unstable"); }