Add Record Create action in the frontend (#8514)
In this PR: - Updated the front-end types for workflows to include CRUD actions and global naming changes - Allow users to create a Record Create action - Scaffold the edit for Record Create action; for now, I render a `<VariableTagInput />` component for every editable field; it's likely we'll change it soon Closes https://github.com/twentyhq/private-issues/issues/142 Demo: https://github.com/user-attachments/assets/6f0b207a-b7d2-46d9-b5ab-9e32bde55d76
This commit is contained in:
committed by
GitHub
parent
316537a68a
commit
c17e18b1e9
@ -1,5 +1,9 @@
|
||||
import { TRIGGER_STEP_ID } from '@/workflow/constants/TriggerStepId';
|
||||
import { WorkflowStep, WorkflowTrigger } from '@/workflow/types/Workflow';
|
||||
import {
|
||||
WorkflowActionType,
|
||||
WorkflowStep,
|
||||
WorkflowTrigger,
|
||||
} from '@/workflow/types/Workflow';
|
||||
import {
|
||||
WorkflowDiagram,
|
||||
WorkflowDiagramEdge,
|
||||
@ -30,12 +34,26 @@ export const generateWorkflowDiagram = ({
|
||||
yPos: number,
|
||||
) => {
|
||||
const nodeId = step.id;
|
||||
|
||||
let nodeActionType: WorkflowActionType;
|
||||
if (step.type === 'RECORD_CRUD') {
|
||||
nodeActionType = `RECORD_CRUD.${step.settings.input.type}`;
|
||||
} else {
|
||||
nodeActionType = step.type;
|
||||
}
|
||||
|
||||
let nodeLabel = step.name;
|
||||
if (step.type === 'RECORD_CRUD') {
|
||||
// FIXME: use activeObjectMetadataItems to get labelSingular
|
||||
nodeLabel = `${capitalize(step.settings.input.type.toLowerCase())} ${capitalize(step.settings.input.objectName)}`;
|
||||
}
|
||||
|
||||
nodes.push({
|
||||
id: nodeId,
|
||||
data: {
|
||||
nodeType: 'action',
|
||||
actionType: step.type,
|
||||
label: step.name,
|
||||
actionType: nodeActionType,
|
||||
label: nodeLabel,
|
||||
},
|
||||
position: {
|
||||
x: xPos,
|
||||
|
||||
@ -1,10 +1,15 @@
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { WorkflowStep, WorkflowStepType } from '@/workflow/types/Workflow';
|
||||
import { assertUnreachable } from '@/workflow/utils/assertUnreachable';
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
export const getStepDefaultDefinition = (
|
||||
type: WorkflowStepType,
|
||||
): WorkflowStep => {
|
||||
export const getStepDefaultDefinition = ({
|
||||
type,
|
||||
activeObjectMetadataItems,
|
||||
}: {
|
||||
type: WorkflowStepType;
|
||||
activeObjectMetadataItems: ObjectMetadataItem[];
|
||||
}): WorkflowStep => {
|
||||
const newStepId = v4();
|
||||
|
||||
switch (type) {
|
||||
@ -57,6 +62,34 @@ export const getStepDefaultDefinition = (
|
||||
},
|
||||
};
|
||||
}
|
||||
case 'RECORD_CRUD.CREATE': {
|
||||
return {
|
||||
id: newStepId,
|
||||
name: 'Record Create',
|
||||
type: 'RECORD_CRUD',
|
||||
valid: false,
|
||||
settings: {
|
||||
input: {
|
||||
type: 'CREATE',
|
||||
objectName: activeObjectMetadataItems[0].nameSingular,
|
||||
objectRecord: {},
|
||||
},
|
||||
outputSchema: {},
|
||||
errorHandlingOptions: {
|
||||
continueOnFailure: {
|
||||
value: false,
|
||||
},
|
||||
retryOnFailure: {
|
||||
value: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
case 'RECORD_CRUD.DELETE':
|
||||
case 'RECORD_CRUD.UPDATE': {
|
||||
throw new Error('Not implemented yet');
|
||||
}
|
||||
default: {
|
||||
return assertUnreachable(type, `Unknown type: ${type}`);
|
||||
}
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
import {
|
||||
WorkflowAction,
|
||||
WorkflowRecordCreateAction,
|
||||
} from '@/workflow/types/Workflow';
|
||||
|
||||
export const isWorkflowRecordCreateAction = (
|
||||
action: WorkflowAction,
|
||||
): action is WorkflowRecordCreateAction => {
|
||||
return (
|
||||
action.type === 'RECORD_CRUD' && action.settings.input.type === 'CREATE'
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user