Add the possibility to run workflows with manual trigger from the command K with no records selected (#8342)
https://github.com/user-attachments/assets/9f094439-8d19-4a6b-883b-456294f691d8
This commit is contained in:
@ -1,11 +0,0 @@
|
|||||||
import { useRecoilValue } from 'recoil';
|
|
||||||
|
|
||||||
import { isCurrentUserLoadedState } from '@/auth/states/isCurrentUserLoadingState';
|
|
||||||
import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
|
|
||||||
|
|
||||||
export const useUserOrMetadataLoading = () => {
|
|
||||||
const isCurrentUserLoaded = useRecoilValue(isCurrentUserLoadedState);
|
|
||||||
const objectMetadataItems = useRecoilValue(objectMetadataItemsState);
|
|
||||||
|
|
||||||
return !isCurrentUserLoaded || objectMetadataItems.length === 0;
|
|
||||||
};
|
|
||||||
@ -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 />}</>;
|
||||||
|
};
|
||||||
@ -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;
|
||||||
|
};
|
||||||
@ -6,6 +6,7 @@ import { contextStoreCurrentObjectMetadataIdComponentState } from '@/context-sto
|
|||||||
import { contextStoreNumberOfSelectedRecordsComponentState } from '@/context-store/states/contextStoreNumberOfSelectedRecordsComponentState';
|
import { contextStoreNumberOfSelectedRecordsComponentState } from '@/context-store/states/contextStoreNumberOfSelectedRecordsComponentState';
|
||||||
import { useObjectMetadataItemById } from '@/object-metadata/hooks/useObjectMetadataItemById';
|
import { useObjectMetadataItemById } from '@/object-metadata/hooks/useObjectMetadataItemById';
|
||||||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
|
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
|
||||||
|
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
|
||||||
|
|
||||||
const globalRecordActionEffects = [ExportRecordsActionEffect];
|
const globalRecordActionEffects = [ExportRecordsActionEffect];
|
||||||
|
|
||||||
@ -29,6 +30,8 @@ export const RecordActionMenuEntriesSetter = () => {
|
|||||||
objectId: contextStoreCurrentObjectMetadataId ?? '',
|
objectId: contextStoreCurrentObjectMetadataId ?? '',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const isWorkflowEnabled = useIsFeatureEnabled('IS_WORKFLOW_ENABLED');
|
||||||
|
|
||||||
if (!objectMetadataItem) {
|
if (!objectMetadataItem) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Object metadata item not found for id ${contextStoreCurrentObjectMetadataId}`,
|
`Object metadata item not found for id ${contextStoreCurrentObjectMetadataId}`,
|
||||||
@ -56,7 +59,7 @@ export const RecordActionMenuEntriesSetter = () => {
|
|||||||
objectMetadataItem={objectMetadataItem}
|
objectMetadataItem={objectMetadataItem}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
{contextStoreNumberOfSelectedRecords === 1 && (
|
{contextStoreNumberOfSelectedRecords === 1 && isWorkflowEnabled && (
|
||||||
<WorkflowRunRecordActionEffect
|
<WorkflowRunRecordActionEffect
|
||||||
objectMetadataItem={objectMetadataItem}
|
objectMetadataItem={objectMetadataItem}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import { recordStoreFamilyState } from '@/object-record/record-store/states/reco
|
|||||||
import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar';
|
import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar';
|
||||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||||
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
|
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
|
||||||
import { useAllActiveWorkflowVersionsForObject } from '@/workflow/hooks/useAllActiveWorkflowVersionsForObject';
|
import { useAllActiveWorkflowVersions } from '@/workflow/hooks/useAllActiveWorkflowVersions';
|
||||||
import { useRunWorkflowVersion } from '@/workflow/hooks/useRunWorkflowVersion';
|
import { useRunWorkflowVersion } from '@/workflow/hooks/useRunWorkflowVersion';
|
||||||
|
|
||||||
import { useTheme } from '@emotion/react';
|
import { useTheme } from '@emotion/react';
|
||||||
@ -34,11 +34,10 @@ export const WorkflowRunRecordActionEffect = ({
|
|||||||
recordStoreFamilyState(selectedRecordId ?? ''),
|
recordStoreFamilyState(selectedRecordId ?? ''),
|
||||||
);
|
);
|
||||||
|
|
||||||
const { records: activeWorkflowVersions } =
|
const { records: activeWorkflowVersions } = useAllActiveWorkflowVersions({
|
||||||
useAllActiveWorkflowVersionsForObject({
|
objectMetadataItem,
|
||||||
objectNameSingular: objectMetadataItem.nameSingular,
|
triggerType: 'MANUAL',
|
||||||
triggerType: 'MANUAL',
|
});
|
||||||
});
|
|
||||||
|
|
||||||
const { runWorkflowVersion } = useRunWorkflowVersion();
|
const { runWorkflowVersion } = useRunWorkflowVersion();
|
||||||
|
|
||||||
@ -57,7 +56,7 @@ export const WorkflowRunRecordActionEffect = ({
|
|||||||
] of activeWorkflowVersions.entries()) {
|
] of activeWorkflowVersions.entries()) {
|
||||||
addActionMenuEntry({
|
addActionMenuEntry({
|
||||||
type: 'workflow-run',
|
type: 'workflow-run',
|
||||||
key: `workflow-run-${activeWorkflowVersion.workflow.name}`,
|
key: `workflow-run-${activeWorkflowVersion.id}`,
|
||||||
label: capitalize(activeWorkflowVersion.workflow.name),
|
label: capitalize(activeWorkflowVersion.workflow.name),
|
||||||
position: index,
|
position: index,
|
||||||
Icon: IconSettingsAutomation,
|
Icon: IconSettingsAutomation,
|
||||||
@ -84,9 +83,7 @@ export const WorkflowRunRecordActionEffect = ({
|
|||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
for (const activeWorkflowVersion of activeWorkflowVersions) {
|
for (const activeWorkflowVersion of activeWorkflowVersions) {
|
||||||
removeActionMenuEntry(
|
removeActionMenuEntry(`workflow-run-${activeWorkflowVersion.id}`);
|
||||||
`workflow-run-${activeWorkflowVersion.workflow.name}`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [
|
}, [
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { GlobalActionMenuEntriesSetter } from '@/action-menu/actions/global-actions/components/GlobalActionMenuEntriesSetter';
|
||||||
import { RecordActionMenuEntriesSetter } from '@/action-menu/actions/record-actions/components/RecordActionMenuEntriesSetter';
|
import { RecordActionMenuEntriesSetter } from '@/action-menu/actions/record-actions/components/RecordActionMenuEntriesSetter';
|
||||||
import { ActionMenuConfirmationModals } from '@/action-menu/components/ActionMenuConfirmationModals';
|
import { ActionMenuConfirmationModals } from '@/action-menu/components/ActionMenuConfirmationModals';
|
||||||
import { RecordIndexActionMenuBar } from '@/action-menu/components/RecordIndexActionMenuBar';
|
import { RecordIndexActionMenuBar } from '@/action-menu/components/RecordIndexActionMenuBar';
|
||||||
@ -27,6 +28,7 @@ export const RecordIndexActionMenu = () => {
|
|||||||
<ActionMenuConfirmationModals />
|
<ActionMenuConfirmationModals />
|
||||||
<RecordIndexActionMenuEffect />
|
<RecordIndexActionMenuEffect />
|
||||||
<RecordActionMenuEntriesSetter />
|
<RecordActionMenuEntriesSetter />
|
||||||
|
<GlobalActionMenuEntriesSetter />
|
||||||
</ActionMenuContext.Provider>
|
</ActionMenuContext.Provider>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { GlobalActionMenuEntriesSetter } from '@/action-menu/actions/global-actions/components/GlobalActionMenuEntriesSetter';
|
||||||
import { RecordActionMenuEntriesSetter } from '@/action-menu/actions/record-actions/components/RecordActionMenuEntriesSetter';
|
import { RecordActionMenuEntriesSetter } from '@/action-menu/actions/record-actions/components/RecordActionMenuEntriesSetter';
|
||||||
import { ActionMenuConfirmationModals } from '@/action-menu/components/ActionMenuConfirmationModals';
|
import { ActionMenuConfirmationModals } from '@/action-menu/components/ActionMenuConfirmationModals';
|
||||||
import { ActionMenuContext } from '@/action-menu/contexts/ActionMenuContext';
|
import { ActionMenuContext } from '@/action-menu/contexts/ActionMenuContext';
|
||||||
@ -47,6 +48,7 @@ export const RecordShowActionMenu = ({
|
|||||||
/>
|
/>
|
||||||
<ActionMenuConfirmationModals />
|
<ActionMenuConfirmationModals />
|
||||||
<RecordActionMenuEntriesSetter />
|
<RecordActionMenuEntriesSetter />
|
||||||
|
<GlobalActionMenuEntriesSetter />
|
||||||
</ActionMenuContext.Provider>
|
</ActionMenuContext.Provider>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { GlobalActionMenuEntriesSetter } from '@/action-menu/actions/global-actions/components/GlobalActionMenuEntriesSetter';
|
||||||
import { RecordActionMenuEntriesSetter } from '@/action-menu/actions/record-actions/components/RecordActionMenuEntriesSetter';
|
import { RecordActionMenuEntriesSetter } from '@/action-menu/actions/record-actions/components/RecordActionMenuEntriesSetter';
|
||||||
import { ActionMenuConfirmationModals } from '@/action-menu/components/ActionMenuConfirmationModals';
|
import { ActionMenuConfirmationModals } from '@/action-menu/components/ActionMenuConfirmationModals';
|
||||||
import { RecordShowRightDrawerActionMenuBar } from '@/action-menu/components/RecordShowRightDrawerActionMenuBar';
|
import { RecordShowRightDrawerActionMenuBar } from '@/action-menu/components/RecordShowRightDrawerActionMenuBar';
|
||||||
@ -23,6 +24,7 @@ export const RecordShowRightDrawerActionMenu = () => {
|
|||||||
<RecordShowRightDrawerActionMenuBar />
|
<RecordShowRightDrawerActionMenuBar />
|
||||||
<ActionMenuConfirmationModals />
|
<ActionMenuConfirmationModals />
|
||||||
<RecordActionMenuEntriesSetter />
|
<RecordActionMenuEntriesSetter />
|
||||||
|
<GlobalActionMenuEntriesSetter />
|
||||||
</ActionMenuContext.Provider>
|
</ActionMenuContext.Provider>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -6,9 +6,14 @@ export const RecordShowRightDrawerActionMenuBar = () => {
|
|||||||
const actionMenuEntries = useRecoilComponentValueV2(
|
const actionMenuEntries = useRecoilComponentValueV2(
|
||||||
actionMenuEntriesComponentSelector,
|
actionMenuEntriesComponentSelector,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const standardActionMenuEntries = actionMenuEntries.filter(
|
||||||
|
(actionMenuEntry) => actionMenuEntry.type === 'standard',
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{actionMenuEntries.map((actionMenuEntry) => (
|
{standardActionMenuEntries.map((actionMenuEntry) => (
|
||||||
<RecordShowActionMenuBarEntry entry={actionMenuEntry} />
|
<RecordShowActionMenuBarEntry entry={actionMenuEntry} />
|
||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -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 };
|
||||||
|
};
|
||||||
@ -1,52 +0,0 @@
|
|||||||
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
|
|
||||||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
|
|
||||||
import { generateDepthOneRecordGqlFields } from '@/object-record/graphql/utils/generateDepthOneRecordGqlFields';
|
|
||||||
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
|
|
||||||
import {
|
|
||||||
Workflow,
|
|
||||||
WorkflowTriggerType,
|
|
||||||
WorkflowVersion,
|
|
||||||
} from '@/workflow/types/Workflow';
|
|
||||||
|
|
||||||
export const useAllActiveWorkflowVersionsForObject = ({
|
|
||||||
objectNameSingular,
|
|
||||||
triggerType,
|
|
||||||
}: {
|
|
||||||
objectNameSingular: string;
|
|
||||||
triggerType: WorkflowTriggerType;
|
|
||||||
}) => {
|
|
||||||
const { objectMetadataItem } = useObjectMetadataItem({
|
|
||||||
objectNameSingular,
|
|
||||||
});
|
|
||||||
|
|
||||||
const { records } = useFindManyRecords<
|
|
||||||
WorkflowVersion & { workflow: Workflow }
|
|
||||||
>({
|
|
||||||
objectNameSingular: CoreObjectNameSingular.WorkflowVersion,
|
|
||||||
filter: {
|
|
||||||
and: [
|
|
||||||
{
|
|
||||||
status: {
|
|
||||||
eq: 'ACTIVE',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
trigger: {
|
|
||||||
like: `%"type": "${triggerType}"%`,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
trigger: {
|
|
||||||
like: `%"objectType": "${objectNameSingular}"%`,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
recordGqlFields: {
|
|
||||||
...generateDepthOneRecordGqlFields({ objectMetadataItem }),
|
|
||||||
workflow: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return { records };
|
|
||||||
};
|
|
||||||
@ -17,7 +17,7 @@ export const useRunWorkflowVersion = () => {
|
|||||||
|
|
||||||
const runWorkflowVersion = async (
|
const runWorkflowVersion = async (
|
||||||
workflowVersionId: string,
|
workflowVersionId: string,
|
||||||
payload: Record<string, any>,
|
payload?: Record<string, any>,
|
||||||
) => {
|
) => {
|
||||||
await mutate({
|
await mutate({
|
||||||
variables: { input: { workflowVersionId, payload } },
|
variables: { input: { workflowVersionId, payload } },
|
||||||
|
|||||||
@ -65,6 +65,7 @@ export type WorkflowDatabaseEventTrigger = BaseTrigger & {
|
|||||||
eventName: string;
|
eventName: string;
|
||||||
input?: object;
|
input?: object;
|
||||||
outputSchema: object;
|
outputSchema: object;
|
||||||
|
objectType?: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user