scaffolder: Support conditional if on output links and text (#33332)

* Add sample template for conditional output demo

Add a scaffolder template that exercises conditional `if` on output
links and text items, for testing issue #24805.

Signed-off-by: Dmitry Gusev <gusevda90@gmail.com>

* Support conditional `if` on scaffolder output links and text

Add `if` property to output link and text items in scaffolder templates,
allowing template authors to conditionally show/hide output items based
on parameters or step results. Items with a falsy `if` condition are
filtered out before being sent to the frontend.

Signed-off-by: Dmitry Gusev <gusevda90@gmail.com>

* Add changesets for conditional output feature

Signed-off-by: Dmitry Gusev <gusevda90@gmail.com>

* Document conditional if on output links and text

Signed-off-by: Dmitry Gusev <gusevda90@gmail.com>

* Guard against non-object items in output arrays

Signed-off-by: Dmitry Gusev <gusevda90@gmail.com>

* Skip array items in output if-filtering destructuring

Add Array.isArray guard to prevent corrupting array items
into plain objects during the rest-destructuring step.

Signed-off-by: Dmitry Gusev <gusevda90@gmail.com>

* Extract filterConditionalItems helper to deduplicate logic

Signed-off-by: Dmitry Gusev <gusevda90@gmail.com>

* Align output if schema descriptions with step if semantics

Signed-off-by: Dmitry Gusev <gusevda90@gmail.com>

* Fix docs quality check: replace 'falsy' wording

Signed-off-by: Dmitry Gusev <gusevda90@gmail.com>

* Refactor filterConditionalItems to use flatMap and generics

Replace .filter().map() with a single flatMap call and make the function
generic to eliminate JsonArray casts at call sites.

Signed-off-by: Dmitry Gusev <gusevda90@gmail.com>

---------

Signed-off-by: Dmitry Gusev <gusevda90@gmail.com>
This commit is contained in:
Dmitry Gusev
2026-04-14 15:29:04 +03:00
committed by GitHub
parent aa08b7f135
commit 3ef6078b70
11 changed files with 270 additions and 3 deletions
+2
View File
@@ -270,6 +270,7 @@ export interface ScaffolderGetIntegrationsListResponse {
// @public (undocumented)
export type ScaffolderOutputLink = {
if?: string | boolean;
title?: string;
icon?: string;
url?: string;
@@ -278,6 +279,7 @@ export type ScaffolderOutputLink = {
// @public (undocumented)
export type ScaffolderOutputText = {
if?: string | boolean;
title?: string;
icon?: string;
content?: string;
@@ -261,6 +261,10 @@
"type": "object",
"required": [],
"properties": {
"if": {
"type": ["string", "boolean"],
"description": "A templated condition that excludes this link when evaluated to false. If the condition is true or not defined, the link is included. The condition is true, if the input is not `false`, `undefined`, `null`, `\"\"`, `0`, or `[]`."
},
"url": {
"type": "string",
"description": "A url in a standard uri format.",
@@ -295,6 +299,10 @@
"type": "object",
"required": [],
"properties": {
"if": {
"type": ["string", "boolean"],
"description": "A templated condition that excludes this text when evaluated to false. If the condition is true or not defined, the text is included. The condition is true, if the input is not `false`, `undefined`, `null`, `\"\"`, `0`, or `[]`."
},
"title": {
"type": "string",
"description": "A user friendly display name for the text.",
+2
View File
@@ -136,6 +136,7 @@ export type ListTemplatingExtensionsResponse = {
/** @public */
export type ScaffolderOutputLink = {
if?: string | boolean;
title?: string;
icon?: string;
url?: string;
@@ -144,6 +145,7 @@ export type ScaffolderOutputLink = {
/** @public */
export type ScaffolderOutputText = {
if?: string | boolean;
title?: string;
icon?: string;
content?: string;