The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
feat(workflow): Node settings page for step error handling (#25314)
Thomas Trompetteb96afdc68b45
diff --git a/packages/twenty-front/src/modules/side-panel/constants/SidePanelPagesConfig.tsx b/packages/twenty-front/src/modules/side-panel/constants/SidePanelPagesConfig.tsxindex baa2da046a6..6fcd4058973 100644--- a/packages/twenty-front/src/modules/side-panel/constants/SidePanelPagesConfig.tsx+++ b/packages/twenty-front/src/modules/side-panel/constants/SidePanelPagesConfig.tsx@@ -29,6 +29,7 @@ import { SidePanelEditRichTextPage } from '@/side-panel/pages/rich-text-page/comimport { SidePanelSearchRecordsPage } from '@/side-panel/pages/search/components/SidePanelSearchRecordsPage';import { SidePanelWorkflowCreateStep } from '@/side-panel/pages/workflow/step/create/components/SidePanelWorkflowCreateStep';import { SidePanelWorkflowEditStep } from '@/side-panel/pages/workflow/step/edit/components/SidePanelWorkflowEditStep';+import { SidePanelWorkflowStepSettings } from '@/side-panel/pages/workflow/step/settings/components/SidePanelWorkflowStepSettings';import { SidePanelWorkflowEditStepType } from '@/side-panel/pages/workflow/step/edit/components/SidePanelWorkflowEditStepType';import { SidePanelWorkflowRunViewStep } from '@/side-panel/pages/workflow/step/view-run/components/SidePanelWorkflowRunViewStep';import { SidePanelWorkflowViewStep } from '@/side-panel/pages/workflow/step/view/components/SidePanelWorkflowViewStep';@@ -51,6 +52,7 @@ export const SIDE_PANEL_PAGES_CONFIG = new Map<[SidePanelPages.WorkflowStepCreate, <SidePanelWorkflowCreateStep />],[SidePanelPages.WorkflowStepEditType, <SidePanelWorkflowEditStepType />],[SidePanelPages.WorkflowStepEdit, <SidePanelWorkflowEditStep />],+ [SidePanelPages.WorkflowStepSettings, <SidePanelWorkflowStepSettings />],[SidePanelPages.WorkflowStepView, <SidePanelWorkflowViewStep />],[SidePanelPages.WorkflowRunStepView, <SidePanelWorkflowRunViewStep />],[SidePanelPages.SearchRecords, <SidePanelSearchRecordsPage />],diff --git a/packages/twenty-front/src/modules/side-panel/pages/workflow/hooks/useSidePanelWorkflowNavigation.ts b/packages/twenty-front/src/modules/side-panel/pages/workflow/hooks/useSidePanelWorkflowNavigation.tsindex 989e1f43f87..d958ea4007a 100644--- a/packages/twenty-front/src/modules/side-panel/pages/workflow/hooks/useSidePanelWorkflowNavigation.ts+++ b/packages/twenty-front/src/modules/side-panel/pages/workflow/hooks/useSidePanelWorkflowNavigation.ts@@ -15,6 +15,7 @@ import { isDefined } from 'twenty-shared/utils';import {IconBolt,type IconComponent,+ IconSettings,IconSettingsAutomation,} from 'twenty-ui/icon';import { v4 } from 'uuid';@@ -130,6 +131,41 @@ export const useSidePanelWorkflowNavigation = () => {[navigateSidePanel, store],);+ const openWorkflowStepSettingsInSidePanel = useCallback(+ ({ workflowId, stepId }: { workflowId: string; stepId: string }) => {+ const pageId = v4();++ store.set(+ sidePanelWorkflowIdComponentState.atomFamily({+ instanceId: pageId,+ }),+ workflowId,+ );++ store.set(+ sidePanelWorkflowStepIdComponentState.atomFamily({+ instanceId: pageId,+ }),+ stepId,+ );++ store.set(+ workflowSelectedNodeComponentState.atomFamily({+ instanceId: workflowId,+ }),+ stepId,+ );++ navigateSidePanel({+ page: SidePanelPages.WorkflowStepSettings,+ pageTitle: t`Node settings`,+ pageIcon: IconSettings,+ pageId,+ });+ },+ [navigateSidePanel, store],+ );+const openWorkflowEditStepTypeInSidePanel = useCallback((workflowId: string) => {const pageId = v4();@@ -269,6 +305,7 @@ export const useSidePanelWorkflowNavigation = () => {openWorkflowTriggerTypeInSidePanel,openWorkflowCreateStepInSidePanel,openWorkflowEditStepInSidePanel,+ openWorkflowStepSettingsInSidePanel,openWorkflowEditStepTypeInSidePanel,openWorkflowViewStepInSidePanel,openWorkflowRunViewStepInSidePanel,diff --git a/packages/twenty-front/src/modules/side-panel/pages/workflow/step/settings/components/SidePanelWorkflowStepSettings.tsx b/packages/twenty-front/src/modules/side-panel/pages/workflow/step/settings/components/SidePanelWorkflowStepSettings.tsxnew file mode 100644index 00000000000..1b20ac6ad2d--- /dev/null+++ b/packages/twenty-front/src/modules/side-panel/pages/workflow/step/settings/components/SidePanelWorkflowStepSettings.tsx@@ -0,0 +1,21 @@+import { useSidePanelWorkflowIdOrThrow } from '@/side-panel/pages/workflow/hooks/useSidePanelWorkflowIdOrThrow';+import { SidePanelWorkflowStepSettingsContent } from '@/side-panel/pages/workflow/step/settings/components/SidePanelWorkflowStepSettingsContent';+import { getWorkflowVisualizerComponentInstanceId } from '@/workflow/utils/getWorkflowVisualizerComponentInstanceId';+import { WorkflowVisualizerComponentInstanceContext } from '@/workflow/workflow-diagram/states/contexts/WorkflowVisualizerComponentInstanceContext';++export const SidePanelWorkflowStepSettings = () => {+ const workflowId = useSidePanelWorkflowIdOrThrow();+ const instanceId = getWorkflowVisualizerComponentInstanceId({+ recordId: workflowId,+ });++ return (+ <WorkflowVisualizerComponentInstanceContext.Provider+ value={{+ instanceId,+ }}+ >+ <SidePanelWorkflowStepSettingsContent />+ </WorkflowVisualizerComponentInstanceContext.Provider>+ );+};diff --git a/packages/twenty-front/src/modules/side-panel/pages/workflow/step/settings/components/SidePanelWorkflowStepSettingsContent.tsx b/packages/twenty-front/src/modules/side-panel/pages/workflow/step/settings/components/SidePanelWorkflowStepSettingsContent.tsxnew file mode 100644index 00000000000..e89aca6005f--- /dev/null+++ b/packages/twenty-front/src/modules/side-panel/pages/workflow/step/settings/components/SidePanelWorkflowStepSettingsContent.tsx@@ -0,0 +1,108 @@+import { useState } from 'react';+import { isDefined } from 'twenty-shared/utils';+import { STEP_RETRY_DELAYS_MS } from 'twenty-shared/workflow';+import { InputLabel } from 'twenty-ui/input';++import { FormBooleanFieldToggleInput } from '@/object-record/record-field/ui/form-types/components/FormBooleanFieldToggleInput';+import { FormFieldInputContainer } from '@/ui/input/components/FormFieldInputContainer';+import { Select } from '@/ui/input/components/Select';+import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';+import { useFlowOrThrow } from '@/workflow/hooks/useFlowOrThrow';+import { type WorkflowAction } from '@/workflow/types/Workflow';+import { workflowSelectedNodeComponentState } from '@/workflow/workflow-diagram/states/workflowSelectedNodeComponentState';+import { WorkflowStepBody } from '@/workflow/workflow-steps/components/WorkflowStepBody';+import { useUpdateStep } from '@/workflow/workflow-steps/hooks/useUpdateStep';+import { useLingui } from '@lingui/react/macro';++type StepErrorHandlingOptions =+ WorkflowAction['settings']['errorHandlingOptions'];++const SidePanelWorkflowStepSettingsForm = ({+ step,+}: {+ step: WorkflowAction;+}) => {+ const { t } = useLingui();+ const { updateStep } = useUpdateStep();++ const [errorHandlingOptions, setErrorHandlingOptions] =+ useState<StepErrorHandlingOptions>(step.settings.errorHandlingOptions);++ const updateErrorHandlingOptions = async (+ partialOptions: Partial<StepErrorHandlingOptions>,+ ) => {+ const previousOptions = errorHandlingOptions;+ const updatedOptions = { ...errorHandlingOptions, ...partialOptions };++ setErrorHandlingOptions(updatedOptions);++ try {+ await updateStep({+ ...step,+ settings: {+ ...step.settings,+ errorHandlingOptions: updatedOptions,+ },+ } as WorkflowAction);+ } catch {+ setErrorHandlingOptions((currentOptions) => ({+ ...currentOptions,+ ...('continueOnFailure' in partialOptions+ ? { continueOnFailure: previousOptions.continueOnFailure }+ : {}),+ ...('retryOnFailure' in partialOptions+ ? { retryOnFailure: previousOptions.retryOnFailure }+ : {}),+ }));+ }+ };++ return (+ <WorkflowStepBody>+ {step.type !== 'IF_ELSE' && (+ <FormBooleanFieldToggleInput+ description={t`Continue on failure`}+ value={errorHandlingOptions.continueOnFailure.value}+ onChange={(value) =>+ updateErrorHandlingOptions({ continueOnFailure: { value } })+ }+ hint={t`Keep executing the next nodes even if this one fails`}+ />+ )}+ <FormFieldInputContainer>+ <InputLabel>{t`Retry on failure`}</InputLabel>+ <Select+ dropdownId="workflow-step-settings-retry-count"+ options={[+ { label: t`Disabled`, value: 0 },+ ...STEP_RETRY_DELAYS_MS.map((_, index) => ({+ label: index === 0 ? t`1 retry` : t`${index + 1} retries`,+ value: index + 1,+ })),+ ]}+ value={Number(errorHandlingOptions.retryOnFailure.value) || 0}+ onChange={(value) =>+ updateErrorHandlingOptions({ retryOnFailure: { value } })+ }+ />+ </FormFieldInputContainer>+ </WorkflowStepBody>+ );+};++export const SidePanelWorkflowStepSettingsContent = () => {+ const flow = useFlowOrThrow();+ const workflowSelectedNode = useAtomComponentStateValue(+ workflowSelectedNodeComponentState,+ );++ const step = flow.steps?.find(+ (candidateStep) => candidateStep.id === workflowSelectedNode,+ );++ if (!isDefined(step)) {+ return null;+ }++ return <SidePanelWorkflowStepSettingsForm key={step.id} step={step} />;+};diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowStepFooter.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowStepFooter.tsxindex 4de7ffba04f..d5ed515eaec 100644--- a/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowStepFooter.tsx+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowStepFooter.tsx@@ -18,7 +18,7 @@ import { useId } from 'react';import { SettingsPath } from 'twenty-shared/types';import { isDefined } from 'twenty-shared/utils';import { TRIGGER_STEP_ID } from 'twenty-shared/workflow';-import { IconLego, IconTrash, IconUsers } from 'twenty-ui/icon';+import { IconLego, IconSettings, IconTrash, IconUsers } from 'twenty-ui/icon';import { Button } from 'twenty-ui/input';import { MenuItem } from 'twenty-ui/navigation';import { useNavigateSettings } from '~/hooks/useNavigateSettings';@@ -37,6 +37,7 @@ export const WorkflowStepFooter = ({const workflowId = useSidePanelWorkflowIdOrThrow();const {openWorkflowEditStepTypeInSidePanel,+ openWorkflowStepSettingsInSidePanel,openWorkflowTriggerTypeInSidePanel,} = useSidePanelWorkflowNavigation();const { deleteStep } = useDeleteStep();@@ -54,7 +55,10 @@ export const WorkflowStepFooter = ({const selectableItemIdArray = [WORKFLOW_STEP_OPTIONS_MENU_ITEM_IDS.changeNode,...(stepId !== TRIGGER_STEP_ID- ? [WORKFLOW_STEP_OPTIONS_MENU_ITEM_IDS.duplicateNode]+ ? [+ WORKFLOW_STEP_OPTIONS_MENU_ITEM_IDS.duplicateNode,+ WORKFLOW_STEP_OPTIONS_MENU_ITEM_IDS.nodeSettings,+ ]: []),...(hasViewAgentOption ? ['view-agent'] : []),...(hasViewRoleOption ? ['view-role'] : []),@@ -83,6 +87,11 @@ export const WorkflowStepFooter = ({deleteStep(stepId);};+ const handleNodeSettings = () => {+ closeDropdown(dropdownId);+ openWorkflowStepSettingsInSidePanel({ workflowId, stepId });+ };+const handleViewAgent = () => {closeDropdown(dropdownId);if (isDefined(agentId)) {@@ -121,6 +130,22 @@ export const WorkflowStepFooter = ({}onDeleteNode={!shouldPinDeleteButton ? handleDeleteNode : undefined}>+ {stepId !== TRIGGER_STEP_ID ? (+ <SelectableListItem+ itemId={WORKFLOW_STEP_OPTIONS_MENU_ITEM_IDS.nodeSettings}+ onEnter={handleNodeSettings}+ >+ <MenuItem+ focused={+ selectedItemId ===+ WORKFLOW_STEP_OPTIONS_MENU_ITEM_IDS.nodeSettings+ }+ onClick={handleNodeSettings}+ text={t`Node settings`}+ LeftIcon={IconSettings}+ />+ </SelectableListItem>+ ) : null}{hasViewAgentOption ? (<SelectableListItem itemId="view-agent" onEnter={handleViewAgent}><MenuItemdiff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/constants/WorkflowStepOptionsMenuItemIds.ts b/packages/twenty-front/src/modules/workflow/workflow-steps/constants/WorkflowStepOptionsMenuItemIds.tsindex 7e46e3ec7dd..28b2aa84bcb 100644--- a/packages/twenty-front/src/modules/workflow/workflow-steps/constants/WorkflowStepOptionsMenuItemIds.ts+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/constants/WorkflowStepOptionsMenuItemIds.ts@@ -1,5 +1,6 @@export const WORKFLOW_STEP_OPTIONS_MENU_ITEM_IDS = {changeNode: 'change-node',duplicateNode: 'duplicate-node',+ nodeSettings: 'node-settings',deleteNode: 'delete-node',} as const;diff --git a/packages/twenty-shared/src/types/SidePanelPages.ts b/packages/twenty-shared/src/types/SidePanelPages.tsindex d0278b81d6a..f0b9254f415 100644--- a/packages/twenty-shared/src/types/SidePanelPages.ts+++ b/packages/twenty-shared/src/types/SidePanelPages.ts@@ -15,6 +15,7 @@ export enum SidePanelPages {WorkflowStepView = 'workflow-step-view',WorkflowStepEdit = 'workflow-step-edit',WorkflowRunStepView = 'workflow-run-step-view',+ WorkflowStepSettings = 'workflow-step-settings',SearchRecords = 'search-records',AskAI = 'ask-ai',PageLayoutDashboardWidgetTypeSelect = 'page-layout-dashboard-widget-type-select',