-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the possibility to run workflows with manual trigger from the com…
…mand K with no records selected (#8342) https://github.com/user-attachments/assets/9f094439-8d19-4a6b-883b-456294f691d8
- Loading branch information
1 parent
ac7d740
commit 7f51eb8
Showing
13 changed files
with
172 additions
and
76 deletions.
There are no files selected for viewing
11 changes: 0 additions & 11 deletions
11
packages/twenty-front/src/loading/hooks/useUserOrMetadataLoading.ts
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...c/modules/action-menu/actions/global-actions/components/GlobalActionMenuEntriesSetter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { WorkflowRunActionEffect } from '@/action-menu/actions/global-actions/workflow-run-actions/components/WorkflowRunActionEffect'; | ||
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled'; | ||
|
||
export const GlobalActionMenuEntriesSetter = () => { | ||
const isWorkflowEnabled = useIsFeatureEnabled('IS_WORKFLOW_ENABLED'); | ||
|
||
return <>{isWorkflowEnabled && <WorkflowRunActionEffect />}</>; | ||
}; |
68 changes: 68 additions & 0 deletions
68
...n-menu/actions/global-actions/workflow-run-actions/components/WorkflowRunActionEffect.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { useActionMenuEntries } from '@/action-menu/hooks/useActionMenuEntries'; | ||
import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar'; | ||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar'; | ||
import { useAllActiveWorkflowVersions } from '@/workflow/hooks/useAllActiveWorkflowVersions'; | ||
import { useRunWorkflowVersion } from '@/workflow/hooks/useRunWorkflowVersion'; | ||
|
||
import { useTheme } from '@emotion/react'; | ||
import { useEffect } from 'react'; | ||
import { IconSettingsAutomation } from 'twenty-ui'; | ||
import { capitalize } from '~/utils/string/capitalize'; | ||
|
||
export const WorkflowRunActionEffect = () => { | ||
const { addActionMenuEntry, removeActionMenuEntry } = useActionMenuEntries(); | ||
|
||
const { records: activeWorkflowVersions } = useAllActiveWorkflowVersions({ | ||
triggerType: 'MANUAL', | ||
}); | ||
|
||
const { runWorkflowVersion } = useRunWorkflowVersion(); | ||
|
||
const { enqueueSnackBar } = useSnackBar(); | ||
|
||
const theme = useTheme(); | ||
|
||
useEffect(() => { | ||
for (const [ | ||
index, | ||
activeWorkflowVersion, | ||
] of activeWorkflowVersions.entries()) { | ||
addActionMenuEntry({ | ||
type: 'workflow-run', | ||
key: `workflow-run-${activeWorkflowVersion.id}`, | ||
label: capitalize(activeWorkflowVersion.workflow.name), | ||
position: index, | ||
Icon: IconSettingsAutomation, | ||
onClick: async () => { | ||
await runWorkflowVersion(activeWorkflowVersion.id); | ||
|
||
enqueueSnackBar('', { | ||
variant: SnackBarVariant.Success, | ||
title: `${capitalize(activeWorkflowVersion.workflow.name)} starting...`, | ||
icon: ( | ||
<IconSettingsAutomation | ||
size={16} | ||
color={theme.snackBar.success.color} | ||
/> | ||
), | ||
}); | ||
}, | ||
}); | ||
} | ||
|
||
return () => { | ||
for (const activeWorkflowVersion of activeWorkflowVersions) { | ||
removeActionMenuEntry(`workflow-run-${activeWorkflowVersion.id}`); | ||
} | ||
}; | ||
}, [ | ||
activeWorkflowVersions, | ||
addActionMenuEntry, | ||
enqueueSnackBar, | ||
removeActionMenuEntry, | ||
runWorkflowVersion, | ||
theme.snackBar.success.color, | ||
]); | ||
|
||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/twenty-front/src/modules/workflow/hooks/useAllActiveWorkflowVersions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem'; | ||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular'; | ||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem'; | ||
import { generateDepthOneRecordGqlFields } from '@/object-record/graphql/utils/generateDepthOneRecordGqlFields'; | ||
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords'; | ||
import { | ||
Workflow, | ||
WorkflowTriggerType, | ||
WorkflowVersion, | ||
} from '@/workflow/types/Workflow'; | ||
import { isDefined } from 'twenty-ui'; | ||
|
||
export const useAllActiveWorkflowVersions = ({ | ||
objectMetadataItem, | ||
triggerType, | ||
}: { | ||
objectMetadataItem?: ObjectMetadataItem; | ||
triggerType: WorkflowTriggerType; | ||
}) => { | ||
const filters = [ | ||
{ | ||
status: { | ||
eq: 'ACTIVE', | ||
}, | ||
}, | ||
{ | ||
trigger: { | ||
like: `%"type": "${triggerType}"%`, | ||
}, | ||
}, | ||
]; | ||
|
||
if (isDefined(objectMetadataItem)) { | ||
filters.push({ | ||
trigger: { | ||
like: `%"objectType": "${objectMetadataItem.nameSingular}"%`, | ||
}, | ||
}); | ||
} | ||
|
||
const { objectMetadataItem: workflowVersionObjectMetadataItem } = | ||
useObjectMetadataItem({ | ||
objectNameSingular: CoreObjectNameSingular.WorkflowVersion, | ||
}); | ||
|
||
const { records } = useFindManyRecords< | ||
WorkflowVersion & { workflow: Workflow } | ||
>({ | ||
objectNameSingular: CoreObjectNameSingular.WorkflowVersion, | ||
filter: { | ||
and: filters, | ||
}, | ||
recordGqlFields: { | ||
...generateDepthOneRecordGqlFields({ | ||
objectMetadataItem: workflowVersionObjectMetadataItem, | ||
}), | ||
workflow: true, | ||
}, | ||
}); | ||
|
||
// TODO: refactor when we can use 'not like' in the RawJson filter | ||
if (!isDefined(objectMetadataItem)) { | ||
return { | ||
records: records.filter( | ||
(record) => !isDefined(record.trigger?.settings.objectType), | ||
), | ||
}; | ||
} | ||
|
||
return { records }; | ||
}; |
52 changes: 0 additions & 52 deletions
52
packages/twenty-front/src/modules/workflow/hooks/useAllActiveWorkflowVersionsForObject.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters