Skip to content

The open alternative to Salesforce, designed for AI.

App logic function as step (#17525)

Thomas Trompette3ad7a9ac9454
diff --git a/packages/twenty-front/src/generated-metadata/graphql.ts b/packages/twenty-front/src/generated-metadata/graphql.ts
index d8e70e89b7a..d707329401a 100644
--- a/packages/twenty-front/src/generated-metadata/graphql.ts
+++ b/packages/twenty-front/src/generated-metadata/graphql.ts
@@ -1147,6 +1147,10 @@ export type CreateWorkflowVersionEdgeInput = {
export type CreateWorkflowVersionStepInput = {
/** Step ID */
id?: InputMaybe<Scalars['String']>;
+ /** Logic function ID */
+ logicFunctionId?: InputMaybe<Scalars['UUID']>;
+ /** Step name */
+ name?: InputMaybe<Scalars['String']>;
/** Next step ID */
nextStepId?: InputMaybe<Scalars['UUID']>;
/** Parent step connection options */
@@ -5146,6 +5150,7 @@ export enum WorkflowActionType {
HTTP_REQUEST = 'HTTP_REQUEST',
IF_ELSE = 'IF_ELSE',
ITERATOR = 'ITERATOR',
+ LOGIC_FUNCTION = 'LOGIC_FUNCTION',
SEND_EMAIL = 'SEND_EMAIL',
UPDATE_RECORD = 'UPDATE_RECORD',
UPSERT_RECORD = 'UPSERT_RECORD'
diff --git a/packages/twenty-front/src/generated/graphql.ts b/packages/twenty-front/src/generated/graphql.ts
index 2cf9f695827..c2dd291d6b5 100644
--- a/packages/twenty-front/src/generated/graphql.ts
+++ b/packages/twenty-front/src/generated/graphql.ts
@@ -1114,6 +1114,10 @@ export type CreateWorkflowVersionEdgeInput = {
export type CreateWorkflowVersionStepInput = {
/** Step ID */
id?: InputMaybe<Scalars['String']>;
+ /** Logic function ID */
+ logicFunctionId?: InputMaybe<Scalars['UUID']>;
+ /** Step name */
+ name?: InputMaybe<Scalars['String']>;
/** Next step ID */
nextStepId?: InputMaybe<Scalars['UUID']>;
/** Parent step connection options */
@@ -4921,6 +4925,7 @@ export enum WorkflowActionType {
HTTP_REQUEST = 'HTTP_REQUEST',
IF_ELSE = 'IF_ELSE',
ITERATOR = 'ITERATOR',
+ LOGIC_FUNCTION = 'LOGIC_FUNCTION',
SEND_EMAIL = 'SEND_EMAIL',
UPDATE_RECORD = 'UPDATE_RECORD',
UPSERT_RECORD = 'UPSERT_RECORD'
diff --git a/packages/twenty-front/src/modules/command-menu/pages/workflow/action/components/CommandMenuWorkflowSelectAction.tsx b/packages/twenty-front/src/modules/command-menu/pages/workflow/action/components/CommandMenuWorkflowSelectAction.tsx
index b2c9a87640d..1d8bc27f3c6 100644
--- a/packages/twenty-front/src/modules/command-menu/pages/workflow/action/components/CommandMenuWorkflowSelectAction.tsx
+++ b/packages/twenty-front/src/modules/command-menu/pages/workflow/action/components/CommandMenuWorkflowSelectAction.tsx
@@ -1,4 +1,5 @@
import { WorkflowActionMenuItems } from '@/command-menu/pages/workflow/action/components/WorkflowActionMenuItems';
+import { useGetManyLogicFunctions } from '@/settings/logic-functions/hooks/useGetManyLogicFunctions';
import { type WorkflowActionType } from '@/workflow/types/Workflow';
import { RightDrawerStepListContainer } from '@/workflow/workflow-steps/components/RightDrawerWorkflowSelectStepContainer';
import { RightDrawerWorkflowSelectStepTitle } from '@/workflow/workflow-steps/components/RightDrawerWorkflowSelectStepTitle';
@@ -7,19 +8,40 @@ import { CORE_ACTIONS } from '@/workflow/workflow-steps/workflow-actions/constan
import { FLOW_ACTIONS } from '@/workflow/workflow-steps/workflow-actions/constants/FlowActions';
import { HUMAN_INPUT_ACTIONS } from '@/workflow/workflow-steps/workflow-actions/constants/HumanInputActions';
import { RECORD_ACTIONS } from '@/workflow/workflow-steps/workflow-actions/constants/RecordActions';
+import { getActionIconColorOrThrow } from '@/workflow/workflow-steps/workflow-actions/utils/getActionIconColorOrThrow';
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
+import { useTheme } from '@emotion/react';
import { useLingui } from '@lingui/react/macro';
+import { IconFunction } from 'twenty-ui/display';
+import { MenuItem } from 'twenty-ui/navigation';
import { FeatureFlagKey } from '~/generated/graphql';
+export type WorkflowActionSelection =
+ | { type: WorkflowActionType; logicFunctionId?: undefined; name?: undefined }
+ | { type: 'LOGIC_FUNCTION'; logicFunctionId: string; name: string };
+
export const CommandMenuWorkflowSelectAction = ({
onActionSelected,
}: {
- onActionSelected: (actionType: WorkflowActionType) => void;
+ onActionSelected: (selection: WorkflowActionSelection) => void;
}) => {
const isAiEnabled = useIsFeatureEnabled(FeatureFlagKey.IS_AI_ENABLED);
+ const theme = useTheme();
const { t } = useLingui();
+ const { logicFunctions } = useGetManyLogicFunctions();
+
+ const toolFunctions = logicFunctions.filter((fn) => fn.isTool === true);
+
+ const handleActionClick = (actionType: WorkflowActionType) => {
+ onActionSelected({ type: actionType });
+ };
+
+ const handleFunctionClick = (logicFunctionId: string, name: string) => {
+ onActionSelected({ type: 'LOGIC_FUNCTION', logicFunctionId, name });
+ };
+
return (
<RightDrawerStepListContainer>
<RightDrawerWorkflowSelectStepTitle>
@@ -27,7 +49,7 @@ export const CommandMenuWorkflowSelectAction = ({
</RightDrawerWorkflowSelectStepTitle>
<WorkflowActionMenuItems
actions={RECORD_ACTIONS}
- onClick={onActionSelected}
+ onClick={handleActionClick}
/>
{isAiEnabled && (
@@ -37,7 +59,7 @@ export const CommandMenuWorkflowSelectAction = ({
</RightDrawerWorkflowSelectStepTitle>
<WorkflowActionMenuItems
actions={AI_ACTIONS}
- onClick={onActionSelected}
+ onClick={handleActionClick}
/>
</>
)}
@@ -47,7 +69,7 @@ export const CommandMenuWorkflowSelectAction = ({
</RightDrawerWorkflowSelectStepTitle>
<WorkflowActionMenuItems
actions={FLOW_ACTIONS}
- onClick={onActionSelected}
+ onClick={handleActionClick}
/>
<RightDrawerWorkflowSelectStepTitle>
@@ -55,7 +77,7 @@ export const CommandMenuWorkflowSelectAction = ({
</RightDrawerWorkflowSelectStepTitle>
<WorkflowActionMenuItems
actions={CORE_ACTIONS}
- onClick={onActionSelected}
+ onClick={handleActionClick}
/>
<RightDrawerWorkflowSelectStepTitle>
@@ -63,8 +85,33 @@ export const CommandMenuWorkflowSelectAction = ({
</RightDrawerWorkflowSelectStepTitle>
<WorkflowActionMenuItems
actions={HUMAN_INPUT_ACTIONS}
- onClick={onActionSelected}
+ onClick={handleActionClick}
/>
+
+ {toolFunctions.length > 0 && (
+ <>
+ <RightDrawerWorkflowSelectStepTitle>
+ {t`Applications`}
+ </RightDrawerWorkflowSelectStepTitle>
+ {toolFunctions.map((fn) => (
+ <MenuItem
+ key={fn.id}
+ withIconContainer={true}
+ LeftIcon={() => (
+ <IconFunction
+ color={getActionIconColorOrThrow({
+ theme,
+ actionType: 'LOGIC_FUNCTION',
+ })}
+ size={16}
+ />
+ )}
+ text={fn.name}
+ onClick={() => handleFunctionClick(fn.id, fn.name)}
+ />
+ ))}
+ </>
+ )}
</RightDrawerStepListContainer>
);
};
diff --git a/packages/twenty-front/src/modules/command-menu/pages/workflow/step/create/components/CommandMenuWorkflowCreateStepContent.tsx b/packages/twenty-front/src/modules/command-menu/pages/workflow/step/create/components/CommandMenuWorkflowCreateStepContent.tsx
index 26319055137..e1bb6753c1b 100644
--- a/packages/twenty-front/src/modules/command-menu/pages/workflow/step/create/components/CommandMenuWorkflowCreateStepContent.tsx
+++ b/packages/twenty-front/src/modules/command-menu/pages/workflow/step/create/components/CommandMenuWorkflowCreateStepContent.tsx
@@ -1,5 +1,8 @@
import { useWorkflowCommandMenu } from '@/command-menu/hooks/useWorkflowCommandMenu';
-import { CommandMenuWorkflowSelectAction } from '@/command-menu/pages/workflow/action/components/CommandMenuWorkflowSelectAction';
+import {
+ CommandMenuWorkflowSelectAction,
+ type WorkflowActionSelection,
+} from '@/command-menu/pages/workflow/action/components/CommandMenuWorkflowSelectAction';
import { commandMenuNavigationStackState } from '@/command-menu/states/commandMenuNavigationStackState';
import { useRecoilComponentState } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentState';
import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue';
@@ -55,7 +58,7 @@ export const CommandMenuWorkflowCreateStepContent = () => {
await updateStep(updatedStep);
};
- const handleCreateStep = async (actionType: WorkflowActionType) => {
+ const handleCreateStep = async (selection: WorkflowActionSelection) => {
if (!isDefined(workflowVisualizerWorkflowId)) {
throw new Error(
'Workflow ID must be configured for the edge when creating a step',
@@ -66,11 +69,13 @@ export const CommandMenuWorkflowCreateStepContent = () => {
workflowInsertStepIds;
const createdStep = await createStep({
- newStepType: actionType,
+ newStepType: selection.type,
parentStepId,
nextStepId,
position,
connectionOptions,
+ logicFunctionId: selection.logicFunctionId,
+ name: selection.name,
});
if (!isDefined(createdStep)) {
diff --git a/packages/twenty-front/src/modules/command-menu/pages/workflow/step/edit/components/CommandMenuWorkflowEditStepTypeContent.tsx b/packages/twenty-front/src/modules/command-menu/pages/workflow/step/edit/components/CommandMenuWorkflowEditStepTypeContent.tsx
index 44c2e2d08d6..1e8abe431f9 100644
--- a/packages/twenty-front/src/modules/command-menu/pages/workflow/step/edit/components/CommandMenuWorkflowEditStepTypeContent.tsx
+++ b/packages/twenty-front/src/modules/command-menu/pages/workflow/step/edit/components/CommandMenuWorkflowEditStepTypeContent.tsx
@@ -1,5 +1,8 @@
import { useWorkflowCommandMenu } from '@/command-menu/hooks/useWorkflowCommandMenu';
-import { CommandMenuWorkflowSelectAction } from '@/command-menu/pages/workflow/action/components/CommandMenuWorkflowSelectAction';
+import {
+ CommandMenuWorkflowSelectAction,
+ type WorkflowActionSelection,
+} from '@/command-menu/pages/workflow/action/components/CommandMenuWorkflowSelectAction';
import { commandMenuNavigationStackState } from '@/command-menu/states/commandMenuNavigationStackState';
import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue';
import { useFlowOrThrow } from '@/workflow/hooks/useFlowOrThrow';
@@ -34,7 +37,7 @@ export const CommandMenuWorkflowEditStepTypeContent = () => {
commandMenuNavigationStackState,
);
- const handleUpdateStepType = async (actionType: WorkflowActionType) => {
+ const handleUpdateStepType = async (selection: WorkflowActionSelection) => {
if (!isDefined(workflowVisualizerWorkflowId)) {
throw new Error(
'Workflow ID must be configured for the edge when creating a step',
@@ -49,10 +52,26 @@ export const CommandMenuWorkflowEditStepTypeContent = () => {
throw new Error('Step not found');
}
- const { updatedStep } = await updateStep({
- ...existingStep,
- type: actionType,
- } as WorkflowAction);
+ const stepUpdate =
+ selection.type === 'LOGIC_FUNCTION'
+ ? {
+ ...existingStep,
+ type: selection.type,
+ name: selection.name,
+ settings: {
+ ...existingStep.settings,
+ input: {
+ logicFunctionId: selection.logicFunctionId,
+ logicFunctionInput: {},
+ },
+ },
+ }
+ : {
+ ...existingStep,
+ type: selection.type,
+ };
+
+ const { updatedStep } = await updateStep(stepUpdate as WorkflowAction);
if (!isDefined(updatedStep)) {
return;
diff --git a/packages/twenty-front/src/modules/workflow/types/Workflow.ts b/packages/twenty-front/src/modules/workflow/types/Workflow.ts
index 6885c89c8dc..dfcb6bb82ab 100644
--- a/packages/twenty-front/src/modules/workflow/types/Workflow.ts
+++ b/packages/twenty-front/src/modules/workflow/types/Workflow.ts
@@ -7,6 +7,7 @@ import {
type workflowCreateRecordActionSchema,
type workflowCronTriggerSchema,
type workflowDatabaseEventTriggerSchema,
+ type workflowDelayActionSchema,
type workflowDeleteRecordActionSchema,
type workflowEmptyActionSchema,
type workflowFilterActionSchema,
@@ -15,6 +16,7 @@ import {
type workflowHttpRequestActionSchema,
type workflowIfElseActionSchema,
type workflowIteratorActionSchema,
+ type workflowLogicFunctionActionSchema,
type workflowManualTriggerSchema,
type workflowRunSchema,
type workflowRunStateSchema,
@@ -25,11 +27,13 @@ import {
type workflowUpdateRecordActionSchema,
type workflowUpsertRecordActionSchema,
type workflowWebhookTriggerSchema,
- type workflowDelayActionSchema,
} from 'twenty-shared/workflow';
import { type z } from 'zod';
export type WorkflowCodeAction = z.infer<typeof workflowCodeActionSchema>;
+export type WorkflowLogicFunctionAction = z.infer<
+ typeof workflowLogicFunctionActionSchema
+>;
export type WorkflowSendEmailAction = z.infer<
typeof workflowSendEmailActionSchema
>;
@@ -63,6 +67,7 @@ export type WorkflowEmptyAction = z.infer<typeof workflowEmptyActionSchema>;
export type WorkflowAction =
| WorkflowCodeAction
+ | WorkflowLogicFunctionAction
| WorkflowSendEmailAction
| WorkflowCreateRecordAction
| WorkflowUpdateRecordAction
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowRunStepNodeDetail.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowRunStepNodeDetail.tsx
index 9784b5a8276..cc7897a4bdd 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowRunStepNodeDetail.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowRunStepNodeDetail.tsx
@@ -5,7 +5,7 @@ import {
} from '@/workflow/types/Workflow';
import { getStepDefinitionOrThrow } from '@/workflow/utils/getStepDefinitionOrThrow';
import { WorkflowEditActionAiAgent } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/components/WorkflowEditActionAiAgent';
-import { WorkflowActionLogicFunction } from '@/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowActionLogicFunction';
+import { WorkflowActionCode } from '@/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowActionCode';
import { WorkflowEditActionCreateRecord } from '@/workflow/workflow-steps/workflow-actions/components/WorkflowEditActionCreateRecord';
import { WorkflowEditActionDeleteRecord } from '@/workflow/workflow-steps/workflow-actions/components/WorkflowEditActionDeleteRecord';
import { WorkflowEditActionEmpty } from '@/workflow/workflow-steps/workflow-actions/components/WorkflowEditActionEmpty';
@@ -15,10 +15,11 @@ import { WorkflowEditActionUpsertRecord } from '@/workflow/workflow-steps/workfl
import { WorkflowEditActionDelay } from '@/workflow/workflow-steps/workflow-actions/delay-actions/components/WorkflowEditActionDelay';
import { WorkflowEditActionFilter } from '@/workflow/workflow-steps/workflow-actions/filter-action/components/WorkflowEditActionFilter';
import { WorkflowEditActionFindRecords } from '@/workflow/workflow-steps/workflow-actions/find-records-action/components/WorkflowEditActionFindRecords';
-import { WorkflowEditActionIfElse } from '@/workflow/workflow-steps/workflow-actions/if-else-action/components/WorkflowEditActionIfElse';
import { WorkflowEditActionFormFiller } from '@/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowEditActionFormFiller';
import { WorkflowEditActionHttpRequest } from '@/workflow/workflow-steps/workflow-actions/http-request-action/components/WorkflowEditActionHttpRequest';
+import { WorkflowEditActionIfElse } from '@/workflow/workflow-steps/workflow-actions/if-else-action/components/WorkflowEditActionIfElse';
import { WorkflowEditActionIterator } from '@/workflow/workflow-steps/workflow-actions/iterator-action/components/WorkflowEditActionIterator';
+import { WorkflowEditActionLogicFunction } from '@/workflow/workflow-steps/workflow-actions/logic-function-action/components/WorkflowEditActionLogicFunction';
import { WorkflowEditTriggerCronForm } from '@/workflow/workflow-trigger/components/WorkflowEditTriggerCronForm';
import { WorkflowEditTriggerDatabaseEventForm } from '@/workflow/workflow-trigger/components/WorkflowEditTriggerDatabaseEventForm';
import { WorkflowEditTriggerManual } from '@/workflow/workflow-trigger/components/WorkflowEditTriggerManual';
@@ -106,7 +107,18 @@ export const WorkflowRunStepNodeDetail = ({
switch (stepDefinition.definition.type) {
case 'CODE': {
return (
- <WorkflowActionLogicFunction
+ <WorkflowActionCode
+ key={stepId}
+ action={stepDefinition.definition}
+ actionOptions={{
+ readonly: true,
+ }}
+ />
+ );
+ }
+ case 'LOGIC_FUNCTION': {
+ return (
+ <WorkflowEditActionLogicFunction
key={stepId}
action={stepDefinition.definition}
actionOptions={{
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowStepDetail.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowStepDetail.tsx
index 1d66899b18d..8aa3d524f9c 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowStepDetail.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowStepDetail.tsx
@@ -4,7 +4,7 @@ import {
} from '@/workflow/types/Workflow';
import { getStepDefinitionOrThrow } from '@/workflow/utils/getStepDefinitionOrThrow';
import { WorkflowEditActionAiAgent } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/components/WorkflowEditActionAiAgent';
-import { WorkflowActionLogicFunction } from '@/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowActionLogicFunction';
+import { WorkflowActionCode } from '@/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowActionCode';
import { WorkflowEditActionCreateRecord } from '@/workflow/workflow-steps/workflow-actions/components/WorkflowEditActionCreateRecord';
import { WorkflowEditActionDeleteRecord } from '@/workflow/workflow-steps/workflow-actions/components/WorkflowEditActionDeleteRecord';
import { WorkflowEditActionEmpty } from '@/workflow/workflow-steps/workflow-actions/components/WorkflowEditActionEmpty';
@@ -14,10 +14,11 @@ import { WorkflowEditActionUpsertRecord } from '@/workflow/workflow-steps/workfl
import { WorkflowEditActionDelay } from '@/workflow/workflow-steps/workflow-actions/delay-actions/components/WorkflowEditActionDelay';
import { WorkflowEditActionFilter } from '@/workflow/workflow-steps/workflow-actions/filter-action/components/WorkflowEditActionFilter';
import { WorkflowEditActionFindRecords } from '@/workflow/workflow-steps/workflow-actions/find-records-action/components/WorkflowEditActionFindRecords';
-import { WorkflowEditActionIfElse } from '@/workflow/workflow-steps/workflow-actions/if-else-action/components/WorkflowEditActionIfElse';
import { WorkflowEditActionFormBuilder } from '@/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowEditActionFormBuilder';
import { WorkflowEditActionHttpRequest } from '@/workflow/workflow-steps/workflow-actions/http-request-action/components/WorkflowEditActionHttpRequest';
+import { WorkflowEditActionIfElse } from '@/workflow/workflow-steps/workflow-actions/if-else-action/components/WorkflowEditActionIfElse';
import { WorkflowEditActionIterator } from '@/workflow/workflow-steps/workflow-actions/iterator-action/components/WorkflowEditActionIterator';
+import { WorkflowEditActionLogicFunction } from '@/workflow/workflow-steps/workflow-actions/logic-function-action/components/WorkflowEditActionLogicFunction';
import { WorkflowEditTriggerCronForm } from '@/workflow/workflow-trigger/components/WorkflowEditTriggerCronForm';
import { WorkflowEditTriggerDatabaseEventForm } from '@/workflow/workflow-trigger/components/WorkflowEditTriggerDatabaseEventForm';
import { WorkflowEditTriggerManual } from '@/workflow/workflow-trigger/components/WorkflowEditTriggerManual';
@@ -108,7 +109,16 @@ export const WorkflowStepDetail = ({
switch (stepDefinition.definition.type) {
case 'CODE': {
return (
- <WorkflowActionLogicFunction
+ <WorkflowActionCode
+ key={stepId}
+ action={stepDefinition.definition}
+ actionOptions={props}
+ />
+ );
+ }
+ case 'LOGIC_FUNCTION': {
+ return (
+ <WorkflowEditActionLogicFunction
key={stepId}
action={stepDefinition.definition}
actionOptions={props}
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/hooks/useCreateStep.ts b/packages/twenty-front/src/modules/workflow/workflow-steps/hooks/useCreateStep.ts
index 22758a5636e..5714f70609f 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/hooks/useCreateStep.ts
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/hooks/useCreateStep.ts
@@ -36,6 +36,8 @@ export const useCreateStep = () => {
connectionOptions,
shouldSelectNode = true,
workflowVersionId: providedWorkflowVersionId,
+ logicFunctionId,
+ name,
}: {
newStepType: WorkflowActionType;
parentStepId: string | undefined;
@@ -44,6 +46,8 @@ export const useCreateStep = () => {
connectionOptions?: WorkflowStepConnectionOptions;
shouldSelectNode?: boolean;
workflowVersionId?: string;
+ logicFunctionId?: string;
+ name?: string;
}) => {
if (isLoading === true) {
return;
@@ -65,6 +69,8 @@ export const useCreateStep = () => {
nextStepId,
position,
parentStepConnectionOptions: connectionOptions,
+ logicFunctionId,
+ name,
})
)?.data?.createWorkflowVersionStep;
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowActionLogicFunction.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowActionCode.tsx
similarity index 56%
rename from packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowActionLogicFunction.tsx
rename to packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowActionCode.tsx
index 788361495c3..aef500b3623 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowActionLogicFunction.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowActionCode.tsx
@@ -2,7 +2,7 @@ import { type WorkflowCodeAction } from '@/workflow/types/Workflow';
import { lazy, Suspense } from 'react';
import { RightDrawerSkeletonLoader } from '~/loading/components/RightDrawerSkeletonLoader';
-type WorkflowActionLogicFunctionProps = {
+type WorkflowActionCodeProps = {
action: WorkflowCodeAction;
actionOptions:
| {
@@ -14,35 +14,32 @@ type WorkflowActionLogicFunctionProps = {
};
};
-const WorkflowEditActionLogicFunction = lazy(() =>
+const WorkflowEditActionCode = lazy(() =>
import(
- '@/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionLogicFunction'
+ '@/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionCode'
).then((module) => ({
- default: module.WorkflowEditActionLogicFunction,
+ default: module.WorkflowEditActionCode,
})),
);
-const WorkflowReadonlyActionLogicFunction = lazy(() =>
+const WorkflowReadonlyActionCode = lazy(() =>
import(
- '@/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowReadonlyActionLogicFunction'
+ '@/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowReadonlyActionCode'
).then((module) => ({
- default: module.WorkflowReadonlyActionLogicFunction,
+ default: module.WorkflowReadonlyActionCode,
})),
);
-export const WorkflowActionLogicFunction = ({
+export const WorkflowActionCode = ({
action,
actionOptions,
-}: WorkflowActionLogicFunctionProps) => {
+}: WorkflowActionCodeProps) => {
return (
<Suspense fallback={<RightDrawerSkeletonLoader />}>
{actionOptions.readonly ? (
- <WorkflowReadonlyActionLogicFunction action={action} />
+ <WorkflowReadonlyActionCode action={action} />
) : (
- <WorkflowEditActionLogicFunction
- action={action}
- actionOptions={actionOptions}
- />
+ <WorkflowEditActionCode action={action} actionOptions={actionOptions} />
)}
</Suspense>
);
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowLogicFunctionCodeEditor.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowCodeEditor.tsx
similarity index 93%
rename from packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowLogicFunctionCodeEditor.tsx
rename to packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowCodeEditor.tsx
index 41b390292ba..c01167c26a0 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowLogicFunctionCodeEditor.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowCodeEditor.tsx
@@ -24,7 +24,7 @@ const StyledFullScreenButtonContainer = styled.div`
z-index: 1;
`;
-type WorkflowLogicFunctionCodeEditorProps = {
+type WorkflowCodeEditorProps = {
value?: string;
onChange: (value: string) => void;
onMount: (editor: editor.IStandaloneCodeEditor, monaco: Monaco) => void;
@@ -34,7 +34,7 @@ type WorkflowLogicFunctionCodeEditorProps = {
onEnterFullScreen?: () => void;
};
-export const WorkflowLogicFunctionCodeEditor = ({
+export const WorkflowCodeEditor = ({
value,
onChange,
onMount,
@@ -42,7 +42,7 @@ export const WorkflowLogicFunctionCodeEditor = ({
readonly = false,
fullScreenMode = false,
onEnterFullScreen,
-}: WorkflowLogicFunctionCodeEditorProps) => {
+}: WorkflowCodeEditorProps) => {
const { t } = useLingui();
return (
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionLogicFunction.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionCode.tsx
similarity index 96%
rename from packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionLogicFunction.tsx
rename to packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionCode.tsx
index 995fcf1ffd9..488491af35e 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionLogicFunction.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionCode.tsx
@@ -25,8 +25,8 @@ import { useHotkeysOnFocusedElement } from '@/ui/utilities/hotkey/hooks/useHotke
import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside';
import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue';
import { WorkflowStepBody } from '@/workflow/workflow-steps/components/WorkflowStepBody';
-import { WorkflowEditActionLogicFunctionFields } from '@/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionLogicFunctionFields';
-import { WorkflowLogicFunctionCodeEditor } from '@/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowLogicFunctionCodeEditor';
+import { WorkflowCodeEditor } from '@/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowCodeEditor';
+import { WorkflowEditActionCodeFields } from '@/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionCodeFields';
import { WORKFLOW_LOGIC_FUNCTION_TAB_LIST_COMPONENT_ID } from '@/workflow/workflow-steps/workflow-actions/code-action/constants/WorkflowLogicFunctionTabListComponentId';
import {
type LogicFunctionTestData,
@@ -77,7 +77,7 @@ const StyledFullScreenCodeEditorContainer = styled.div`
min-height: 0;
`;
-type WorkflowEditActionLogicFunctionProps = {
+type WorkflowEditActionCodeProps = {
action: WorkflowCodeAction;
actionOptions:
| {
@@ -93,10 +93,10 @@ type LogicFunctionInputFormData = {
[field: string]: string | LogicFunctionInputFormData;
};
-export const WorkflowEditActionLogicFunction = ({
+export const WorkflowEditActionCode = ({
action,
actionOptions,
-}: WorkflowEditActionLogicFunctionProps) => {
+}: WorkflowEditActionCodeProps) => {
const { t } = useLingui();
const [isFullScreen, setIsFullScreen] = useState(false);
const isMobile = useIsMobile();
@@ -391,7 +391,7 @@ export const WorkflowEditActionLogicFunction = ({
const fullScreenOverlay = renderFullScreenModal(
<div data-globally-prevent-click-outside="true">
- <WorkflowEditActionLogicFunctionFields
+ <WorkflowEditActionCodeFields
functionInput={functionInput}
VariablePicker={WorkflowVariablePicker}
onInputChange={handleInputChange}
@@ -428,13 +428,13 @@ export const WorkflowEditActionLogicFunction = ({
<WorkflowStepBody>
{activeTabId === WorkflowLogicFunctionTabId.CODE && (
<>
- <WorkflowEditActionLogicFunctionFields
+ <WorkflowEditActionCodeFields
functionInput={functionInput}
VariablePicker={WorkflowVariablePicker}
onInputChange={handleInputChange}
readonly={actionOptions.readonly}
/>
- <WorkflowLogicFunctionCodeEditor
+ <WorkflowCodeEditor
value={indexFileContent}
onChange={handleCodeChange}
onMount={handleEditorDidMount}
@@ -452,7 +452,7 @@ export const WorkflowEditActionLogicFunction = ({
)}
{activeTabId === WorkflowLogicFunctionTabId.TEST && (
<>
- <WorkflowEditActionLogicFunctionFields
+ <WorkflowEditActionCodeFields
functionInput={logicFunctionTestData.input}
onInputChange={handleTestInputChange}
readonly={actionOptions.readonly}
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionLogicFunctionFields.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionCodeFields.tsx
similarity index 83%
rename from packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionLogicFunctionFields.tsx
rename to packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionCodeFields.tsx
index 9e493c1d680..8832687c9a9 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionLogicFunctionFields.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionCodeFields.tsx
@@ -3,38 +3,40 @@ import { FormTextFieldInput } from '@/object-record/record-field/ui/form-types/c
import { type VariablePickerComponent } from '@/object-record/record-field/ui/form-types/types/VariablePickerComponent';
import { InputLabel } from '@/ui/input/components/InputLabel';
import { type FunctionInput } from '@/workflow/workflow-steps/workflow-actions/code-action/types/FunctionInput';
-import { t } from '@lingui/core/macro';
import styled from '@emotion/styled';
+import { t } from '@lingui/core/macro';
import { isObject } from '@sniptt/guards';
-const StyledContainer = styled.div`
+const StyledContainer = styled.div<{ fullWidth?: boolean }>`
display: flex;
gap: ${({ theme }) => theme.spacing(3)};
flex-wrap: wrap;
> * {
flex: 1;
- min-width: 200px;
+ min-width: ${({ fullWidth }) => (fullWidth ? '100%' : '200px')};
}
`;
-type WorkflowEditActionLogicFunctionFieldsProps = {
+type WorkflowEditActionCodeFieldsProps = {
functionInput: FunctionInput;
path?: string[];
readonly?: boolean;
onInputChange?: (value: any, path: string[]) => void | Promise<void>;
VariablePicker?: VariablePickerComponent;
+ fullWidth?: boolean;
};
-export const WorkflowEditActionLogicFunctionFields = ({
+export const WorkflowEditActionCodeFields = ({
functionInput,
path = [],
readonly,
onInputChange,
VariablePicker,
-}: WorkflowEditActionLogicFunctionFieldsProps) => {
+ fullWidth,
+}: WorkflowEditActionCodeFieldsProps) => {
return (
- <StyledContainer>
+ <StyledContainer fullWidth={fullWidth}>
{Object.entries(functionInput).map(([inputKey, inputValue]) => {
const currentPath = [...path, inputKey];
const pathKey = currentPath.join('.');
@@ -44,12 +46,13 @@ export const WorkflowEditActionLogicFunctionFields = ({
<div key={pathKey}>
<InputLabel>{inputKey}</InputLabel>
<FormNestedFieldInputContainer>
- <WorkflowEditActionLogicFunctionFields
+ <WorkflowEditActionCodeFields
functionInput={inputValue}
path={currentPath}
readonly={readonly}
onInputChange={onInputChange}
VariablePicker={VariablePicker}
+ fullWidth={fullWidth}
/>
</FormNestedFieldInputContainer>
</div>
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowReadonlyActionLogicFunction.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowReadonlyActionCode.tsx
similarity index 87%
rename from packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowReadonlyActionLogicFunction.tsx
rename to packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowReadonlyActionCode.tsx
index 089681c7a5b..7ad1dc2fbe3 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowReadonlyActionLogicFunction.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowReadonlyActionCode.tsx
@@ -3,28 +3,28 @@ import { useLogicFunctionUpdateFormState } from '@/settings/logic-functions/hook
import { type WorkflowCodeAction } from '@/workflow/types/Workflow';
import { INDEX_FILE_NAME } from '@/logic-functions/constants/IndexFileName';
+import { SOURCE_FOLDER_NAME } from '@/logic-functions/constants/SourceFolderName';
import { WorkflowStepBody } from '@/workflow/workflow-steps/components/WorkflowStepBody';
-import { WorkflowEditActionLogicFunctionFields } from '@/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionLogicFunctionFields';
+import { WorkflowEditActionCodeFields } from '@/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionCodeFields';
import { getWrongExportedFunctionMarkers } from '@/workflow/workflow-steps/workflow-actions/code-action/utils/getWrongExportedFunctionMarkers';
import styled from '@emotion/styled';
import { type Monaco } from '@monaco-editor/react';
import { type editor } from 'monaco-editor';
import { AutoTypings } from 'monaco-editor-auto-typings';
import { CodeEditor } from 'twenty-ui/input';
-import { SOURCE_FOLDER_NAME } from '@/logic-functions/constants/SourceFolderName';
const StyledCodeEditorContainer = styled.div`
display: flex;
flex-direction: column;
`;
-type WorkflowReadonlyActionLogicFunctionProps = {
+type WorkflowReadonlyActionCodeProps = {
action: WorkflowCodeAction;
};
-export const WorkflowReadonlyActionLogicFunction = ({
+export const WorkflowReadonlyActionCode = ({
action,
-}: WorkflowReadonlyActionLogicFunctionProps) => {
+}: WorkflowReadonlyActionCodeProps) => {
const logicFunctionId = action.settings.input.logicFunctionId;
const logicFunctionVersion = action.settings.input.logicFunctionVersion;
@@ -63,7 +63,7 @@ export const WorkflowReadonlyActionLogicFunction = ({
return (
<>
<WorkflowStepBody>
- <WorkflowEditActionLogicFunctionFields
+ <WorkflowEditActionCodeFields
functionInput={action.settings.input.logicFunctionInput}
readonly
/>
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/__stories__/WorkflowEditActionLogicFunction.stories.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/__stories__/WorkflowEditActionCode.stories.tsx
similarity index 94%
rename from packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/__stories__/WorkflowEditActionLogicFunction.stories.tsx
rename to packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/__stories__/WorkflowEditActionCode.stories.tsx
index f7ee68ea6d5..21c108d4a81 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/__stories__/WorkflowEditActionLogicFunction.stories.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/code-action/components/__stories__/WorkflowEditActionCode.stories.tsx
@@ -1,5 +1,5 @@
import { type WorkflowCodeAction } from '@/workflow/types/Workflow';
-import { WorkflowEditActionLogicFunction } from '@/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionLogicFunction';
+import { WorkflowEditActionCode } from '@/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionCode';
import { type Meta, type StoryObj } from '@storybook/react-vite';
import { graphql, HttpResponse } from 'msw';
import { fn } from 'storybook/test';
@@ -75,9 +75,9 @@ const CONFIGURED_ACTION: WorkflowCodeAction = {
},
};
-const meta: Meta<typeof WorkflowEditActionLogicFunction> = {
+const meta: Meta<typeof WorkflowEditActionCode> = {
title: 'Modules/Workflow/Actions/Code/EditAction',
- component: WorkflowEditActionLogicFunction,
+ component: WorkflowEditActionCode,
parameters: {
msw: {
handlers: [
@@ -138,7 +138,7 @@ const meta: Meta<typeof WorkflowEditActionLogicFunction> = {
export default meta;
-type Story = StoryObj<typeof WorkflowEditActionLogicFunction>;
+type Story = StoryObj<typeof WorkflowEditActionCode>;
export const Default: Story = {
args: {
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowFormEmptyMessage.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/WorkflowMessage.tsx
similarity index 75%
rename from packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowFormEmptyMessage.tsx
rename to packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/WorkflowMessage.tsx
index 098690ccb11..74cad1de185 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowFormEmptyMessage.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/WorkflowMessage.tsx
@@ -2,7 +2,6 @@ import { FormFieldInputContainer } from '@/object-record/record-field/ui/form-ty
import { FormFieldInputInnerContainer } from '@/object-record/record-field/ui/form-types/components/FormFieldInputInnerContainer';
import { FormFieldInputRowContainer } from '@/object-record/record-field/ui/form-types/components/FormFieldInputRowContainer';
import styled from '@emotion/styled';
-import { useLingui } from '@lingui/react/macro';
const StyledMessageContainer = styled.div`
padding-bottom: ${({ theme }) => theme.spacing(4)};
@@ -40,24 +39,28 @@ const StyledFieldContainer = styled.div`
width: 100%;
`;
-export const WorkflowFormEmptyMessage = () => {
- const { t } = useLingui();
-
+export const WorkflowMessage = ({
+ title,
+ description,
+}: {
+ title: string;
+ description: string;
+}) => {
return (
<StyledMessageContainer>
<FormFieldInputContainer>
<FormFieldInputRowContainer multiline maxHeight={124}>
<FormFieldInputInnerContainer
- formFieldInputInstanceId="empty-form-message"
+ formFieldInputInstanceId="workflow-message"
hasRightElement={false}
>
<StyledFieldContainer>
<StyledMessageContentContainer>
- <StyledMessageTitle data-testid="empty-form-message-title">
- {t`Add inputs to your form`}
+ <StyledMessageTitle data-testid="workflow-message-title">
+ {title}
</StyledMessageTitle>
- <StyledMessageDescription data-testid="empty-form-message-description">
- {t`Click on "Add Field" below to add the first input to your form. The form will pop up on the user's screen when the workflow is launched from a manual trigger. For other types of triggers, it will be displayed in the Workflow run record page.`}
+ <StyledMessageDescription data-testid="workflow-message-description">
+ {description}
</StyledMessageDescription>
</StyledMessageContentContainer>
</StyledFieldContainer>
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/__stories__/WorkflowFormEmptyMessage.stories.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/__stories__/WorkflowMessage.stories.tsx
similarity index 57%
rename from packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/__stories__/WorkflowFormEmptyMessage.stories.tsx
rename to packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/__stories__/WorkflowMessage.stories.tsx
index 5e6cf4e72dd..8d2e5c24044 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/__stories__/WorkflowFormEmptyMessage.stories.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/components/__stories__/WorkflowMessage.stories.tsx
@@ -1,10 +1,10 @@
-import { WorkflowFormEmptyMessage } from '@/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowFormEmptyMessage';
+import { WorkflowMessage } from '@/workflow/workflow-steps/workflow-actions/components/WorkflowMessage';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { expect, within } from 'storybook/test';
-const meta: Meta<typeof WorkflowFormEmptyMessage> = {
- title: 'Modules/Workflow/Actions/Form/WorkflowFormEmptyMessage',
- component: WorkflowFormEmptyMessage,
+const meta: Meta<typeof WorkflowMessage> = {
+ title: 'Modules/Workflow/Actions/Form/WorkflowMessage',
+ component: WorkflowMessage,
parameters: {
layout: 'centered',
},
@@ -12,17 +12,17 @@ const meta: Meta<typeof WorkflowFormEmptyMessage> = {
};
export default meta;
-type Story = StoryObj<typeof WorkflowFormEmptyMessage>;
+type Story = StoryObj<typeof WorkflowMessage>;
export const Default: Story = {
args: {},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const messageTitleContainer = await canvas.findByTestId(
- 'empty-form-message-title',
+ 'workflow-message-title',
);
const messageDescriptionContainer = await canvas.findByTestId(
- 'empty-form-message-description',
+ 'workflow-message-description',
);
expect(messageTitleContainer).toBeVisible();
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowEditActionFormBuilder.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowEditActionFormBuilder.tsx
index 46edca03876..9e1551a8406 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowEditActionFormBuilder.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowEditActionFormBuilder.tsx
@@ -8,8 +8,8 @@ import { DraggableList } from '@/ui/layout/draggable-list/components/DraggableLi
import { type WorkflowFormAction } from '@/workflow/types/Workflow';
import { WorkflowStepBody } from '@/workflow/workflow-steps/components/WorkflowStepBody';
import { WorkflowStepFooter } from '@/workflow/workflow-steps/components/WorkflowStepFooter';
+import { WorkflowMessage } from '@/workflow/workflow-steps/workflow-actions/components/WorkflowMessage';
import { WorkflowEditActionFormFieldSettings } from '@/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowEditActionFormFieldSettings';
-import { WorkflowFormEmptyMessage } from '@/workflow/workflow-steps/workflow-actions/form-action/components/WorkflowFormEmptyMessage';
import { type WorkflowFormActionField } from '@/workflow/workflow-steps/workflow-actions/form-action/types/WorkflowFormActionField';
import { getDefaultFormFieldSettings } from '@/workflow/workflow-steps/workflow-actions/form-action/utils/getDefaultFormFieldSettings';
import { css, useTheme } from '@emotion/react';
@@ -214,7 +214,10 @@ export const WorkflowEditActionFormBuilder = ({
<>
<StyledWorkflowStepBody>
{formData.length === 0 && (
- <WorkflowFormEmptyMessage data-testid="empty-form-message" />
+ <WorkflowMessage
+ title={t`Add inputs to your form`}
+ description={t`Click on "Add Field" below to add the first input to your form. The form will pop up on the user's screen when the workflow is launched from a manual trigger. For other types of triggers, it will be displayed in the Workflow run record page.`}
+ />
)}
<DraggableList
onDragEnd={handleDragEnd}
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/__stories__/WorkflowEditActionFormBuilder.stories.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/__stories__/WorkflowEditActionFormBuilder.stories.tsx
index dd4de399625..e12041068ba 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/__stories__/WorkflowEditActionFormBuilder.stories.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/form-action/components/__stories__/WorkflowEditActionFormBuilder.stories.tsx
@@ -180,7 +180,7 @@ export const EmptyForm: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const messageContainer = await canvas.findByTestId(
- 'empty-form-message-title',
+ 'workflow-message-title',
);
expect(messageContainer).toBeVisible();
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/logic-function-action/components/WorkflowEditActionLogicFunction.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/logic-function-action/components/WorkflowEditActionLogicFunction.tsx
new file mode 100644
index 00000000000..a3d140d5827
--- /dev/null
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/logic-function-action/components/WorkflowEditActionLogicFunction.tsx
@@ -0,0 +1,131 @@
+import { getDefaultFunctionInputFromInputSchema } from '@/logic-functions/utils/getDefaultFunctionInputFromInputSchema';
+import { mergeDefaultFunctionInputAndFunctionInput } from '@/logic-functions/utils/mergeDefaultFunctionInputAndFunctionInput';
+import { useGetOneLogicFunction } from '@/settings/logic-functions/hooks/useGetOneLogicFunction';
+import { type WorkflowLogicFunctionAction } from '@/workflow/types/Workflow';
+import { WorkflowStepBody } from '@/workflow/workflow-steps/components/WorkflowStepBody';
+import { WorkflowStepFooter } from '@/workflow/workflow-steps/components/WorkflowStepFooter';
+import { WorkflowEditActionCodeFields } from '@/workflow/workflow-steps/workflow-actions/code-action/components/WorkflowEditActionCodeFields';
+import { setNestedValue } from '@/workflow/workflow-steps/workflow-actions/code-action/utils/setNestedValue';
+import { WorkflowMessage } from '@/workflow/workflow-steps/workflow-actions/components/WorkflowMessage';
+import { WorkflowVariablePicker } from '@/workflow/workflow-variables/components/WorkflowVariablePicker';
+import styled from '@emotion/styled';
+import { useLingui } from '@lingui/react/macro';
+import { isObject } from '@sniptt/guards';
+import { useMemo } from 'react';
+import { isDefined } from 'twenty-shared/utils';
+import { useDebouncedCallback } from 'use-debounce';
+
+const StyledContainer = styled.div`
+ display: flex;
+ flex-direction: column;
+ gap: ${({ theme }) => theme.spacing(4)};
+`;
+
+type WorkflowEditActionLogicFunctionProps = {
+ action: WorkflowLogicFunctionAction;
+ actionOptions:
+ | {
+ readonly: true;
+ }
+ | {
+ readonly?: false;
+ onActionUpdate: (action: WorkflowLogicFunctionAction) => void;
+ };
+};
+
+export const WorkflowEditActionLogicFunction = ({
+ action,
+ actionOptions,
+}: WorkflowEditActionLogicFunctionProps) => {
+ const { t } = useLingui();
+
+ const logicFunctionId = action.settings.input.logicFunctionId;
+
+ const { logicFunction, loading } = useGetOneLogicFunction({
+ id: logicFunctionId,
+ });
+
+ const functionInput = useMemo(() => {
+ const toolInputSchema = logicFunction?.toolInputSchema;
+
+ if (!isDefined(toolInputSchema)) {
+ return action.settings.input.logicFunctionInput ?? {};
+ }
+
+ const schemaArray = Array.isArray(toolInputSchema)
+ ? toolInputSchema
+ : [toolInputSchema];
+
+ const defaultInput = getDefaultFunctionInputFromInputSchema(schemaArray)[0];
+
+ if (!isObject(defaultInput)) {
+ return action.settings.input.logicFunctionInput ?? {};
+ }
+
+ return mergeDefaultFunctionInputAndFunctionInput({
+ newInput: defaultInput,
+ oldInput: action.settings.input.logicFunctionInput ?? {},
+ });
+ }, [
+ logicFunction?.toolInputSchema,
+ action.settings.input.logicFunctionInput,
+ ]);
+
+ const updateAction = useDebouncedCallback(
+ (actionUpdate: Partial<WorkflowLogicFunctionAction>) => {
+ if (actionOptions.readonly === true) {
+ return;
+ }
+
+ actionOptions.onActionUpdate({
+ ...action,
+ ...actionUpdate,
+ });
+ },
+ 500,
+ );
+
+ const handleInputChange = (value: unknown, path: string[]) => {
+ const updatedFunctionInput = setNestedValue(functionInput, path, value);
+
+ updateAction({
+ settings: {
+ ...action.settings,
+ input: {
+ ...action.settings.input,
+ logicFunctionInput: updatedFunctionInput,
+ },
+ },
+ });
+ };
+
+ if (loading) {
+ return null;
+ }
+
+ const hasInputFields = Object.keys(functionInput).length > 0;
+
+ return (
+ <>
+ <WorkflowStepBody>
+ <StyledContainer>
+ {hasInputFields ? (
+ <WorkflowEditActionCodeFields
+ functionInput={functionInput}
+ readonly={actionOptions.readonly}
+ onInputChange={handleInputChange}
+ VariablePicker={WorkflowVariablePicker}
+ fullWidth
+ />
+ ) : (
+ <WorkflowMessage
+ title={t`No input fields for this action`}
+ description={t`You can see the function logic in your application settings.`}
+ />
+ )}
+ </StyledContainer>
+ </WorkflowStepBody>
+ {!actionOptions.readonly && <WorkflowStepFooter stepId={action.id} />}
+ </>
+ );
+};
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/utils/getActionHeaderTypeOrThrow.ts b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/utils/getActionHeaderTypeOrThrow.ts
index 28b9d38b19b..31f2d30d038 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/utils/getActionHeaderTypeOrThrow.ts
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/utils/getActionHeaderTypeOrThrow.ts
@@ -27,5 +27,9 @@ export const getActionHeaderTypeOrThrow = (actionType: WorkflowActionType) => {
return msg`AI`;
}
+ if (actionType === 'LOGIC_FUNCTION') {
+ return msg`Application`;
+ }
+
return msg`Action`;
};
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/utils/getActionIcon.ts b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/utils/getActionIcon.ts
index 6dfb95e32d0..f2159449b3d 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/utils/getActionIcon.ts
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/utils/getActionIcon.ts
@@ -19,6 +19,8 @@ export const getActionIcon = (actionType: WorkflowActionType) => {
case 'HTTP_REQUEST':
case 'SEND_EMAIL':
return CORE_ACTIONS.find((item) => item.type === actionType)?.icon;
+ case 'LOGIC_FUNCTION':
+ return 'IconFunction';
case 'FORM':
return HUMAN_INPUT_ACTIONS.find((item) => item.type === actionType)?.icon;
case 'ITERATOR':
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/utils/getActionIconColorOrThrow.ts b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/utils/getActionIconColorOrThrow.ts
index 8f9d4c57d95..5eb21311bb8 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/utils/getActionIconColorOrThrow.ts
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/workflow-actions/utils/getActionIconColorOrThrow.ts
@@ -11,6 +11,7 @@ export const getActionIconColorOrThrow = ({
}) => {
switch (actionType) {
case 'CODE':
+ case 'LOGIC_FUNCTION':
case 'HTTP_REQUEST':
case 'SEND_EMAIL':
return theme.color.red;
diff --git a/packages/twenty-server/src/engine/core-modules/workflow/dtos/create-workflow-version-step-input.dto.ts b/packages/twenty-server/src/engine/core-modules/workflow/dtos/create-workflow-version-step-input.dto.ts
index 51758dc6302..6e4d15e763c 100644
--- a/packages/twenty-server/src/engine/core-modules/workflow/dtos/create-workflow-version-step-input.dto.ts
+++ b/packages/twenty-server/src/engine/core-modules/workflow/dtos/create-workflow-version-step-input.dto.ts
@@ -51,4 +51,16 @@ export class CreateWorkflowVersionStepInput {
nullable: true,
})
id?: string;
+
+ @Field(() => String, {
+ description: 'Step name',
+ nullable: true,
+ })
+ name?: string;
+
+ @Field(() => UUIDScalarType, {
+ description: 'Logic function ID',
+ nullable: true,
+ })
+ logicFunctionId?: string;
}
diff --git a/packages/twenty-server/src/modules/workflow/workflow-builder/workflow-version-edge/workflow-version-edge.workspace-service.ts b/packages/twenty-server/src/modules/workflow/workflow-builder/workflow-version-edge/workflow-version-edge.workspace-service.ts
index 94b3a8fbf9d..acff5967d56 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-builder/workflow-version-edge/workflow-version-edge.workspace-service.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-builder/workflow-version-edge/workflow-version-edge.workspace-service.ts
@@ -535,7 +535,7 @@ export class WorkflowVersionEdgeWorkspaceService {
input: {
...sourceStep.settings.input,
initialLoopStepIds: currentInitialLoopStepIds.filter(
- (id) => id !== target,
+ (id: string) => id !== target,
),
},
},
diff --git a/packages/twenty-server/src/modules/workflow/workflow-builder/workflow-version-step/utils/insert-step.ts b/packages/twenty-server/src/modules/workflow/workflow-builder/workflow-version-step/utils/insert-step.ts
index 6eac5226606..14d42edc1e1 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-builder/workflow-version-step/utils/insert-step.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-builder/workflow-version-step/utils/insert-step.ts
@@ -198,7 +198,7 @@ const updateStepsWithOptions = ({
initialLoopStepIds: [
...new Set([
...(step.settings.input.initialLoopStepIds?.filter(
- (id) => id !== nextStepId,
+ (id: string) => id !== nextStepId,
) || []),
insertedStepId,
]),
diff --git a/packages/twenty-server/src/modules/workflow/workflow-builder/workflow-version-step/workflow-version-step-creation.workspace-service.ts b/packages/twenty-server/src/modules/workflow/workflow-builder/workflow-version-step/workflow-version-step-creation.workspace-service.ts
index a8485f9d044..49c4eb77383 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-builder/workflow-version-step/workflow-version-step-creation.workspace-service.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-builder/workflow-version-step/workflow-version-step-creation.workspace-service.ts
@@ -11,8 +11,8 @@ import {
import { computeWorkflowVersionStepChanges } from 'src/modules/workflow/workflow-builder/utils/compute-workflow-version-step-updates.util';
import { WorkflowSchemaWorkspaceService } from 'src/modules/workflow/workflow-builder/workflow-schema/workflow-schema.workspace-service';
import { insertStep } from 'src/modules/workflow/workflow-builder/workflow-version-step/utils/insert-step';
-import { WorkflowVersionStepOperationsWorkspaceService } from 'src/modules/workflow/workflow-builder/workflow-version-step/workflow-version-step-operations.workspace-service';
import { WorkflowVersionStepHelpersWorkspaceService } from 'src/modules/workflow/workflow-builder/workflow-version-step/workflow-version-step-helpers.workspace-service';
+import { WorkflowVersionStepOperationsWorkspaceService } from 'src/modules/workflow/workflow-builder/workflow-version-step/workflow-version-step-operations.workspace-service';
import { type WorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';
@Injectable()
@@ -38,6 +38,8 @@ export class WorkflowVersionStepCreationWorkspaceService {
position,
parentStepConnectionOptions,
id,
+ logicFunctionId,
+ name,
} = input;
const workflowVersion =
@@ -59,6 +61,8 @@ export class WorkflowVersionStepCreationWorkspaceService {
position,
workflowVersionId,
id,
+ logicFunctionId,
+ name,
},
);
diff --git a/packages/twenty-server/src/modules/workflow/workflow-builder/workflow-version-step/workflow-version-step-operations.workspace-service.ts b/packages/twenty-server/src/modules/workflow/workflow-builder/workflow-version-step/workflow-version-step-operations.workspace-service.ts
index 1219d566e2a..f8049437f5e 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-builder/workflow-version-step/workflow-version-step-operations.workspace-service.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-builder/workflow-version-step/workflow-version-step-operations.workspace-service.ts
@@ -20,9 +20,9 @@ import { type WorkflowStepPositionInput } from 'src/engine/core-modules/workflow
import { AiAgentRoleService } from 'src/engine/metadata-modules/ai/ai-agent-role/ai-agent-role.service';
import { AgentEntity } from 'src/engine/metadata-modules/ai/ai-agent/entities/agent.entity';
import { DEFAULT_SMART_MODEL } from 'src/engine/metadata-modules/ai/ai-models/constants/ai-models.const';
+import { LogicFunctionService } from 'src/engine/metadata-modules/logic-function/logic-function.service';
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import { RoleTargetEntity } from 'src/engine/metadata-modules/role-target/role-target.entity';
-import { LogicFunctionService } from 'src/engine/metadata-modules/logic-function/logic-function.service';
import { GlobalWorkspaceOrmManager } from 'src/engine/twenty-orm/global-workspace-datasource/global-workspace-orm.manager';
import { buildSystemAuthContext } from 'src/engine/twenty-orm/utils/build-system-auth-context.util';
import { WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';
@@ -135,12 +135,16 @@ export class WorkflowVersionStepOperationsWorkspaceService {
workflowVersionId,
position,
id,
+ logicFunctionId,
+ name,
}: {
type: WorkflowActionType;
workspaceId: string;
workflowVersionId: string;
position?: WorkflowStepPositionInput;
id?: string;
+ logicFunctionId?: string;
+ name?: string;
}): Promise<{
builtStep: WorkflowAction;
additionalCreatedSteps?: WorkflowAction[];
@@ -195,6 +199,29 @@ export class WorkflowVersionStepOperationsWorkspaceService {
},
};
}
+ case WorkflowActionType.LOGIC_FUNCTION: {
+ if (!logicFunctionId) {
+ throw new WorkflowVersionStepException(
+ 'Logic function ID is required for LOGIC_FUNCTION step',
+ WorkflowVersionStepExceptionCode.INVALID_REQUEST,
+ );
+ }
+
+ return {
+ builtStep: {
+ ...baseStep,
+ name: name ?? 'Logic Function',
+ type: WorkflowActionType.LOGIC_FUNCTION,
+ settings: {
+ ...BASE_STEP_DEFINITION,
+ input: {
+ logicFunctionId,
+ logicFunctionInput: {},
+ },
+ },
+ },
+ };
+ }
case WorkflowActionType.SEND_EMAIL: {
return {
builtStep: {
diff --git a/packages/twenty-server/src/modules/workflow/workflow-builder/workflow-version/workflow-version.workspace-service.ts b/packages/twenty-server/src/modules/workflow/workflow-builder/workflow-version/workflow-version.workspace-service.ts
index 1a87c4b9321..8e1e4bb3eea 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-builder/workflow-version/workflow-version.workspace-service.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-builder/workflow-version/workflow-version.workspace-service.ts
@@ -288,7 +288,7 @@ export class WorkflowVersionWorkspaceService {
...remappedStep.settings.input,
initialLoopStepIds:
source.settings.input.initialLoopStepIds.map(
- (oldId) => oldToNewIdMap.get(oldId) ?? oldId,
+ (oldId: string) => oldToNewIdMap.get(oldId) ?? oldId,
),
},
};
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/factories/workflow-action.factory.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/factories/workflow-action.factory.ts
index 10939d5e786..227a40b61ab 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-executor/factories/workflow-action.factory.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/factories/workflow-action.factory.ts
@@ -14,6 +14,7 @@ import { FilterWorkflowAction } from 'src/modules/workflow/workflow-executor/wor
import { FormWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/form/form.workflow-action';
import { IfElseWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/if-else/if-else.workflow-action';
import { IteratorWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/iterator/iterator.workflow-action';
+import { LogicFunctionWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/logic-function/logic-function.workflow-action';
import { CreateRecordWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/create-record.workflow-action';
import { DeleteRecordWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/delete-record.workflow-action';
import { FindRecordsWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/find-records.workflow-action';
@@ -26,6 +27,7 @@ import { WorkflowActionType } from 'src/modules/workflow/workflow-executor/workf
export class WorkflowActionFactory {
constructor(
private readonly codeWorkflowAction: CodeWorkflowAction,
+ private readonly logicFunctionWorkflowAction: LogicFunctionWorkflowAction,
private readonly createRecordWorkflowAction: CreateRecordWorkflowAction,
private readonly upsertRecordWorkflowAction: UpsertRecordWorkflowAction,
private readonly updateRecordWorkflowAction: UpdateRecordWorkflowAction,
@@ -45,6 +47,8 @@ export class WorkflowActionFactory {
switch (stepType) {
case WorkflowActionType.CODE:
return this.codeWorkflowAction;
+ case WorkflowActionType.LOGIC_FUNCTION:
+ return this.logicFunctionWorkflowAction;
case WorkflowActionType.SEND_EMAIL:
return this.toolExecutorWorkflowAction;
case WorkflowActionType.CREATE_RECORD:
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/logic-function/guards/is-workflow-logic-function-action.guard.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/logic-function/guards/is-workflow-logic-function-action.guard.ts
new file mode 100644
index 00000000000..a65db5f641b
--- /dev/null
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/logic-function/guards/is-workflow-logic-function-action.guard.ts
@@ -0,0 +1,10 @@
+import {
+ type WorkflowAction,
+ WorkflowActionType,
+} from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';
+
+export const isWorkflowLogicFunctionAction = (
+ action: WorkflowAction,
+): action is WorkflowAction & { type: WorkflowActionType.LOGIC_FUNCTION } => {
+ return action.type === WorkflowActionType.LOGIC_FUNCTION;
+};
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/logic-function/logic-function-action.module.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/logic-function/logic-function-action.module.ts
new file mode 100644
index 00000000000..c00d83a0755
--- /dev/null
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/logic-function/logic-function-action.module.ts
@@ -0,0 +1,12 @@
+import { Module } from '@nestjs/common';
+
+import { WorkspaceManyOrAllFlatEntityMapsCacheModule } from 'src/engine/metadata-modules/flat-entity/services/workspace-many-or-all-flat-entity-maps-cache.module';
+import { LogicFunctionModule } from 'src/engine/metadata-modules/logic-function/logic-function.module';
+import { LogicFunctionWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/logic-function/logic-function.workflow-action';
+
+@Module({
+ imports: [LogicFunctionModule, WorkspaceManyOrAllFlatEntityMapsCacheModule],
+ providers: [LogicFunctionWorkflowAction],
+ exports: [LogicFunctionWorkflowAction],
+})
+export class LogicFunctionActionModule {}
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/logic-function/logic-function.workflow-action.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/logic-function/logic-function.workflow-action.ts
new file mode 100644
index 00000000000..fdf4aaa8775
--- /dev/null
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/logic-function/logic-function.workflow-action.ts
@@ -0,0 +1,88 @@
+import { Injectable } from '@nestjs/common';
+
+import { resolveInput } from 'twenty-shared/utils';
+
+import { type WorkflowAction } from 'src/modules/workflow/workflow-executor/interfaces/workflow-action.interface';
+
+import { WorkspaceManyOrAllFlatEntityMapsCacheService } from 'src/engine/metadata-modules/flat-entity/services/workspace-many-or-all-flat-entity-maps-cache.service';
+import { LogicFunctionService } from 'src/engine/metadata-modules/logic-function/logic-function.service';
+import {
+ WorkflowStepExecutorException,
+ WorkflowStepExecutorExceptionCode,
+} from 'src/modules/workflow/workflow-executor/exceptions/workflow-step-executor.exception';
+import { type WorkflowActionInput } from 'src/modules/workflow/workflow-executor/types/workflow-action-input';
+import { type WorkflowActionOutput } from 'src/modules/workflow/workflow-executor/types/workflow-action-output.type';
+import { findStepOrThrow } from 'src/modules/workflow/workflow-executor/utils/find-step-or-throw.util';
+import { isWorkflowLogicFunctionAction } from 'src/modules/workflow/workflow-executor/workflow-actions/logic-function/guards/is-workflow-logic-function-action.guard';
+import { WorkflowLogicFunctionActionInput } from 'src/modules/workflow/workflow-executor/workflow-actions/logic-function/types/workflow-logic-function-action-input.type';
+
+@Injectable()
+export class LogicFunctionWorkflowAction implements WorkflowAction {
+ constructor(
+ private readonly logicFunctionService: LogicFunctionService,
+ private readonly flatEntityMapsCacheService: WorkspaceManyOrAllFlatEntityMapsCacheService,
+ ) {}
+
+ async execute({
+ currentStepId,
+ steps,
+ context,
+ runInfo,
+ }: WorkflowActionInput): Promise<WorkflowActionOutput> {
+ const step = findStepOrThrow({
+ stepId: currentStepId,
+ steps,
+ });
+
+ if (!isWorkflowLogicFunctionAction(step)) {
+ throw new WorkflowStepExecutorException(
+ 'Step is not a logic function action',
+ WorkflowStepExecutorExceptionCode.INVALID_STEP_TYPE,
+ );
+ }
+
+ const workflowActionInput = resolveInput(
+ step.settings.input,
+ context,
+ ) as WorkflowLogicFunctionActionInput;
+
+ try {
+ const { workspaceId } = runInfo;
+
+ const { flatLogicFunctionMaps } =
+ await this.flatEntityMapsCacheService.getOrRecomputeManyOrAllFlatEntityMaps(
+ {
+ workspaceId,
+ flatMapsKeys: ['flatLogicFunctionMaps'],
+ },
+ );
+
+ const logicFunction =
+ flatLogicFunctionMaps.byId[workflowActionInput.logicFunctionId];
+
+ if (!logicFunction) {
+ throw new WorkflowStepExecutorException(
+ `Logic function with id ${workflowActionInput.logicFunctionId} not found`,
+ WorkflowStepExecutorExceptionCode.INVALID_STEP_TYPE,
+ );
+ }
+
+ const version = logicFunction.latestVersion ?? 'draft';
+
+ const result = await this.logicFunctionService.executeOneLogicFunction({
+ id: workflowActionInput.logicFunctionId,
+ workspaceId,
+ payload: workflowActionInput.logicFunctionInput,
+ version,
+ });
+
+ if (result.error) {
+ return { error: result.error.errorMessage };
+ }
+
+ return { result: result.data || {} };
+ } catch (error) {
+ return { error: error.message };
+ }
+ }
+}
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/logic-function/types/workflow-logic-function-action-input.type.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/logic-function/types/workflow-logic-function-action-input.type.ts
new file mode 100644
index 00000000000..1af28ef3ed0
--- /dev/null
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/logic-function/types/workflow-logic-function-action-input.type.ts
@@ -0,0 +1,7 @@
+export type WorkflowLogicFunctionActionInput = {
+ logicFunctionId: string;
+ logicFunctionInput: {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ [key: string]: any;
+ };
+};
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/logic-function/types/workflow-logic-function-action-settings.type.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/logic-function/types/workflow-logic-function-action-settings.type.ts
new file mode 100644
index 00000000000..1e055648dd8
--- /dev/null
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/logic-function/types/workflow-logic-function-action-settings.type.ts
@@ -0,0 +1,6 @@
+import { type WorkflowLogicFunctionActionInput } from 'src/modules/workflow/workflow-executor/workflow-actions/logic-function/types/workflow-logic-function-action-input.type';
+import { type BaseWorkflowActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-settings.type';
+
+export type WorkflowLogicFunctionActionSettings = BaseWorkflowActionSettings & {
+ input: WorkflowLogicFunctionActionInput;
+};
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-type.enum.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-type.enum.ts
index 5e3b7f41070..79716ffb28b 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-type.enum.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action-type.enum.ts
@@ -1,5 +1,6 @@
export enum WorkflowActionType {
CODE = 'CODE',
+ LOGIC_FUNCTION = 'LOGIC_FUNCTION',
SEND_EMAIL = 'SEND_EMAIL',
CREATE_RECORD = 'CREATE_RECORD',
UPDATE_RECORD = 'UPDATE_RECORD',
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type.ts
index c819ed14f7c..fc755f4c451 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type.ts
@@ -6,6 +6,7 @@ import { type WorkflowFormActionSettings } from 'src/modules/workflow/workflow-e
import { type WorkflowHttpRequestActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/http-request/types/workflow-http-request-action-settings.type';
import { type WorkflowIfElseActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/if-else/types/workflow-if-else-action-settings.type';
import { type WorkflowIteratorActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/iterator/types/workflow-iterator-action-settings.type';
+import { type WorkflowLogicFunctionActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/logic-function/types/workflow-logic-function-action-settings.type';
import { type WorkflowSendEmailActionSettings } from 'src/modules/workflow/workflow-executor/workflow-actions/mail-sender/types/workflow-send-email-action-settings.type';
import {
type WorkflowCreateRecordActionSettings,
@@ -40,6 +41,11 @@ export type WorkflowCodeAction = BaseWorkflowAction & {
settings: WorkflowCodeActionSettings;
};
+export type WorkflowLogicFunctionAction = BaseWorkflowAction & {
+ type: WorkflowActionType.LOGIC_FUNCTION;
+ settings: WorkflowLogicFunctionActionSettings;
+};
+
export type WorkflowSendEmailAction = BaseWorkflowAction & {
type: WorkflowActionType.SEND_EMAIL;
settings: WorkflowSendEmailActionSettings;
@@ -111,6 +117,7 @@ export type WorkflowDelayAction = BaseWorkflowAction & {
export type WorkflowAction =
| WorkflowCodeAction
+ | WorkflowLogicFunctionAction
| WorkflowSendEmailAction
| WorkflowCreateRecordAction
| WorkflowUpdateRecordAction
diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-executor.module.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-executor.module.ts
index c12cf6583f2..ab6bc242f3a 100644
--- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-executor.module.ts
+++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-executor.module.ts
@@ -13,6 +13,7 @@ import { FilterActionModule } from 'src/modules/workflow/workflow-executor/workf
import { FormActionModule } from 'src/modules/workflow/workflow-executor/workflow-actions/form/form-action.module';
import { IfElseActionModule } from 'src/modules/workflow/workflow-executor/workflow-actions/if-else/if-else-action.module';
import { IteratorActionModule } from 'src/modules/workflow/workflow-executor/workflow-actions/iterator/iterator-action.module';
+import { LogicFunctionActionModule } from 'src/modules/workflow/workflow-executor/workflow-actions/logic-function/logic-function-action.module';
import { RecordCRUDActionModule } from 'src/modules/workflow/workflow-executor/workflow-actions/record-crud/record-crud-action.module';
import { ToolExecutorWorkflowAction } from 'src/modules/workflow/workflow-executor/workflow-actions/tool-executor-workflow-action';
import { WorkflowExecutorWorkspaceService } from 'src/modules/workflow/workflow-executor/workspace-services/workflow-executor.workspace-service';
@@ -23,6 +24,7 @@ import { WorkflowRunModule } from 'src/modules/workflow/workflow-runner/workflow
WorkflowCommonModule,
WorkflowRunModule,
CodeActionModule,
+ LogicFunctionActionModule,
DelayActionModule,
RecordCRUDActionModule,
FormActionModule,
diff --git a/packages/twenty-shared/src/workflow/index.ts b/packages/twenty-shared/src/workflow/index.ts
index be58f0d7fe9..ae7690e3bbd 100644
--- a/packages/twenty-shared/src/workflow/index.ts
+++ b/packages/twenty-shared/src/workflow/index.ts
@@ -41,6 +41,8 @@ export {
} from './schemas/if-else-action-settings-schema';
export { workflowIteratorActionSchema } from './schemas/iterator-action-schema';
export { workflowIteratorActionSettingsSchema } from './schemas/iterator-action-settings-schema';
+export { workflowLogicFunctionActionSchema } from './schemas/logic-function-action-schema';
+export { workflowLogicFunctionActionSettingsSchema } from './schemas/logic-function-action-settings-schema';
export { workflowManualTriggerSchema } from './schemas/manual-trigger-schema';
export { objectRecordSchema } from './schemas/object-record-schema';
export { workflowSendEmailActionSchema } from './schemas/send-email-action-schema';
diff --git a/packages/twenty-shared/src/workflow/schemas/logic-function-action-schema.ts b/packages/twenty-shared/src/workflow/schemas/logic-function-action-schema.ts
new file mode 100644
index 00000000000..b73ed0d615e
--- /dev/null
+++ b/packages/twenty-shared/src/workflow/schemas/logic-function-action-schema.ts
@@ -0,0 +1,9 @@
+import { z } from 'zod';
+import { baseWorkflowActionSchema } from './base-workflow-action-schema';
+import { workflowLogicFunctionActionSettingsSchema } from './logic-function-action-settings-schema';
+
+export const workflowLogicFunctionActionSchema =
+ baseWorkflowActionSchema.extend({
+ type: z.literal('LOGIC_FUNCTION'),
+ settings: workflowLogicFunctionActionSettingsSchema,
+ });
diff --git a/packages/twenty-shared/src/workflow/schemas/logic-function-action-settings-schema.ts b/packages/twenty-shared/src/workflow/schemas/logic-function-action-settings-schema.ts
new file mode 100644
index 00000000000..0b133b1279e
--- /dev/null
+++ b/packages/twenty-shared/src/workflow/schemas/logic-function-action-settings-schema.ts
@@ -0,0 +1,10 @@
+import { z } from 'zod';
+import { baseWorkflowActionSettingsSchema } from './base-workflow-action-settings-schema';
+
+export const workflowLogicFunctionActionSettingsSchema =
+ baseWorkflowActionSettingsSchema.extend({
+ input: z.object({
+ logicFunctionId: z.string(),
+ logicFunctionInput: z.record(z.string(), z.any()),
+ }),
+ });
diff --git a/packages/twenty-shared/src/workflow/schemas/workflow-action-schema.ts b/packages/twenty-shared/src/workflow/schemas/workflow-action-schema.ts
index eb917d19947..ba50ecc8c47 100644
--- a/packages/twenty-shared/src/workflow/schemas/workflow-action-schema.ts
+++ b/packages/twenty-shared/src/workflow/schemas/workflow-action-schema.ts
@@ -10,6 +10,7 @@ import { workflowFormActionSchema } from './form-action-schema';
import { workflowHttpRequestActionSchema } from './http-request-action-schema';
import { workflowIfElseActionSchema } from './if-else-action-schema';
import { workflowIteratorActionSchema } from './iterator-action-schema';
+import { workflowLogicFunctionActionSchema } from './logic-function-action-schema';
import { workflowSendEmailActionSchema } from './send-email-action-schema';
import { workflowUpdateRecordActionSchema } from './update-record-action-schema';
import { workflowUpsertRecordActionSchema } from './upsert-record-action-schema';
@@ -17,6 +18,7 @@ import { workflowDelayActionSchema } from './workflow-delay-action-schema';
export const workflowActionSchema = z.discriminatedUnion('type', [
workflowCodeActionSchema,
+ workflowLogicFunctionActionSchema,
workflowSendEmailActionSchema,
workflowCreateRecordActionSchema,
workflowUpdateRecordActionSchema,