From f0a75d8ad57e3633712b61b2bb78cc9e9317f087 Mon Sep 17 00:00:00 2001
From: David Baker <dbkr@users.noreply.github.com>
Date: Tue, 27 Aug 2024 10:59:54 +0100
Subject: [PATCH] Add a config option to control the default widget container
 height (#12893)

* Add a config option to control the default widget container height

* Oops: need to remember to git checkout
---
 src/IConfigOptions.ts                         |  1 +
 src/components/views/rooms/AppsDrawer.tsx     |  3 +-
 .../views/rooms/AppsDrawer-test.tsx           | 84 +++++++++++++++++++
 3 files changed, 87 insertions(+), 1 deletion(-)
 create mode 100644 test/components/views/rooms/AppsDrawer-test.tsx

diff --git a/src/IConfigOptions.ts b/src/IConfigOptions.ts
index 69c8349965..c305b17ca5 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<string, boolean>; // <FeatureName, EnabledBool>
diff --git a/src/components/views/rooms/AppsDrawer.tsx b/src/components/views/rooms/AppsDrawer.tsx
index 2247edce04..6da77499fa 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<IPersistentResizerProps> = ({
         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 0000000000..3da0f0560f
--- /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(
+            <AppsDrawer
+                userId={client.getUserId()!}
+                room={room}
+                resizeNotifier={dummyResizeNotifier}
+                showApps={true}
+            />,
+            {
+                wrapper: ({ ...rest }) => <MatrixClientContext.Provider value={client} {...rest} />,
+            },
+        );
+
+        const appsDrawerResizer = container.getElementsByClassName("mx_AppsDrawer_resizer")[0] as HTMLElement;
+        expect(appsDrawerResizer.style.height).toBe("500px");
+    });
+});
-- 
GitLab