From 12e562f379e4fecf145aba298750d2d983e9d808 Mon Sep 17 00:00:00 2001 From: Camila Belo Date: Sat, 21 Oct 2023 13:10:22 +0200 Subject: [PATCH] refactor(catalog): extract apis extensions file Signed-off-by: Camila Belo --- plugins/catalog/src/alpha/apis.tsx | 51 ++++++++++++++++++++++++++++ plugins/catalog/src/alpha/plugin.tsx | 37 ++------------------ 2 files changed, 53 insertions(+), 35 deletions(-) create mode 100644 plugins/catalog/src/alpha/apis.tsx diff --git a/plugins/catalog/src/alpha/apis.tsx b/plugins/catalog/src/alpha/apis.tsx new file mode 100644 index 0000000000..a887a33a04 --- /dev/null +++ b/plugins/catalog/src/alpha/apis.tsx @@ -0,0 +1,51 @@ +/* + * 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 { + createApiFactory, + discoveryApiRef, + fetchApiRef, + storageApiRef, +} from '@backstage/core-plugin-api'; +import { CatalogClient } from '@backstage/catalog-client'; +import { createApiExtension } from '@backstage/frontend-plugin-api'; +import { + catalogApiRef, + starredEntitiesApiRef, +} from '@backstage/plugin-catalog-react'; +import { DefaultStarredEntitiesApi } from '../apis'; + +export const CatalogApi = createApiExtension({ + factory: createApiFactory({ + api: catalogApiRef, + deps: { + discoveryApi: discoveryApiRef, + fetchApi: fetchApiRef, + }, + factory: ({ discoveryApi, fetchApi }) => + new CatalogClient({ discoveryApi, fetchApi }), + }), +}); + +export const StarredEntitiesApi = createApiExtension({ + factory: createApiFactory({ + api: starredEntitiesApiRef, + deps: { storageApi: storageApiRef }, + factory: ({ storageApi }) => new DefaultStarredEntitiesApi({ storageApi }), + }), +}); + +export default [CatalogApi, StarredEntitiesApi]; diff --git a/plugins/catalog/src/alpha/plugin.tsx b/plugins/catalog/src/alpha/plugin.tsx index 9f6094d288..c40bb55aa5 100644 --- a/plugins/catalog/src/alpha/plugin.tsx +++ b/plugins/catalog/src/alpha/plugin.tsx @@ -18,15 +18,8 @@ import React from 'react'; import Grid from '@material-ui/core/Grid'; import HomeIcon from '@material-ui/icons/Home'; -import { - createApiFactory, - discoveryApiRef, - fetchApiRef, - storageApiRef, -} from '@backstage/core-plugin-api'; import { convertLegacyRouteRef } from '@backstage/core-plugin-api/alpha'; import { - createApiExtension, createPageExtension, createPlugin, createNavItemExtension, @@ -34,12 +27,9 @@ import { createExtensionInput, } from '@backstage/frontend-plugin-api'; -import { CatalogClient } from '@backstage/catalog-client'; import { AsyncEntityProvider, - catalogApiRef, entityRouteRef, - starredEntitiesApiRef, } from '@backstage/plugin-catalog-react'; import { createEntityContentExtension, @@ -48,7 +38,6 @@ import { } from '@backstage/plugin-catalog-react/alpha'; import { createSearchResultListItemExtension } from '@backstage/plugin-search-react/alpha'; -import { DefaultStarredEntitiesApi } from '../apis'; import { createComponentRouteRef, createFromTemplateRouteRef, @@ -57,30 +46,9 @@ import { } from '../routes'; import { useEntityFromUrl } from '../components/CatalogEntityPage/useEntityFromUrl'; +import apis from './apis'; import filters from './filters'; -/** @alpha */ -export const CatalogApi = createApiExtension({ - factory: createApiFactory({ - api: catalogApiRef, - deps: { - discoveryApi: discoveryApiRef, - fetchApi: fetchApiRef, - }, - factory: ({ discoveryApi, fetchApi }) => - new CatalogClient({ discoveryApi, fetchApi }), - }), -}); - -/** @alpha */ -export const StarredEntitiesApi = createApiExtension({ - factory: createApiFactory({ - api: starredEntitiesApiRef, - deps: { storageApi: storageApiRef }, - factory: ({ storageApi }) => new DefaultStarredEntitiesApi({ storageApi }), - }), -}); - /** @alpha */ export const CatalogSearchResultListItemExtension = createSearchResultListItemExtension({ @@ -195,9 +163,8 @@ export default createPlugin({ createFromTemplate: convertLegacyRouteRef(createFromTemplateRouteRef), }, extensions: [ + ...apis, ...filters, - CatalogApi, - StarredEntitiesApi, CatalogSearchResultListItemExtension, CatalogIndexPage, CatalogEntityPage,