Prevent testing malformed workflows and allow testing workflows with cron trigger (#13045)
## Before https://github.com/user-attachments/assets/ca0c50af-f759-4466-a262-ad8bdd548b89 ## After https://github.com/user-attachments/assets/647a2181-bf28-4a0b-ab3f-faaf13a0f1d6
This commit is contained in:
committed by
GitHub
parent
333b51b18c
commit
7a2b6bd4d6
@ -17,6 +17,11 @@ import { ActionType } from '@/action-menu/actions/types/ActionType';
|
||||
import { ActionViewType } from '@/action-menu/actions/types/ActionViewType';
|
||||
import { CoreObjectNamePlural } from '@/object-metadata/types/CoreObjectNamePlural';
|
||||
import { AppPath } from '@/types/AppPath';
|
||||
import {
|
||||
WorkflowStep,
|
||||
WorkflowTrigger,
|
||||
WorkflowWithCurrentVersion,
|
||||
} from '@/workflow/types/Workflow';
|
||||
import { msg } from '@lingui/core/macro';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import {
|
||||
@ -28,6 +33,21 @@ import {
|
||||
IconVersions,
|
||||
} from 'twenty-ui/display';
|
||||
|
||||
const areWorkflowTriggerAndStepsDefined = (
|
||||
workflowWithCurrentVersion: WorkflowWithCurrentVersion | undefined,
|
||||
): workflowWithCurrentVersion is WorkflowWithCurrentVersion & {
|
||||
currentVersion: {
|
||||
trigger: WorkflowTrigger;
|
||||
steps: Array<WorkflowStep>;
|
||||
};
|
||||
} => {
|
||||
return (
|
||||
isDefined(workflowWithCurrentVersion?.currentVersion?.trigger) &&
|
||||
isDefined(workflowWithCurrentVersion.currentVersion?.steps) &&
|
||||
workflowWithCurrentVersion.currentVersion.steps.length > 0
|
||||
);
|
||||
};
|
||||
|
||||
export const WORKFLOW_ACTIONS_CONFIG = inheritActionsFromDefaultConfig({
|
||||
config: {
|
||||
[WorkflowSingleRecordActionKeys.ACTIVATE]: {
|
||||
@ -40,9 +60,7 @@ export const WORKFLOW_ACTIONS_CONFIG = inheritActionsFromDefaultConfig({
|
||||
type: ActionType.Standard,
|
||||
scope: ActionScope.RecordSelection,
|
||||
shouldBeRegistered: ({ selectedRecord, workflowWithCurrentVersion }) =>
|
||||
isDefined(workflowWithCurrentVersion?.currentVersion?.trigger) &&
|
||||
isDefined(workflowWithCurrentVersion.currentVersion?.steps) &&
|
||||
workflowWithCurrentVersion.currentVersion.steps.length > 0 &&
|
||||
areWorkflowTriggerAndStepsDefined(workflowWithCurrentVersion) &&
|
||||
(workflowWithCurrentVersion.currentVersion.status === 'DRAFT' ||
|
||||
!workflowWithCurrentVersion.versions?.some(
|
||||
(version) => version.status === 'ACTIVE',
|
||||
@ -158,14 +176,15 @@ export const WORKFLOW_ACTIONS_CONFIG = inheritActionsFromDefaultConfig({
|
||||
type: ActionType.Standard,
|
||||
scope: ActionScope.RecordSelection,
|
||||
shouldBeRegistered: ({ selectedRecord, workflowWithCurrentVersion }) =>
|
||||
isDefined(workflowWithCurrentVersion?.currentVersion?.trigger) &&
|
||||
areWorkflowTriggerAndStepsDefined(workflowWithCurrentVersion) &&
|
||||
((workflowWithCurrentVersion.currentVersion.trigger.type === 'MANUAL' &&
|
||||
!isDefined(
|
||||
workflowWithCurrentVersion.currentVersion.trigger.settings
|
||||
.objectType,
|
||||
)) ||
|
||||
workflowWithCurrentVersion.currentVersion.trigger.type ===
|
||||
'WEBHOOK') &&
|
||||
'WEBHOOK' ||
|
||||
workflowWithCurrentVersion.currentVersion.trigger.type === 'CRON') &&
|
||||
!isDefined(selectedRecord?.deletedAt),
|
||||
availableOn: [
|
||||
ActionViewType.SHOW_PAGE,
|
||||
|
||||
Reference in New Issue
Block a user