refator: group core component ref in a object

Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
Camila Belo
2023-11-20 09:37:24 +01:00
parent 413f05a6c9
commit a9da252cb4
7 changed files with 35 additions and 46 deletions
@@ -17,7 +17,7 @@
import React from 'react';
import {
createComponentExtension,
coreNotFoundErrorPageComponentRef,
coreComponentsRefs,
} from '@backstage/frontend-plugin-api';
import { Box, Typography } from '@material-ui/core';
import { Button } from '@backstage/core-components';
@@ -57,6 +57,6 @@ export function CustomNotFoundErrorPage() {
}
export default createComponentExtension({
ref: coreNotFoundErrorPageComponentRef,
ref: coreComponentsRefs.notFoundErrorPage,
component: async () => CustomNotFoundErrorPage,
});
@@ -18,20 +18,17 @@ import {
Extension,
ComponentRef,
createComponentExtension,
coreProgressComponentRef,
coreBootErrorPageComponentRef,
coreNotFoundErrorPageComponentRef,
coreErrorBoundaryFallbackComponentRef,
coreComponentsRefs,
} 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: coreProgressComponentRef,
BootErrorPage: coreBootErrorPageComponentRef,
NotFoundErrorPage: coreNotFoundErrorPageComponentRef,
ErrorBoundaryFallback: coreErrorBoundaryFallbackComponentRef,
Progress: coreComponentsRefs.progress,
BootErrorPage: coreComponentsRefs.bootErrorPage,
NotFoundErrorPage: coreComponentsRefs.notFoundErrorPage,
ErrorBoundaryFallback: coreComponentsRefs.errorBoundaryFallback,
};
/** @public */
@@ -19,7 +19,7 @@ import {
createExtension,
coreExtensionData,
createExtensionInput,
coreNotFoundErrorPageComponentRef,
coreComponentsRefs,
useApi,
componentsApiRef,
} from '@backstage/frontend-plugin-api';
@@ -42,7 +42,7 @@ export const CoreRoutes = createExtension({
const Routes = () => {
const componentsApi = useApi(componentsApiRef);
const NotFoundErrorPage = componentsApi.getComponent(
coreNotFoundErrorPageComponentRef,
coreComponentsRefs.notFoundErrorPage,
);
const element = useRoutes([
@@ -16,31 +16,28 @@
import {
createComponentExtension,
coreProgressComponentRef,
coreBootErrorPageComponentRef,
coreNotFoundErrorPageComponentRef,
coreErrorBoundaryFallbackComponentRef,
coreComponentsRefs,
} from '@backstage/frontend-plugin-api';
// eslint-disable-next-line @backstage/no-relative-monorepo-imports
import { components as defaultComponents } from '../../../app-defaults/src/defaults';
// eslint-disable-next-line @backstage/no-relative-monorepo-imports
export const DefaultProgressComponent = createComponentExtension({
ref: coreProgressComponentRef,
ref: coreComponentsRefs.progress,
component: async () => defaultComponents.Progress,
});
export const DefaultBootErrorPageComponent = createComponentExtension({
ref: coreBootErrorPageComponentRef,
ref: coreComponentsRefs.bootErrorPage,
component: async () => defaultComponents.BootErrorPage,
});
export const DefaultNotFoundErrorPageComponent = createComponentExtension({
ref: coreNotFoundErrorPageComponentRef,
ref: coreComponentsRefs.notFoundErrorPage,
component: async () => defaultComponents.NotFoundErrorPage,
});
export const DefaultErrorBoundaryComponent = createComponentExtension({
ref: coreErrorBoundaryFallbackComponentRef,
ref: coreComponentsRefs.errorBoundaryFallback,
component: async () => defaultComponents.ErrorBoundaryFallback,
});
+6 -10
View File
@@ -331,7 +331,12 @@ export type CoreBootErrorPageComponent = ComponentType<
>;
// @public (undocumented)
export const coreBootErrorPageComponentRef: ComponentRef<CoreBootErrorPageComponent>;
export const coreComponentsRefs: {
progress: ComponentRef<CoreProgressComponent>;
bootErrorPage: ComponentRef<CoreBootErrorPageComponent>;
notFoundErrorPage: ComponentRef<CoreNotFoundErrorPageComponent>;
errorBoundaryFallback: ComponentRef<CoreErrorBoundaryFallbackComponent>;
};
// @public (undocumented)
export type CoreErrorBoundaryFallbackComponent = ComponentType<
@@ -342,9 +347,6 @@ export type CoreErrorBoundaryFallbackComponent = ComponentType<
}>
>;
// @public (undocumented)
export const coreErrorBoundaryFallbackComponentRef: ComponentRef<CoreErrorBoundaryFallbackComponent>;
// @public (undocumented)
export const coreExtensionData: {
reactElement: ConfigurableExtensionDataRef<JSX_2.Element, {}>;
@@ -368,15 +370,9 @@ export type CoreNotFoundErrorPageComponent = ComponentType<
PropsWithChildren<{}>
>;
// @public (undocumented)
export const coreNotFoundErrorPageComponentRef: ComponentRef<CoreNotFoundErrorPageComponent>;
// @public (undocumented)
export type CoreProgressComponent = ComponentType<PropsWithChildren<{}>>;
// @public (undocumented)
export const coreProgressComponentRef: ComponentRef<CoreProgressComponent>;
// @public (undocumented)
export function createApiExtension<
TConfig extends {},
@@ -40,24 +40,29 @@ export function createComponentRef<T>(options: {
};
}
/** @public */
export const coreProgressComponentRef =
createComponentRef<CoreProgressComponent>({ id: 'core.components.progress' });
const coreProgressComponentRef = createComponentRef<CoreProgressComponent>({
id: 'core.components.progress',
});
/** @public */
export const coreBootErrorPageComponentRef =
const coreBootErrorPageComponentRef =
createComponentRef<CoreBootErrorPageComponent>({
id: 'core.components.bootErrorPage',
});
/** @public */
export const coreNotFoundErrorPageComponentRef =
const coreNotFoundErrorPageComponentRef =
createComponentRef<CoreNotFoundErrorPageComponent>({
id: 'core.components.notFoundErrorPage',
});
/** @public */
export const coreErrorBoundaryFallbackComponentRef =
const coreErrorBoundaryFallbackComponentRef =
createComponentRef<CoreErrorBoundaryFallbackComponent>({
id: 'core.components.errorBoundaryFallback',
});
/** @public */
export const coreComponentsRefs = {
progress: coreProgressComponentRef,
bootErrorPage: coreBootErrorPageComponentRef,
notFoundErrorPage: coreNotFoundErrorPageComponentRef,
errorBoundaryFallback: coreErrorBoundaryFallbackComponentRef,
};
@@ -14,13 +14,7 @@
* limitations under the License.
*/
export {
coreProgressComponentRef,
coreBootErrorPageComponentRef,
coreErrorBoundaryFallbackComponentRef,
coreNotFoundErrorPageComponentRef,
type ComponentRef,
} from './ComponentRef';
export { coreComponentsRefs, type ComponentRef } from './ComponentRef';
export { ExtensionError } from './ExtensionError';