Execute workflow form action (#11099)
- create a form filler component - send the response on submit - put back a field name. We need it for the step output - validate a form is well set before activation TODO: - we need to refresh to see the form submitted. We need to discuss about a strategy - the response is not saved in the step settings. We need a new endpoint to update workflow run step https://github.com/user-attachments/assets/0f34a6cd-ed8c-4d9a-a1d4-51455cc83443
This commit is contained in:
@ -1,8 +1,15 @@
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
|
||||
import {
|
||||
WorkflowVersionStatus,
|
||||
WorkflowVersionWorkspaceEntity,
|
||||
} from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
|
||||
import { WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';
|
||||
import { WorkflowFormActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/form/types/workflow-form-action-settings.type';
|
||||
import {
|
||||
WorkflowAction,
|
||||
WorkflowActionType,
|
||||
} from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';
|
||||
import {
|
||||
WorkflowTriggerException,
|
||||
WorkflowTriggerExceptionCode,
|
||||
@ -58,6 +65,10 @@ function assertVersionIsValid(workflowVersion: WorkflowVersionWorkspaceEntity) {
|
||||
workflowVersion.trigger.type,
|
||||
workflowVersion.trigger.settings,
|
||||
);
|
||||
|
||||
workflowVersion.steps.forEach((step) => {
|
||||
assertStepIsValid(step);
|
||||
});
|
||||
}
|
||||
|
||||
function assertTriggerSettingsAreValid(
|
||||
@ -188,3 +199,46 @@ function assertDatabaseEventTriggerSettingsAreValid(settings: any) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function assertStepIsValid(step: WorkflowAction) {
|
||||
switch (step.type) {
|
||||
case WorkflowActionType.FORM:
|
||||
assertFormStepIsValid(step.settings);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function assertFormStepIsValid(settings: WorkflowFormActionSettings) {
|
||||
if (!settings.input) {
|
||||
throw new WorkflowTriggerException(
|
||||
'No input provided in form step',
|
||||
WorkflowTriggerExceptionCode.INVALID_WORKFLOW_TRIGGER,
|
||||
);
|
||||
}
|
||||
|
||||
// Check all fields have unique and defined names
|
||||
const fieldNames = settings.input.map((fieldMetadata) => fieldMetadata.name);
|
||||
const uniqueFieldNames = new Set(fieldNames);
|
||||
|
||||
if (fieldNames.length !== uniqueFieldNames.size) {
|
||||
throw new WorkflowTriggerException(
|
||||
'Form action fields must have unique names',
|
||||
WorkflowTriggerExceptionCode.INVALID_WORKFLOW_VERSION,
|
||||
);
|
||||
}
|
||||
|
||||
// Check all fields have defined labels and types
|
||||
settings.input.forEach((fieldMetadata) => {
|
||||
if (
|
||||
!isNonEmptyString(fieldMetadata.label) ||
|
||||
!isNonEmptyString(fieldMetadata.type)
|
||||
) {
|
||||
throw new WorkflowTriggerException(
|
||||
'Form action fields must have a defined label and type',
|
||||
WorkflowTriggerExceptionCode.INVALID_WORKFLOW_VERSION,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user