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 { ActionViewType } from '@/action-menu/actions/types/ActionViewType';
|
||||||
import { CoreObjectNamePlural } from '@/object-metadata/types/CoreObjectNamePlural';
|
import { CoreObjectNamePlural } from '@/object-metadata/types/CoreObjectNamePlural';
|
||||||
import { AppPath } from '@/types/AppPath';
|
import { AppPath } from '@/types/AppPath';
|
||||||
|
import {
|
||||||
|
WorkflowStep,
|
||||||
|
WorkflowTrigger,
|
||||||
|
WorkflowWithCurrentVersion,
|
||||||
|
} from '@/workflow/types/Workflow';
|
||||||
import { msg } from '@lingui/core/macro';
|
import { msg } from '@lingui/core/macro';
|
||||||
import { isDefined } from 'twenty-shared/utils';
|
import { isDefined } from 'twenty-shared/utils';
|
||||||
import {
|
import {
|
||||||
@ -28,6 +33,21 @@ import {
|
|||||||
IconVersions,
|
IconVersions,
|
||||||
} from 'twenty-ui/display';
|
} 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({
|
export const WORKFLOW_ACTIONS_CONFIG = inheritActionsFromDefaultConfig({
|
||||||
config: {
|
config: {
|
||||||
[WorkflowSingleRecordActionKeys.ACTIVATE]: {
|
[WorkflowSingleRecordActionKeys.ACTIVATE]: {
|
||||||
@ -40,9 +60,7 @@ export const WORKFLOW_ACTIONS_CONFIG = inheritActionsFromDefaultConfig({
|
|||||||
type: ActionType.Standard,
|
type: ActionType.Standard,
|
||||||
scope: ActionScope.RecordSelection,
|
scope: ActionScope.RecordSelection,
|
||||||
shouldBeRegistered: ({ selectedRecord, workflowWithCurrentVersion }) =>
|
shouldBeRegistered: ({ selectedRecord, workflowWithCurrentVersion }) =>
|
||||||
isDefined(workflowWithCurrentVersion?.currentVersion?.trigger) &&
|
areWorkflowTriggerAndStepsDefined(workflowWithCurrentVersion) &&
|
||||||
isDefined(workflowWithCurrentVersion.currentVersion?.steps) &&
|
|
||||||
workflowWithCurrentVersion.currentVersion.steps.length > 0 &&
|
|
||||||
(workflowWithCurrentVersion.currentVersion.status === 'DRAFT' ||
|
(workflowWithCurrentVersion.currentVersion.status === 'DRAFT' ||
|
||||||
!workflowWithCurrentVersion.versions?.some(
|
!workflowWithCurrentVersion.versions?.some(
|
||||||
(version) => version.status === 'ACTIVE',
|
(version) => version.status === 'ACTIVE',
|
||||||
@ -158,14 +176,15 @@ export const WORKFLOW_ACTIONS_CONFIG = inheritActionsFromDefaultConfig({
|
|||||||
type: ActionType.Standard,
|
type: ActionType.Standard,
|
||||||
scope: ActionScope.RecordSelection,
|
scope: ActionScope.RecordSelection,
|
||||||
shouldBeRegistered: ({ selectedRecord, workflowWithCurrentVersion }) =>
|
shouldBeRegistered: ({ selectedRecord, workflowWithCurrentVersion }) =>
|
||||||
isDefined(workflowWithCurrentVersion?.currentVersion?.trigger) &&
|
areWorkflowTriggerAndStepsDefined(workflowWithCurrentVersion) &&
|
||||||
((workflowWithCurrentVersion.currentVersion.trigger.type === 'MANUAL' &&
|
((workflowWithCurrentVersion.currentVersion.trigger.type === 'MANUAL' &&
|
||||||
!isDefined(
|
!isDefined(
|
||||||
workflowWithCurrentVersion.currentVersion.trigger.settings
|
workflowWithCurrentVersion.currentVersion.trigger.settings
|
||||||
.objectType,
|
.objectType,
|
||||||
)) ||
|
)) ||
|
||||||
workflowWithCurrentVersion.currentVersion.trigger.type ===
|
workflowWithCurrentVersion.currentVersion.trigger.type ===
|
||||||
'WEBHOOK') &&
|
'WEBHOOK' ||
|
||||||
|
workflowWithCurrentVersion.currentVersion.trigger.type === 'CRON') &&
|
||||||
!isDefined(selectedRecord?.deletedAt),
|
!isDefined(selectedRecord?.deletedAt),
|
||||||
availableOn: [
|
availableOn: [
|
||||||
ActionViewType.SHOW_PAGE,
|
ActionViewType.SHOW_PAGE,
|
||||||
|
|||||||
Reference in New Issue
Block a user