Front Extensibility: Introduce Front Component Entity (#17175)
As part of the extensibility effort, we are introducing a new engine entity called "Front Component". This represents a dynamic react component that will be rendered in CommandMenu actions or in PageLayout widgets This PR introduce the entity and all the necessary boilerplate to make it syncable and cachable in the engine
This commit is contained in:
+71
@@ -0,0 +1,71 @@
|
||||
import { UseGuards, UseInterceptors } from '@nestjs/common';
|
||||
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
|
||||
|
||||
import { PermissionFlagType } from 'twenty-shared/constants';
|
||||
|
||||
import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
|
||||
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
|
||||
import { NoPermissionGuard } from 'src/engine/guards/no-permission.guard';
|
||||
import { SettingsPermissionGuard } from 'src/engine/guards/settings-permission.guard';
|
||||
import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
|
||||
import { CreateFrontComponentInput } from 'src/engine/metadata-modules/front-component/dtos/create-front-component.input';
|
||||
import { FrontComponentDTO } from 'src/engine/metadata-modules/front-component/dtos/front-component.dto';
|
||||
import { UpdateFrontComponentInput } from 'src/engine/metadata-modules/front-component/dtos/update-front-component.input';
|
||||
import { FrontComponentService } from 'src/engine/metadata-modules/front-component/front-component.service';
|
||||
import { FrontComponentGraphqlApiExceptionInterceptor } from 'src/engine/metadata-modules/front-component/interceptors/front-component-graphql-api-exception.interceptor';
|
||||
import { WorkspaceMigrationBuilderGraphqlApiExceptionInterceptor } from 'src/engine/workspace-manager/workspace-migration/interceptors/workspace-migration-builder-graphql-api-exception.interceptor';
|
||||
|
||||
@UseGuards(WorkspaceAuthGuard)
|
||||
@UseInterceptors(
|
||||
WorkspaceMigrationBuilderGraphqlApiExceptionInterceptor,
|
||||
FrontComponentGraphqlApiExceptionInterceptor,
|
||||
)
|
||||
@Resolver(() => FrontComponentDTO)
|
||||
export class FrontComponentResolver {
|
||||
constructor(private readonly frontComponentService: FrontComponentService) {}
|
||||
|
||||
@Query(() => [FrontComponentDTO])
|
||||
@UseGuards(NoPermissionGuard)
|
||||
async frontComponents(
|
||||
@AuthWorkspace() workspace: WorkspaceEntity,
|
||||
): Promise<FrontComponentDTO[]> {
|
||||
return await this.frontComponentService.findAll(workspace.id);
|
||||
}
|
||||
|
||||
@Query(() => FrontComponentDTO, { nullable: true })
|
||||
@UseGuards(NoPermissionGuard)
|
||||
async frontComponent(
|
||||
@Args('id', { type: () => UUIDScalarType }) id: string,
|
||||
@AuthWorkspace() workspace: WorkspaceEntity,
|
||||
): Promise<FrontComponentDTO | null> {
|
||||
return await this.frontComponentService.findById(id, workspace.id);
|
||||
}
|
||||
|
||||
@Mutation(() => FrontComponentDTO)
|
||||
@UseGuards(SettingsPermissionGuard(PermissionFlagType.APPLICATIONS))
|
||||
async createFrontComponent(
|
||||
@Args('input') input: CreateFrontComponentInput,
|
||||
@AuthWorkspace() workspace: WorkspaceEntity,
|
||||
): Promise<FrontComponentDTO> {
|
||||
return await this.frontComponentService.create(input, workspace.id);
|
||||
}
|
||||
|
||||
@Mutation(() => FrontComponentDTO)
|
||||
@UseGuards(SettingsPermissionGuard(PermissionFlagType.APPLICATIONS))
|
||||
async updateFrontComponent(
|
||||
@Args('input') input: UpdateFrontComponentInput,
|
||||
@AuthWorkspace() workspace: WorkspaceEntity,
|
||||
): Promise<FrontComponentDTO> {
|
||||
return await this.frontComponentService.update(input, workspace.id);
|
||||
}
|
||||
|
||||
@Mutation(() => FrontComponentDTO)
|
||||
@UseGuards(SettingsPermissionGuard(PermissionFlagType.APPLICATIONS))
|
||||
async deleteFrontComponent(
|
||||
@Args('id', { type: () => UUIDScalarType }) id: string,
|
||||
@AuthWorkspace() workspace: WorkspaceEntity,
|
||||
): Promise<FrontComponentDTO> {
|
||||
return await this.frontComponentService.delete(id, workspace.id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user