Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Store the current flow definition in a state to not depend on a specific workflow version #10352

Merged
merged 5 commits into from
Feb 20, 2025

Conversation

Devessier
Copy link
Contributor

@Devessier Devessier commented Feb 20, 2025

This PR introduces a new Recoil state to store the flow.

A few parts of the application need to know the definition of the current flow. Previously, we stored the workflow version's ID and fetched its definition with the useWorkflowVersion hook. However, we must use another strategy to visualize workflow runs. Indeed, we now store the definition of the workflow in the workflow run output when it is executed. This is useful for draft versions, which can change between the moment they were executed and the moment they are visualized.

@Devessier Devessier marked this pull request as ready for review February 20, 2025 11:08
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR introduces a new Recoil state to manage workflow flow definitions, decoupling workflow visualization from version IDs to better handle draft versions that may change between execution and visualization.

  • Added packages/twenty-front/src/modules/workflow/states/flowState.ts to store workflow definitions directly in state instead of relying on version IDs
  • Added packages/twenty-front/src/modules/workflow/hooks/useFlowOrThrow.ts to safely access flow definitions with proper error handling
  • Added E2E test in packages/twenty-e2e-testing/tests/workflow-run.spec.ts to verify executed draft versions display correctly after changes
  • Modified WorkflowRunVisualizerEffect and WorkflowVersionVisualizerEffect to use flow state instead of version IDs
  • Refactored step detail components to use flow state directly, removing RightDrawerWorkflowViewStepContent.tsx in favor of a simpler implementation

14 file(s) reviewed, 11 comment(s)
Edit PR Review Bot Settings | Greptile

export const useFlowOrThrow = () => {
const flow = useRecoilValue(flowState);
if (!isDefined(flow)) {
throw new Error('Expected the flow to be defined');
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider including more context in the error message about where/when the flow should have been defined

Comment on lines +6 to +7
trigger: WorkflowTrigger | null;
steps: WorkflowAction[] | null;
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider using undefined instead of null for trigger and steps. Using both undefined and null as possible empty values can lead to inconsistent null checks across the codebase.

} as const;
}

if (!isDefined(workflowVersion.steps)) {
if (!isDefined(steps)) {
throw new Error(
'Malformed workflow version: missing steps information; be sure to create at least one step before trying to edit one',
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Error message still references 'workflow version' but the function no longer works with version objects

trigger: workflowRun.output.flow.trigger,
steps: workflowRun.output.flow.steps,
});
}, [setFlow, workflowRun.output]);
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider adding workflowRun as a dependency to handle cases where the entire workflowRun object changes

Comment on lines +78 to +81
setFlow({
trigger: currentVersion.trigger,
steps: currentVersion.steps,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider deep cloning trigger and steps to prevent potential mutation of currentVersion state

}

const workflowVersion = useWorkflowVersion(workflowVersionId);
const flow = useFlowOrThrow();
Copy link
Contributor

Choose a reason for hiding this comment

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

style: useFlowOrThrow could throw before workflowSelectedNode check, causing confusing error messages

| {
stepId: string;
workflowVersion: WorkflowVersion;
readonly: true;
onTriggerUpdate?: undefined;
onActionUpdate?: undefined;
}
| {
stepId: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Duplicate stepId property in the second union type - this is already defined in the base type on line 25

Suggested change
stepId: string;
readonly?: false;

...props
}: WorkflowStepDetailProps) => {
const stepDefinition = getStepDefinitionOrThrow({
stepId,
workflowVersion,
trigger,
steps,
});
if (!isDefined(stepDefinition) || !isDefined(stepDefinition.definition)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider throwing an error with more context when stepDefinition or its definition is undefined, rather than silently returning null

Comment on lines +8 to +22
await workflowVisualizer.createInitialTrigger('manual');

const manualTriggerAvailabilitySelect = page.getByRole('button', {
name: 'When record(s) are selected',
});

await manualTriggerAvailabilitySelect.click();

const alwaysAvailableOption = page.getByText(
'When no record(s) are selected',
);

await alwaysAvailableOption.click();

await workflowVisualizer.closeSidePanel();
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Trigger configuration steps could be extracted into a helper function for reuse in other tests.

@bosiraphael bosiraphael self-requested a review February 20, 2025 15:37
Copy link
Contributor

@bosiraphael bosiraphael left a comment

Choose a reason for hiding this comment

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

LGTM, left a comment

…onents/RightDrawerWorkflowViewStep.tsx

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@Devessier Devessier merged commit 05d00e6 into main Feb 20, 2025
47 checks passed
@Devessier Devessier deleted the wire-workflow-runs-to-side-panel branch February 20, 2025 16:12
Copy link
Contributor

Thanks @Devessier for your contribution!
This marks your 76th PR on the repo. You're top 1% of all our contributors 🎉
See contributor page - Share on LinkedIn - Share on Twitter

Contributions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants