Prior to this commit, we had a default Glimmer component that was responsible for handling generic rendering of notifications in the user menu, and many notification types had a custom Glimmer component that inherited from the default component to customize how they were rendered. That implementation was less than ideal because it meant plugins would have to create Glimmer components to customize notification types added by them and that would make the surface area of the API too big. This commit changes the implementation so there's only one Glimmer component for rendering notifications, and then notification types that need to be customized can create a regular JavaScript class - `renderDirector` in the code - that provides the Glimmer component with the content it should display. We also introduce an API for plugins to register a renderer for a notification type or override an existing one. Some of the changes are partially extracted from https://github.com/discourse/discourse/pull/17379.
20 lines
533 B
JavaScript
20 lines
533 B
JavaScript
import { getRenderDirector } from "discourse/lib/notification-item";
|
|
import sessionFixtures from "discourse/tests/fixtures/session-fixtures";
|
|
import User from "discourse/models/user";
|
|
import Site from "discourse/models/site";
|
|
|
|
export function createRenderDirector(
|
|
notification,
|
|
notificationType,
|
|
siteSettings
|
|
) {
|
|
const director = getRenderDirector(
|
|
notificationType,
|
|
notification,
|
|
User.create(sessionFixtures["/session/current.json"].current_user),
|
|
siteSettings,
|
|
Site.current()
|
|
);
|
|
return director;
|
|
}
|