-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Implement customisations & login component Module API 1.11.0 #32687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
a957e97
1758ce8
2f6ff91
385f186
3ce6c90
c2e348b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| Copyright 2026 Element Creations Ltd. | ||
|
|
||
| SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial | ||
| Please see LICENSE files in the repository root for full details. | ||
| */ | ||
|
|
||
| import type { UIComponent, CustomisationsApi as ICustomisationsApi } from "@element-hq/element-web-module-api"; | ||
|
|
||
| export class CustomisationsApi implements ICustomisationsApi { | ||
| private shouldShowComponentFunctions = new Set<(component: UIComponent) => boolean | void>(); | ||
|
Check warning on line 11 in apps/web/src/modules/customisationsApi.ts
|
||
|
|
||
| /** | ||
| * Method to register a callback which can affect whether a given component is drawn or not. | ||
| * @param fn - the callback, if it returns true the component will be rendered, if false it will not be. | ||
| * If undefined will defer to next callback, ultimately falling through to `true` if none return false. | ||
|
||
| */ | ||
| public registerShouldShowComponent(fn: (this: void, component: UIComponent) => boolean | void): void { | ||
| this.shouldShowComponentFunctions.add(fn); | ||
| } | ||
|
|
||
| /** | ||
| * Method to check whether, according to any registered modules, a given component should be rendered. | ||
| * @param component - the component to check | ||
| */ | ||
| public shouldShowComponent(component: UIComponent): boolean | void { | ||
| for (const fn of this.shouldShowComponentFunctions) { | ||
| const v = fn(component); | ||
| if (typeof v === "boolean") { | ||
| return v; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| Copyright 2026 Element Creations Ltd. | ||
|
|
||
| SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial | ||
| Please see LICENSE files in the repository root for full details. | ||
| */ | ||
|
|
||
| import { CustomisationsApi } from "../../../src/modules/customisationsApi"; | ||
| import { UIComponent } from "../../../src/settings/UIFeature.ts"; | ||
|
|
||
| describe("CustomisationsApi", () => { | ||
| let api: CustomisationsApi; | ||
|
|
||
| beforeEach(() => { | ||
| api = new CustomisationsApi(); | ||
| }); | ||
|
|
||
| it("should register a shouldShowComponent callback", () => { | ||
| const shouldShowComponent = jest.fn().mockReturnValue(true); | ||
| api.registerShouldShowComponent(shouldShowComponent); | ||
| expect(api.shouldShowComponent(UIComponent.CreateRooms)).toBe(true); | ||
| expect(shouldShowComponent).toHaveBeenCalledWith("UIComponent.roomCreation"); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.