refactor(catalog): extract pages extensions file

Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
Camila Belo
2023-10-21 13:12:00 +02:00
parent 12e562f379
commit 3f65bb7208
2 changed files with 86 additions and 63 deletions
+83
View File
@@ -0,0 +1,83 @@
/*
* 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 { convertLegacyRouteRef } from '@backstage/core-plugin-api/alpha';
import {
createPageExtension,
coreExtensionData,
createExtensionInput,
} from '@backstage/frontend-plugin-api';
import {
AsyncEntityProvider,
entityRouteRef,
} from '@backstage/plugin-catalog-react';
import { entityContentTitleExtensionDataRef } from '@backstage/plugin-catalog-react/alpha';
import { rootRouteRef } from '../routes';
import { useEntityFromUrl } from '../components/CatalogEntityPage/useEntityFromUrl';
export const CatalogIndexPage = createPageExtension({
id: 'plugin.catalog.page.index',
defaultPath: '/catalog',
routeRef: convertLegacyRouteRef(rootRouteRef),
inputs: {
filters: createExtensionInput({
element: coreExtensionData.reactElement,
}),
},
loader: async ({ inputs }) => {
const { BaseCatalogPage } = await import('../components/CatalogPage');
const filters = inputs.filters.map(filter => filter.element);
return <BaseCatalogPage filters={<>{filters}</>} />;
},
});
export const CatalogEntityPage = createPageExtension({
id: 'plugin.catalog.page.entity',
defaultPath: '/catalog/:namespace/:kind/:name',
routeRef: convertLegacyRouteRef(entityRouteRef),
inputs: {
contents: createExtensionInput({
element: coreExtensionData.reactElement,
path: coreExtensionData.routePath,
routeRef: coreExtensionData.routeRef.optional(),
title: entityContentTitleExtensionDataRef,
}),
},
loader: async ({ inputs }) => {
const { EntityLayout } = await import('../components/EntityLayout');
const Component = () => {
return (
<AsyncEntityProvider {...useEntityFromUrl()}>
<EntityLayout>
{inputs.contents.map(content => (
<EntityLayout.Route
key={content.path}
path={content.path}
title={content.title}
>
{content.element}
</EntityLayout.Route>
))}
</EntityLayout>
</AsyncEntityProvider>
);
};
return <Component />;
},
});
export default [CatalogIndexPage, CatalogEntityPage];
+3 -63
View File
@@ -20,21 +20,16 @@ import HomeIcon from '@material-ui/icons/Home';
import { convertLegacyRouteRef } from '@backstage/core-plugin-api/alpha';
import {
createPageExtension,
createPlugin,
createNavItemExtension,
coreExtensionData,
createExtensionInput,
} from '@backstage/frontend-plugin-api';
import {
AsyncEntityProvider,
entityRouteRef,
} from '@backstage/plugin-catalog-react';
import { entityRouteRef } from '@backstage/plugin-catalog-react';
import {
createEntityContentExtension,
createEntityCardExtension,
entityContentTitleExtensionDataRef,
} from '@backstage/plugin-catalog-react/alpha';
import { createSearchResultListItemExtension } from '@backstage/plugin-search-react/alpha';
@@ -44,9 +39,9 @@ import {
rootRouteRef,
viewTechDocRouteRef,
} from '../routes';
import { useEntityFromUrl } from '../components/CatalogEntityPage/useEntityFromUrl';
import apis from './apis';
import pages from './pages';
import filters from './filters';
/** @alpha */
@@ -60,60 +55,6 @@ export const CatalogSearchResultListItemExtension =
),
});
const CatalogIndexPage = createPageExtension({
id: 'plugin.catalog.page.index',
defaultPath: '/catalog',
routeRef: convertLegacyRouteRef(rootRouteRef),
inputs: {
filters: createExtensionInput({
element: coreExtensionData.reactElement,
}),
},
loader: async ({ inputs }) => {
const { BaseCatalogPage } = await import('../components/CatalogPage');
return (
<BaseCatalogPage
filters={<>{inputs.filters.map(filter => filter.element)}</>}
/>
);
},
});
const CatalogEntityPage = createPageExtension({
id: 'plugin.catalog.page.entity',
defaultPath: '/catalog/:namespace/:kind/:name',
routeRef: convertLegacyRouteRef(entityRouteRef),
inputs: {
contents: createExtensionInput({
element: coreExtensionData.reactElement,
path: coreExtensionData.routePath,
routeRef: coreExtensionData.routeRef.optional(),
title: entityContentTitleExtensionDataRef,
}),
},
loader: async ({ inputs }) => {
const { EntityLayout } = await import('../components/EntityLayout');
const Component = () => {
return (
<AsyncEntityProvider {...useEntityFromUrl()}>
<EntityLayout>
{inputs.contents.map(content => (
<EntityLayout.Route
key={content.path}
path={content.path}
title={content.title}
>
{content.element}
</EntityLayout.Route>
))}
</EntityLayout>
</AsyncEntityProvider>
);
};
return <Component />;
},
});
const EntityAboutCard = createEntityCardExtension({
id: 'about',
loader: async () =>
@@ -164,10 +105,9 @@ export default createPlugin({
},
extensions: [
...apis,
...pages,
...filters,
CatalogSearchResultListItemExtension,
CatalogIndexPage,
CatalogEntityPage,
CatalogNavItem,
OverviewEntityContent,
EntityAboutCard,