From 973e9d42dd226e9556102e0f1cd662c6ef3c5272 Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Wed, 19 May 2021 13:53:52 +0200 Subject: [PATCH] catalog: Use route ref for navigation Signed-off-by: Johan Haals --- .../EntityOrphanWarning/EntityOrphanWarning.test.tsx | 8 +++++++- .../EntityOrphanWarning/EntityOrphanWarning.tsx | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/plugins/catalog/src/components/EntityOrphanWarning/EntityOrphanWarning.test.tsx b/plugins/catalog/src/components/EntityOrphanWarning/EntityOrphanWarning.test.tsx index b33c026d4e..b9582f019e 100644 --- a/plugins/catalog/src/components/EntityOrphanWarning/EntityOrphanWarning.test.tsx +++ b/plugins/catalog/src/components/EntityOrphanWarning/EntityOrphanWarning.test.tsx @@ -14,11 +14,12 @@ * limitations under the License. */ -import { ApiProvider, ApiRegistry } from '@backstage/core'; +import { ApiProvider, ApiRegistry, createRouteRef } from '@backstage/core'; import { CatalogApi, catalogApiRef, + catalogRouteRef, EntityProvider, } from '@backstage/plugin-catalog-react'; import { renderInTestApp } from '@backstage/test-utils'; @@ -54,6 +55,11 @@ describe('', () => { , + { + mountedRoutes: { + '/create': catalogRouteRef, + }, + }, ); expect( getByText( diff --git a/plugins/catalog/src/components/EntityOrphanWarning/EntityOrphanWarning.tsx b/plugins/catalog/src/components/EntityOrphanWarning/EntityOrphanWarning.tsx index 173e9093fc..070c36c56c 100644 --- a/plugins/catalog/src/components/EntityOrphanWarning/EntityOrphanWarning.tsx +++ b/plugins/catalog/src/components/EntityOrphanWarning/EntityOrphanWarning.tsx @@ -15,7 +15,8 @@ */ import { Entity } from '@backstage/catalog-model'; -import { useEntity } from '@backstage/plugin-catalog-react'; +import { useRouteRef } from '@backstage/core'; +import { catalogRouteRef, useEntity } from '@backstage/plugin-catalog-react'; import { Alert } from '@material-ui/lab'; import React, { useState } from 'react'; import { useNavigate } from 'react-router'; @@ -29,12 +30,13 @@ export const isOrphan = (entity: Entity) => */ export const EntityOrphanWarning = () => { const navigate = useNavigate(); + const catalogLink = useRouteRef(catalogRouteRef); const [confirmationDialogOpen, setConfirmationDialogOpen] = useState(false); const { entity } = useEntity(); const cleanUpAfterRemoval = async () => { setConfirmationDialogOpen(false); - navigate('/'); + navigate(catalogLink()); }; return (