Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create default view for workflows + fix task and note targets #6620

Merged
merged 3 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ export class DataSeedWorkspaceCommand extends CommandRunner {
entityManager,
dataSourceMetadata.schema,
objectMetadataMap,
featureFlags,
);
},
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { EntityManager } from 'typeorm';
import { v4 } from 'uuid';

import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import { activitiesAllView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/activities-all.view';
import { companiesAllView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/companies-all.view';
Expand All @@ -10,12 +12,19 @@ import { opportunitiesByStageView } from 'src/engine/workspace-manager/standard-
import { peopleAllView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/people-all.view';
import { tasksAllView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/tasks-all.view';
import { tasksByStatusView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/tasks-by-status.view';
import { workflowsAllView } from 'src/engine/workspace-manager/standard-objects-prefill-data/views/workflows-all.view';

export const viewPrefillData = async (
entityManager: EntityManager,
schemaName: string,
objectMetadataMap: Record<string, ObjectMetadataEntity>,
featureFlags?: FeatureFlagEntity[],
) => {
const isWorkflowEnabled =
featureFlags?.find(
(featureFlag) => featureFlag.key === FeatureFlagKey.IsWorkflowEnabled,
)?.value ?? false;

const viewDefinitions = [
await companiesAllView(objectMetadataMap),
await peopleAllView(objectMetadataMap),
Expand All @@ -25,6 +34,7 @@ export const viewPrefillData = async (
await notesAllView(objectMetadataMap),
await tasksAllView(objectMetadataMap),
await tasksByStatusView(objectMetadataMap),
...(isWorkflowEnabled ? [await workflowsAllView(objectMetadataMap)] : []),
];

const viewDefinitionsWithId = viewDefinitions.map((viewDefinition) => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
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';

export const workflowsAllView = async (
objectMetadataMap: Record<string, ObjectMetadataEntity>,
) => {
Comment on lines +5 to +7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding JSDoc comment for function description and parameters

return {
name: 'All Workflows',
objectMetadataId: objectMetadataMap[STANDARD_OBJECT_IDS.workflow].id,
type: 'table',
key: null,
position: 0,
icon: 'IconSettingsAutomation',
kanbanFieldMetadataId: '',
filters: [],
fields: [
{
fieldMetadataId:
objectMetadataMap[STANDARD_OBJECT_IDS.workflow].fields[
WORKFLOW_STANDARD_FIELD_IDS.name
],
position: 0,
isVisible: true,
size: 210,
},
{
fieldMetadataId:
objectMetadataMap[STANDARD_OBJECT_IDS.workflow].fields[
WORKFLOW_STANDARD_FIELD_IDS.publishedVersionId
],
position: 1,
isVisible: true,
size: 150,
},
],
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ export const NOTE_TARGET_STANDARD_FIELD_IDS = {
company: 'c500fbc0-d6f2-4982-a959-5a755431696c',
opportunity: '20202020-4e42-417a-a705-76581c9ade79',
custom: '20202020-3d12-4579-94ee-7117c1bad492',
workflow: '20202020-eb46-47c5-8f3f-f3f93e7aec20',
};

export const OPPORTUNITY_STANDARD_FIELD_IDS = {
Expand Down Expand Up @@ -346,6 +347,7 @@ export const TASK_TARGET_STANDARD_FIELD_IDS = {
company: '20202020-4703-4a4e-948c-487b0c60a92c',
opportunity: '20202020-6cb2-4c01-a9a5-aca3dbc11d41',
custom: '20202020-41c1-4c9a-8c75-be0971ef89af',
workflow: '20202020-a16c-47a3-b21c-c41c9bcac659',
};

export const VIEW_FIELD_STANDARD_FIELD_IDS = {
Expand Down Expand Up @@ -405,6 +407,8 @@ export const WORKFLOW_STANDARD_FIELD_IDS = {
activityTargets: '20202020-9d65-445a-899d-1c6f1cf3a9ab',
attachments: '20202020-ea95-4d4d-81cd-9921740316b8',
timelineActivities: '20202020-dd79-492a-9d11-58333ed0f71a',
taskTargets: '20202020-0094-4e79-b934-03eaa8ab949c',
noteTargets: '20202020-40aa-4839-965e-972a2f72e08d',
};

export const WORKFLOW_VERSION_STANDARD_FIELD_IDS = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Relation } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/relation.interface';

import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
import { CustomWorkspaceEntity } from 'src/engine/twenty-orm/custom.workspace-entity';
import { WorkspaceDynamicRelation } from 'src/engine/twenty-orm/decorators/workspace-dynamic-relation.decorator';
import { WorkspaceEntity } from 'src/engine/twenty-orm/decorators/workspace-entity.decorator';
import { WorkspaceGate } from 'src/engine/twenty-orm/decorators/workspace-gate.decorator';
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator';
import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator';
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
Expand All @@ -15,6 +17,7 @@ import { CompanyWorkspaceEntity } from 'src/modules/company/standard-objects/com
import { NoteWorkspaceEntity } from 'src/modules/note/standard-objects/note.workspace-entity';
import { OpportunityWorkspaceEntity } from 'src/modules/opportunity/standard-objects/opportunity.workspace-entity';
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
import { WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';

@WorkspaceEntity({
standardId: STANDARD_OBJECT_IDS.noteTarget,
Expand Down Expand Up @@ -100,4 +103,25 @@ export class NoteTargetWorkspaceEntity extends BaseWorkspaceEntity {
inverseSideFieldKey: 'noteTargets',
})
custom: Relation<CustomWorkspaceEntity>;

@WorkspaceRelation({
standardId: NOTE_TARGET_STANDARD_FIELD_IDS.workflow,
type: RelationMetadataType.MANY_TO_ONE,
label: 'Workflow',
description: 'Note workflow',
icon: 'IconTargetArrow',
inverseSideTarget: () => WorkflowWorkspaceEntity,
inverseSideFieldKey: 'noteTargets',
})
@WorkspaceGate({
featureFlag: FeatureFlagKey.IsWorkflowEnabled,
})
@WorkspaceIsNullable()
workflow: Relation<WorkflowWorkspaceEntity> | null;

@WorkspaceJoinColumn('workflow')
@WorkspaceGate({
featureFlag: FeatureFlagKey.IsWorkflowEnabled,
})
workflowId: string | null;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Relation } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/relation.interface';

import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
import { CustomWorkspaceEntity } from 'src/engine/twenty-orm/custom.workspace-entity';
import { WorkspaceDynamicRelation } from 'src/engine/twenty-orm/decorators/workspace-dynamic-relation.decorator';
import { WorkspaceEntity } from 'src/engine/twenty-orm/decorators/workspace-entity.decorator';
import { WorkspaceGate } from 'src/engine/twenty-orm/decorators/workspace-gate.decorator';
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator';
import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator';
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
Expand All @@ -15,6 +17,7 @@ import { CompanyWorkspaceEntity } from 'src/modules/company/standard-objects/com
import { OpportunityWorkspaceEntity } from 'src/modules/opportunity/standard-objects/opportunity.workspace-entity';
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
import { TaskWorkspaceEntity } from 'src/modules/task/standard-objects/task.workspace-entity';
import { WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';

@WorkspaceEntity({
standardId: STANDARD_OBJECT_IDS.taskTarget,
Expand Down Expand Up @@ -100,4 +103,25 @@ export class TaskTargetWorkspaceEntity extends BaseWorkspaceEntity {
inverseSideFieldKey: 'taskTargets',
})
custom: Relation<CustomWorkspaceEntity>;

@WorkspaceRelation({
standardId: TASK_TARGET_STANDARD_FIELD_IDS.workflow,
type: RelationMetadataType.MANY_TO_ONE,
label: 'Workflow',
description: 'Task workflow',
icon: 'IconTargetArrow',
inverseSideTarget: () => WorkflowWorkspaceEntity,
inverseSideFieldKey: 'taskTargets',
})
@WorkspaceGate({
featureFlag: FeatureFlagKey.IsWorkflowEnabled,
})
@WorkspaceIsNullable()
workflow: Relation<WorkflowWorkspaceEntity> | null;

@WorkspaceJoinColumn('workflow')
@WorkspaceGate({
featureFlag: FeatureFlagKey.IsWorkflowEnabled,
})
workflowId: string | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync
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 { WorkflowVersionWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-version.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';

@WorkspaceEntity({
standardId: STANDARD_OBJECT_IDS.workflow,
Expand Down Expand Up @@ -136,4 +138,26 @@ export class WorkflowWorkspaceEntity extends BaseWorkspaceEntity {
@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[]>;
}
Loading