From ca957d7a7d7fc6dcc6e85ead6e332524c40bd8d2 Mon Sep 17 00:00:00 2001 From: Camila Belo Date: Thu, 28 Sep 2023 21:22:49 +0200 Subject: [PATCH] feat(adr): create search result item extension Signed-off-by: Camila Belo --- plugins/adr/alpha-api-report.md | 12 +++++++ plugins/adr/package.json | 5 +-- plugins/adr/src/alpha.ts | 16 --------- plugins/adr/src/alpha.tsx | 58 +++++++++++++++++++++++++++++++++ yarn.lock | 1 + 5 files changed, 74 insertions(+), 18 deletions(-) delete mode 100644 plugins/adr/src/alpha.ts create mode 100644 plugins/adr/src/alpha.tsx diff --git a/plugins/adr/alpha-api-report.md b/plugins/adr/alpha-api-report.md index 7ce9f6f055..9d0bd071b1 100644 --- a/plugins/adr/alpha-api-report.md +++ b/plugins/adr/alpha-api-report.md @@ -3,8 +3,16 @@ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). ```ts +import { BackstagePlugin } from '@backstage/frontend-plugin-api'; +import { Extension } from '@backstage/frontend-plugin-api'; import { TranslationRef } from '@backstage/core-plugin-api/alpha'; +// @alpha (undocumented) +export const AdrSearchResultListItemExtension: Extension<{ + lineClamp: number; + noTrack: boolean; +}>; + // @alpha (undocumented) export const adrTranslationRef: TranslationRef< 'adr', @@ -15,5 +23,9 @@ export const adrTranslationRef: TranslationRef< } >; +// @alpha (undocumented) +const _default: BackstagePlugin; +export default _default; + // (No @packageDocumentation comment for this package) ``` diff --git a/plugins/adr/package.json b/plugins/adr/package.json index dd1e736f8a..d0db1a4ff2 100644 --- a/plugins/adr/package.json +++ b/plugins/adr/package.json @@ -6,13 +6,13 @@ "license": "Apache-2.0", "exports": { ".": "./src/index.ts", - "./alpha": "./src/alpha.ts", + "./alpha": "./src/alpha.tsx", "./package.json": "./package.json" }, "typesVersions": { "*": { "alpha": [ - "src/alpha.ts" + "src/alpha.tsx" ], "package.json": [ "package.json" @@ -45,6 +45,7 @@ "@backstage/catalog-model": "workspace:^", "@backstage/core-components": "workspace:^", "@backstage/core-plugin-api": "workspace:^", + "@backstage/frontend-plugin-api": "workspace:^", "@backstage/integration-react": "workspace:^", "@backstage/plugin-adr-common": "workspace:^", "@backstage/plugin-catalog-react": "workspace:^", diff --git a/plugins/adr/src/alpha.ts b/plugins/adr/src/alpha.ts deleted file mode 100644 index 587cfce3d6..0000000000 --- a/plugins/adr/src/alpha.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2023 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -export * from './translations'; diff --git a/plugins/adr/src/alpha.tsx b/plugins/adr/src/alpha.tsx new file mode 100644 index 0000000000..1f6fa0711d --- /dev/null +++ b/plugins/adr/src/alpha.tsx @@ -0,0 +1,58 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from 'react'; +import { + createPlugin, + createSchemaFromZod, +} from '@backstage/frontend-plugin-api'; +import { createSearchResultListItemExtension } from '@backstage/plugin-search-react/alpha'; +import { AdrDocument } from '@backstage/plugin-adr-common'; + +export * from './translations'; + +function isAdrDocument(result: any): result is AdrDocument { + return result.entityRef; +} + +/** @alpha */ +export const AdrSearchResultListItemExtension = + createSearchResultListItemExtension({ + id: 'adr', + configSchema: createSchemaFromZod(z => + z.object({ + // TODO: Define how the icon can be configurable + noTrack: z.boolean().default(false), + lineClamp: z.number().default(5), + }), + ), + predicate: result => result.type === 'adr', + component: async ({ config }) => { + const { AdrSearchResultListItem } = await import( + './search/AdrSearchResultListItem' + ); + return ({ result, ...rest }) => + isAdrDocument(result) ? ( + + ) : null; + }, + }); + +/** @alpha */ +export default createPlugin({ + id: 'adr', + extensions: [AdrSearchResultListItemExtension], +}); diff --git a/yarn.lock b/yarn.lock index 3dd3f6315b..8fd8bbe045 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4501,6 +4501,7 @@ __metadata: "@backstage/core-components": "workspace:^" "@backstage/core-plugin-api": "workspace:^" "@backstage/dev-utils": "workspace:^" + "@backstage/frontend-plugin-api": "workspace:^" "@backstage/integration-react": "workspace:^" "@backstage/plugin-adr-common": "workspace:^" "@backstage/plugin-catalog-react": "workspace:^"