From 1285c2fe60063ee9d26237d36e695227f2a90ca1 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Fri, 14 Jan 2022 11:13:18 +0100 Subject: [PATCH] org: switched catalog index route to use an external route ref Signed-off-by: Patrik Oldsberg --- .changeset/tough-wombats-taste.md | 11 ++++++++++ packages/app/src/App.tsx | 4 ++++ plugins/org/api-report.md | 8 ++++++- .../OwnershipCard/OwnershipCard.stories.tsx | 6 +++--- .../OwnershipCard/OwnershipCard.test.tsx | 10 ++++----- .../Cards/OwnershipCard/OwnershipCard.tsx | 4 ++-- plugins/org/src/plugin.ts | 4 ++++ plugins/org/src/routes.ts | 21 +++++++++++++++++++ 8 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 .changeset/tough-wombats-taste.md create mode 100644 plugins/org/src/routes.ts diff --git a/.changeset/tough-wombats-taste.md b/.changeset/tough-wombats-taste.md new file mode 100644 index 0000000000..2d034f35b6 --- /dev/null +++ b/.changeset/tough-wombats-taste.md @@ -0,0 +1,11 @@ +--- +'@backstage/plugin-org': minor +--- + +**BREAKING**: Added a new and required `catalogIndex` external route. It should typically be linked to the `catalogIndex` route of the Catalog plugin: + +```ts +bind(orgPlugin.externalRoutes, { + catalogIndex: catalogPlugin.routes.catalogIndex, +}); +``` diff --git a/packages/app/src/App.tsx b/packages/app/src/App.tsx index 59f107c70d..43cb635bb3 100644 --- a/packages/app/src/App.tsx +++ b/packages/app/src/App.tsx @@ -53,6 +53,7 @@ import { CostInsightsPage, CostInsightsProjectGrowthInstructionsPage, } from '@backstage/plugin-cost-insights'; +import { orgPlugin } from '@backstage/plugin-org'; import { ExplorePage, explorePlugin } from '@backstage/plugin-explore'; import { GcpProjectsPage } from '@backstage/plugin-gcp-projects'; import { GraphiQLPage } from '@backstage/plugin-graphiql'; @@ -125,6 +126,9 @@ const app = createApp({ bind(scaffolderPlugin.externalRoutes, { registerComponent: catalogImportPlugin.routes.importPage, }); + bind(orgPlugin.externalRoutes, { + catalogIndex: catalogPlugin.routes.catalogIndex, + }); }, }); diff --git a/plugins/org/api-report.md b/plugins/org/api-report.md index 19f5acda69..b181a3aab4 100644 --- a/plugins/org/api-report.md +++ b/plugins/org/api-report.md @@ -7,6 +7,7 @@ import { BackstagePlugin } from '@backstage/core-plugin-api'; import { Entity } from '@backstage/catalog-model'; +import { ExternalRouteRef } from '@backstage/core-plugin-api'; import { GroupEntity } from '@backstage/catalog-model'; import { InfoCardVariants } from '@backstage/core-components'; import { UserEntity } from '@backstage/catalog-model'; @@ -74,7 +75,12 @@ export const MembersListCard: (_props: { // Warning: (ae-missing-release-tag) "orgPlugin" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // // @public (undocumented) -const orgPlugin: BackstagePlugin<{}, {}>; +const orgPlugin: BackstagePlugin< + {}, + { + catalogIndex: ExternalRouteRef; + } +>; export { orgPlugin }; export { orgPlugin as plugin }; diff --git a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.stories.tsx b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.stories.tsx index 6a20035dfa..a0536e1a74 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.stories.tsx +++ b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.stories.tsx @@ -19,7 +19,6 @@ import { ApiProvider } from '@backstage/core-app-api'; import { CatalogApi, catalogApiRef, - catalogRouteRef, EntityProvider, } from '@backstage/plugin-catalog-react'; import { TestApiRegistry, wrapInTestApp } from '@backstage/test-utils'; @@ -31,6 +30,7 @@ import { } from '@backstage/theme'; import { Grid, ThemeProvider } from '@material-ui/core'; import React from 'react'; +import { catalogIndexRouteRef } from '../../../routes'; import { OwnershipCard } from './OwnershipCard'; export default { @@ -100,7 +100,7 @@ export const Default = () => , { - mountedRoutes: { '/catalog': catalogRouteRef }, + mountedRoutes: { '/catalog': catalogIndexRouteRef }, }, ); @@ -134,6 +134,6 @@ export const Themed = () => , { - mountedRoutes: { '/catalog': catalogRouteRef }, + mountedRoutes: { '/catalog': catalogIndexRouteRef }, }, ); diff --git a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.test.tsx b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.test.tsx index 439365e583..26a79dfaee 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.test.tsx +++ b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.test.tsx @@ -23,11 +23,11 @@ import { CatalogApi, catalogApiRef, EntityProvider, - catalogRouteRef, } from '@backstage/plugin-catalog-react'; import { renderInTestApp, TestApiProvider } from '@backstage/test-utils'; import { queryByText } from '@testing-library/react'; import React from 'react'; +import { catalogIndexRouteRef } from '../../../routes'; import { OwnershipCard } from './OwnershipCard'; const items = [ @@ -159,7 +159,7 @@ describe('OwnershipCard', () => { , { mountedRoutes: { - '/create': catalogRouteRef, + '/create': catalogIndexRouteRef, }, }, ); @@ -205,7 +205,7 @@ describe('OwnershipCard', () => { , { mountedRoutes: { - '/create': catalogRouteRef, + '/create': catalogIndexRouteRef, }, }, ); @@ -236,7 +236,7 @@ describe('OwnershipCard', () => { , { mountedRoutes: { - '/create': catalogRouteRef, + '/create': catalogIndexRouteRef, }, }, ); @@ -282,7 +282,7 @@ describe('OwnershipCard', () => { , { mountedRoutes: { - '/create': catalogRouteRef, + '/create': catalogIndexRouteRef, }, }, ); diff --git a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.tsx b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.tsx index d3a90d63e3..c89534ea7a 100644 --- a/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.tsx +++ b/plugins/org/src/components/Cards/OwnershipCard/OwnershipCard.tsx @@ -25,7 +25,6 @@ import { import { useApi, useRouteRef } from '@backstage/core-plugin-api'; import { catalogApiRef, - catalogRouteRef, formatEntityRefTitle, isOwnerOf, useEntity, @@ -42,6 +41,7 @@ import qs from 'qs'; import React from 'react'; import pluralize from 'pluralize'; import useAsync from 'react-use/lib/useAsync'; +import { catalogIndexRouteRef } from '../../../routes'; type EntityTypeProps = { kind: string; @@ -138,7 +138,7 @@ export const OwnershipCard = ({ }) => { const { entity } = useEntity(); const catalogApi = useApi(catalogApiRef); - const catalogLink = useRouteRef(catalogRouteRef); + const catalogLink = useRouteRef(catalogIndexRouteRef); const { loading, diff --git a/plugins/org/src/plugin.ts b/plugins/org/src/plugin.ts index b2183db8ef..5da517f1db 100644 --- a/plugins/org/src/plugin.ts +++ b/plugins/org/src/plugin.ts @@ -17,9 +17,13 @@ import { createComponentExtension, createPlugin, } from '@backstage/core-plugin-api'; +import { catalogIndexRouteRef } from './routes'; export const orgPlugin = createPlugin({ id: 'org', + externalRoutes: { + catalogIndex: catalogIndexRouteRef, + }, }); export const EntityGroupProfileCard = orgPlugin.provide( diff --git a/plugins/org/src/routes.ts b/plugins/org/src/routes.ts new file mode 100644 index 0000000000..aa24c1b1cc --- /dev/null +++ b/plugins/org/src/routes.ts @@ -0,0 +1,21 @@ +/* + * Copyright 2020 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 { createExternalRouteRef } from '@backstage/core-plugin-api'; + +export const catalogIndexRouteRef = createExternalRouteRef({ + id: 'catalog-index', +});