From 28f1ab2e1a885aaa541121ad57b0b279f78f95f7 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sat, 23 Sep 2023 17:37:56 +0200 Subject: [PATCH] catalog: replace configure with i18n Signed-off-by: Patrik Oldsberg --- .changeset/gentle-elephants-fold.md | 20 ++++++++++++++++ plugins/catalog/alpha-api-report.md | 18 +++++++++++++++ plugins/catalog/api-report.md | 3 +-- plugins/catalog/package.json | 19 ++++++++++++--- plugins/catalog/src/alpha.ts | 17 ++++++++++++++ .../CatalogPage/DefaultCatalogPage.test.tsx | 3 +-- .../CatalogPage/DefaultCatalogPage.tsx | 10 ++++---- plugins/catalog/src/plugin.ts | 9 -------- .../src/{options.ts => translation.ts} | 23 ++++++++----------- 9 files changed, 88 insertions(+), 34 deletions(-) create mode 100644 .changeset/gentle-elephants-fold.md create mode 100644 plugins/catalog/alpha-api-report.md create mode 100644 plugins/catalog/src/alpha.ts rename plugins/catalog/src/{options.ts => translation.ts} (61%) diff --git a/.changeset/gentle-elephants-fold.md b/.changeset/gentle-elephants-fold.md new file mode 100644 index 0000000000..480ee41e7a --- /dev/null +++ b/.changeset/gentle-elephants-fold.md @@ -0,0 +1,20 @@ +--- +'@backstage/plugin-catalog': minor +--- + +The catalog plugin no longer implements the experimental reconfiguration API. The create button title can now instead be configured using the new experimental internationalization API, via the `catalogTranslationRef` exported at `/alpha`. For example: + +```ts +import { catalogTranslationRef } from '@backstage/plugin-catalog/alpha'; + +const app = createApp({ + __experimentalTranslations: { + resources: [ + createTranslationMessages({ + ref: catalogTranslationRef, + catalog_page_create_button_title: 'Create Software', + }), + ], + }, +}); +``` diff --git a/plugins/catalog/alpha-api-report.md b/plugins/catalog/alpha-api-report.md new file mode 100644 index 0000000000..27de408f86 --- /dev/null +++ b/plugins/catalog/alpha-api-report.md @@ -0,0 +1,18 @@ +## API Report File for "@backstage/plugin-catalog" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +import { TranslationRef } from '@backstage/core-plugin-api/alpha'; + +// @alpha (undocumented) +export const catalogTranslationRef: TranslationRef< + 'catalog', + { + readonly catalog_page_title: '{{orgName}} Catalog'; + readonly catalog_page_create_button_title: 'Create'; + } +>; + +// (No @packageDocumentation comment for this package) +``` diff --git a/plugins/catalog/api-report.md b/plugins/catalog/api-report.md index c8956dcbe8..8173c395ba 100644 --- a/plugins/catalog/api-report.md +++ b/plugins/catalog/api-report.md @@ -117,8 +117,7 @@ export const catalogPlugin: BackstagePlugin< }, true >; - }, - CatalogInputPluginOptions + } >; // @public (undocumented) diff --git a/plugins/catalog/package.json b/plugins/catalog/package.json index 10a9eaf35e..dc03fb7b86 100644 --- a/plugins/catalog/package.json +++ b/plugins/catalog/package.json @@ -6,9 +6,22 @@ "types": "src/index.ts", "license": "Apache-2.0", "publishConfig": { - "access": "public", - "main": "dist/index.esm.js", - "types": "dist/index.d.ts" + "access": "public" + }, + "exports": { + ".": "./src/index.ts", + "./alpha": "./src/alpha.ts", + "./package.json": "./package.json" + }, + "typesVersions": { + "*": { + "alpha": [ + "src/alpha.ts" + ], + "package.json": [ + "package.json" + ] + } }, "backstage": { "role": "frontend-plugin" diff --git a/plugins/catalog/src/alpha.ts b/plugins/catalog/src/alpha.ts new file mode 100644 index 0000000000..3509c1fb7f --- /dev/null +++ b/plugins/catalog/src/alpha.ts @@ -0,0 +1,17 @@ +/* + * 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 './translation'; diff --git a/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.test.tsx b/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.test.tsx index f31d3baf39..b7d3ca3ed8 100644 --- a/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.test.tsx +++ b/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.test.tsx @@ -29,7 +29,6 @@ import { MockStarredEntitiesApi, starredEntitiesApiRef, } from '@backstage/plugin-catalog-react'; -import { MockPluginProvider } from '@backstage/test-utils/alpha'; import { mockBreakpoint, MockStorageApi, @@ -133,7 +132,7 @@ describe('DefaultCatalogPage', () => { [starredEntitiesApiRef, new MockStarredEntitiesApi()], ]} > - {children} + {children} , { mountedRoutes: { diff --git a/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.tsx b/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.tsx index 04f39ee66c..fb9b282d57 100644 --- a/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.tsx +++ b/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.tsx @@ -41,7 +41,8 @@ import { import React, { ReactNode } from 'react'; import { createComponentRouteRef } from '../../routes'; import { CatalogTable, CatalogTableRow } from '../CatalogTable'; -import { useCatalogPluginOptions } from '../../options'; +import { catalogTranslationRef } from '../../translation'; +import { useTranslationRef } from '@backstage/core-plugin-api/alpha'; /** * Props for root catalog pages. @@ -71,15 +72,14 @@ export function DefaultCatalogPage(props: DefaultCatalogPageProps) { const orgName = useApi(configApiRef).getOptionalString('organization.name') ?? 'Backstage'; const createComponentLink = useRouteRef(createComponentRouteRef); - - const { createButtonTitle } = useCatalogPluginOptions(); + const { t } = useTranslationRef(catalogTranslationRef); return ( - + All your software catalog entities diff --git a/plugins/catalog/src/plugin.ts b/plugins/catalog/src/plugin.ts index 711f52767a..3410984ec3 100644 --- a/plugins/catalog/src/plugin.ts +++ b/plugins/catalog/src/plugin.ts @@ -52,7 +52,6 @@ import { HasSystemsCardProps } from './components/HasSystemsCard'; import { RelatedEntitiesCardProps } from './components/RelatedEntitiesCard'; import { CatalogSearchResultListItemProps } from './components/CatalogSearchResultListItem'; import { rootRouteRef } from './routes'; -import { CatalogInputPluginOptions, CatalogPluginOptions } from './options'; /** @public */ export const catalogPlugin = createPlugin({ @@ -83,14 +82,6 @@ export const catalogPlugin = createPlugin({ viewTechDoc: viewTechDocRouteRef, createFromTemplate: createFromTemplateRouteRef, }, - __experimentalConfigure( - options?: CatalogInputPluginOptions, - ): CatalogPluginOptions { - const defaultOptions = { - createButtonTitle: 'Create', - }; - return { ...defaultOptions, ...options }; - }, }); /** @public */ diff --git a/plugins/catalog/src/options.ts b/plugins/catalog/src/translation.ts similarity index 61% rename from plugins/catalog/src/options.ts rename to plugins/catalog/src/translation.ts index 4ea6449a4b..2d1e3f2c8a 100644 --- a/plugins/catalog/src/options.ts +++ b/plugins/catalog/src/translation.ts @@ -1,5 +1,5 @@ /* - * Copyright 2020 The Backstage Authors + * 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. @@ -14,16 +14,13 @@ * limitations under the License. */ -import { usePluginOptions } from '@backstage/core-plugin-api/alpha'; +import { createTranslationRef } from '@backstage/core-plugin-api/alpha'; -export type CatalogPluginOptions = { - createButtonTitle: string; -}; - -/** @ignore */ -export type CatalogInputPluginOptions = { - createButtonTitle: string; -}; - -export const useCatalogPluginOptions = () => - usePluginOptions(); +/** @alpha */ +export const catalogTranslationRef = createTranslationRef({ + id: 'catalog', + messages: { + catalog_page_title: `{{orgName}} Catalog`, + catalog_page_create_button_title: 'Create', + }, +});