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

Commit

Permalink
Add a config option to control the default widget container height (#…
Browse files Browse the repository at this point in the history
…12893)

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

* Oops: need to remember to git checkout
  • Loading branch information
dbkr committed Aug 27, 2024
1 parent e599428 commit f0a75d8
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/IConfigOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
3 changes: 2 additions & 1 deletion src/components/views/rooms/AppsDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 (
Expand Down
84 changes: 84 additions & 0 deletions test/components/views/rooms/AppsDrawer-test.tsx
Original file line number Diff line number Diff line change
@@ -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");
});
});

0 comments on commit f0a75d8

Please sign in to comment.