Pre hook for dashboard creation + updates on the entity (#14354)

Closes https://github.com/twentyhq/core-team-issues/issues/1417

- The pre-hook creates a page-layout and links it to the dashboard
- Added `position`, `createdBy`, `attachments`, `searchVector`,
`favorites` to the dashboard entity
- Updated the view seed
- Updated the page layout services to work within a transaction
This commit is contained in:
Raphaël Bosi
2025-09-09 14:55:22 +02:00
committed by GitHub
parent 861cb1c222
commit 3d2d14eb71
19 changed files with 657 additions and 115 deletions
@@ -0,0 +1,63 @@
import { Injectable } from '@nestjs/common';
import { InjectDataSource } from '@nestjs/typeorm';
import { DataSource } from 'typeorm';
import { type WorkspacePreQueryHookInstance } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/interfaces/workspace-query-hook.interface';
import { type CreateOneResolverArgs } from 'src/engine/api/graphql/workspace-resolver-builder/interfaces/workspace-resolvers-builder.interface';
import { WorkspaceQueryHook } from 'src/engine/api/graphql/workspace-query-runner/workspace-query-hook/decorators/workspace-query-hook.decorator';
import { type AuthContext } from 'src/engine/core-modules/auth/types/auth-context.type';
import { PageLayoutType } from 'src/engine/core-modules/page-layout/enums/page-layout-type.enum';
import { PageLayoutTabService } from 'src/engine/core-modules/page-layout/services/page-layout-tab.service';
import { PageLayoutService } from 'src/engine/core-modules/page-layout/services/page-layout.service';
import { workspaceValidator } from 'src/engine/core-modules/workspace/workspace.validate';
import { type DashboardWorkspaceEntity } from 'src/modules/dashboard/standard-objects/dashboard.workspace-entity';
@Injectable()
@WorkspaceQueryHook(`dashboard.createOne`)
export class DashboardCreateOnePreQueryHook
implements WorkspacePreQueryHookInstance
{
constructor(
private readonly pageLayoutService: PageLayoutService,
private readonly pageLayoutTabService: PageLayoutTabService,
@InjectDataSource()
private readonly coreDataSource: DataSource,
) {}
async execute(
authContext: AuthContext,
_objectName: string,
payload: CreateOneResolverArgs<DashboardWorkspaceEntity>,
): Promise<CreateOneResolverArgs<DashboardWorkspaceEntity>> {
const workspace = authContext.workspace;
workspaceValidator.assertIsDefinedOrThrow(workspace);
return await this.coreDataSource.transaction(async (manager) => {
const pageLayout = await this.pageLayoutService.create(
{
type: PageLayoutType.DASHBOARD,
objectMetadataId: null,
name: 'Dashboard Layout',
},
workspace.id,
manager,
);
await this.pageLayoutTabService.create(
{
title: 'Tab 1',
pageLayoutId: pageLayout.id,
},
workspace.id,
manager,
);
payload.data.pageLayoutId = pageLayout.id;
return payload;
});
}
}
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { PageLayoutModule } from 'src/engine/core-modules/page-layout/page-layout.module';
import { DashboardCreateOnePreQueryHook } from 'src/modules/dashboard/query-hooks/dashboard-create-one.pre-query.hook';
@Module({
imports: [PageLayoutModule],
providers: [DashboardCreateOnePreQueryHook],
})
export class DashboardQueryHookModule {}