Skip to content

Commit 965a36c

Browse files
hannahblairgradio-pr-botCopilot
authored
workflow: dont render nodes for optional params on spawn (#13489)
* dont render nodes for optional params * add changeset * format * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <[email protected]> --------- Co-authored-by: gradio-pr-bot <[email protected]> Co-authored-by: Copilot Autofix powered by AI <[email protected]>
1 parent e0e2445 commit 965a36c

3 files changed

Lines changed: 21 additions & 8 deletions

File tree

‎.changeset/three-bags-check.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@gradio/workflowcanvas": patch
3+
"gradio": patch
4+
---
5+
6+
fix:workflow: dont render nodes for optional params on spawn

‎js/workflowcanvas/workflow/WorkflowCanvas.svelte‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1494,11 +1494,14 @@
14941494
// Skip ports with `choices` — they render an inline dropdown in
14951495
// the node body, so an auto-wired reference would be redundant
14961496
// (and worse, the reference is a plain textbox).
1497-
const inputPorts = spaceNode.inputs.filter(
1497+
const typedInputs = spaceNode.inputs.filter(
14981498
(p) =>
14991499
SUBGRAPH_PORT_TYPES.has(p.type) &&
15001500
!(p.choices && p.choices.length > 0)
15011501
);
1502+
const requiredInputs = typedInputs.filter((p) => p.required !== false);
1503+
const inputPorts =
1504+
requiredInputs.length > 0 ? requiredInputs : typedInputs;
15021505
const outputPorts = spaceNode.outputs.filter((p) =>
15031506
SUBGRAPH_PORT_TYPES.has(p.type)
15041507
);

‎js/workflowcanvas/workflow/WorkflowNodeSF.svelte‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@
7272
let labelInput: HTMLInputElement;
7373
let showAllInputs = $state(false);
7474
75-
const INPUT_COLLAPSE_THRESHOLD = 3;
76-
7775
function castChoiceValue(v: string, portType: PortType): NodeDataValue {
7876
if (portType === "number") {
7977
const n = Number(v);
@@ -338,14 +336,18 @@
338336

339337
<!-- Input ports -->
340338
{#if node.inputs.length > 0}
341-
{@const collapsible = node.inputs.length > INPUT_COLLAPSE_THRESHOLD}
339+
{@const hiddenCount = node.inputs.filter(
340+
(p) =>
341+
p.required === false && !connectedPorts.has(`${node.id}:${p.id}:input`)
342+
).length}
343+
{@const collapsible = hiddenCount > 0}
342344
<div class="ports" class:widget-ports={hasWidget}>
343-
{#each node.inputs as port, i}
345+
{#each node.inputs as port}
344346
{@const portConnected = connectedPorts.has(
345347
`${node.id}:${port.id}:input`
346348
)}
347349
{@const visible =
348-
showAllInputs || i < INPUT_COLLAPSE_THRESHOLD || portConnected}
350+
showAllInputs || portConnected || port.required !== false}
349351
{#if visible}
350352
<div class="port-row input-row" class:widget-port={hasWidget}>
351353
<!-- svelte-ignore a11y_no_static_element_interactions -->
@@ -483,8 +485,10 @@
483485
showAllInputs = !showAllInputs;
484486
}}
485487
>
486-
{#if showAllInputs}▴ show less{:else}▾ {node.inputs.length -
487-
INPUT_COLLAPSE_THRESHOLD} more params{/if}
488+
{#if showAllInputs}▴ show less{:else}▾ {hiddenCount} optional param{hiddenCount ===
489+
1
490+
? ""
491+
: "s"}{/if}
488492
</button>
489493
{/if}
490494
</div>

0 commit comments

Comments
 (0)