improve naming of techdocs reader page component, to avoid exporting two with same name

Signed-off-by: Emma Indal <emma.indahl@gmail.com>
This commit is contained in:
Emma Indal
2022-02-22 15:35:05 +01:00
parent 5a85ef7f3f
commit fc9e664329
2 changed files with 38 additions and 9 deletions
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import React from 'react';
import { TechDocsPage } from './TechDocsPage';
import { TechDocsReaderPage } from './TechDocsReaderPage';
import { render, act } from '@testing-library/react';
import { ConfigReader } from '@backstage/config';
import {
@@ -51,7 +51,7 @@ const { useParams }: { useParams: jest.Mock } =
jest.requireMock('react-router-dom');
global.scroll = jest.fn();
describe('<TechDocsPage />', () => {
describe('<TechDocsReaderPage />', () => {
it('should render techdocs page', async () => {
useParams.mockReturnValue({
entityRef: 'Component::backstage',
@@ -101,7 +101,7 @@ describe('<TechDocsPage />', () => {
const rendered = render(
wrapInTestApp(
<ApiProvider apis={apiRegistry}>
<TechDocsPage />
<TechDocsReaderPage />
</ApiProvider>,
),
);
@@ -158,7 +158,7 @@ describe('<TechDocsPage />', () => {
const rendered = render(
wrapInTestApp(
<ApiProvider apis={apiRegistry}>
<TechDocsPage>
<TechDocsReaderPage>
{({ techdocsMetadataValue }) => (
<Header
type="documentation"
@@ -166,7 +166,7 @@ describe('<TechDocsPage />', () => {
subtitle={techdocsMetadataValue?.site_name}
/>
)}
</TechDocsPage>
</TechDocsReaderPage>
</ApiProvider>,
),
);
@@ -25,7 +25,12 @@ import { EntityName } from '@backstage/catalog-model';
import { useApi, useApp } from '@backstage/core-plugin-api';
import { Page } from '@backstage/core-components';
export type TechDocsPageRenderFunction = ({
/**
* Helper function that gives the children of {@link TechDocsReaderPage} acccess to techdocs and entity metadata
*
* @public
*/
export type TechDocsReaderPageRenderFunction = ({
techdocsMetadataValue,
entityMetadataValue,
entityRef,
@@ -36,11 +41,22 @@ export type TechDocsPageRenderFunction = ({
onReady: () => void;
}) => JSX.Element;
export type TechDocsPageProps = {
children?: TechDocsPageRenderFunction | React.ReactNode;
/**
* Props for {@link TechDocsReaderPage}
*
* @public
*/
export type TechDocsReaderPageProps = {
children?: TechDocsReaderPageRenderFunction | React.ReactNode;
};
export const TechDocsPage = ({ children }: TechDocsPageProps) => {
/**
* Component responsible for composing a TechDocs reader page experience
*
* @public
*/
export const TechDocsReaderPage = (props: TechDocsReaderPageProps) => {
const { children } = props;
const { NotFoundErrorPage } = useApp().getComponents();
const outlet = useOutlet();
@@ -83,3 +99,16 @@ export const TechDocsPage = ({ children }: TechDocsPageProps) => {
</Page>
);
};
/**
* @public
* @deprecated use {@link TechDocsReaderPage} instead
*/
export const TechDocsPage = TechDocsReaderPage;
/**
* @public
* @deprecated use {@link TechDocsReaderPageRenderFunction} instead
*/
export type TechDocsPageRenderFunction = TechDocsReaderPageRenderFunction;