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

Commit f0a75d8

Browse files
authored
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
1 parent e599428 commit f0a75d8

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

src/IConfigOptions.ts

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export interface IConfigOptions {
9898
integrations_ui_url?: string;
9999
integrations_rest_url?: string;
100100
integrations_widgets_urls?: string[];
101+
default_widget_container_height?: number; // height in pixels
101102

102103
show_labs_settings: boolean;
103104
features?: Record<string, boolean>; // <FeatureName, EnabledBool>

src/components/views/rooms/AppsDrawer.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { clamp, percentageOf, percentageWithin } from "../../../utils/numbers";
3535
import UIStore from "../../../stores/UIStore";
3636
import { ActionPayload } from "../../../dispatcher/payloads";
3737
import Spinner from "../elements/Spinner";
38+
import SdkConfig from "../../../SdkConfig";
3839

3940
interface IProps {
4041
userId: string;
@@ -335,7 +336,7 @@ const PersistentVResizer: React.FC<IPersistentResizerProps> = ({
335336
defaultHeight = clamp(defaultHeight, 0, 100);
336337
defaultHeight = percentageWithin(defaultHeight / 100, minHeight, maxHeight);
337338
} else {
338-
defaultHeight = 280;
339+
defaultHeight = SdkConfig.get().default_widget_container_height ?? 280;
339340
}
340341

341342
return (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
Copyright 2024 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import React from "react";
18+
import { MatrixClient, PendingEventOrdering, Room } from "matrix-js-sdk/src/matrix";
19+
import { render } from "@testing-library/react";
20+
21+
import { stubClient } from "../../../test-utils";
22+
import AppsDrawer from "../../../../src/components/views/rooms/AppsDrawer";
23+
import SdkConfig from "../../../../src/SdkConfig";
24+
import ResizeNotifier from "../../../../src/utils/ResizeNotifier";
25+
import { WidgetLayoutStore } from "../../../../src/stores/widgets/WidgetLayoutStore";
26+
import MatrixClientContext from "../../../../src/contexts/MatrixClientContext";
27+
28+
const ROOM_ID = "!room:id";
29+
30+
describe("AppsDrawer", () => {
31+
let client: MatrixClient;
32+
let room: Room;
33+
let dummyResizeNotifier: ResizeNotifier;
34+
35+
beforeEach(async () => {
36+
client = stubClient();
37+
room = new Room(ROOM_ID, client, client.getUserId()!, {
38+
pendingEventOrdering: PendingEventOrdering.Detached,
39+
});
40+
dummyResizeNotifier = new ResizeNotifier();
41+
});
42+
43+
afterEach(() => {
44+
jest.restoreAllMocks();
45+
});
46+
47+
it("honours default_widget_container_height", () => {
48+
jest.spyOn(SdkConfig, "get").mockImplementation((key) => {
49+
if (!key) {
50+
return {
51+
default_widget_container_height: 500,
52+
};
53+
}
54+
});
55+
jest.spyOn(WidgetLayoutStore.instance, "getContainerWidgets").mockImplementation((room, container) => {
56+
if (container === "top") {
57+
return [
58+
{
59+
id: "testwidget",
60+
creatorUserId: client.getUserId()!,
61+
type: "test",
62+
url: "https://nowhere.dummy/notawidget",
63+
},
64+
];
65+
}
66+
return [];
67+
});
68+
69+
const { container } = render(
70+
<AppsDrawer
71+
userId={client.getUserId()!}
72+
room={room}
73+
resizeNotifier={dummyResizeNotifier}
74+
showApps={true}
75+
/>,
76+
{
77+
wrapper: ({ ...rest }) => <MatrixClientContext.Provider value={client} {...rest} />,
78+
},
79+
);
80+
81+
const appsDrawerResizer = container.getElementsByClassName("mx_AppsDrawer_resizer")[0] as HTMLElement;
82+
expect(appsDrawerResizer.style.height).toBe("500px");
83+
});
84+
});

0 commit comments

Comments
 (0)