frontend-plugin-api: add routes and externalRoutes to plugins
Co-authored-by: Philipp Hugenroth <philipph@spotify.com> Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -16,11 +16,7 @@
|
||||
|
||||
import React from 'react';
|
||||
import { createApp } from '@backstage/frontend-app-api';
|
||||
import {
|
||||
externalPageXRouteRef,
|
||||
pageXRouteRef,
|
||||
pagesPlugin,
|
||||
} from './examples/pagesPlugin';
|
||||
import { pagesPlugin } from './examples/pagesPlugin';
|
||||
import graphiqlPlugin from '@backstage/plugin-graphiql/alpha';
|
||||
import techRadarPlugin from '@backstage/plugin-tech-radar/alpha';
|
||||
import userSettingsPlugin from '@backstage/plugin-user-settings/alpha';
|
||||
@@ -77,7 +73,7 @@ const app = createApp({
|
||||
}),
|
||||
],
|
||||
bindRoutes({ bind }) {
|
||||
bind({ x: externalPageXRouteRef }, { x: pageXRouteRef });
|
||||
bind(pagesPlugin.externalRoutes, { pageX: pagesPlugin.routes.pageX });
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -129,5 +129,12 @@ export const pagesPlugin = createPlugin({
|
||||
// // OR
|
||||
// // 'page1'
|
||||
// },
|
||||
routes: {
|
||||
page1: page1RouteRef,
|
||||
pageX: pageXRouteRef,
|
||||
},
|
||||
externalRoutes: {
|
||||
pageX: externalPageXRouteRef,
|
||||
},
|
||||
extensions: [IndexPage, Page1, ExternalPage],
|
||||
});
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
|
||||
import { AnyApiFactory } from '@backstage/core-plugin-api';
|
||||
import { AnyApiRef } from '@backstage/core-plugin-api';
|
||||
import { AnyExternalRoutes } from '@backstage/core-plugin-api';
|
||||
import { AnyRoutes } from '@backstage/core-plugin-api';
|
||||
import { AppTheme } from '@backstage/core-plugin-api';
|
||||
import { IconComponent } from '@backstage/core-plugin-api';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
@@ -40,13 +42,20 @@ export type AnyExtensionInputMap = {
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
export interface BackstagePlugin {
|
||||
export interface BackstagePlugin<
|
||||
Routes extends AnyRoutes = AnyRoutes,
|
||||
ExternalRoutes extends AnyExternalRoutes = AnyExternalRoutes,
|
||||
> {
|
||||
// (undocumented)
|
||||
$$type: '@backstage/BackstagePlugin';
|
||||
// (undocumented)
|
||||
extensions: Extension<unknown>[];
|
||||
// (undocumented)
|
||||
externalRoutes: ExternalRoutes;
|
||||
// (undocumented)
|
||||
id: string;
|
||||
// (undocumented)
|
||||
routes: Routes;
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
@@ -205,7 +214,12 @@ export function createPageExtension<
|
||||
): Extension<TConfig>;
|
||||
|
||||
// @public (undocumented)
|
||||
export function createPlugin(options: PluginOptions): BackstagePlugin;
|
||||
export function createPlugin<
|
||||
Routes extends AnyRoutes = AnyRoutes,
|
||||
ExternalRoutes extends AnyExternalRoutes = AnyExternalRoutes,
|
||||
>(
|
||||
options: PluginOptions<Routes, ExternalRoutes>,
|
||||
): BackstagePlugin<Routes, ExternalRoutes>;
|
||||
|
||||
// @public (undocumented)
|
||||
export function createSchemaFromZod<TOutput, TInput>(
|
||||
@@ -338,11 +352,18 @@ export type NavTarget = {
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
export interface PluginOptions {
|
||||
export interface PluginOptions<
|
||||
Routes extends AnyRoutes,
|
||||
ExternalRoutes extends AnyExternalRoutes,
|
||||
> {
|
||||
// (undocumented)
|
||||
extensions?: Extension<unknown>[];
|
||||
// (undocumented)
|
||||
externalRoutes?: ExternalRoutes;
|
||||
// (undocumented)
|
||||
id: string;
|
||||
// (undocumented)
|
||||
routes?: Routes;
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
|
||||
@@ -14,26 +14,44 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AnyExternalRoutes, AnyRoutes } from '@backstage/core-plugin-api';
|
||||
import { Extension } from './createExtension';
|
||||
|
||||
/** @public */
|
||||
export interface PluginOptions {
|
||||
export interface PluginOptions<
|
||||
Routes extends AnyRoutes,
|
||||
ExternalRoutes extends AnyExternalRoutes,
|
||||
> {
|
||||
id: string;
|
||||
routes?: Routes;
|
||||
externalRoutes?: ExternalRoutes;
|
||||
extensions?: Extension<unknown>[];
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export interface BackstagePlugin {
|
||||
export interface BackstagePlugin<
|
||||
Routes extends AnyRoutes = AnyRoutes,
|
||||
ExternalRoutes extends AnyExternalRoutes = AnyExternalRoutes,
|
||||
> {
|
||||
$$type: '@backstage/BackstagePlugin';
|
||||
id: string;
|
||||
extensions: Extension<unknown>[];
|
||||
routes: Routes;
|
||||
externalRoutes: ExternalRoutes;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export function createPlugin(options: PluginOptions): BackstagePlugin {
|
||||
export function createPlugin<
|
||||
Routes extends AnyRoutes = AnyRoutes,
|
||||
ExternalRoutes extends AnyExternalRoutes = AnyExternalRoutes,
|
||||
>(
|
||||
options: PluginOptions<Routes, ExternalRoutes>,
|
||||
): BackstagePlugin<Routes, ExternalRoutes> {
|
||||
return {
|
||||
...options,
|
||||
$$type: '@backstage/BackstagePlugin',
|
||||
routes: options.routes ?? ({} as Routes),
|
||||
externalRoutes: options.externalRoutes ?? ({} as ExternalRoutes),
|
||||
extensions: options.extensions ?? [],
|
||||
$$type: '@backstage/BackstagePlugin',
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user