codify extension points docs (#1947)

This pull request converts the current incomplete textual documentation of the available frontend extension points to in-code definitions that act both as documentation and as type helpers for improving overall code quality. All extension points available in the SCM-Manager core are now available, but no plugin was updated and only those parts of the core codebase had the new types added that did not require runtime changes. The only exception to this is the breadcrumbs, which was a simple change that is fully backwards-compatible.
This commit is contained in:
Konstantin Schaper
2022-03-29 15:04:14 +02:00
committed by GitHub
parent 5006e9b821
commit 4d203ff36f
55 changed files with 962 additions and 430 deletions

View File

@@ -24,7 +24,7 @@
import React from "react";
import { storiesOf } from "@storybook/react";
import Footer from "./Footer";
import { Binder, BinderContext } from "@scm-manager/ui-extensions";
import { Binder, BinderContext, extensionPoints } from "@scm-manager/ui-extensions";
import { Me } from "@scm-manager/ui-types";
import { EXTENSION_POINT } from "../avatar/Avatar";
// @ts-ignore ignore unknown png
@@ -43,11 +43,8 @@ const trillian: Me = {
_links: {},
};
const bindAvatar = (binder: Binder, avatar: string) => {
binder.bind(EXTENSION_POINT, () => {
return avatar;
});
};
const bindAvatar = (binder: Binder, avatar: string) =>
binder.bind<extensionPoints.AvatarFactory>(EXTENSION_POINT, () => avatar);
const bindLinks = (binder: Binder) => {
binder.bind("footer.information", () => <ExternalNavLink to="#" label="REST API" />);

View File

@@ -23,7 +23,7 @@
*/
import React, { FC } from "react";
import { Links, Me } from "@scm-manager/ui-types";
import { ExtensionPoint, useBinder } from "@scm-manager/ui-extensions";
import { ExtensionPoint, extensionPoints, useBinder } from "@scm-manager/ui-extensions";
import { AvatarImage } from "../avatar";
import NavLink from "../navigation/NavLink";
import FooterSection from "./FooterSection";
@@ -84,7 +84,7 @@ const Footer: FC<Props> = ({ me, version, links }) => {
const extensionProps = { me, url: "/me", links };
let meSectionTile;
if (me) {
if (binder.hasExtension(EXTENSION_POINT)) {
if (binder.hasExtension<extensionPoints.AvatarFactory>(EXTENSION_POINT)) {
meSectionTile = <TitleWithAvatar me={me} />;
} else {
meSectionTile = <TitleWithIcon title={me.displayName} icon="user-circle" />;
@@ -105,7 +105,11 @@ const Footer: FC<Props> = ({ me, version, links }) => {
<NavLink to="/me/settings/publicKeys" label={t("profile.publicKeysNavLink")} />
)}
{me?._links?.apiKeys && <NavLink to="/me/settings/apiKeys" label={t("profile.apiKeysNavLink")} />}
<ExtensionPoint name="profile.setting" props={extensionProps} renderAll={true} />
<ExtensionPoint<extensionPoints.ProfileSetting>
name="profile.setting"
props={extensionProps}
renderAll={true}
/>
</FooterSection>
) : null}
<FooterSection title={<TitleWithIcon title={t("footer.information.title")} icon="info-circle" />}>