Skip to content

Commit

Permalink
feat(ui): migrated linear view exposed fields to builder form on load
Browse files Browse the repository at this point in the history
  • Loading branch information
psychedelicious committed Feb 7, 2025
1 parent ffde1e6 commit 88c84a5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
11 changes: 7 additions & 4 deletions invokeai/frontend/web/src/features/nodes/types/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ export const zWorkflowV3 = z.object({
category: zWorkflowCategory.default('user'),
version: z.literal('3.0.0'),
}),
form: z.object({
elements: z.record(z.lazy(() => zFormElement)),
layout: z.array(z.lazy(() => zElementId)),
}),
form: z
.object({
elements: z.record(z.lazy(() => zFormElement)),
layout: z.array(z.lazy(() => zElementId)),
})
// Catch must be a function else changes to the workflows parsed with this schema will mutate the catch value D:
.catch(() => ({ elements: {}, layout: [] })),
});
export type WorkflowV3 = z.infer<typeof zWorkflowV3>;
// #endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
isModelIdentifierFieldInputInstance,
} from 'features/nodes/types/field';
import type { WorkflowV3 } from 'features/nodes/types/workflow';
import { isWorkflowInvocationNode } from 'features/nodes/types/workflow';
import { buildNodeFieldElement, isWorkflowInvocationNode } from 'features/nodes/types/workflow';
import { getNeedsUpdate } from 'features/nodes/util/node/nodeUpdate';
import { t } from 'i18next';
import { keyBy } from 'lodash-es';
Expand Down Expand Up @@ -226,5 +226,27 @@ export const validateWorkflow = async (
});
}
});

if (_workflow.exposedFields.length > 0 && Object.values(_workflow.form.elements).length === 0) {
// Migrated exposed fields to form elements
for (const { nodeId, fieldName } of _workflow.exposedFields) {
const node = keyedNodes[nodeId];
if (!node) {
continue;
}
const nodeTemplate = templates[node.data.type];
if (!nodeTemplate) {
continue;
}
const fieldTemplate = nodeTemplate.inputs[fieldName];
if (!fieldTemplate) {
continue;
}
const element = buildNodeFieldElement(nodeId, fieldName, fieldTemplate.type);
_workflow.form.elements[element.id] = element;
_workflow.form.layout.push(element.id);
}
}

return { workflow: _workflow, warnings };
};

0 comments on commit 88c84a5

Please sign in to comment.