feat(ui): migrated linear view exposed fields to builder form on load

This commit is contained in:
psychedelicious
2025-02-07 14:05:18 +11:00
parent 9c62648283
commit ef0ef875dd
2 changed files with 30 additions and 5 deletions

View File

@@ -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

View File

@@ -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';
@@ -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 };
};