Signed-off-by: nikolar <reyna.nikolayev@autodesk.com>
This commit is contained in:
nikolar
2024-12-03 15:41:04 -08:00
parent b6c017de5d
commit 351952cb93
8 changed files with 49 additions and 33 deletions
@@ -51,17 +51,17 @@ export const DefaultTechDocsHome = (props: TechDocsIndexPageProps) => {
columns,
actions,
ownerPickerMode,
showHeader,
showHeader = true,
options,
title,
subtitle,
hideSupport,
showSupport = true,
} = props;
const Wrapper = showHeader !== false ? TechDocsPageWrapper : React.Fragment;
const Wrapper = showHeader ? TechDocsPageWrapper : React.Fragment;
return (
<Wrapper title={title} subtitle={subtitle}>
<Content>
{hideSupport !== true && (
{showSupport && (
<ContentHeader title="">
<SupportButton>
Discover documentation in your ecosystem.
@@ -127,7 +127,7 @@ describe('TechDocsCustomHome', () => {
screen.queryByText('Discover documentation in your ecosystem.'),
).not.toBeInTheDocument();
});
it('should render SupportButton based on hideSupport prop', async () => {
it('should render SupportButton based on showSupport prop', async () => {
const tabsConfig = [
{
label: 'First Tab',
@@ -137,7 +137,7 @@ describe('TechDocsCustomHome', () => {
description: 'First Tab Description',
panelType: 'DocsCardGrid' as PanelType,
filterPredicate: () => true,
panelProps: { hideSupport: true },
panelProps: { showSupport: false },
},
],
},
@@ -158,7 +158,7 @@ describe('TechDocsCustomHome', () => {
screen.queryByText('Discover documentation in your ecosystem.'),
).not.toBeInTheDocument();
});
it('should hide subtitle when hideSubtitle is true', async () => {
it('should hide subtitle when showSubtitle is false', async () => {
const tabsConfig = [
{
label: 'First Tab',
@@ -179,7 +179,7 @@ describe('TechDocsCustomHome', () => {
tabsConfig={tabsConfig}
title="Custom Title"
subtitle="Custom Subtitle"
hideSubtitle
showSubtitle={false}
/>
</ApiProvider>,
{
@@ -25,7 +25,7 @@ import {
useEntityOwnership,
} from '@backstage/plugin-catalog-react';
import { Entity } from '@backstage/catalog-model';
import { DocsTable } from './Tables';
import { DocsTable, DocsTableRow } from './Tables';
import { DocsCardGrid, InfoCardGrid } from './Grids';
import { TechDocsPageWrapper } from './TechDocsPageWrapper';
import { TechDocsIndexPage } from './TechDocsIndexPage';
@@ -38,6 +38,7 @@ import {
WarningPanel,
SupportButton,
ContentHeader,
TableOptions,
} from '@backstage/core-components';
import { useApi } from '@backstage/core-plugin-api';
import { TECHDOCS_ANNOTATION } from '@backstage/plugin-techdocs-common';
@@ -61,6 +62,19 @@ export type PanelType =
| 'TechDocsIndexPage'
| 'InfoCardGrid';
/**
* Type representing Panel props
*
* @public
*/
export interface PanelProps {
showHeader?: boolean;
showSupport?: boolean;
options?: TableOptions<DocsTableRow>;
linkContent?: string | JSX.Element;
linkDestination?: (entity: Entity) => string;
}
/**
* Type representing a TechDocsCustomHome panel.
*
@@ -72,7 +86,7 @@ export interface PanelConfig {
panelType: PanelType;
panelCSS?: CSSProperties;
filterPredicate: ((entity: Entity) => boolean) | string;
panelProps?: Record<string, any>;
panelProps?: PanelProps;
}
/**
@@ -135,7 +149,7 @@ export const CustomDocsPanel = ({
<>
{config.panelProps?.showHeader !== false && (
<ContentHeader title={config.title} description={config.description}>
{index === 0 && config.panelProps?.hideSupport !== true && (
{index === 0 && config.panelProps?.showSupport !== false && (
<SupportButton>
Discover documentation in your ecosystem.
</SupportButton>
@@ -163,11 +177,11 @@ export type TechDocsCustomHomeProps = {
filter?: EntityFilterQuery;
title?: string;
subtitle?: string;
hideSubtitle?: boolean;
showSubtitle?: boolean;
};
export const TechDocsCustomHome = (props: TechDocsCustomHomeProps) => {
const { tabsConfig, filter, title, subtitle, hideSubtitle } = props;
const { tabsConfig, filter, title, subtitle, showSubtitle = true } = props;
const [selectedTab, setSelectedTab] = useState<number>(0);
const catalogApi: CatalogApi = useApi(catalogApiRef);
@@ -202,7 +216,7 @@ export const TechDocsCustomHome = (props: TechDocsCustomHomeProps) => {
<TechDocsPageWrapper
title={title}
subtitle={subtitle}
hideSubtitle={hideSubtitle}
showSubtitle={showSubtitle}
>
<Content>
<Progress />
@@ -216,7 +230,7 @@ export const TechDocsCustomHome = (props: TechDocsCustomHomeProps) => {
<TechDocsPageWrapper
title={title}
subtitle={subtitle}
hideSubtitle={hideSubtitle}
showSubtitle={showSubtitle}
>
<Content>
<WarningPanel
@@ -234,7 +248,7 @@ export const TechDocsCustomHome = (props: TechDocsCustomHomeProps) => {
<TechDocsPageWrapper
title={title}
subtitle={subtitle}
hideSubtitle={hideSubtitle}
showSubtitle={showSubtitle}
>
<HeaderTabs
selectedIndex={selectedTab}
@@ -39,7 +39,7 @@ export type TechDocsIndexPageProps = {
actions?: TableProps<DocsTableRow>['actions'];
ownerPickerMode?: EntityOwnerPickerProps['mode'];
showHeader?: boolean;
hideSupport?: boolean;
showSupport?: boolean;
options?: TableOptions<DocsTableRow>;
title?: string;
subtitle?: string;
@@ -28,7 +28,7 @@ export type TechDocsPageWrapperProps = {
children?: React.ReactNode;
title?: string;
subtitle?: string;
hideSubtitle?: boolean;
showSubtitle?: boolean;
};
/**
@@ -37,7 +37,7 @@ export type TechDocsPageWrapperProps = {
* @public
*/
export const TechDocsPageWrapper = (props: TechDocsPageWrapperProps) => {
const { children, title, subtitle, hideSubtitle } = props;
const { children, title, subtitle, showSubtitle = true } = props;
const configApi = useApi(configApiRef);
const generatedSubtitle =
subtitle ||
@@ -48,7 +48,7 @@ export const TechDocsPageWrapper = (props: TechDocsPageWrapperProps) => {
return (
<PageWithHeader
title={title || 'Documentation'}
subtitle={hideSubtitle ? undefined : generatedSubtitle}
subtitle={showSubtitle ? generatedSubtitle : undefined}
themeId="documentation"
>
{children}