Draft(WIP): Add reconfigure to plugin
Signed-off-by: bnechyporenko <bnechyporenko@bol.com>
This commit is contained in:
@@ -20,6 +20,7 @@ import {
|
||||
Extension,
|
||||
AnyRoutes,
|
||||
AnyExternalRoutes,
|
||||
AnyMetadata,
|
||||
PluginFeatureFlagConfig,
|
||||
} from './types';
|
||||
import { AnyApiFactory } from '../apis';
|
||||
@@ -30,9 +31,16 @@ import { AnyApiFactory } from '../apis';
|
||||
export class PluginImpl<
|
||||
Routes extends AnyRoutes,
|
||||
ExternalRoutes extends AnyExternalRoutes,
|
||||
> implements BackstagePlugin<Routes, ExternalRoutes>
|
||||
PluginMetadata extends AnyMetadata,
|
||||
> implements BackstagePlugin<Routes, ExternalRoutes, PluginMetadata>
|
||||
{
|
||||
constructor(private readonly config: PluginConfig<Routes, ExternalRoutes>) {}
|
||||
constructor(
|
||||
private readonly config: PluginConfig<
|
||||
Routes,
|
||||
ExternalRoutes,
|
||||
PluginMetadata
|
||||
>,
|
||||
) {}
|
||||
|
||||
getId(): string {
|
||||
return this.config.id;
|
||||
@@ -58,6 +66,11 @@ export class PluginImpl<
|
||||
return extension.expose(this);
|
||||
}
|
||||
|
||||
reconfigure(metadata: PluginMetadata): BackstagePlugin {
|
||||
this.config.metadata = metadata;
|
||||
return this;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return `plugin{${this.config.id}}`;
|
||||
}
|
||||
@@ -72,8 +85,9 @@ export class PluginImpl<
|
||||
export function createPlugin<
|
||||
Routes extends AnyRoutes = {},
|
||||
ExternalRoutes extends AnyExternalRoutes = {},
|
||||
PluginMetadata extends AnyMetadata = {},
|
||||
>(
|
||||
config: PluginConfig<Routes, ExternalRoutes>,
|
||||
): BackstagePlugin<Routes, ExternalRoutes> {
|
||||
config: PluginConfig<Routes, ExternalRoutes, PluginMetadata>,
|
||||
): BackstagePlugin<Routes, ExternalRoutes, PluginMetadata> {
|
||||
return new PluginImpl(config);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,13 @@ export type AnyRoutes = { [name: string]: RouteRef | SubRouteRef };
|
||||
*/
|
||||
export type AnyExternalRoutes = { [name: string]: ExternalRouteRef };
|
||||
|
||||
/**
|
||||
* Catch-all metadata type.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type AnyMetadata = { [name: string]: any };
|
||||
|
||||
/**
|
||||
* Plugin type.
|
||||
*
|
||||
@@ -52,6 +59,7 @@ export type AnyExternalRoutes = { [name: string]: ExternalRouteRef };
|
||||
export type BackstagePlugin<
|
||||
Routes extends AnyRoutes = {},
|
||||
ExternalRoutes extends AnyExternalRoutes = {},
|
||||
PluginMetadata extends AnyMetadata = {},
|
||||
> = {
|
||||
getId(): string;
|
||||
getApis(): Iterable<AnyApiFactory>;
|
||||
@@ -60,6 +68,7 @@ export type BackstagePlugin<
|
||||
*/
|
||||
getFeatureFlags(): Iterable<PluginFeatureFlagConfig>;
|
||||
provide<T>(extension: Extension<T>): T;
|
||||
reconfigure(metadata: PluginMetadata): BackstagePlugin;
|
||||
routes: Routes;
|
||||
externalRoutes: ExternalRoutes;
|
||||
};
|
||||
@@ -82,12 +91,14 @@ export type PluginFeatureFlagConfig = {
|
||||
export type PluginConfig<
|
||||
Routes extends AnyRoutes,
|
||||
ExternalRoutes extends AnyExternalRoutes,
|
||||
PluginMetadata extends AnyMetadata,
|
||||
> = {
|
||||
id: string;
|
||||
apis?: Iterable<AnyApiFactory>;
|
||||
routes?: Routes;
|
||||
externalRoutes?: ExternalRoutes;
|
||||
featureFlags?: PluginFeatureFlagConfig[];
|
||||
metadata?: PluginMetadata;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,6 @@ import {
|
||||
ContentHeader,
|
||||
CreateButton,
|
||||
PageWithHeader,
|
||||
SupportButton,
|
||||
TableColumn,
|
||||
TableProps,
|
||||
} from '@backstage/core-components';
|
||||
@@ -39,6 +38,12 @@ import { createComponentRouteRef } from '../../routes';
|
||||
import { CatalogTable, CatalogTableRow } from '../CatalogTable';
|
||||
import { CatalogKindHeader } from '../CatalogKindHeader';
|
||||
|
||||
export type DefaultCatalogMetadataProps = {
|
||||
createComponentTitle: string;
|
||||
supportButtonText: string;
|
||||
supportButton: () => JSX.Element;
|
||||
};
|
||||
|
||||
/**
|
||||
* Props for root catalog pages.
|
||||
*
|
||||
@@ -50,6 +55,7 @@ export interface DefaultCatalogPageProps {
|
||||
actions?: TableProps<CatalogTableRow>['actions'];
|
||||
initialKind?: string;
|
||||
tableOptions?: TableProps<CatalogTableRow>['options'];
|
||||
metadata?: DefaultCatalogMetadataProps;
|
||||
}
|
||||
|
||||
export function DefaultCatalogPage(props: DefaultCatalogPageProps) {
|
||||
@@ -72,10 +78,10 @@ export function DefaultCatalogPage(props: DefaultCatalogPageProps) {
|
||||
titleComponent={<CatalogKindHeader initialFilter={initialKind} />}
|
||||
>
|
||||
<CreateButton
|
||||
title="Create Component"
|
||||
title={props.metadata?.createComponentTitle || ''}
|
||||
to={createComponentLink && createComponentLink()}
|
||||
/>
|
||||
<SupportButton>All your software catalog entities</SupportButton>
|
||||
{props.metadata?.supportButton()}
|
||||
</ContentHeader>
|
||||
<CatalogFilterLayout>
|
||||
<CatalogFilterLayout.Filters>
|
||||
|
||||
@@ -72,6 +72,12 @@ export const catalogPlugin = createPlugin({
|
||||
createComponent: createComponentRouteRef,
|
||||
viewTechDoc: viewTechDocRouteRef,
|
||||
},
|
||||
metadata: {
|
||||
createComponentTitle: 'Create Component',
|
||||
supportButton: () =>
|
||||
import('@backstage/core-components').then(m => m.SupportButton),
|
||||
supportButtonText: 'All your software catalog entities',
|
||||
},
|
||||
});
|
||||
|
||||
/** @public */
|
||||
|
||||
Reference in New Issue
Block a user