From ed3a404de0590a9ce937a1ec15b23f39477a833d Mon Sep 17 00:00:00 2001 From: Nikita Nek Dudnik Date: Fri, 5 Jun 2020 14:23:44 +0200 Subject: [PATCH] fix: show list of components in removal dialog --- .../components/CatalogPage/CatalogPage.tsx | 1 - .../ComponentPage/ComponentPage.tsx | 20 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/plugins/catalog/src/components/CatalogPage/CatalogPage.tsx b/plugins/catalog/src/components/CatalogPage/CatalogPage.tsx index b23519a668..a682fa93ee 100644 --- a/plugins/catalog/src/components/CatalogPage/CatalogPage.tsx +++ b/plugins/catalog/src/components/CatalogPage/CatalogPage.tsx @@ -99,7 +99,6 @@ const CatalogPage: FC<{}> = () => { rowData && rowData.location ? rowData.location.type !== 'github' : true, }), ]; - return (
diff --git a/plugins/catalog/src/components/ComponentPage/ComponentPage.tsx b/plugins/catalog/src/components/ComponentPage/ComponentPage.tsx index 481a5aeac9..346d1fe97c 100644 --- a/plugins/catalog/src/components/ComponentPage/ComponentPage.tsx +++ b/plugins/catalog/src/components/ComponentPage/ComponentPage.tsx @@ -30,7 +30,8 @@ import ComponentRemovalDialog from '../ComponentRemovalDialog/ComponentRemovalDi import { SentryIssuesWidget } from '@backstage/plugin-sentry'; import { Grid } from '@material-ui/core'; import { catalogApiRef } from '../..'; -import { envelopeToComponent } from '../../data/utils'; +import { envelopeToComponent as entityToComponent } from '../../data/utils'; +import { Component } from '../../data/component'; const REDIRECT_DELAY = 1000; @@ -54,19 +55,20 @@ const ComponentPage: FC = ({ match, history }) => { const errorApi = useApi(errorApiRef); const catalogApi = useApi(catalogApiRef); - const catalogRequest = useAsync(async () => { + const { value: component, error, loading } = useAsync(async () => { const entity = await catalogApi.getEntityByName(match.params.name); - return entity; + const location = await catalogApi.getLocationByEntity(entity); + return { ...entityToComponent(entity), location }; }); useEffect(() => { - if (catalogRequest.error) { + if (error) { errorApi.post(new Error('Component not found!')); setTimeout(() => { history.push('/catalog'); }, REDIRECT_DELAY); } - }, [catalogRequest.error, errorApi, history]); + }, [error, errorApi, history]); if (componentName === '') { history.push('/catalog'); @@ -81,14 +83,12 @@ const ComponentPage: FC = ({ match, history }) => { history.push('/catalog'); }; - const component = envelopeToComponent(catalogRequest.value! ?? {}); - return ( -
+
- {confirmationDialogOpen && catalogRequest.value && ( + {confirmationDialogOpen && component && ( = ({ match, history }) => {