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

Implement contextual actions for the workflows #8814

Open
wants to merge 30 commits into
base: main
Choose a base branch
from

Conversation

bosiraphael
Copy link
Contributor

@bosiraphael bosiraphael commented Nov 29, 2024

Implemented the following actions for the workflows:

  • Test Workflow
  • Discard Draft
  • Activate Draft
  • Activate Workflow Last Published Version
  • Deactivate Workflow
  • See Workflow Executions
  • See Workflow Active Version
  • See Workflow Versions History

And the following actions for the workflow versions:

  • Use As Draft
  • See Workflow Versions History
  • See Workflow Executions

Video example:

Enregistrement.de.l.ecran.2024-11-29.a.16.38.20.mov

A few of these actions are links to the relations of the workflow object (link to a filtered table). To generalize this behavior, I will create an hook named useSeeRelationsActionSingleRecordAction to automatically generate links to a showPage if the relation is a Many To One or to a filtered table if the relation is a One to Many for all the record types.
I will also create actions which will allow to create a relation.

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 implements comprehensive workflow management functionality through contextual actions in the action menu system. Here's a summary of the key changes:

  • Added workflow-specific actions (test, activate/deactivate, draft management) with proper state handling and user feedback
  • Implemented workflow version management actions (use as draft, view history, executions) with navigation support
  • Created new hooks for workflow operations with proper cleanup and state management
  • Added confirmation modals for destructive actions like discarding drafts
  • Added success notifications with icons for workflow execution status

Key points to review:

  • Error handling is missing in several workflow action hooks
  • Potential race conditions in state management between workflow and version loading
  • Some hooks have inconsistent logic in onClick handlers (e.g., deactivate workflow)
  • No loading states implemented for async operations
  • Position parameters could benefit from centralized constants instead of hardcoded values

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

Comment on lines +62 to +68
{contextStoreTargetedRecordsRule.mode === 'exclusion' ||
(contextStoreTargetedRecordsRule.mode === 'selection' &&
contextStoreTargetedRecordsRule.selectedRecordIds.length > 1 && (
<MultipleRecordsActionMenuEntrySetterEffect
objectMetadataItem={objectMetadataItem}
/>
))}
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: The exclusion mode check is incorrectly structured - the OR condition will always evaluate the second expression. This should be grouped with parentheses to properly handle both conditions

Comment on lines +25 to +26
registerDeleteMultipleRecordsAction({ position: 0 });
registerExportMultipleRecordsAction({ position: 1 });
Copy link
Contributor

Choose a reason for hiding this comment

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

style: position parameter is now passed during registration rather than hook initialization, which could cause issues if these actions are registered multiple times with different positions

Comment on lines 30 to +31
unregisterDeleteMultipleRecordsAction();
unregisterExportViewNoSelectionRecordsAction();
unregisterExportMultipleRecordsAction();
Copy link
Contributor

Choose a reason for hiding this comment

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

style: unregister functions no longer receive position parameters while register functions do - consider making the APIs more consistent

objectMetadataItem={objectMetadataItem}
/>
{objectMetadataItem.nameSingular === CoreObjectNameSingular.Workflow && (
<WorkflowSingleRecordActionMenuEntrySetterEffect startPosition={3} />
Copy link
Contributor

Choose a reason for hiding this comment

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

style: startPosition={3} is hardcoded in multiple places. Consider making this configurable or using a constant to avoid magic numbers

Comment on lines +17 to +25
{objectMetadataItem.nameSingular === CoreObjectNameSingular.Workflow && (
<WorkflowSingleRecordActionMenuEntrySetterEffect startPosition={3} />
)}
{objectMetadataItem.nameSingular ===
CoreObjectNameSingular.WorkflowVersion && (
<WorkflowVersionsSingleRecordActionMenuEntrySetterEffect
startPosition={3}
/>
)}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: workflow and workflow version checks could be combined into a switch statement for better maintainability as more object types are added

import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
import { Workflow, WorkflowVersion } from '@/workflow/types/Workflow';

export const useActiveWorkflowVersion = (workflowId?: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

style: missing JSDoc documentation for the hook's purpose, parameters, and return value

},
});

return workflowVersions?.[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: no handling for case where multiple active versions exist - could lead to inconsistent state

Comment on lines +15 to +17
workflowId: {
eq: workflowId,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: no validation if workflowId is undefined - could cause unnecessary query execution

Comment on lines 36 to 38
await mutate({
variables: { input: { workflowVersionId, payload } },
});
Copy link
Contributor

Choose a reason for hiding this comment

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

style: no error handling for failed mutations - consider wrapping in try/catch to show error snackbar

payload?: Record<string, any>;
}) => {
await mutate({
variables: { input: { workflowVersionId, payload } },
});

enqueueSnackBar('', {
Copy link
Contributor

Choose a reason for hiding this comment

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

style: empty message string passed to snackbar - consider removing the empty string parameter if not needed

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.

1 participant