From bfc7c50a09c85c9bad217178447a2be0e0362cb6 Mon Sep 17 00:00:00 2001 From: Phil Kuang Date: Mon, 8 Aug 2022 15:30:25 -0400 Subject: [PATCH] feat(adrs): display associated entity in AdrSearchResultListItem Signed-off-by: Phil Kuang --- .changeset/cyan-carpets-build.md | 9 +++++++++ .../adr-backend/src/search/DefaultAdrCollatorFactory.ts | 1 + plugins/adr-backend/src/search/createMadrParser.ts | 3 +++ plugins/adr-common/api-report.md | 2 ++ plugins/adr-common/src/index.ts | 8 ++++++++ plugins/adr/package.json | 1 + plugins/adr/src/search/AdrSearchResultListItem.tsx | 9 +++++++++ 7 files changed, 33 insertions(+) create mode 100644 .changeset/cyan-carpets-build.md diff --git a/.changeset/cyan-carpets-build.md b/.changeset/cyan-carpets-build.md new file mode 100644 index 0000000000..eca260c34c --- /dev/null +++ b/.changeset/cyan-carpets-build.md @@ -0,0 +1,9 @@ +--- +'@backstage/plugin-adr': minor +'@backstage/plugin-adr-backend': minor +'@backstage/plugin-adr-common': minor +--- + +Display associated entity as a chip in `AdrSearchResultListItem` + +BREAKING: `AdrDocument` now includes a `entityRef` property, if you have a custom `AdrParser` you will have to supply this property in your returned documents diff --git a/plugins/adr-backend/src/search/DefaultAdrCollatorFactory.ts b/plugins/adr-backend/src/search/DefaultAdrCollatorFactory.ts index e0c90af767..811b52ba82 100644 --- a/plugins/adr-backend/src/search/DefaultAdrCollatorFactory.ts +++ b/plugins/adr-backend/src/search/DefaultAdrCollatorFactory.ts @@ -142,6 +142,7 @@ export class DefaultAdrCollatorFactory implements DocumentCollatorFactory { 'metadata.annotations', 'metadata.name', 'metadata.namespace', + 'metadata.title', ], }, { token }, diff --git a/plugins/adr-backend/src/search/createMadrParser.ts b/plugins/adr-backend/src/search/createMadrParser.ts index 9efd49754a..6b77ec2fa7 100644 --- a/plugins/adr-backend/src/search/createMadrParser.ts +++ b/plugins/adr-backend/src/search/createMadrParser.ts @@ -16,6 +16,7 @@ import { DateTime } from 'luxon'; import { marked } from 'marked'; +import { stringifyEntityRef } from '@backstage/catalog-model'; import { MADR_DATE_FORMAT } from '@backstage/plugin-adr-common'; import { AdrParser } from './types'; @@ -101,6 +102,8 @@ export const createMadrParser = ( text: content, status: adrStatus, date: adrDate, + entityRef: stringifyEntityRef(entity), + entityTitle: entity.metadata.title, location: applyArgsToFormat(locationTemplate, { namespace: entity.metadata.namespace || 'default', kind: entity.kind, diff --git a/plugins/adr-common/api-report.md b/plugins/adr-common/api-report.md index 290d984181..0236b355a5 100644 --- a/plugins/adr-common/api-report.md +++ b/plugins/adr-common/api-report.md @@ -10,6 +10,8 @@ import { ScmIntegrationRegistry } from '@backstage/integration'; // @public export interface AdrDocument extends IndexableDocument { date?: string; + entityRef: string; + entityTitle?: string; status?: string; } diff --git a/plugins/adr-common/src/index.ts b/plugins/adr-common/src/index.ts index 94b6b788c8..c3a048d9d1 100644 --- a/plugins/adr-common/src/index.ts +++ b/plugins/adr-common/src/index.ts @@ -84,6 +84,14 @@ export const madrFilePathFilter: AdrFilePathFilterFn = (path: string) => * @public */ export interface AdrDocument extends IndexableDocument { + /** + * Ref of the entity associated with this ADR + */ + entityRef: string; + /** + * Title of the entity associated with this ADR + */ + entityTitle?: string; /** * ADR status label */ diff --git a/plugins/adr/package.json b/plugins/adr/package.json index e9c2f05e0f..dfe3a233b9 100644 --- a/plugins/adr/package.json +++ b/plugins/adr/package.json @@ -22,6 +22,7 @@ "postpack": "backstage-cli package postpack" }, "dependencies": { + "@backstage/catalog-model": "^1.1.0", "@backstage/core-components": "^0.11.0-next.2", "@backstage/core-plugin-api": "^1.0.5-next.0", "@backstage/integration-react": "^1.1.3-next.1", diff --git a/plugins/adr/src/search/AdrSearchResultListItem.tsx b/plugins/adr/src/search/AdrSearchResultListItem.tsx index 677e39fc11..e9e05a9df2 100644 --- a/plugins/adr/src/search/AdrSearchResultListItem.tsx +++ b/plugins/adr/src/search/AdrSearchResultListItem.tsx @@ -23,9 +23,11 @@ import { ListItemText, makeStyles, } from '@material-ui/core'; +import { parseEntityRef } from '@backstage/catalog-model'; import { Link } from '@backstage/core-components'; import { useAnalytics } from '@backstage/core-plugin-api'; import { AdrDocument } from '@backstage/plugin-adr-common'; +import { humanizeEntityRef } from '@backstage/plugin-catalog-react'; import { ResultHighlight } from '@backstage/plugin-search-common'; import { HighlightedSearchResultText } from '@backstage/plugin-search-react'; @@ -104,6 +106,13 @@ export const AdrSearchResultListItem = ({ } /> + {result.status && ( )}