46e5420d20
# Introduction In this pull request we're introducing new standard page layout, tabs and widget ( 1 page layout, 1 tab and 8 widgets ) and also a new opportunity field Also now prefilling new records, 6 opportunities and a dashboard. ## Standard declaration ### New workspace creation Relies on existing standard declaration builder ### Backfill command We've been hacking through the standard builder in order to extract only the standard page layout entities, updated their entity dependencies to match the workspace ids so the validation passes ## Remark - Refactored the `PageLayoutWidget` configuration type to be dynamically typed through a generic discriminated union --------- Co-authored-by: prastoin <paul@twenty.com>
66 lines
2.2 KiB
TypeScript
66 lines
2.2 KiB
TypeScript
import { FieldActorSource } from 'twenty-shared/types';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
import { type EntityManager } from 'typeorm';
|
|
|
|
import { type FlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-maps.type';
|
|
import { findFlatEntityByUniversalIdentifier } from 'src/engine/metadata-modules/flat-entity/utils/find-flat-entity-by-universal-identifier.util';
|
|
import { type FlatPageLayout } from 'src/engine/metadata-modules/flat-page-layout/types/flat-page-layout.type';
|
|
import { STANDARD_PAGE_LAYOUTS } from 'src/engine/workspace-manager/twenty-standard-application/constants/standard-page-layout.constant';
|
|
|
|
export const MY_FIRST_DASHBOARD_ID = 'f31ecf3b-87d3-4e8a-a84b-b6f0f3f8c7e2';
|
|
|
|
export const prefillDashboards = async (
|
|
entityManager: EntityManager,
|
|
schemaName: string,
|
|
flatPageLayoutMaps: FlatEntityMaps<FlatPageLayout>,
|
|
) => {
|
|
const myFirstDashboardPageLayout = findFlatEntityByUniversalIdentifier({
|
|
flatEntityMaps: flatPageLayoutMaps,
|
|
universalIdentifier:
|
|
STANDARD_PAGE_LAYOUTS.myFirstDashboard.universalIdentifier,
|
|
});
|
|
|
|
if (!isDefined(myFirstDashboardPageLayout)) {
|
|
throw new Error(
|
|
`Page layout with universalIdentifier '${STANDARD_PAGE_LAYOUTS.myFirstDashboard.universalIdentifier}' not found`,
|
|
);
|
|
}
|
|
|
|
await entityManager
|
|
.createQueryBuilder()
|
|
.insert()
|
|
.into(`${schemaName}.dashboard`, [
|
|
'id',
|
|
'title',
|
|
'pageLayoutId',
|
|
'position',
|
|
'createdBySource',
|
|
'createdByWorkspaceMemberId',
|
|
'createdByName',
|
|
'createdByContext',
|
|
'updatedBySource',
|
|
'updatedByWorkspaceMemberId',
|
|
'updatedByName',
|
|
'updatedByContext',
|
|
])
|
|
.orIgnore()
|
|
.values([
|
|
{
|
|
id: MY_FIRST_DASHBOARD_ID,
|
|
title: 'My First Dashboard',
|
|
pageLayoutId: myFirstDashboardPageLayout.id,
|
|
position: 0,
|
|
createdBySource: FieldActorSource.SYSTEM,
|
|
createdByWorkspaceMemberId: null,
|
|
createdByName: 'System',
|
|
createdByContext: {},
|
|
updatedBySource: FieldActorSource.SYSTEM,
|
|
updatedByWorkspaceMemberId: null,
|
|
updatedByName: 'System',
|
|
updatedByContext: {},
|
|
},
|
|
])
|
|
.returning('*')
|
|
.execute();
|
|
};
|