Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split record crud actions #8930

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ export const WorkflowDiagramStepNodeBase = ({
</StyledStepNodeLabelIconContainer>
);
}
case 'RECORD_CRUD.UPDATE':
case 'RECORD_CRUD.CREATE': {
case 'CREATE_RECORD':
case 'UPDATE_RECORD':
case 'DELETE_RECORD': {
thomtrp marked this conversation as resolved.
Show resolved Hide resolved
return (
<StyledStepNodeLabelIconContainer>
<IconAddressBook
Expand All @@ -88,10 +89,6 @@ export const WorkflowDiagramStepNodeBase = ({
</StyledStepNodeLabelIconContainer>
);
}

case 'RECORD_CRUD.DELETE': {
return null;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ import {
} from '@/workflow/types/Workflow';
import { assertUnreachable } from '@/workflow/utils/assertUnreachable';
import { getStepDefinitionOrThrow } from '@/workflow/utils/getStepDefinitionOrThrow';
import { WorkflowEditActionFormRecordCreate } from '@/workflow/workflow-actions/components/WorkflowEditActionFormRecordCreate';
import { WorkflowEditActionFormRecordDelete } from '@/workflow/workflow-actions/components/WorkflowEditActionFormRecordDelete';
import { WorkflowEditActionFormRecordUpdate } from '@/workflow/workflow-actions/components/WorkflowEditActionFormRecordUpdate';
import { WorkflowEditActionFormCreateRecord } from '@/workflow/workflow-actions/components/WorkflowEditActionFormCreateRecord';
import { WorkflowEditActionFormDeleteRecord } from '@/workflow/workflow-actions/components/WorkflowEditActionFormDeleteRecord';
import { WorkflowEditActionFormSendEmail } from '@/workflow/workflow-actions/components/WorkflowEditActionFormSendEmail';
import { isWorkflowRecordCreateAction } from '@/workflow/workflow-actions/utils/isWorkflowRecordCreateAction';
import { isWorkflowRecordDeleteAction } from '@/workflow/workflow-actions/utils/isWorkflowRecordDeleteAction';
import { isWorkflowRecordUpdateAction } from '@/workflow/workflow-actions/utils/isWorkflowRecordUpdateAction';
import { WorkflowEditActionFormUpdateRecord } from '@/workflow/workflow-actions/components/WorkflowEditActionFormUpdateRecord';
import { lazy, Suspense } from 'react';
import { isDefined } from 'twenty-ui';
import { RightDrawerSkeletonLoader } from '~/loading/components/RightDrawerSkeletonLoader';
Expand Down Expand Up @@ -107,42 +104,35 @@ export const WorkflowStepDetail = ({
/>
);
}
case 'RECORD_CRUD': {
if (isWorkflowRecordCreateAction(stepDefinition.definition)) {
return (
<WorkflowEditActionFormRecordCreate
action={stepDefinition.definition}
actionOptions={props}
/>
);
}

if (isWorkflowRecordUpdateAction(stepDefinition.definition)) {
return (
<WorkflowEditActionFormRecordUpdate
action={stepDefinition.definition}
actionOptions={props}
/>
);
}
case 'CREATE_RECORD': {
return (
<WorkflowEditActionFormCreateRecord
action={stepDefinition.definition}
actionOptions={props}
/>
);
}

if (isWorkflowRecordDeleteAction(stepDefinition.definition)) {
return (
<WorkflowEditActionFormRecordDelete
action={stepDefinition.definition}
actionOptions={props}
/>
);
}
case 'UPDATE_RECORD': {
return (
<WorkflowEditActionFormUpdateRecord
action={stepDefinition.definition}
actionOptions={props}
/>
);
}

return null;
case 'DELETE_RECORD': {
return (
<WorkflowEditActionFormDeleteRecord
action={stepDefinition.definition}
actionOptions={props}
/>
);
}
}

return assertUnreachable(
stepDefinition.definition,
`Expected the step to have an handler; ${JSON.stringify(stepDefinition)}`,
);
return null;
thomtrp marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ export const ACTIONS: Array<{
},
{
label: 'Create Record',
type: 'RECORD_CRUD.CREATE',
type: 'CREATE_RECORD',
icon: IconAddressBook,
},
{
label: 'Update Record',
type: 'RECORD_CRUD.UPDATE',
type: 'UPDATE_RECORD',
icon: IconAddressBook,
},
{
label: 'Delete Record',
type: 'RECORD_CRUD.DELETE',
type: 'DELETE_RECORD',
icon: IconAddressBook,
},
];
72 changes: 31 additions & 41 deletions packages/twenty-front/src/modules/workflow/types/Workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,26 @@ export type WorkflowSendEmailActionSettings = BaseWorkflowActionSettings & {

type ObjectRecord = Record<string, any>;
thomtrp marked this conversation as resolved.
Show resolved Hide resolved

export type WorkflowCreateRecordActionInput = {
type: 'CREATE';
objectName: string;
objectRecord: ObjectRecord;
};

export type WorkflowUpdateRecordActionInput = {
type: 'UPDATE';
objectName: string;
objectRecord: ObjectRecord;
objectRecordId: string;
export type WorkflowCreateRecordActionSettings = BaseWorkflowActionSettings & {
input: {
objectName: string;
objectRecord: ObjectRecord;
};
};

export type WorkflowDeleteRecordActionInput = {
type: 'DELETE';
objectName: string;
objectRecordId: string;
export type WorkflowUpdateRecordActionSettings = BaseWorkflowActionSettings & {
input: {
objectName: string;
objectRecord: ObjectRecord;
objectRecordId: string;
};
};

export type WorkflowRecordCRUDActionInput =
| WorkflowCreateRecordActionInput
| WorkflowUpdateRecordActionInput
| WorkflowDeleteRecordActionInput;

export type WorkflowRecordCRUDType = WorkflowRecordCRUDActionInput['type'];

export type WorkflowRecordCRUDActionSettings = BaseWorkflowActionSettings & {
input: WorkflowRecordCRUDActionInput;
export type WorkflowDeleteRecordActionSettings = BaseWorkflowActionSettings & {
input: {
objectName: string;
objectRecordId: string;
};
};

type BaseWorkflowAction = {
Expand All @@ -78,35 +70,33 @@ export type WorkflowSendEmailAction = BaseWorkflowAction & {
settings: WorkflowSendEmailActionSettings;
};

export type WorkflowRecordCRUDAction = BaseWorkflowAction & {
type: 'RECORD_CRUD';
settings: WorkflowRecordCRUDActionSettings;
export type WorkflowCreateRecordAction = BaseWorkflowAction & {
type: 'CREATE_RECORD';
settings: WorkflowCreateRecordActionSettings;
};

export type WorkflowRecordCreateAction = WorkflowRecordCRUDAction & {
settings: { input: { type: 'CREATE' } };
export type WorkflowUpdateRecordAction = BaseWorkflowAction & {
type: 'UPDATE_RECORD';
settings: WorkflowUpdateRecordActionSettings;
};

export type WorkflowRecordUpdateAction = WorkflowRecordCRUDAction & {
settings: { input: { type: 'UPDATE' } };
};

export type WorkflowRecordDeleteAction = WorkflowRecordCRUDAction & {
settings: { input: { type: 'DELETE' } };
export type WorkflowDeleteRecordAction = BaseWorkflowAction & {
type: 'DELETE_RECORD';
settings: WorkflowDeleteRecordActionSettings;
};

export type WorkflowAction =
| WorkflowCodeAction
| WorkflowSendEmailAction
| WorkflowRecordCRUDAction;
| WorkflowCreateRecordAction
| WorkflowUpdateRecordAction
| WorkflowDeleteRecordAction;

thomtrp marked this conversation as resolved.
Show resolved Hide resolved
export type WorkflowStep = WorkflowAction;
export type WorkflowActionType = WorkflowAction['type'];
thomtrp marked this conversation as resolved.
Show resolved Hide resolved

export type WorkflowActionType =
| Exclude<WorkflowAction['type'], WorkflowRecordCRUDAction['type']>
| `${WorkflowRecordCRUDAction['type']}.${WorkflowRecordCRUDType}`;
export type WorkflowStep = WorkflowAction;

export type WorkflowStepType = WorkflowActionType;
export type WorkflowStepType = WorkflowStep['type'];

type BaseTrigger = {
name?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { TRIGGER_STEP_ID } from '@/workflow/constants/TriggerStepId';
import {
WorkflowActionType,
WorkflowStep,
WorkflowTrigger,
} from '@/workflow/types/Workflow';
import { WorkflowStep, WorkflowTrigger } from '@/workflow/types/Workflow';
import {
WorkflowDiagram,
WorkflowDiagramEdge,
Expand Down Expand Up @@ -35,25 +31,12 @@ export const generateWorkflowDiagram = ({
) => {
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: nodeActionType,
name: isDefined(step.name) ? step.name : nodeLabel,
actionType: step.type,
name: step.name,
},
position: {
x: xPos,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FormFieldInput } from '@/object-record/record-field/components/FormFiel
import { Select, SelectOption } from '@/ui/input/components/Select';
import { WorkflowEditGenericFormBase } from '@/workflow/components/WorkflowEditGenericFormBase';
import { WorkflowVariablePicker } from '@/workflow/components/WorkflowVariablePicker';
import { WorkflowRecordCreateAction } from '@/workflow/types/Workflow';
import { WorkflowCreateRecordAction } from '@/workflow/types/Workflow';
import { useTheme } from '@emotion/react';
import { useEffect, useState } from 'react';
import {
Expand All @@ -18,15 +18,15 @@ import { JsonValue } from 'type-fest';
import { useDebouncedCallback } from 'use-debounce';
import { FieldMetadataType } from '~/generated/graphql';

type WorkflowEditActionFormRecordCreateProps = {
action: WorkflowRecordCreateAction;
type WorkflowEditActionFormCreateRecordProps = {
action: WorkflowCreateRecordAction;
actionOptions:
| {
readonly: true;
}
| {
readonly?: false;
onActionUpdate: (action: WorkflowRecordCreateAction) => void;
onActionUpdate: (action: WorkflowCreateRecordAction) => void;
};
};

Expand All @@ -35,10 +35,10 @@ type CreateRecordFormData = {
[field: string]: unknown;
};

export const WorkflowEditActionFormRecordCreate = ({
export const WorkflowEditActionFormCreateRecord = ({
action,
actionOptions,
}: WorkflowEditActionFormRecordCreateProps) => {
}: WorkflowEditActionFormCreateRecordProps) => {
const theme = useTheme();
const { getIcon } = useIcons();

Expand Down Expand Up @@ -118,7 +118,6 @@ export const WorkflowEditActionFormRecordCreate = ({
settings: {
...action.settings,
input: {
type: 'CREATE',
objectName: updatedObjectName,
objectRecord: updatedOtherFields,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilte
import { Select, SelectOption } from '@/ui/input/components/Select';
import { WorkflowEditGenericFormBase } from '@/workflow/components/WorkflowEditGenericFormBase';
import { WorkflowSingleRecordPicker } from '@/workflow/components/WorkflowSingleRecordPicker';
import { WorkflowRecordDeleteAction } from '@/workflow/types/Workflow';
import { WorkflowDeleteRecordAction } from '@/workflow/types/Workflow';
import { useTheme } from '@emotion/react';
import { useEffect, useState } from 'react';
import {
Expand All @@ -15,15 +15,15 @@ import {
import { JsonValue } from 'type-fest';
import { useDebouncedCallback } from 'use-debounce';

type WorkflowEditActionFormRecordDeleteProps = {
action: WorkflowRecordDeleteAction;
type WorkflowEditActionFormDeleteRecordProps = {
action: WorkflowDeleteRecordAction;
actionOptions:
| {
readonly: true;
}
| {
readonly?: false;
onActionUpdate: (action: WorkflowRecordDeleteAction) => void;
onActionUpdate: (action: WorkflowDeleteRecordAction) => void;
};
};

Expand All @@ -32,10 +32,10 @@ type DeleteRecordFormData = {
objectRecordId: string;
};

export const WorkflowEditActionFormRecordDelete = ({
export const WorkflowEditActionFormDeleteRecord = ({
action,
actionOptions,
}: WorkflowEditActionFormRecordDeleteProps) => {
}: WorkflowEditActionFormDeleteRecordProps) => {
const theme = useTheme();
const { getIcon } = useIcons();

Expand Down Expand Up @@ -100,7 +100,6 @@ export const WorkflowEditActionFormRecordDelete = ({
settings: {
...action.settings,
input: {
type: 'DELETE',
objectName: updatedObjectName,
objectRecordId: updatedObjectRecordId ?? '',
},
Expand Down
Loading
Loading