diff --git a/plugins/techdocs/src/home/components/Grids/DocsCardGrid.tsx b/plugins/techdocs/src/home/components/Grids/DocsCardGrid.tsx index d2947b5f64..2d5d5fa7c0 100644 --- a/plugins/techdocs/src/home/components/Grids/DocsCardGrid.tsx +++ b/plugins/techdocs/src/home/components/Grids/DocsCardGrid.tsx @@ -16,12 +16,18 @@ import { rootDocsRouteRef } from '../../../routes'; import { toLowerMaybe } from '../../../helpers'; -import { Entity } from '@backstage/catalog-model'; +import useAsync from 'react-use/esm/useAsync'; +import { + EntityRefPresentationSnapshot, + entityPresentationApiRef, +} from '@backstage/plugin-catalog-react'; +import { Entity, stringifyEntityRef } from '@backstage/catalog-model'; import { useApi, useRouteRef, configApiRef } from '@backstage/core-plugin-api'; import { LinkButton, ItemCardGrid, ItemCardHeader, + Progress, } from '@backstage/core-components'; import Card from '@material-ui/core/Card'; import CardActions from '@material-ui/core/CardActions'; @@ -47,6 +53,22 @@ export const DocsCardGrid = (props: DocsCardGridProps) => { const { entities } = props; const getRouteToReaderPageFor = useRouteRef(rootDocsRouteRef); const config = useApi(configApiRef); + const entityPresentationApi = useApi(entityPresentationApiRef); + const { value: entityRefToPresentation, loading } = useAsync(async () => { + return new Map( + await Promise.all( + entities?.map(async entity => { + const presentation = await entityPresentationApi.forEntity(entity) + .promise; + return [stringifyEntityRef(entity), presentation] as [ + string, + EntityRefPresentationSnapshot, + ]; + }) || [], + ), + ); + }); + if (loading) return ; if (!entities) return null; return ( @@ -56,7 +78,10 @@ export const DocsCardGrid = (props: DocsCardGridProps) => { {entity.metadata.description} diff --git a/plugins/techdocs/src/home/components/Grids/InfoCardGrid.tsx b/plugins/techdocs/src/home/components/Grids/InfoCardGrid.tsx index 769ec8e145..5a71710174 100644 --- a/plugins/techdocs/src/home/components/Grids/InfoCardGrid.tsx +++ b/plugins/techdocs/src/home/components/Grids/InfoCardGrid.tsx @@ -15,9 +15,19 @@ */ import React from 'react'; -import { Entity } from '@backstage/catalog-model'; +import useAsync from 'react-use/esm/useAsync'; +import { Entity, stringifyEntityRef } from '@backstage/catalog-model'; import { useApi, useRouteRef, configApiRef } from '@backstage/core-plugin-api'; -import { ItemCardGrid, InfoCard, Link } from '@backstage/core-components'; +import { + ItemCardGrid, + InfoCard, + Link, + Progress, +} from '@backstage/core-components'; +import { + EntityRefPresentationSnapshot, + entityPresentationApiRef, +} from '@backstage/plugin-catalog-react'; import { makeStyles } from '@material-ui/core/styles'; import { rootDocsRouteRef } from '../../../routes'; import { toLowerMaybe } from '../../../helpers'; @@ -71,7 +81,22 @@ export const InfoCardGrid = (props: InfoCardGridProps) => { name: toLowerMaybe(entity.metadata.name, config), }); }; - + const entityPresentationApi = useApi(entityPresentationApiRef); + const { value: entityRefToPresentation, loading } = useAsync(async () => { + return new Map( + await Promise.all( + entities?.map(async entity => { + const presentation = await entityPresentationApi.forEntity(entity) + .promise; + return [stringifyEntityRef(entity), presentation] as [ + string, + EntityRefPresentationSnapshot, + ]; + }) || [], + ), + ); + }); + if (loading) return ; if (!entities || !entities?.length) return null; return ( @@ -79,7 +104,10 @@ export const InfoCardGrid = (props: InfoCardGridProps) => {
{entity?.metadata?.description}