diff --git a/packages/catalog-client/src/CatalogClient.ts b/packages/catalog-client/src/CatalogClient.ts index e0314b9eb8..3a4c0455ad 100644 --- a/packages/catalog-client/src/CatalogClient.ts +++ b/packages/catalog-client/src/CatalogClient.ts @@ -51,7 +51,7 @@ export class CatalogClient implements CatalogApi { options?: CatalogRequestOptions, ): Promise { const { kind, namespace, name } = Object.fromEntries( - Object.entries(request.entityName).map(([k, v]) => [ + Object.entries(request.entityRef).map(([k, v]) => [ k, encodeURIComponent(v), ]), diff --git a/packages/catalog-client/src/types/api.ts b/packages/catalog-client/src/types/api.ts index 609d67eac1..234c49c779 100644 --- a/packages/catalog-client/src/types/api.ts +++ b/packages/catalog-client/src/types/api.ts @@ -30,7 +30,7 @@ export type CatalogEntitiesRequest = { /** @public */ export type CatalogEntityAncestorsRequest = { - entityName: EntityName; + entityRef: EntityName; }; /** @public */ diff --git a/plugins/catalog/package.json b/plugins/catalog/package.json index 8c55c606b1..c2b8aaf4d6 100644 --- a/plugins/catalog/package.json +++ b/plugins/catalog/package.json @@ -37,6 +37,7 @@ "@backstage/core-plugin-api": "^0.1.9", "@backstage/integration-react": "^0.1.11", "@backstage/plugin-catalog-react": "^0.5.1", + "@backstage/errors": "^0.1.2", "@backstage/theme": "^0.2.10", "@material-ui/core": "^4.12.2", "@material-ui/icons": "^4.9.1", @@ -63,4 +64,4 @@ "files": [ "dist" ] -} +} \ No newline at end of file diff --git a/plugins/catalog/src/components/EntityProcessingErrorsPanel/EntityProcessingErrorsPanel.tsx b/plugins/catalog/src/components/EntityProcessingErrorsPanel/EntityProcessingErrorsPanel.tsx index f4636f26db..9e7ea20f85 100644 --- a/plugins/catalog/src/components/EntityProcessingErrorsPanel/EntityProcessingErrorsPanel.tsx +++ b/plugins/catalog/src/components/EntityProcessingErrorsPanel/EntityProcessingErrorsPanel.tsx @@ -25,10 +25,12 @@ import { catalogApiRef, useEntity } from '@backstage/plugin-catalog-react'; import { Box } from '@material-ui/core'; import React from 'react'; import { ResponseErrorPanel } from '@backstage/core-components'; -import { ENTITY_STATUS_CATALOG_PROCESSING_TYPE } from '@backstage/catalog-client'; +import { + CatalogApi, + ENTITY_STATUS_CATALOG_PROCESSING_TYPE, +} from '@backstage/catalog-client'; import { useApi, ApiHolder } from '@backstage/core-plugin-api'; import { useAsync } from 'react-use'; -import { CatalogApi } from '@backstage/catalog-client'; import { SerializedError } from '@backstage/errors'; const errorFilter = (i: UNSTABLE_EntityStatusItem) => @@ -37,10 +39,10 @@ const errorFilter = (i: UNSTABLE_EntityStatusItem) => i.type === ENTITY_STATUS_CATALOG_PROCESSING_TYPE; async function getOwnAndAncestorsErrors( - entityName: EntityName, + entityRef: EntityName, catalogApi: CatalogApi, ): Promise { - const ancestors = await catalogApi.getEntityAncestors({ entityName }); + const ancestors = await catalogApi.getEntityAncestors({ entityRef }); return ancestors.items.flatMap(item => { const statuses = item.entity.status?.items ?? []; return statuses @@ -52,9 +54,9 @@ async function getOwnAndAncestorsErrors( export const hasCatalogProcessingErrors = async ( entity: Entity, - context: { apiRegistry: ApiHolder }, + context: { apis: ApiHolder }, ) => { - const catalogApi = context.apiRegistry.get(catalogApiRef); + const catalogApi = context.apis.get(catalogApiRef); if (!catalogApi) { throw new Error(`No implementation available for ${catalogApiRef}`); } @@ -66,67 +68,14 @@ export const hasCatalogProcessingErrors = async ( return errors.length > 0; }; -/** - * Displays a list of errors if the entity is invalid. - */ -export const EntityProcessingErrorsPanel = () => { - /* - const { entity } = useEntity(); - const catalogProcessingErrors = - (entity?.status?.items?.filter( - errorFilter, - ) as Required[]) || []; - - return ( - <> - {catalogProcessingErrors.map(({ error }, index) => ( - - - - ))} - - ); - */ - // move this logic into the existing component - const { entity } = useEntity(); - const catalogApi = useApi(catalogApiRef); - - const { loading, error, value } = useAsync(() => { - return getOwnAndAncestorsErrors(getEntityName(entity), catalogApi); - }, [stringifyEntityRef(entity), catalogApi]); - - if (error) { - return ( - - - - ); - } - - if (loading || !value?.length) { - return null; - } - - return ( - <> - {value.map((ancestorError, index) => ( - - - - ))} - - ); -}; - /** * Displays a list of errors from the ancestors of the current entity. */ -export const EntityAncestorsProcessingErrorsPanel = () => { - // move this logic into the existing component +export const EntityProcessingErrorsPanel = () => { const { entity } = useEntity(); const catalogApi = useApi(catalogApiRef); - const { loading, error, value } = useAsync(() => { + const { loading, error, value } = useAsync(async () => { return getOwnAndAncestorsErrors(getEntityName(entity), catalogApi); }, [stringifyEntityRef(entity), catalogApi]); diff --git a/plugins/catalog/src/components/EntitySwitch/EntitySwitch.tsx b/plugins/catalog/src/components/EntitySwitch/EntitySwitch.tsx index 201e884f43..bf2caac525 100644 --- a/plugins/catalog/src/components/EntitySwitch/EntitySwitch.tsx +++ b/plugins/catalog/src/components/EntitySwitch/EntitySwitch.tsx @@ -30,7 +30,7 @@ const ENTITY_SWITCH_KEY = 'core.backstage.entitySwitch'; const EntitySwitchCase = (_: { if?: ( entity: Entity, - context: { apiRegistry: ApiHolder }, + context: { apis: ApiHolder }, ) => boolean | Promise; children: ReactNode; }) => null; @@ -40,14 +40,14 @@ attachComponentData(EntitySwitchCase, ENTITY_SWITCH_KEY, true); type SwitchCase = { if?: ( entity: Entity, - context: { apiRegistry: ApiHolder }, + context: { apis: ApiHolder }, ) => boolean | Promise; children: JSX.Element; }; export const EntitySwitch = ({ children }: PropsWithChildren<{}>) => { const { entity } = useEntity(); - const apiRegistry = useApiHolder(); + const apis = useApiHolder(); const switchCases = useElementFilter(children, collection => collection .selectByComponentData({ @@ -69,7 +69,7 @@ export const EntitySwitch = ({ children }: PropsWithChildren<{}>) => { } try { - const matches = await condition(entity, { apiRegistry }); + const matches = await condition(entity, { apis }); return matches ? output : null; } catch { return null;