Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
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 @@ -208,6 +208,7 @@ export const WorkflowDiagramCanvasBase = ({
const [connectionStartInfo, setConnectionStartInfo] = useState<{
nodeId: string;
handleId: string;
startPosition: { x: number; y: number };
} | null>(null);

const { nodes, edges } = useMemo(() => {
Expand Down Expand Up @@ -501,13 +502,24 @@ export const WorkflowDiagramCanvasBase = ({
}, [clearEdgeHover]);

const handleConnectStart = (
_: MouseEvent | TouchEvent,
event: MouseEvent | TouchEvent,
params: OnConnectStartParams,
) => {
if (isDefined(params.nodeId) && isDefined(params.handleId)) {
const mouseEvent = event instanceof MouseEvent ? event : null;
if (!isDefined(mouseEvent) || !isDefined(containerRef.current)) {
return;
}

const bounds = containerRef.current.getBoundingClientRect();

setConnectionStartInfo({
nodeId: params.nodeId,
handleId: params.handleId,
startPosition: {
x: mouseEvent.clientX - bounds.left,
y: mouseEvent.clientY - bounds.top,
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this useful ? can't we simply deactivate the handle when the node is an if-else?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The startPosition is needed to differentiate between a simple click on the handle and an actual drag (when the user drags from the handle to create a new node). Without tracking the start position, we can’t measure the drag distance, and every handle click would end up creating a node. This behavior applies to all node types, not just if-else.

});
}
};
Expand Down Expand Up @@ -542,6 +554,15 @@ export const WorkflowDiagramCanvasBase = ({
y: event.clientY - bounds.top,
};

const MIN_DRAG_DISTANCE = 5;
const deltaX = screenPosition.x - startInfo.startPosition.x;
const deltaY = screenPosition.y - startInfo.startPosition.y;
const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);

if (distance < MIN_DRAG_DISTANCE) {
return;
}

const flowPosition = workflowDiagramScreenToFlowPosition(screenPosition);

if (!isDefined(flowPosition)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import { AdvancedFilterCommandMenuColumn } from '@/object-record/advanced-filter/command-menu/components/AdvancedFilterCommandMenuColumn';
import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue';
import { WorkflowStepFilterFieldSelect } from '@/workflow/workflow-steps/filters/components/WorkflowStepFilterFieldSelect';
import { WorkflowStepFilterLogicalOperatorCell } from '@/workflow/workflow-steps/filters/components/WorkflowStepFilterLogicalOperatorCell';
import { WorkflowStepFilterOperandSelect } from '@/workflow/workflow-steps/filters/components/WorkflowStepFilterOperandSelect';
import { WorkflowStepFilterOptionsDropdown } from '@/workflow/workflow-steps/filters/components/WorkflowStepFilterOptionsDropdown';
import { WorkflowStepFilterValueInput } from '@/workflow/workflow-steps/filters/components/WorkflowStepFilterValueInput';
import { useChildStepFiltersAndChildStepFilterGroups } from '@/workflow/workflow-steps/filters/hooks/useChildStepFiltersAndChildStepFilterGroups';
import { WorkflowStepFilterContext } from '@/workflow/workflow-steps/filters/states/context/WorkflowStepFilterContext';
import { currentStepFilterGroupsComponentState } from '@/workflow/workflow-steps/filters/states/currentStepFilterGroupsComponentState';
import styled from '@emotion/styled';
import { useContext } from 'react';
import { type StepFilter, type StepFilterGroup } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';

type WorkflowStepFilterColumnProps = {
stepFilterGroup: StepFilterGroup;
stepFilter: StepFilter;
stepFilterIndex: number;
isIfBranch?: boolean;
firstFilterLabel?: string;
};

Expand All @@ -32,32 +27,11 @@ export const WorkflowStepFilterColumn = ({
stepFilterGroup,
stepFilter,
stepFilterIndex,
isIfBranch,
firstFilterLabel,
}: WorkflowStepFilterColumnProps) => {
const { readonly } = useContext(WorkflowStepFilterContext);

const stepFilterGroups = useRecoilComponentValue(
currentStepFilterGroupsComponentState,
);

const rootStepFilterGroup = stepFilterGroups?.find(
(filterGroup) => !isDefined(filterGroup.parentStepFilterGroupId),
);

const { childStepFilters, childStepFilterGroups } =
useChildStepFiltersAndChildStepFilterGroups({
stepFilterGroupId: rootStepFilterGroup?.id ?? '',
});

const isLastFilterInIfBranch =
isIfBranch &&
isDefined(rootStepFilterGroup) &&
stepFilter.stepFilterGroupId === rootStepFilterGroup.id &&
childStepFilters.length === 1 &&
childStepFilterGroups.length === 0;

const shouldShowDropdown = !readonly && !isLastFilterInIfBranch;
const shouldShowDropdown = !readonly;

return (
<AdvancedFilterCommandMenuColumn>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/ho
import { useGetUpdatableWorkflowVersionOrThrow } from '@/workflow/hooks/useGetUpdatableWorkflowVersionOrThrow';
import { useWorkflowWithCurrentVersion } from '@/workflow/hooks/useWorkflowWithCurrentVersion';
import { workflowVisualizerWorkflowIdComponentState } from '@/workflow/states/workflowVisualizerWorkflowIdComponentState';
import { type WorkflowIfElseAction } from '@/workflow/types/Workflow';
import { useDeleteWorkflowVersionStep } from '@/workflow/workflow-steps/hooks/useDeleteWorkflowVersionStep';
import { useResetWorkflowAiAgentPermissionsStateOnCommandMenuClose } from '@/workflow/workflow-steps/workflow-actions/ai-agent-action/hooks/useResetWorkflowAiAgentPermissionsStateOnCommandMenuClose';
import { getEmptyChildStepIds } from '@/workflow/workflow-steps/workflow-actions/if-else-action/utils/getEmptyChildStepIds';
import { useStepsOutputSchema } from '@/workflow/workflow-variables/hooks/useStepsOutputSchema';
import { isDefined } from 'twenty-shared/utils';

Expand All @@ -32,31 +30,6 @@ export const useDeleteStep = () => {
? steps.find((step) => step.id === stepId)
: undefined;

if (
isDefined(stepToDelete) &&
isDefined(steps) &&
stepToDelete.type === 'IF_ELSE'
) {
const emptyChildStepIds = getEmptyChildStepIds({
ifElseAction: stepToDelete as WorkflowIfElseAction,
allSteps: steps,
});

for (const emptyChildStepId of emptyChildStepIds) {
await deleteWorkflowVersionStep({
workflowVersionId,
stepId: emptyChildStepId,
});
}

if (emptyChildStepIds.length > 0) {
deleteStepsOutputSchema({
stepIds: emptyChildStepIds,
workflowVersionId,
});
}
}

await deleteWorkflowVersionStep({
workflowVersionId,
stepId,
Comment on lines 30 to 35

This comment was marked as outdated.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useApolloCoreClient } from '@/object-metadata/hooks/useApolloCoreClient';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { useFindOneRecordQuery } from '@/object-record/hooks/useFindOneRecordQuery';
import { DELETE_WORKFLOW_VERSION_STEP } from '@/workflow/graphql/mutations/deleteWorkflowVersionStep';
import { useUpdateWorkflowVersionCache } from '@/workflow/workflow-steps/hooks/useUpdateWorkflowVersionCache';
import { useMutation } from '@apollo/client';
Expand All @@ -13,6 +15,11 @@ export const useDeleteWorkflowVersionStep = () => {

const { updateWorkflowVersionCache } = useUpdateWorkflowVersionCache();

const { findOneRecordQuery: findOneWorkflowVersionQuery } =
useFindOneRecordQuery({
objectNameSingular: CoreObjectNameSingular.WorkflowVersion,
});

const [mutate] = useMutation<
DeleteWorkflowVersionStepMutation,
DeleteWorkflowVersionStepMutationVariables
Expand All @@ -23,7 +30,16 @@ export const useDeleteWorkflowVersionStep = () => {
const deleteWorkflowVersionStep = async (
input: DeleteWorkflowVersionStepInput,
) => {
const result = await mutate({ variables: { input } });
const result = await mutate({
variables: { input },
awaitRefetchQueries: true,
refetchQueries: [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we stop removing the empty node, we can remove that refetch logic. Updating cache will be enough

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FelixMalfait suggested that we should remove the empty nodes. LMK what should we do @thomtrp ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep it for now

{
query: findOneWorkflowVersionQuery,
variables: { objectRecordId: input.workflowVersionId },
},
],
});

const workflowVersionStepChanges = result?.data?.deleteWorkflowVersionStep;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ const isParentStep = ({
);
}

if (potentialParentStep.type === 'IF_ELSE') {
return !!potentialParentStep.settings.input.branches?.some((branch) =>
branch.nextStepIds?.includes(currentStep.id),
);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌


if (currentStep.type === 'ITERATOR') {
return !!(
potentialParentStep.nextStepIds?.includes(currentStep.id) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,45 +58,70 @@ export const WorkflowIfElseBranchEditor = ({

const isIfBranch = branchIndex === 0;

const isLastFilterInIfBranch = (stepFilter: {
stepFilterGroupId: string;
}): boolean => {
const childStepFilters = childStepFiltersAndChildStepFilterGroups.filter(
(child) => !isStepFilterGroupChildAStepFilterGroup(child),
);
const childStepFilterGroups =
childStepFiltersAndChildStepFilterGroups.filter(
isStepFilterGroupChildAStepFilterGroup,
);

return (
isIfBranch &&
isDefined(branchFilterGroup) &&
stepFilter.stepFilterGroupId === branchFilterGroup.id &&
childStepFilters.length === 1 &&
childStepFilterGroups.length === 0
);
};

return (
<WorkflowStepFilterContext.Provider
value={{
stepId: action.id,
readonly,
onFilterSettingsUpdate,
}}
>
<StyledBranchContainer>
<StyledFiltersContainer>
{isDefined(branchFilterGroup) &&
childStepFiltersAndChildStepFilterGroups.map(
(stepFilterGroupChild, stepFilterGroupChildIndex) =>
isStepFilterGroupChildAStepFilterGroup(stepFilterGroupChild) ? (
<StyledBranchContainer>
<StyledFiltersContainer>
{isDefined(branchFilterGroup) &&
childStepFiltersAndChildStepFilterGroups.map(
(stepFilterGroupChild, stepFilterGroupChildIndex) => (
<WorkflowStepFilterContext.Provider
key={stepFilterGroupChild.id}
value={{
stepId: action.id,
readonly: isStepFilterGroupChildAStepFilterGroup(
stepFilterGroupChild,
)
? readonly
: readonly || isLastFilterInIfBranch(stepFilterGroupChild),
onFilterSettingsUpdate,
}}
>
{isStepFilterGroupChildAStepFilterGroup(
stepFilterGroupChild,
) ? (
<WorkflowStepFilterGroupColumn
key={stepFilterGroupChild.id}
parentStepFilterGroup={branchFilterGroup}
stepFilterGroup={stepFilterGroupChild}
stepFilterGroupIndex={stepFilterGroupChildIndex}
/>
) : (
<WorkflowStepFilterColumn
key={stepFilterGroupChild.id}
stepFilterGroup={branchFilterGroup}
stepFilter={stepFilterGroupChild}
stepFilterIndex={stepFilterGroupChildIndex}
isIfBranch={isIfBranch}
firstFilterLabel={i18n._(branchLabel)}
/>
),
)}
</StyledFiltersContainer>
)}
</WorkflowStepFilterContext.Provider>
),
)}
</StyledFiltersContainer>

{!readonly && isDefined(branchFilterGroup) && (
<WorkflowStepFilterAddFilterRuleSelect
stepFilterGroup={branchFilterGroup}
/>
)}
</StyledBranchContainer>
</WorkflowStepFilterContext.Provider>
{!readonly && isDefined(branchFilterGroup) && (
<WorkflowStepFilterAddFilterRuleSelect
stepFilterGroup={branchFilterGroup}
/>
)}
</StyledBranchContainer>
);
};
Loading