-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
8191 command k workflow trigger for selected record (#8315)
Closes #8191 https://github.com/user-attachments/assets/694da229-cc91-4df2-97a0-49cd5dabcf12
- Loading branch information
1 parent
0893774
commit d1531aa
Showing
44 changed files
with
533 additions
and
199 deletions.
There are no files selected for viewing
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
104 changes: 104 additions & 0 deletions
104
...s/record-actions/workflow-run-record-actions/components/WorkflowRunRecordActionEffect.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,104 @@ | ||
import { useActionMenuEntries } from '@/action-menu/hooks/useActionMenuEntries'; | ||
import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState'; | ||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem'; | ||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState'; | ||
import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar'; | ||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar'; | ||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2'; | ||
import { useAllActiveWorkflowVersionsForObject } from '@/workflow/hooks/useAllActiveWorkflowVersionsForObject'; | ||
import { useRunWorkflowVersion } from '@/workflow/hooks/useRunWorkflowVersion'; | ||
|
||
import { useTheme } from '@emotion/react'; | ||
import { useEffect } from 'react'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { IconSettingsAutomation, isDefined } from 'twenty-ui'; | ||
import { capitalize } from '~/utils/string/capitalize'; | ||
|
||
export const WorkflowRunRecordActionEffect = ({ | ||
objectMetadataItem, | ||
}: { | ||
objectMetadataItem: ObjectMetadataItem; | ||
}) => { | ||
const { addActionMenuEntry, removeActionMenuEntry } = useActionMenuEntries(); | ||
|
||
const contextStoreTargetedRecordsRule = useRecoilComponentValueV2( | ||
contextStoreTargetedRecordsRuleComponentState, | ||
); | ||
|
||
const selectedRecordId = | ||
contextStoreTargetedRecordsRule.mode === 'selection' | ||
? contextStoreTargetedRecordsRule.selectedRecordIds[0] | ||
: undefined; | ||
|
||
const selectedRecord = useRecoilValue( | ||
recordStoreFamilyState(selectedRecordId ?? ''), | ||
); | ||
|
||
const { records: activeWorkflowVersions } = | ||
useAllActiveWorkflowVersionsForObject({ | ||
objectNameSingular: objectMetadataItem.nameSingular, | ||
triggerType: 'MANUAL', | ||
}); | ||
|
||
const { runWorkflowVersion } = useRunWorkflowVersion(); | ||
|
||
const { enqueueSnackBar } = useSnackBar(); | ||
|
||
const theme = useTheme(); | ||
|
||
useEffect(() => { | ||
if (!isDefined(objectMetadataItem) || objectMetadataItem.isRemote) { | ||
return; | ||
} | ||
|
||
for (const [ | ||
index, | ||
activeWorkflowVersion, | ||
] of activeWorkflowVersions.entries()) { | ||
addActionMenuEntry({ | ||
type: 'workflow-run', | ||
key: `workflow-run-${activeWorkflowVersion.workflow.name}`, | ||
label: capitalize(activeWorkflowVersion.workflow.name), | ||
position: index, | ||
Icon: IconSettingsAutomation, | ||
onClick: async () => { | ||
if (!isDefined(selectedRecord)) { | ||
return; | ||
} | ||
|
||
await runWorkflowVersion(activeWorkflowVersion.id, selectedRecord); | ||
|
||
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.workflow.name}`, | ||
); | ||
} | ||
}; | ||
}, [ | ||
activeWorkflowVersions, | ||
addActionMenuEntry, | ||
enqueueSnackBar, | ||
objectMetadataItem, | ||
removeActionMenuEntry, | ||
runWorkflowVersion, | ||
selectedRecord, | ||
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
Oops, something went wrong.