Add option to hide text output buttons

Signed-off-by: Vladimir Kobzev <vkobzev@bol.com>
This commit is contained in:
Vladimir Kobzev
2025-01-16 10:24:18 +01:00
parent 3e0a20f753
commit 2003fc2360
5 changed files with 44 additions and 16 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-react': patch
---
Adds an option to hide text output buttons
@@ -89,6 +89,7 @@ export type ScaffolderOutputText = {
title?: string;
icon?: string;
content?: string;
showButton?: boolean;
default?: boolean;
};
@@ -78,4 +78,22 @@ describe('<DefaultTemplateOutputs />', () => {
expect(queryByTestId('output-box')).toBeNull();
expect(queryByTestId('text-output-box')).toBeNull();
});
it('should not render the link output box when output only contains text with showButton set to false', async () => {
const output = {
text: [
{ title: 'Text 1', content: 'Hello, **world**!', showButton: false },
{ title: 'Text 2', content: 'Hello, **mars**!', showButton: false },
],
};
const { queryByTestId } = await renderInTestApp(
<DefaultTemplateOutputs output={output} />,
{
mountedRoutes: {
'/catalog/:namespace/:kind/:name': entityRouteRef,
},
},
);
expect(queryByTestId('output-box')).toBeNull();
});
});
@@ -56,7 +56,9 @@ export const DefaultTemplateOutputs = (props: {
return null;
}
const emptyOutput = Object.keys(output).length === 0;
const emptyOutput =
(output.links || []).length === 0 &&
Object.values(output.text || {}).filter(o => o.showButton).length === 0;
return (
<>
@@ -39,23 +39,25 @@ export const TextOutputs = (props: {
<>
{text
.filter(({ content }) => content !== undefined)
.map(({ title, icon }, i) => {
.map(({ title, icon, showButton = true }, i) => {
const Icon = iconResolver(icon);
return (
<Button
key={i}
startIcon={<Icon />}
component="div"
color="primary"
onClick={() => {
if (index !== i) {
setIndex?.(i);
}
}}
variant={index === i ? 'outlined' : undefined}
>
{title}
</Button>
showButton && (
<Button
key={i}
startIcon={<Icon />}
component="div"
color="primary"
onClick={() => {
if (index !== i) {
setIndex?.(i);
}
}}
variant={index === i ? 'outlined' : undefined}
>
{title}
</Button>
)
);
})}
</>