From f2cffe520edfc8c2668b5b66910e1fbac2625223 Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Thu, 25 Feb 2021 23:28:42 -0500 Subject: [PATCH 1/3] Add org name to page title --- .changeset/light-vans-hide.md | 5 ++++ .../ApiExplorerPage/ApiExplorerLayout.tsx | 29 +++++++++++-------- 2 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 .changeset/light-vans-hide.md diff --git a/.changeset/light-vans-hide.md b/.changeset/light-vans-hide.md new file mode 100644 index 0000000000..ccc1339959 --- /dev/null +++ b/.changeset/light-vans-hide.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-api-docs': patch +--- + +Add organization name to the API Explorer page title diff --git a/plugins/api-docs/src/components/ApiExplorerPage/ApiExplorerLayout.tsx b/plugins/api-docs/src/components/ApiExplorerPage/ApiExplorerLayout.tsx index 0720ecf45b..b82166f4cd 100644 --- a/plugins/api-docs/src/components/ApiExplorerPage/ApiExplorerLayout.tsx +++ b/plugins/api-docs/src/components/ApiExplorerPage/ApiExplorerLayout.tsx @@ -14,20 +14,25 @@ * limitations under the License. */ -import { Header, Page } from '@backstage/core'; +import { Header, Page, useApi, configApiRef } from '@backstage/core'; import React from 'react'; type Props = { children?: React.ReactNode; }; - -export const ApiExplorerLayout = ({ children }: Props) => ( - -
- {children} - -); +export const ApiExplorerLayout = ({ children }: Props) => { + const configApi = useApi(configApiRef); + const generatedSubtitle = `${ + configApi.getString('organization.name') ?? 'Backstage' + } API Explorer`; + return ( + +
+ {children} + + ); +}; From 94c7c25a86a9ed3c0d6b6313c19856168a2676f4 Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Thu, 25 Feb 2021 23:41:13 -0500 Subject: [PATCH 2/3] Add config call to test --- .../ApiExplorerPage/ApiExplorerPage.test.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/plugins/api-docs/src/components/ApiExplorerPage/ApiExplorerPage.test.tsx b/plugins/api-docs/src/components/ApiExplorerPage/ApiExplorerPage.test.tsx index 67462b630c..223734504b 100644 --- a/plugins/api-docs/src/components/ApiExplorerPage/ApiExplorerPage.test.tsx +++ b/plugins/api-docs/src/components/ApiExplorerPage/ApiExplorerPage.test.tsx @@ -15,7 +15,14 @@ */ import { Entity } from '@backstage/catalog-model'; -import { ApiProvider, ApiRegistry, storageApiRef } from '@backstage/core'; +import { + ApiProvider, + ApiRegistry, + storageApiRef, + ConfigApi, + configApiRef, + ConfigReader, +} from '@backstage/core'; import { CatalogApi, catalogApiRef } from '@backstage/plugin-catalog-react'; import { MockStorageApi, wrapInTestApp } from '@backstage/test-utils'; import { render } from '@testing-library/react'; @@ -50,6 +57,12 @@ describe('ApiCatalogPage', () => { Promise.resolve({ id: 'id', type: 'github', target: 'url' }), }; + const configApi: ConfigApi = new ConfigReader({ + organization: { + name: 'My Company', + }, + }); + const apiDocsConfig = { getApiDefinitionWidget: () => undefined, }; @@ -60,6 +73,7 @@ describe('ApiCatalogPage', () => { { // https://github.com/mbrn/material-table/issues/1293 it('should render', async () => { const { findByText } = renderWrapped(); - expect(await findByText(/Backstage API Explorer/)).toBeInTheDocument(); + expect(await findByText(/My Company API Explorer/)).toBeInTheDocument(); }); }); From 7a1b6133ae527ac1ba512debb13cfa909c1f82e4 Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Mon, 1 Mar 2021 12:11:58 -0500 Subject: [PATCH 3/3] Change get method for optional value --- .../src/components/ApiExplorerPage/ApiExplorerLayout.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/api-docs/src/components/ApiExplorerPage/ApiExplorerLayout.tsx b/plugins/api-docs/src/components/ApiExplorerPage/ApiExplorerLayout.tsx index b82166f4cd..add886fead 100644 --- a/plugins/api-docs/src/components/ApiExplorerPage/ApiExplorerLayout.tsx +++ b/plugins/api-docs/src/components/ApiExplorerPage/ApiExplorerLayout.tsx @@ -23,7 +23,7 @@ type Props = { export const ApiExplorerLayout = ({ children }: Props) => { const configApi = useApi(configApiRef); const generatedSubtitle = `${ - configApi.getString('organization.name') ?? 'Backstage' + configApi.getOptionalString('organization.name') ?? 'Backstage' } API Explorer`; return (