From f3dc243432bb50f7ace732c49d287bdedb2f05d1 Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Mon, 25 Apr 2022 09:52:02 +0200 Subject: [PATCH] Account for case when builder is external, entity exists, but docs do not. Co-authored-by: Jeremy Guarini Signed-off-by: Eric Peterson --- .../TechDocsReaderPageHeader.test.tsx | 22 +++++++++++++++++++ .../TechDocsReaderPageHeader.tsx | 10 +++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/plugins/techdocs/src/reader/components/TechDocsReaderPageHeader/TechDocsReaderPageHeader.test.tsx b/plugins/techdocs/src/reader/components/TechDocsReaderPageHeader/TechDocsReaderPageHeader.test.tsx index 71456a6942..da193430d5 100644 --- a/plugins/techdocs/src/reader/components/TechDocsReaderPageHeader/TechDocsReaderPageHeader.test.tsx +++ b/plugins/techdocs/src/reader/components/TechDocsReaderPageHeader/TechDocsReaderPageHeader.test.tsx @@ -148,6 +148,28 @@ describe('', () => { }); }); + it('should not render a techdocs page header if techdocs metadata is missing', async () => { + getTechDocsMetadata.mockResolvedValue(undefined); + + await act(async () => { + const rendered = await renderInTestApp( + + + , + { + mountedRoutes: { + '/catalog/:namespace/:kind/:name/*': entityRouteRef, + '/docs': rootRouteRef, + }, + }, + ); + + await waitFor(() => { + expect(rendered.container.innerHTML).not.toContain('header'); + }); + }); + }); + it('should render a link back to the component page', async () => { getTechDocsMetadata.mockResolvedValue(mockTechDocsMetadata); diff --git a/plugins/techdocs/src/reader/components/TechDocsReaderPageHeader/TechDocsReaderPageHeader.tsx b/plugins/techdocs/src/reader/components/TechDocsReaderPageHeader/TechDocsReaderPageHeader.tsx index c0ef1fa95a..204ac835e4 100644 --- a/plugins/techdocs/src/reader/components/TechDocsReaderPageHeader/TechDocsReaderPageHeader.tsx +++ b/plugins/techdocs/src/reader/components/TechDocsReaderPageHeader/TechDocsReaderPageHeader.tsx @@ -71,7 +71,7 @@ export const TechDocsReaderPageHeader = ( subtitle, setSubtitle, entityRef, - metadata: { value: metadata }, + metadata: { value: metadata, loading: metadataLoading }, entityMetadata: { value: entityMetadata, loading: entityMetadataLoading }, } = useTechDocsReaderPage(); @@ -146,9 +146,11 @@ export const TechDocsReaderPageHeader = ( ); - // If there is no entity metadata, there's no reason to show the header. - if (entityMetadataLoading === false && entityMetadata === undefined) - return null; + // If there is no entity or techdocs metadata, there's no reason to show the + // header (hides the header on 404 error pages). + const noEntMetadata = !entityMetadataLoading && entityMetadata === undefined; + const noTdMetadata = !metadataLoading && metadata === undefined; + if (noEntMetadata || noTdMetadata) return null; return (