Add workflow statuses (#6765)

Following figma updates
https://www.figma.com/design/PNBfTgOVraw557OXChYagk/Explo?node-id=21872-7929&t=DOUzd6rzwr6lprcs-0

- No activity targets for workflow entities for now
- Adding a direct relation between workflow run et workflow
- Adding a status on the version (draft, active, deactivated)
- Adding a list of statuses on workflow 
- publishedVersionId => lastPublishedVersionId

Also adding:
- the endpoint to deactivate a version
This commit is contained in:
Thomas Trompette
2024-08-28 14:53:25 +02:00
committed by GitHub
parent da23ca3c23
commit ff1adb06b2
25 changed files with 419 additions and 289 deletions

View File

@ -18,6 +18,7 @@ import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-re
import { WORKFLOW_RUN_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
import { WorkflowVersionWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
import { WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';
export enum WorkflowRunStatus {
NOT_STARTED = 'NOT_STARTED',
@ -111,8 +112,8 @@ export class WorkflowRunWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceRelation({
standardId: WORKFLOW_RUN_STANDARD_FIELD_IDS.workflowVersion,
type: RelationMetadataType.MANY_TO_ONE,
label: 'Workflow',
description: 'WorkflowVersion workflow',
label: 'Workflow version',
description: 'Workflow version linked to the run.',
icon: 'IconVersions',
inverseSideTarget: () => WorkflowVersionWorkspaceEntity,
inverseSideFieldKey: 'runs',
@ -121,4 +122,18 @@ export class WorkflowRunWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceJoinColumn('workflowVersion')
workflowVersionId: string;
@WorkspaceRelation({
standardId: WORKFLOW_RUN_STANDARD_FIELD_IDS.workflow,
type: RelationMetadataType.MANY_TO_ONE,
label: 'Workflow',
description: 'Workflow linked to the run.',
icon: 'IconSettingsAutomation',
inverseSideTarget: () => WorkflowWorkspaceEntity,
inverseSideFieldKey: 'runs',
})
workflow: Relation<WorkflowWorkspaceEntity>;
@WorkspaceJoinColumn('workflow')
workflowId: string;
}

View File

@ -24,6 +24,33 @@ import { WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-ob
import { WorkflowStep } from 'src/modules/workflow/common/types/workflow-step.type';
import { WorkflowTrigger } from 'src/modules/workflow/common/types/workflow-trigger.type';
export enum WorkflowVersionStatus {
DRAFT = 'DRAFT',
ACTIVE = 'ACTIVE',
DEACTIVATED = 'DEACTIVATED',
}
export const WorkflowVersionStatusOptions = [
{
value: WorkflowVersionStatus.DRAFT,
label: 'Draft',
position: 0,
color: 'yellow',
},
{
value: WorkflowVersionStatus.ACTIVE,
label: 'Active',
position: 1,
color: 'green',
},
{
value: WorkflowVersionStatus.DEACTIVATED,
label: 'Deactivated',
position: 2,
color: 'gray',
},
];
@WorkspaceEntity({
standardId: STANDARD_OBJECT_IDS.workflowVersion,
namePlural: 'workflowVersions',
@ -65,6 +92,16 @@ export class WorkflowVersionWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceIsNullable()
steps: WorkflowStep[] | null;
@WorkspaceField({
standardId: WORKFLOW_VERSION_STANDARD_FIELD_IDS.status,
type: FieldMetadataType.SELECT,
label: 'Version status',
description: 'The workflow version status',
options: WorkflowVersionStatusOptions,
defaultValue: "'DRAFT'",
})
status: WorkflowVersionStatus;
// Relations
@WorkspaceRelation({
standardId: WORKFLOW_VERSION_STANDARD_FIELD_IDS.workflow,

View File

@ -15,14 +15,14 @@ import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
import { WORKFLOW_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
import { ActivityTargetWorkspaceEntity } from 'src/modules/activity/standard-objects/activity-target.workspace-entity';
import { AttachmentWorkspaceEntity } from 'src/modules/attachment/standard-objects/attachment.workspace-entity';
import { FavoriteWorkspaceEntity } from 'src/modules/favorite/standard-objects/favorite.workspace-entity';
import { NoteTargetWorkspaceEntity } from 'src/modules/note/standard-objects/note-target.workspace-entity';
import { TaskTargetWorkspaceEntity } from 'src/modules/task/standard-objects/task-target.workspace-entity';
import { TimelineActivityWorkspaceEntity } from 'src/modules/timeline/standard-objects/timeline-activity.workspace-entity';
import { WorkflowEventListenerWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-event-listener.workspace-entity';
import { WorkflowVersionWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
import { WorkflowRunWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-run.workspace-entity';
import {
WorkflowVersionStatus,
WorkflowVersionStatusOptions,
WorkflowVersionWorkspaceEntity,
} from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
@WorkspaceEntity({
standardId: STANDARD_OBJECT_IDS.workflow,
@ -47,14 +47,24 @@ export class WorkflowWorkspaceEntity extends BaseWorkspaceEntity {
name: string;
@WorkspaceField({
standardId: WORKFLOW_STANDARD_FIELD_IDS.publishedVersionId,
standardId: WORKFLOW_STANDARD_FIELD_IDS.lastPublishedVersionId,
type: FieldMetadataType.TEXT,
label: 'Published Version Id',
description: 'The workflow published version id',
label: 'Last published Version Id',
description: 'The workflow last published version id',
icon: 'IconVersions',
})
@WorkspaceIsNullable()
publishedVersionId: string | null;
lastPublishedVersionId: string | null;
@WorkspaceField({
standardId: WORKFLOW_STANDARD_FIELD_IDS.statuses,
type: FieldMetadataType.MULTI_SELECT,
label: 'Statuses',
description: 'The current statuses of the workflow versions',
options: WorkflowVersionStatusOptions,
})
@WorkspaceIsNullable()
statuses: WorkflowVersionStatus[] | null;
@WorkspaceField({
standardId: WORKFLOW_STANDARD_FIELD_IDS.position,
@ -80,6 +90,18 @@ export class WorkflowWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceIsNullable()
versions: Relation<WorkflowVersionWorkspaceEntity[]>;
@WorkspaceRelation({
standardId: WORKFLOW_STANDARD_FIELD_IDS.runs,
type: RelationMetadataType.ONE_TO_MANY,
label: 'Runs',
description: 'Workflow runs linked to the workflow.',
icon: 'IconVersions',
inverseSideTarget: () => WorkflowRunWorkspaceEntity,
onDelete: RelationOnDeleteAction.SET_NULL,
})
@WorkspaceIsNullable()
runs: Relation<WorkflowRunWorkspaceEntity>;
@WorkspaceRelation({
standardId: WORKFLOW_STANDARD_FIELD_IDS.eventListeners,
type: RelationMetadataType.ONE_TO_MANY,
@ -92,17 +114,6 @@ export class WorkflowWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceIsNullable()
eventListeners: Relation<WorkflowEventListenerWorkspaceEntity[]>;
@WorkspaceRelation({
standardId: WORKFLOW_STANDARD_FIELD_IDS.activityTargets,
type: RelationMetadataType.ONE_TO_MANY,
label: 'Activities',
description: 'Activities tied to the contact',
icon: 'IconCheckbox',
inverseSideTarget: () => ActivityTargetWorkspaceEntity,
onDelete: RelationOnDeleteAction.CASCADE,
})
activityTargets: Relation<ActivityTargetWorkspaceEntity[]>;
@WorkspaceRelation({
standardId: WORKFLOW_STANDARD_FIELD_IDS.favorites,
type: RelationMetadataType.ONE_TO_MANY,
@ -114,50 +125,4 @@ export class WorkflowWorkspaceEntity extends BaseWorkspaceEntity {
})
@WorkspaceIsSystem()
favorites: Relation<FavoriteWorkspaceEntity[]>;
@WorkspaceRelation({
standardId: WORKFLOW_STANDARD_FIELD_IDS.attachments,
type: RelationMetadataType.ONE_TO_MANY,
label: 'Attachments',
description: 'Attachments linked to the contact.',
icon: 'IconFileImport',
inverseSideTarget: () => AttachmentWorkspaceEntity,
onDelete: RelationOnDeleteAction.CASCADE,
})
attachments: Relation<AttachmentWorkspaceEntity[]>;
@WorkspaceRelation({
standardId: WORKFLOW_STANDARD_FIELD_IDS.timelineActivities,
type: RelationMetadataType.ONE_TO_MANY,
label: 'Events',
description: 'Events linked to the workflow',
icon: 'IconTimelineEvent',
inverseSideTarget: () => TimelineActivityWorkspaceEntity,
onDelete: RelationOnDeleteAction.CASCADE,
})
@WorkspaceIsNullable()
@WorkspaceIsSystem()
timelineActivities: Relation<TimelineActivityWorkspaceEntity[]>;
@WorkspaceRelation({
standardId: WORKFLOW_STANDARD_FIELD_IDS.taskTargets,
type: RelationMetadataType.ONE_TO_MANY,
label: 'Tasks',
description: 'Tasks tied to the workflow',
icon: 'IconCheckbox',
inverseSideTarget: () => TaskTargetWorkspaceEntity,
onDelete: RelationOnDeleteAction.CASCADE,
})
taskTargets: Relation<TaskTargetWorkspaceEntity[]>;
@WorkspaceRelation({
standardId: WORKFLOW_STANDARD_FIELD_IDS.noteTargets,
type: RelationMetadataType.ONE_TO_MANY,
label: 'Notes',
description: 'Notes tied to the workflow',
icon: 'IconNotes',
inverseSideTarget: () => NoteTargetWorkspaceEntity,
onDelete: RelationOnDeleteAction.CASCADE,
})
noteTargets: Relation<NoteTargetWorkspaceEntity[]>;
}

View File

@ -12,7 +12,7 @@ import {
export class WorkflowCommonWorkspaceService {
constructor(private readonly twentyORMManager: TwentyORMManager) {}
async getWorkflowVersion(workflowVersionId: string): Promise<
async getWorkflowVersionOrFail(workflowVersionId: string): Promise<
Omit<WorkflowVersionWorkspaceEntity, 'trigger'> & {
trigger: WorkflowTrigger;
}