Skip to content
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

Add support for rendering a custom wrapper around Element #25537

Merged
merged 13 commits into from Aug 30, 2023

Conversation

maheichyk
Copy link
Contributor

@maheichyk maheichyk commented Jun 8, 2023

Type: Enhancement
Related: https://github.com/matrix-org/matrix-react-sdk-module-api

This PR suggests to add possibility to add a wrapper around of Element that is configurable via module API.

This could be used to show custom header and footer.

It depends on PR to matrix-react-sdk-module-api: matrix-org/matrix-react-sdk-module-api#13

Checklist

  • Tests written for new code (and old code if feasible)
  • Linter and other CI checks pass
  • Sign-off given on the changes (see CONTRIBUTING.md)

Here's what your changelog entry will look like:

✨ Features

  • Add support for rendering a custom wrapper around Element (#25537). Contributed by @maheichyk.

Signed-off-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net>
@github-actions github-actions bot added Z-Community-PR Issue is solved by a community member's PR T-Enhancement labels Jun 8, 2023
@t3chguy
Copy link
Member

t3chguy commented Jun 8, 2023

Why is a banner preferable over toasts which are the direction the rest of the app design went? We ditched top app banners years ago in favour of toasts

@maheichyk maheichyk marked this pull request as ready for review June 8, 2023 10:48
@maheichyk maheichyk requested a review from a team as a code owner June 8, 2023 10:48
t3chguy
t3chguy previously requested changes Jun 8, 2023
Copy link
Member

@t3chguy t3chguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI is very unhappy, that'll need fixing before code review

Also not sure what benefit there is to this approach vs just injecting DOM elements or adding additional React roots.

@maheichyk
Copy link
Contributor Author

Why is a banner preferable over toasts which are the direction the rest of the app design went? We ditched top app banners years ago in favour of toasts

It looks that toasts are a bit different, they are more like notifications with some action items. In our case we would like to have some region on the top that is always shown and includes some components: custom menu, logo, etc.

@t3chguy
Copy link
Member

t3chguy commented Jun 8, 2023

custom menu, logo, etc.

This sounds like better suited by adding your own React root or just injecting DOM elements, no?

@maheichyk
Copy link
Contributor Author

custom menu, logo, etc.

This sounds like better suited by adding your own React root or just injecting DOM elements, no?

We would like to have a stable API that can be used for this feature. In addition, we want to put a component there that could toggle widgets in the Element (the idea here is to add more API changes to matrix-react-sdk-module-api to make the toggle possible). Not sure if multiple reacts roots fit into that.

@maheichyk
Copy link
Contributor Author

CI is very unhappy, that'll need fixing before code review

This PR depends on matrix-react-sdk-module-api PR that is not merged yet. Maybe it is better to make this PR a draft.

@t3chguy t3chguy marked this pull request as draft June 8, 2023 12:57
@t3chguy
Copy link
Member

t3chguy commented Jun 8, 2023

Not sure if multiple reacts roots fit into that.

Sure, the buttons would be calling upon the Module API to perform actions either way, not like we'd be passing a context/props into the components from this end, given this end has no access to any such thing anyway.

@Johennes Johennes added A-Timesheet-1 Log any time spent on this into the A-Timesheet-1 project and removed Z-Community-PR Issue is solved by a community member's PR labels Jun 12, 2023
@Johennes
Copy link
Contributor

@maheichyk to reiterate @t3chguy's point, if all you want is a container at the top of the chat window, you should be able to inject that at the start of the body in your fork. That customization wouldn't depend on anything specific in Element Web or the React SDK. This means it's not possible for us to break it by changes in the FOSS code which then eliminates the need to create a stable API for it.

As @t3chguy says, if you want to trigger other functions from within the container, we should expose those in the module API so that you have a stable interface to rely upon.

Please let us know if there's another use case here that we haven't yet considered.

@dhenneke
Copy link
Contributor

Our use case (I'm in the same team as @maheichyk btw) requires us to not do direct changes in a fork of Element so we would really prefer to have a modularized approach with a proper API.

Let me show an example module to see if I correctly understood your proposal:

export default class ExampleBannerModule extends RuntimeModule {
  public constructor(moduleApi: ModuleApi) {
    super(moduleApi);

    // ... register some lifecycles, add new translations, ...

    // this could also happen in the html file, but we prefer to not edit any upstream files in a fork
    const matrixRoot = document.getElementById("matrixchat");
    matrixRoot.style.height = "calc(100% - 64px)"; // say our banner has a height of 64px
    const newRoot = document.createElement("div");
    document.body.prepend(newRoot);

    // render a custom component. We could also pass the moduleApi to do translations or call any api
    ReactDOM.render(<Banner />, newRoot);
  }
}

There are some limitations, like that we can't know if and when Element was loaded correctly or if the user is logged in. But this could be provided by additional lifecycles/events in the Module API.

@t3chguy
Copy link
Member

t3chguy commented Jun 14, 2023

There are some limitations, like that we can't know if and when Element was loaded correctly or if the user is logged in.

Which the proposed changes to the Module API doesn't give you either, but you could subscribe to the matrix-react-sdk dispatcher to receive those events.

@dhenneke
Copy link
Contributor

[...] subscribe to the matrix-react-sdk dispatcher to receive those events.

While possible, I think this is discouraged to import it directly into the module due to API stability reasons.

@t3chguy
Copy link
Member

t3chguy commented Jun 14, 2023

While possible, I think this is discouraged to import it directly into the module due to API stability reasons.

The alternative is an ever growing scope in the Module API as to what exact state the app is in. Right now you might only need to know when the user logs in, later the exact view they're in (login, registration, room, etc) later also more detail like they're doing verification as part of login, etc. Maintaining this is likely to be even more effort to not break between versions from the react-sdk PoV

@Johennes
Copy link
Contributor

@dhenneke could you share more about what kind of additional data you'd require to be accessible from the banner? You already mentioned app loading and login state above. Are there any others that you're already aware of? Having a holistic view on what you're trying to achieve would help us to properly define the needed interface.

@dhenneke
Copy link
Contributor

I think this banner use case is quite special in that regard. It could be an option to be a bit more flexible in this use case, but we will discuss this internally. The other use cases for the module system are usually more targeted and specific than this.

@dhenneke
Copy link
Contributor

@Johennes currently we don't.

This is part of the effort to unify the UIs of different applications (e.g. Nextcloud) into a greater product suite. In general, it would also be nice to have the user-avatar menu in the top right, but the layout of Element is not really compatible with such a design that a lot of other tools use. So thats non-trivial and isn't really planned.

The banner would e.g. already be displayed when Element is still loading and that might be a bit too early:

element-banner-login.mov

But it might be fine for the initial version until we need more.

(don't worry about the look/layout of the banner in the video; there are reasons on why it is the way it is)

@Johennes
Copy link
Contributor

Thanks for sharing @dhenneke.

The alternative is an ever growing scope in the Module API as to what exact state the app is in. Right now you might only need to know when the user logs in, later the exact view they're in (login, registration, room, etc) later also more detail like they're doing verification as part of login, etc. Maintaining this is likely to be even more effort to not break between versions from the react-sdk PoV

This is a fair concern. I wonder if we could mitigate it with an abstraction? Making high-level states like launching / launched available to modules seems plausible to me. But I agree that we probably wouldn't want to expose too granular states because then any change to them would require breaking the module API.

@germain-gg germain-gg self-requested a review July 19, 2023 10:43
# Conflicts:
#	src/vector/app.tsx
@maheichyk
Copy link
Contributor Author

maheichyk commented Aug 18, 2023

@germain-gg this is just a Draft PR and is basically just for information for now, because it seems that it cannot be built properly until we merge matrix-org/matrix-react-sdk-module-api#13 as it is complaining to missing WrapperLifecycle. So no need to review now, but thanks for the hint - I have requested review on that other PR in module-api.

Signed-off-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net>
@maheichyk maheichyk force-pushed the banner_module_api branch 2 times, most recently from 16a4aaa to 845d911 Compare August 22, 2023 07:05
Signed-off-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net>
@maheichyk maheichyk changed the title Add banner configurable via module API Add support for rendering a custom wrapper around Element Aug 22, 2023
@maheichyk maheichyk marked this pull request as ready for review August 22, 2023 07:22
@maheichyk maheichyk requested a review from a team as a code owner August 22, 2023 07:22
Copy link
Contributor

@germain-gg germain-gg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for updating this! Couple of things that I believe need updating, but we're heading in the right direction

test/app-tests/wrapper-test.tsx Outdated Show resolved Hide resolved
test/app-tests/wrapper-test.tsx Outdated Show resolved Hide resolved
test/app-tests/wrapper-test.tsx Outdated Show resolved Hide resolved
Signed-off-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net>
Copy link
Contributor

@germain-gg germain-gg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, but also pending on the change you suggested doing.
Once done, I will merge this. Thank you 🙏

Mikhail Aheichyk added 2 commits August 28, 2023 10:31
Signed-off-by: Mikhail Aheichyk <mikhail.aheichyk@nordeck.net>
@germain-gg
Copy link
Contributor

@maheichyk thank you for the updates. CI is slightly unhappy, therefore preventing me to merge this

@maheichyk
Copy link
Contributor Author

@maheichyk thank you for the updates. CI is slightly unhappy, therefore preventing me to merge this

@germain-gg seems that there is a problem with the pipeline due to different react types comparing to matrix react sdk, I have asked in dev room as well.

@maheichyk
Copy link
Contributor Author

@germain-gg CI is fine please have a look

@germain-gg germain-gg merged commit 3fd6b62 into element-hq:develop Aug 30, 2023
16 checks passed
@maheichyk
Copy link
Contributor Author

@germain-gg many thanks for the review and merge!

@dhenneke dhenneke deleted the banner_module_api branch August 30, 2023 06:59
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Sep 30, 2023
Changes in [1.11.45](https://github.com/vector-im/element-web/releases/tag/v1.11.45) (2023-09-29)
=================================================================================================

## 🐛 Bug Fixes
 * Fix Emoji font on Safari 17 ([\#11673](matrix-org/matrix-react-sdk#11673)).

Changes in [1.11.44](https://github.com/vector-im/element-web/releases/tag/v1.11.44) (2023-09-26)
=================================================================================================

## ✨ Features
 * Make video & voice call buttons pin conference widget if unpinned ([\#11576](matrix-org/matrix-react-sdk#11576)). Fixes vector-im/customer-retainer#72.
 * OIDC: persist refresh token ([\#11249](matrix-org/matrix-react-sdk#11249)). Contributed by @kerryarchibald.
 * ElementR: Cross user verification ([\#11364](matrix-org/matrix-react-sdk#11364)). Fixes #25752. Contributed by @florianduros.
 * Default intentional mentions ([\#11602](matrix-org/matrix-react-sdk#11602)).
 * Notify users about denied access on ask-to-join  rooms ([\#11480](matrix-org/matrix-react-sdk#11480)). Contributed by @nurjinjafar.
 * Allow setting knock room directory visibility ([\#11529](matrix-org/matrix-react-sdk#11529)). Contributed by @charlynguyen.

## 🐛 Bug Fixes
 * Revert "Fix regression around FacePile with overflow (#11527)" ([\#11634](matrix-org/matrix-react-sdk#11634)). Fixes #26209.
 * Escape placeholder before injecting it into the style ([\#11607](matrix-org/matrix-react-sdk#11607)).
 * Move ViewUser action callback to RoomView ([\#11495](matrix-org/matrix-react-sdk#11495)). Fixes #26040.
 * Fix room timeline search toggling behaviour edge case ([\#11605](matrix-org/matrix-react-sdk#11605)). Fixes #26105.
 * Avoid rendering view-message link in RoomKnocksBar unnecessarily ([\#11598](matrix-org/matrix-react-sdk#11598)). Contributed by @charlynguyen.
 * Use knock rooms sync to reflect the knock state ([\#11596](matrix-org/matrix-react-sdk#11596)). Fixes #26043 and #26044. Contributed by @charlynguyen.
 * Fix avatar in right panel not using the correct font ([\#11593](matrix-org/matrix-react-sdk#11593)). Fixes #26061. Contributed by @MidhunSureshR.
 * Add waits in Spotlight Cypress tests, hoping this unflakes them ([\#11590](matrix-org/matrix-react-sdk#11590)). Fixes #26053, #26140 #26139 and #26138. Contributed by @andybalaam.
 * Fix vertical alignment of default avatar font ([\#11582](matrix-org/matrix-react-sdk#11582)). Fixes #26081.
 * Fix avatars in public room & space search being flex shrunk ([\#11580](matrix-org/matrix-react-sdk#11580)). Fixes #26133.
 * Fix EventTile avatars being rendered with a size of 0 instead of hidden ([\#11558](matrix-org/matrix-react-sdk#11558)). Fixes #26075.

Changes in [1.11.43](https://github.com/vector-im/element-web/releases/tag/v1.11.43) (2023-09-15)
=================================================================================================

(No changes - bumping the version number for an element-desktop release.)

Changes in [1.11.42](https://github.com/vector-im/element-web/releases/tag/v1.11.42) (2023-09-13)
=================================================================================================

## 🐛 Bug Fixes
 * Update Compound to fix Firefox-specific avatar regression ([\#11604](matrix-org/matrix-react-sdk#11604)). Fixes #26155.

Changes in [1.11.41](https://github.com/vector-im/element-web/releases/tag/v1.11.41) (2023-09-12)
=================================================================================================

## 🦖 Deprecations
 * Deprecate customisations in favour of Module API ([\#25736](element-hq/element-web#25736)). Fixes #25733.

## ✨ Features
 * Make SVGR icons use forward ref ([\#26082](element-hq/element-web#26082)).
 * Add support for rendering a custom wrapper around Element ([\#25537](element-hq/element-web#25537)). Contributed by @maheichyk.
 * Allow creating public knock rooms ([\#11481](matrix-org/matrix-react-sdk#11481)). Contributed by @charlynguyen.
 * Render custom images in reactions according to MSC4027 ([\#11087](matrix-org/matrix-react-sdk#11087)). Contributed by @sumnerevans.
 * Introduce room knocks bar ([\#11475](matrix-org/matrix-react-sdk#11475)). Contributed by @charlynguyen.
 * Room header UI updates ([\#11507](matrix-org/matrix-react-sdk#11507)). Fixes #25892.
 * Remove green "verified" bar for encrypted events ([\#11496](matrix-org/matrix-react-sdk#11496)).
 * Update member count on room summary update ([\#11488](matrix-org/matrix-react-sdk#11488)).
 * Support for E2EE in Element Call  ([\#11492](matrix-org/matrix-react-sdk#11492)).
 * Allow requesting to join knock rooms via spotlight ([\#11482](matrix-org/matrix-react-sdk#11482)). Contributed by @charlynguyen.
 * Lock out the first tab if Element is opened in a second tab. ([\#11425](matrix-org/matrix-react-sdk#11425)). Fixes #25157.
 * Change avatar to use Compound implementation ([\#11448](matrix-org/matrix-react-sdk#11448)).

## 🐛 Bug Fixes
 * Fix vertical alignment of default avatar font ([\#11582](matrix-org/matrix-react-sdk#11582)). Fixes #26081.
 * Fix avatars in public room & space search being flex shrunk ([\#11580](matrix-org/matrix-react-sdk#11580)). Fixes #26133.
 * Fix EventTile avatars being rendered with a size of 0 instead of hidden ([\#11558](matrix-org/matrix-react-sdk#11558)). Fixes #26075.
 * Fix compound external assets path in bundle ([\#26069](element-hq/element-web#26069)).
 * Use RoomStateEvent.Update for knocks ([\#11516](matrix-org/matrix-react-sdk#11516)). Contributed by @charlynguyen.
 * Prevent event propagation when clicking icon buttons ([\#11515](matrix-org/matrix-react-sdk#11515)).
 * Only display RoomKnocksBar when feature flag is enabled ([\#11513](matrix-org/matrix-react-sdk#11513)). Contributed by @andybalaam.
 * Fix avatars of knock members for people tab of room settings ([\#11506](matrix-org/matrix-react-sdk#11506)). Fixes #26083. Contributed by @charlynguyen.
 * Fixes read receipt avatar offset ([\#11483](matrix-org/matrix-react-sdk#11483)). Fixes #26067, #26064 #26059 and #26061.
 * Fix avatar defects ([\#11473](matrix-org/matrix-react-sdk#11473)). Fixes #26051 and #26046.
 * Fix consistent avatar output for Percy ([\#11472](matrix-org/matrix-react-sdk#11472)). Fixes #26049 and #26052.
 * Fix colour of avatar and colour matching with username ([\#11470](matrix-org/matrix-react-sdk#11470)). Fixes #26042.
 * Fix incompatibility of Soft Logout with Element-R ([\#11468](matrix-org/matrix-react-sdk#11468)).
 * Fix instances of double translation and guard translation calls using typescript ([\#11443](matrix-org/matrix-react-sdk#11443)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Timesheet-1 Log any time spent on this into the A-Timesheet-1 project T-Enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants