feat: refactor folder structure (#4498)

* feat: wip refactor folder structure

* Fix

* fix position

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Jérémy M
2024-03-15 14:40:58 +01:00
committed by GitHub
parent 52f1b3ac98
commit 94487f6737
760 changed files with 3215 additions and 3155 deletions

View File

@ -0,0 +1,57 @@
import { EntityManager } from 'typeorm';
export const companyPrefillData = async (
entityManager: EntityManager,
schemaName: string,
) => {
await entityManager
.createQueryBuilder()
.insert()
.into(`${schemaName}.company`, [
'name',
'domainName',
'address',
'employees',
'position',
])
.orIgnore()
.values([
{
name: 'Airbnb',
domainName: 'airbnb.com',
address: 'San Francisco',
employees: 5000,
position: 1,
},
{
name: 'Qonto',
domainName: 'qonto.com',
address: 'San Francisco',
employees: 800,
position: 2,
},
{
name: 'Stripe',
domainName: 'stripe.com',
address: 'San Francisco',
employees: 8000,
position: 3,
},
{
name: 'Figma',
domainName: 'figma.com',
address: 'San Francisco',
employees: 800,
position: 4,
},
{
name: 'Notion',
domainName: 'notion.com',
address: 'San Francisco',
employees: 400,
position: 5,
},
])
.returning('*')
.execute();
};

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,41 @@
import { EntityManager } from 'typeorm';
export const pipelineStepPrefillData = async (
entityManager: EntityManager,
schemaName: string,
) => {
await entityManager
.createQueryBuilder()
.insert()
.into(`${schemaName}.pipelineStep`, ['name', 'color', 'position'])
.orIgnore()
.values([
{
name: 'NEW',
color: 'red',
position: 0,
},
{
name: 'SCREENING',
color: 'purple',
position: 1,
},
{
name: 'MEETING',
color: 'sky',
position: 2,
},
{
name: 'PROPOSAL',
color: 'turquoise',
position: 3,
},
{
name: 'CUSTOMER',
color: 'yellow',
position: 4,
},
])
.returning('*')
.execute();
};

View File

@ -0,0 +1,33 @@
import { DataSource, EntityManager } from 'typeorm';
import { ObjectMetadataEntity } from 'src/engine-metadata/object-metadata/object-metadata.entity';
import { viewPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/view';
import { companyPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/company';
import { personPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/person';
import { pipelineStepPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/pipeline-step';
export const standardObjectsPrefillData = async (
workspaceDataSource: DataSource,
schemaName: string,
objectMetadata: ObjectMetadataEntity[],
) => {
const objectMetadataMap = objectMetadata.reduce((acc, object) => {
acc[object.nameSingular] = {
id: object.id,
fields: object.fields.reduce((acc, field) => {
acc[field.name] = field.id;
return acc;
}, {}),
};
return acc;
}, {});
workspaceDataSource.transaction(async (entityManager: EntityManager) => {
await companyPrefillData(entityManager, schemaName);
await personPrefillData(entityManager, schemaName);
await viewPrefillData(entityManager, schemaName, objectMetadataMap);
await pipelineStepPrefillData(entityManager, schemaName);
});
};

View File

@ -0,0 +1,269 @@
import { EntityManager } from 'typeorm';
import { ObjectMetadataEntity } from 'src/engine-metadata/object-metadata/object-metadata.entity';
export const viewPrefillData = async (
entityManager: EntityManager,
schemaName: string,
objectMetadataMap: Record<string, ObjectMetadataEntity>,
) => {
// Creating views
const createdViews = await entityManager
.createQueryBuilder()
.insert()
.into(`${schemaName}.view`, [
'name',
'objectMetadataId',
'type',
'key',
'position',
'icon',
])
.orIgnore()
.values([
{
name: 'All Companies',
objectMetadataId: objectMetadataMap['company'].id,
type: 'table',
key: 'INDEX',
position: 0,
icon: 'IconBuildingSkyscraper',
},
{
name: 'All People',
objectMetadataId: objectMetadataMap['person'].id,
type: 'table',
key: 'INDEX',
position: 0,
icon: 'IconUser',
},
{
name: 'By Stage',
objectMetadataId: objectMetadataMap['opportunity'].id,
type: 'kanban',
key: null,
position: 0,
icon: 'IconLayoutKanban',
},
{
name: 'All Opportunities',
objectMetadataId: objectMetadataMap['opportunity'].id,
type: 'table',
key: 'INDEX',
position: 1,
icon: 'IconTargetArrow',
},
])
.returning('*')
.execute();
const viewIdMap = createdViews.raw.reduce((acc, view) => {
acc[view.name] = view.id;
return acc;
}, {});
// Creating viewFields
await entityManager
.createQueryBuilder()
.insert()
.into(`${schemaName}.viewField`, [
'fieldMetadataId',
'viewId',
'position',
'isVisible',
'size',
])
.orIgnore()
.values([
// Company
{
fieldMetadataId: objectMetadataMap['company'].fields['name'],
viewId: viewIdMap['All Companies'],
position: 0,
isVisible: true,
size: 180,
},
{
fieldMetadataId: objectMetadataMap['company'].fields['domainName'],
viewId: viewIdMap['All Companies'],
position: 1,
isVisible: true,
size: 100,
},
{
fieldMetadataId: objectMetadataMap['company'].fields['accountOwner'],
viewId: viewIdMap['All Companies'],
position: 2,
isVisible: true,
size: 150,
},
{
fieldMetadataId: objectMetadataMap['company'].fields['createdAt'],
viewId: viewIdMap['All Companies'],
position: 3,
isVisible: true,
size: 150,
},
{
fieldMetadataId: objectMetadataMap['company'].fields['employees'],
viewId: viewIdMap['All Companies'],
position: 4,
isVisible: true,
size: 150,
},
{
fieldMetadataId: objectMetadataMap['company'].fields['linkedinLink'],
viewId: viewIdMap['All Companies'],
position: 5,
isVisible: true,
size: 170,
},
{
fieldMetadataId: objectMetadataMap['company'].fields['address'],
viewId: viewIdMap['All Companies'],
position: 6,
isVisible: true,
size: 170,
},
// Person
{
fieldMetadataId: objectMetadataMap['person'].fields['name'],
viewId: viewIdMap['All People'],
position: 0,
isVisible: true,
size: 210,
},
{
fieldMetadataId: objectMetadataMap['person'].fields['email'],
viewId: viewIdMap['All People'],
position: 1,
isVisible: true,
size: 150,
},
{
fieldMetadataId: objectMetadataMap['person'].fields['company'],
viewId: viewIdMap['All People'],
position: 2,
isVisible: true,
size: 150,
},
{
fieldMetadataId: objectMetadataMap['person'].fields['phone'],
viewId: viewIdMap['All People'],
position: 3,
isVisible: true,
size: 150,
},
{
fieldMetadataId: objectMetadataMap['person'].fields['createdAt'],
viewId: viewIdMap['All People'],
position: 4,
isVisible: true,
size: 150,
},
{
fieldMetadataId: objectMetadataMap['person'].fields['city'],
viewId: viewIdMap['All People'],
position: 5,
isVisible: true,
size: 150,
},
{
fieldMetadataId: objectMetadataMap['person'].fields['jobTitle'],
viewId: viewIdMap['All People'],
position: 6,
isVisible: true,
size: 150,
},
{
fieldMetadataId: objectMetadataMap['person'].fields['linkedinLink'],
viewId: viewIdMap['All People'],
position: 7,
isVisible: true,
size: 150,
},
{
fieldMetadataId: objectMetadataMap['person'].fields['xLink'],
viewId: viewIdMap['All People'],
position: 8,
isVisible: true,
size: 150,
},
// Opportunity
{
fieldMetadataId: objectMetadataMap['opportunity'].fields['name'],
viewId: viewIdMap['All Opportunities'],
position: 0,
isVisible: true,
size: 150,
},
{
fieldMetadataId: objectMetadataMap['opportunity'].fields['amount'],
viewId: viewIdMap['All Opportunities'],
position: 1,
isVisible: true,
size: 150,
},
{
fieldMetadataId: objectMetadataMap['opportunity'].fields['closeDate'],
viewId: viewIdMap['All Opportunities'],
position: 2,
isVisible: true,
size: 150,
},
{
fieldMetadataId: objectMetadataMap['opportunity'].fields['probability'],
viewId: viewIdMap['All Opportunities'],
position: 3,
isVisible: true,
size: 150,
},
{
fieldMetadataId:
objectMetadataMap['opportunity'].fields['pointOfContact'],
viewId: viewIdMap['All Opportunities'],
position: 4,
isVisible: true,
size: 150,
},
{
fieldMetadataId: objectMetadataMap['opportunity'].fields['name'],
viewId: viewIdMap['By Stage'],
position: 0,
isVisible: true,
size: 150,
},
{
fieldMetadataId: objectMetadataMap['opportunity'].fields['amount'],
viewId: viewIdMap['By Stage'],
position: 1,
isVisible: true,
size: 150,
},
{
fieldMetadataId: objectMetadataMap['opportunity'].fields['closeDate'],
viewId: viewIdMap['By Stage'],
position: 2,
isVisible: true,
size: 150,
},
{
fieldMetadataId: objectMetadataMap['opportunity'].fields['probability'],
viewId: viewIdMap['By Stage'],
position: 3,
isVisible: true,
size: 150,
},
{
fieldMetadataId:
objectMetadataMap['opportunity'].fields['pointOfContact'],
viewId: viewIdMap['By Stage'],
position: 4,
isVisible: true,
size: 150,
},
])
.execute();
};