frontend-app-api: improve legacy plugin conversion

Co-authored-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Vincenzo Scamporlino <vincenzos@spotify.com>
Co-authored-by: Camila Belo <camilaibs@gmail.com>
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-10-03 15:46:44 +02:00
parent 261e6b3161
commit 4cfc21d6eb
3 changed files with 23 additions and 5 deletions
+1
View File
@@ -42,6 +42,7 @@
"@backstage/plugin-graphiql": "workspace:^",
"@backstage/theme": "workspace:^",
"@backstage/types": "workspace:^",
"@backstage/version-bridge": "workspace:^",
"@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3",
"@types/react": "^16.13.1 || ^17.0.0",
@@ -85,6 +85,7 @@ import { BrowserRouter, Route } from 'react-router-dom';
import { SidebarItem } from '@backstage/core-components';
import { DarkTheme, LightTheme } from '../extensions/themes';
import { extractRouteInfoFromInstanceTree } from '../routing/extractRouteInfoFromInstanceTree';
import { getOrCreateGlobalSingleton } from '@backstage/version-bridge';
/** @public */
export interface ExtensionTreeNode {
@@ -336,25 +337,40 @@ export function createApp(options: {
};
}
// Make sure that we only convert each new plugin instance to its legacy equivalent once
const legacyPluginStore = getOrCreateGlobalSingleton(
'legacy-plugin-compatibility-store',
() => new WeakMap<BackstagePlugin, LegacyBackstagePlugin>(),
);
export function toLegacyPlugin(plugin: BackstagePlugin): LegacyBackstagePlugin {
let legacy = legacyPluginStore.get(plugin);
if (legacy) {
return legacy;
}
const errorMsg = 'Not implemented in legacy plugin compatibility layer';
const notImplemented = () => {
throw new Error(errorMsg);
};
return {
legacy = {
getId(): string {
return plugin.id;
},
get routes(): never {
throw new Error(errorMsg);
get routes() {
return {};
},
get externalRoutes(): never {
throw new Error(errorMsg);
get externalRoutes() {
return {};
},
getApis: notImplemented,
getFeatureFlags: notImplemented,
provide: notImplemented,
};
legacyPluginStore.set(plugin, legacy);
return legacy;
}
function createLegacyAppContext(plugins: BackstagePlugin[]): AppContext {
+1
View File
@@ -4311,6 +4311,7 @@ __metadata:
"@backstage/test-utils": "workspace:^"
"@backstage/theme": "workspace:^"
"@backstage/types": "workspace:^"
"@backstage/version-bridge": "workspace:^"
"@material-ui/core": ^4.12.4
"@material-ui/icons": ^4.11.3
"@testing-library/jest-dom": ^5.10.1