Merge pull request #22376 from drodil/default_scaffolder_output_text
feat: allow defining the default text output in template
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-react': patch
|
||||
---
|
||||
|
||||
Allow defining default output text to be shown
|
||||
@@ -277,6 +277,7 @@ export type ScaffolderOutputText = {
|
||||
title?: string;
|
||||
icon?: string;
|
||||
content?: string;
|
||||
default?: boolean;
|
||||
};
|
||||
|
||||
// @public
|
||||
|
||||
@@ -89,6 +89,7 @@ export type ScaffolderOutputText = {
|
||||
title?: string;
|
||||
icon?: string;
|
||||
content?: string;
|
||||
default?: boolean;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
|
||||
+15
-3
@@ -14,9 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { InfoCard, MarkdownContent } from '@backstage/core-components';
|
||||
import { ScaffolderTaskOutput } from '@backstage/plugin-scaffolder-react';
|
||||
import {
|
||||
ScaffolderOutputText,
|
||||
ScaffolderTaskOutput,
|
||||
} from '@backstage/plugin-scaffolder-react';
|
||||
import { Box, Paper } from '@material-ui/core';
|
||||
import React, { useMemo, useState } from 'react';
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
import { LinkOutputs } from './LinkOutputs';
|
||||
import { TextOutputs } from './TextOutputs';
|
||||
|
||||
@@ -30,9 +33,18 @@ export const DefaultTemplateOutputs = (props: {
|
||||
}) => {
|
||||
const { output } = props;
|
||||
const [textOutputIndex, setTextOutputIndex] = useState<number | undefined>(
|
||||
output?.text?.length ? 0 : undefined,
|
||||
undefined,
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (textOutputIndex === undefined && output?.text) {
|
||||
const defaultIndex = output.text.findIndex(
|
||||
(t: ScaffolderOutputText) => t.default,
|
||||
);
|
||||
setTextOutputIndex(defaultIndex >= 0 ? defaultIndex : 0);
|
||||
}
|
||||
}, [textOutputIndex, output]);
|
||||
|
||||
const textOutput = useMemo(
|
||||
() =>
|
||||
textOutputIndex !== undefined ? output?.text?.[textOutputIndex] : null,
|
||||
|
||||
Reference in New Issue
Block a user