refactor: remove legacy component compat helper

Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
Camila Belo
2023-11-30 10:39:24 +01:00
parent 8b69319f29
commit 08699d8873
6 changed files with 5 additions and 142 deletions
+3 -10
View File
@@ -17,7 +17,7 @@
import React from 'react';
import { createApp } from '@backstage/frontend-app-api';
import { pagesPlugin } from './examples/pagesPlugin';
import { CustomNotFoundErrorPage } from './examples/notFoundErrorPageExtension';
import notFoundErrorPage from './examples/notFoundErrorPageExtension';
import graphiqlPlugin from '@backstage/plugin-graphiql/alpha';
import techRadarPlugin from '@backstage/plugin-tech-radar/alpha';
import userSettingsPlugin from '@backstage/plugin-user-settings/alpha';
@@ -33,10 +33,7 @@ import {
} from '@backstage/frontend-plugin-api';
import techdocsPlugin from '@backstage/plugin-techdocs/alpha';
import { homePage } from './HomePage';
import {
collectLegacyComponents,
collectLegacyRoutes,
} from '@backstage/core-compat-api';
import { collectLegacyRoutes } from '@backstage/core-compat-api';
import { FlatRoutes } from '@backstage/core-app-api';
import { Route } from 'react-router';
import { CatalogImportPage } from '@backstage/plugin-catalog-import';
@@ -118,10 +115,6 @@ const collectedLegacyPlugins = collectLegacyRoutes(
</FlatRoutes>,
);
const legacyAppComponents = collectLegacyComponents({
NotFoundErrorPage: CustomNotFoundErrorPage,
});
const app = createApp({
features: [
graphiqlPlugin,
@@ -137,7 +130,7 @@ const app = createApp({
scmAuthExtension,
scmIntegrationApi,
signInPage,
...legacyAppComponents,
notFoundErrorPage,
],
}),
],
@@ -36,15 +36,9 @@ export function CustomNotFoundErrorPage() {
>
<Typography variant="h1">404</Typography>
<Typography color="textSecondary" paragraph style={{ width: 300 }}>
Bowie was unable to locate this page. Please contact your support team
if this page used to exist.
Unable to locate this page. Please contact your support team if this
page used to exist.
</Typography>
<img
alt="Backstage bowie"
src="https://info.backstage.spotify.com/hs-fs/hubfs/Call%20Bowie%202.png"
width="200"
style={{ filter: 'grayscale(50%)' }}
/>
<Button
variant="contained"
to="/"
-7
View File
@@ -6,9 +6,7 @@
/// <reference types="react" />
import { AnyRouteRefParams } from '@backstage/core-plugin-api';
import { AppComponents } from '@backstage/core-plugin-api';
import { BackstagePlugin } from '@backstage/frontend-plugin-api';
import { ExtensionDefinition } from '@backstage/frontend-plugin-api';
import { ExtensionOverrides } from '@backstage/frontend-plugin-api';
import { ExternalRouteRef } from '@backstage/core-plugin-api';
import { ExternalRouteRef as ExternalRouteRef_2 } from '@backstage/frontend-plugin-api';
@@ -18,11 +16,6 @@ import { RouteRef as RouteRef_2 } from '@backstage/frontend-plugin-api';
import { SubRouteRef } from '@backstage/core-plugin-api';
import { SubRouteRef as SubRouteRef_2 } from '@backstage/frontend-plugin-api';
// @public (undocumented)
export function collectLegacyComponents(
components: Partial<AppComponents>,
): ExtensionDefinition<unknown>[];
// @public (undocumented)
export function collectLegacyRoutes(
flatRoutesElement: JSX.Element,
@@ -1,66 +0,0 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { collectLegacyComponents } from './collectLegacyComponents';
describe('collectLegacyComponents', () => {
const components = {
Progress: () => <div>Progress</div>,
BootErrorPage: () => <div>BootErrorPage</div>,
NotFoundErrorPage: () => <div>NotFoundErrorPage</div>,
ErrorBoundaryFallback: () => <div>ErrorBoundaryFallback</div>,
};
it('should collect legacy routes', () => {
const collected = collectLegacyComponents(components);
expect(
collected.map(p => ({
kind: p.kind,
namespace: p.namespace,
attachTo: p.attachTo,
disabled: p.disabled,
})),
).toEqual([
{
kind: 'component',
namespace: 'core.components.progress',
attachTo: { id: 'core', input: 'components' },
disabled: false,
},
{
kind: 'component',
namespace: 'core.components.bootErrorPage',
attachTo: { id: 'core', input: 'components' },
disabled: false,
},
{
kind: 'component',
namespace: 'core.components.notFoundErrorPage',
attachTo: { id: 'core', input: 'components' },
disabled: false,
},
{
kind: 'component',
namespace: 'core.components.errorBoundaryFallback',
attachTo: { id: 'core', input: 'components' },
disabled: false,
},
]);
});
});
@@ -1,50 +0,0 @@
/*
* Copyright 2023 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
ComponentRef,
createComponentExtension,
coreComponentsRefs,
ExtensionDefinition,
} from '@backstage/frontend-plugin-api';
import { AppComponents } from '@backstage/core-plugin-api';
type ComponentTypes<T = AppComponents> = T[keyof T];
const refs: Record<string, ComponentRef<ComponentTypes>> = {
Progress: coreComponentsRefs.progress,
BootErrorPage: coreComponentsRefs.bootErrorPage,
NotFoundErrorPage: coreComponentsRefs.notFoundErrorPage,
ErrorBoundaryFallback: coreComponentsRefs.errorBoundaryFallback,
};
/** @public */
export function collectLegacyComponents(components: Partial<AppComponents>) {
return Object.entries(components).reduce<ExtensionDefinition<unknown>[]>(
(extensions, [name, component]) => {
const ref = refs[name];
return ref
? extensions.concat(
createComponentExtension({
ref,
component: { sync: () => component },
}),
)
: extensions;
},
[],
);
}
-1
View File
@@ -14,6 +14,5 @@
* limitations under the License.
*/
export { collectLegacyRoutes } from './collectLegacyRoutes';
export { collectLegacyComponents } from './collectLegacyComponents';
export { convertLegacyApp } from './convertLegacyApp';
export { convertLegacyRouteRef } from './convertLegacyRouteRef';