feat: CommandMenuItem entity and FrontComponent support in command menu (#17555)
https://github.com/user-attachments/assets/6f172ffc-d43d-42fd-a26b-94f591fb767e
This commit is contained in:
+3
@@ -7,6 +7,7 @@ import { CustomException } from 'src/utils/custom-exception';
|
||||
export enum CommandMenuItemExceptionCode {
|
||||
COMMAND_MENU_ITEM_NOT_FOUND = 'COMMAND_MENU_ITEM_NOT_FOUND',
|
||||
INVALID_COMMAND_MENU_ITEM_INPUT = 'INVALID_COMMAND_MENU_ITEM_INPUT',
|
||||
WORKFLOW_OR_FRONT_COMPONENT_REQUIRED = 'WORKFLOW_OR_FRONT_COMPONENT_REQUIRED',
|
||||
}
|
||||
|
||||
const getCommandMenuItemExceptionUserFriendlyMessage = (
|
||||
@@ -17,6 +18,8 @@ const getCommandMenuItemExceptionUserFriendlyMessage = (
|
||||
return msg`Command menu item not found.`;
|
||||
case CommandMenuItemExceptionCode.INVALID_COMMAND_MENU_ITEM_INPUT:
|
||||
return msg`Invalid command menu item input.`;
|
||||
case CommandMenuItemExceptionCode.WORKFLOW_OR_FRONT_COMPONENT_REQUIRED:
|
||||
return msg`Either workflow version or front component is required.`;
|
||||
default:
|
||||
assertUnreachable(code);
|
||||
}
|
||||
|
||||
+2
@@ -3,6 +3,7 @@ import { Module } from '@nestjs/common';
|
||||
import { ApplicationModule } from 'src/engine/core-modules/application/application.module';
|
||||
import { FeatureFlagModule } from 'src/engine/core-modules/feature-flag/feature-flag.module';
|
||||
import { CommandMenuItemResolver } from 'src/engine/metadata-modules/command-menu-item/command-menu-item.resolver';
|
||||
import { FrontComponentModule } from 'src/engine/metadata-modules/front-component/front-component.module';
|
||||
import { CommandMenuItemService } from 'src/engine/metadata-modules/command-menu-item/command-menu-item.service';
|
||||
import { CommandMenuItemGraphqlApiExceptionInterceptor } from 'src/engine/metadata-modules/command-menu-item/interceptors/command-menu-item-graphql-api-exception.interceptor';
|
||||
import { FlatCommandMenuItemModule } from 'src/engine/metadata-modules/flat-command-menu-item/flat-command-menu-item.module';
|
||||
@@ -16,6 +17,7 @@ import { WorkspaceMigrationModule } from 'src/engine/workspace-manager/workspace
|
||||
WorkspaceMigrationModule,
|
||||
ApplicationModule,
|
||||
FlatCommandMenuItemModule,
|
||||
FrontComponentModule,
|
||||
FeatureFlagModule,
|
||||
],
|
||||
providers: [
|
||||
|
||||
+28
-1
@@ -1,5 +1,14 @@
|
||||
import { UseGuards, UseInterceptors } from '@nestjs/common';
|
||||
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
|
||||
import {
|
||||
Args,
|
||||
Mutation,
|
||||
Parent,
|
||||
Query,
|
||||
ResolveField,
|
||||
Resolver,
|
||||
} from '@nestjs/graphql';
|
||||
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
|
||||
import { FeatureFlagKey } from 'src/engine/core-modules/feature-flag/enums/feature-flag-key.enum';
|
||||
@@ -16,6 +25,8 @@ import { CommandMenuItemDTO } from 'src/engine/metadata-modules/command-menu-ite
|
||||
import { CreateCommandMenuItemInput } from 'src/engine/metadata-modules/command-menu-item/dtos/create-command-menu-item.input';
|
||||
import { UpdateCommandMenuItemInput } from 'src/engine/metadata-modules/command-menu-item/dtos/update-command-menu-item.input';
|
||||
import { CommandMenuItemGraphqlApiExceptionInterceptor } from 'src/engine/metadata-modules/command-menu-item/interceptors/command-menu-item-graphql-api-exception.interceptor';
|
||||
import { FrontComponentDTO } from 'src/engine/metadata-modules/front-component/dtos/front-component.dto';
|
||||
import { FrontComponentService } from 'src/engine/metadata-modules/front-component/front-component.service';
|
||||
import { WorkspaceMigrationGraphqlApiExceptionInterceptor } from 'src/engine/workspace-manager/workspace-migration/interceptors/workspace-migration-graphql-api-exception.interceptor';
|
||||
|
||||
@UseGuards(WorkspaceAuthGuard, FeatureFlagGuard)
|
||||
@@ -27,8 +38,24 @@ import { WorkspaceMigrationGraphqlApiExceptionInterceptor } from 'src/engine/wor
|
||||
export class CommandMenuItemResolver {
|
||||
constructor(
|
||||
private readonly commandMenuItemService: CommandMenuItemService,
|
||||
private readonly frontComponentService: FrontComponentService,
|
||||
) {}
|
||||
|
||||
@ResolveField(() => FrontComponentDTO, { nullable: true })
|
||||
async frontComponent(
|
||||
@Parent() commandMenuItem: CommandMenuItemDTO,
|
||||
@AuthWorkspace() workspace: WorkspaceEntity,
|
||||
) {
|
||||
if (!isDefined(commandMenuItem.frontComponentId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.frontComponentService.findById(
|
||||
commandMenuItem.frontComponentId,
|
||||
workspace.id,
|
||||
);
|
||||
}
|
||||
|
||||
@Query(() => [CommandMenuItemDTO])
|
||||
@UseGuards(NoPermissionGuard)
|
||||
@RequireFeatureFlag(FeatureFlagKey.IS_COMMAND_MENU_ITEM_ENABLED)
|
||||
|
||||
+12
-3
@@ -17,6 +17,7 @@ import {
|
||||
|
||||
import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
|
||||
import { CommandMenuItemAvailabilityType } from 'src/engine/metadata-modules/command-menu-item/entities/command-menu-item.entity';
|
||||
import { FrontComponentDTO } from 'src/engine/metadata-modules/front-component/dtos/front-component.dto';
|
||||
|
||||
registerEnumType(CommandMenuItemAvailabilityType, {
|
||||
name: 'CommandMenuItemAvailabilityType',
|
||||
@@ -30,9 +31,17 @@ export class CommandMenuItemDTO {
|
||||
id: string;
|
||||
|
||||
@IsUUID()
|
||||
@IsNotEmpty()
|
||||
@Field(() => UUIDScalarType)
|
||||
workflowVersionId: string;
|
||||
@IsOptional()
|
||||
@Field(() => UUIDScalarType, { nullable: true })
|
||||
workflowVersionId?: string;
|
||||
|
||||
@IsUUID()
|
||||
@IsOptional()
|
||||
@Field(() => UUIDScalarType, { nullable: true })
|
||||
frontComponentId?: string;
|
||||
|
||||
@Field(() => FrontComponentDTO, { nullable: true })
|
||||
frontComponent?: FrontComponentDTO | null;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
|
||||
+8
-3
@@ -15,9 +15,14 @@ import { CommandMenuItemAvailabilityType } from 'src/engine/metadata-modules/com
|
||||
@InputType()
|
||||
export class CreateCommandMenuItemInput {
|
||||
@IsUUID()
|
||||
@IsNotEmpty()
|
||||
@Field(() => UUIDScalarType)
|
||||
workflowVersionId: string;
|
||||
@IsOptional()
|
||||
@Field(() => UUIDScalarType, { nullable: true })
|
||||
workflowVersionId?: string;
|
||||
|
||||
@IsUUID()
|
||||
@IsOptional()
|
||||
@Field(() => UUIDScalarType, { nullable: true })
|
||||
frontComponentId?: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
|
||||
+22
-2
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
Check,
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
@@ -10,6 +11,7 @@ import {
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
import { FrontComponentEntity } from 'src/engine/metadata-modules/front-component/entities/front-component.entity';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { SyncableEntity } from 'src/engine/workspace-manager/types/syncable-entity.interface';
|
||||
|
||||
@@ -24,9 +26,17 @@ export enum CommandMenuItemAvailabilityType {
|
||||
'workflowVersionId',
|
||||
'workspaceId',
|
||||
])
|
||||
@Index('IDX_COMMAND_MENU_ITEM_FRONT_COMPONENT_ID_WORKSPACE_ID', [
|
||||
'frontComponentId',
|
||||
'workspaceId',
|
||||
])
|
||||
@Index('IDX_COMMAND_MENU_ITEM_AVAILABILITY_OBJECT_METADATA_ID', [
|
||||
'availabilityObjectMetadataId',
|
||||
])
|
||||
@Check(
|
||||
'CHK_command_menu_item_workflow_or_front_component',
|
||||
'("workflowVersionId" IS NOT NULL AND "frontComponentId" IS NULL) OR ("workflowVersionId" IS NULL AND "frontComponentId" IS NOT NULL)',
|
||||
)
|
||||
export class CommandMenuItemEntity
|
||||
extends SyncableEntity
|
||||
implements Required<CommandMenuItemEntity>
|
||||
@@ -34,8 +44,18 @@ export class CommandMenuItemEntity
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({ nullable: false, type: 'uuid' })
|
||||
workflowVersionId: string;
|
||||
@Column({ nullable: true, type: 'uuid' })
|
||||
workflowVersionId: string | null;
|
||||
|
||||
@Column({ nullable: true, type: 'uuid' })
|
||||
frontComponentId: string | null;
|
||||
|
||||
@ManyToOne(() => FrontComponentEntity, {
|
||||
onDelete: 'CASCADE',
|
||||
nullable: true,
|
||||
})
|
||||
@JoinColumn({ name: 'frontComponentId' })
|
||||
frontComponent: Relation<FrontComponentEntity> | null;
|
||||
|
||||
@Column({ nullable: false })
|
||||
label: string;
|
||||
|
||||
+1
@@ -15,6 +15,7 @@ export const commandMenuItemGraphqlApiExceptionHandler = (error: Error) => {
|
||||
case CommandMenuItemExceptionCode.COMMAND_MENU_ITEM_NOT_FOUND:
|
||||
throw new NotFoundError(error);
|
||||
case CommandMenuItemExceptionCode.INVALID_COMMAND_MENU_ITEM_INPUT:
|
||||
case CommandMenuItemExceptionCode.WORKFLOW_OR_FRONT_COMPONENT_REQUIRED:
|
||||
throw new UserInputError(error);
|
||||
default: {
|
||||
return assertUnreachable(error.code);
|
||||
|
||||
Reference in New Issue
Block a user