Deprecate old relations completely (#12482)
# What Fully deprecate old relations because we have one bug tied to it and it make the codebase complex # How I've made this PR: 1. remove metadata datasource (we only keep 'core') => this was causing extra complexity in the refactor + flaky reset 2. merge dev and demo datasets => as I needed to update the tests which is very painful, I don't want to do it twice 3. remove all code tied to RELATION_METADATA / relation-metadata.resolver, or anything tied to the old relation system 4. Remove ONE_TO_ONE and MANY_TO_MANY that are not supported 5. fix impacts on the different areas : see functional testing below # Functional testing ## Functional testing from the front-end: 1. Database Reset ✅ 2. Sign In ✅ 3. Workspace sign-up ✅ 5. Browsing table / kanban / show ✅ 6. Assigning a record in a one to many / in a many to one ✅ 7. Deleting a record involved in a relation ✅ => broken but not tied to this PR 8. "Add new" from relation picker ✅ => broken but not tied to this PR 9. Creating a Task / Note, Updating a Task / Note relations, Deleting a Task / Note (from table, show page, right drawer) ✅ => broken but not tied to this PR 10. creating a relation from settings (custom / standard x oneToMany / manyToOne) ✅ 11. updating a relation from settings should not be possible ✅ 12. deleting a relation from settings (custom / standard x oneToMany / manyToOne) ✅ 13. Make sure timeline activity still work (relation were involved there), espacially with Task / Note => to be double checked ✅ => Cannot convert undefined or null to object 14. Workspace deletion / User deletion ✅ 15. CSV Import should keep working ✅ 16. Permissions: I have tested without permissions V2 as it's still hard to test v2 work and it's not in prod yet ✅ 17. Workflows global test ✅ ## From the API: 1. Review open-api documentation (REST) ✅ 2. Make sure REST Api are still able to fetch relations ==> won't do, we have a coupling Get/Update/Create there, this requires refactoring 3. Make sure REST Api is still able to update / remove relation => won't do same ## Automated tests 1. lint + typescript ✅ 2. front unit tests: ✅ 3. server unit tests 2 ✅ 4. front stories: ✅ 5. server integration: ✅ 6. chromatic check : expected 0 7. e2e check : expected no more that current failures ## Remove // Todos 1. All are captured by functional tests above, nothing additional to do ## (Un)related regressions 1. Table loading state is not working anymore, we see the empty state before table content 2. Filtering by Creator Tim Ap return empty results 3. Not possible to add Tasks / Notes / Files from show page # Result ## New seeds that can be easily extended <img width="1920" alt="image" src="https://github.com/user-attachments/assets/d290d130-2a5f-44e6-b419-7e42a89eec4b" /> ## -5k lines of code ## No more 'metadata' dataSource (we only have 'core) ## No more relationMetadata (I haven't drop the table yet it's not referenced in the code anymore) ## We are ready to fix the 6 months lag between current API results and our mocked tests ## No more bug on relation creation / deletion --------- Co-authored-by: Weiko <corentin@twenty.com> Co-authored-by: Félix Malfait <felix@twenty.com>
This commit is contained in:
+68
@@ -0,0 +1,68 @@
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
|
||||
import { FieldMetadataSeed } from 'src/engine/workspace-manager/dev-seeder/metadata/types/field-metadata-seed.type';
|
||||
|
||||
export const COMPANY_CUSTOM_FIELD_SEEDS: FieldMetadataSeed[] = [
|
||||
{
|
||||
type: FieldMetadataType.TEXT,
|
||||
name: 'tagline',
|
||||
label: 'Tagline',
|
||||
description: "Company's Tagline",
|
||||
icon: 'IconAdCircle',
|
||||
isActive: true,
|
||||
isNullable: false,
|
||||
isUnique: false,
|
||||
defaultValue: "''",
|
||||
},
|
||||
{
|
||||
type: FieldMetadataType.LINKS,
|
||||
name: 'introVideo',
|
||||
label: 'Intro Video',
|
||||
description: "Company's Intro Video",
|
||||
icon: 'IconVideo',
|
||||
isActive: true,
|
||||
isNullable: true,
|
||||
isUnique: false,
|
||||
},
|
||||
{
|
||||
type: FieldMetadataType.MULTI_SELECT,
|
||||
name: 'workPolicy',
|
||||
label: 'Work Policy',
|
||||
description: "Company's Work Policy",
|
||||
icon: 'IconHome',
|
||||
isActive: true,
|
||||
isNullable: true,
|
||||
isUnique: false,
|
||||
options: [
|
||||
{
|
||||
color: 'green',
|
||||
label: 'On-Site',
|
||||
position: 0,
|
||||
value: 'ON_SITE',
|
||||
},
|
||||
{
|
||||
color: 'turquoise',
|
||||
label: 'Hybrid',
|
||||
position: 1,
|
||||
value: 'HYBRID',
|
||||
},
|
||||
{
|
||||
color: 'sky',
|
||||
label: 'Remote Work',
|
||||
position: 2,
|
||||
value: 'REMOTE_WORK',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: FieldMetadataType.BOOLEAN,
|
||||
name: 'visaSponsorship',
|
||||
label: 'Visa Sponsorship',
|
||||
description: "Company's Visa Sponsorship Policy",
|
||||
icon: 'IconBrandVisa',
|
||||
isActive: true,
|
||||
isNullable: true,
|
||||
isUnique: false,
|
||||
defaultValue: false,
|
||||
},
|
||||
];
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
|
||||
import { FieldMetadataSeed } from 'src/engine/workspace-manager/dev-seeder/metadata/types/field-metadata-seed.type';
|
||||
|
||||
export const PERSON_CUSTOM_FIELD_SEEDS: FieldMetadataSeed[] = [
|
||||
{
|
||||
type: FieldMetadataType.TEXT,
|
||||
name: 'intro',
|
||||
label: 'Intro',
|
||||
description: "Contact's Intro",
|
||||
icon: 'IconNote',
|
||||
isActive: true,
|
||||
isNullable: true,
|
||||
isUnique: false,
|
||||
},
|
||||
{
|
||||
type: FieldMetadataType.PHONES,
|
||||
name: 'whatsapp',
|
||||
label: 'Whatsapp',
|
||||
description: "Contact's Whatsapp Number",
|
||||
icon: 'IconBrandWhatsapp',
|
||||
isActive: true,
|
||||
isNullable: false,
|
||||
isUnique: false,
|
||||
defaultValue: {
|
||||
primaryPhoneNumber: "''",
|
||||
primaryPhoneCountryCode: "'FR'",
|
||||
primaryPhoneCallingCode: "'+33'",
|
||||
additionalPhones: null,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: FieldMetadataType.MULTI_SELECT,
|
||||
name: 'workPreference',
|
||||
label: 'Work Preference',
|
||||
description: "Person's Work Preference",
|
||||
icon: 'IconHome',
|
||||
isActive: true,
|
||||
isNullable: true,
|
||||
isUnique: false,
|
||||
options: [
|
||||
{
|
||||
color: 'green',
|
||||
label: 'On-Site',
|
||||
position: 0,
|
||||
value: 'ON_SITE',
|
||||
},
|
||||
{
|
||||
color: 'turquoise',
|
||||
label: 'Hybrid',
|
||||
position: 1,
|
||||
value: 'HYBRID',
|
||||
},
|
||||
{
|
||||
color: 'sky',
|
||||
label: 'Remote Work',
|
||||
position: 2,
|
||||
value: 'REMOTE_WORK',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: FieldMetadataType.RATING,
|
||||
name: 'performanceRating',
|
||||
label: 'Performance Rating',
|
||||
description: "Person's Performance Rating",
|
||||
icon: 'IconStars',
|
||||
isActive: true,
|
||||
isNullable: true,
|
||||
isUnique: false,
|
||||
options: [
|
||||
{
|
||||
label: '1',
|
||||
value: 'RATING_1',
|
||||
position: 0,
|
||||
},
|
||||
{
|
||||
label: '2',
|
||||
value: 'RATING_2',
|
||||
position: 1,
|
||||
},
|
||||
{
|
||||
label: '3',
|
||||
value: 'RATING_3',
|
||||
position: 2,
|
||||
},
|
||||
{
|
||||
label: '4',
|
||||
value: 'RATING_4',
|
||||
position: 3,
|
||||
},
|
||||
{
|
||||
label: '5',
|
||||
value: 'RATING_5',
|
||||
position: 4,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
|
||||
import { FieldMetadataSeed } from 'src/engine/workspace-manager/dev-seeder/metadata/types/field-metadata-seed.type';
|
||||
|
||||
export const PET_CUSTOM_FIELD_SEEDS: FieldMetadataSeed[] = [
|
||||
{
|
||||
type: FieldMetadataType.SELECT,
|
||||
label: 'Species',
|
||||
name: 'species',
|
||||
options: [
|
||||
{ label: 'Dog', value: 'DOG', position: 0, color: 'blue' },
|
||||
{ label: 'Cat', value: 'CAT', position: 1, color: 'red' },
|
||||
{ label: 'Bird', value: 'BIRD', position: 2, color: 'green' },
|
||||
{ label: 'Fish', value: 'FISH', position: 3, color: 'yellow' },
|
||||
{ label: 'Rabbit', value: 'RABBIT', position: 4, color: 'purple' },
|
||||
{ label: 'Hamster', value: 'HAMSTER', position: 5, color: 'orange' },
|
||||
],
|
||||
},
|
||||
{
|
||||
type: FieldMetadataType.MULTI_SELECT,
|
||||
label: 'Traits',
|
||||
name: 'traits',
|
||||
options: [
|
||||
{ label: 'Playful', value: 'PLAYFUL', position: 0, color: 'blue' },
|
||||
{ label: 'Friendly', value: 'FRIENDLY', position: 1, color: 'red' },
|
||||
{
|
||||
label: 'Protective',
|
||||
value: 'PROTECTIVE',
|
||||
position: 2,
|
||||
color: 'green',
|
||||
},
|
||||
{ label: 'Shy', value: 'SHY', position: 3, color: 'yellow' },
|
||||
{ label: 'Brave', value: 'BRAVE', position: 4, color: 'purple' },
|
||||
{ label: 'Curious', value: 'CURIOUS', position: 5, color: 'orange' },
|
||||
],
|
||||
},
|
||||
{
|
||||
type: FieldMetadataType.TEXT,
|
||||
label: 'Comments',
|
||||
name: 'comments',
|
||||
},
|
||||
{
|
||||
type: FieldMetadataType.NUMBER,
|
||||
label: 'Age',
|
||||
name: 'age',
|
||||
},
|
||||
{
|
||||
type: FieldMetadataType.ADDRESS,
|
||||
label: 'Location',
|
||||
name: 'location',
|
||||
},
|
||||
{
|
||||
type: FieldMetadataType.PHONES,
|
||||
label: 'Vet phone',
|
||||
name: 'vetPhone',
|
||||
},
|
||||
{
|
||||
type: FieldMetadataType.EMAILS,
|
||||
label: 'Vet email',
|
||||
name: 'vetEmail',
|
||||
},
|
||||
{
|
||||
type: FieldMetadataType.DATE,
|
||||
label: 'Birthday',
|
||||
name: 'birthday',
|
||||
},
|
||||
{
|
||||
type: FieldMetadataType.BOOLEAN,
|
||||
label: 'Is good with kids',
|
||||
name: 'isGoodWithKids',
|
||||
},
|
||||
{
|
||||
type: FieldMetadataType.LINKS,
|
||||
label: 'Pictures',
|
||||
name: 'pictures',
|
||||
},
|
||||
{
|
||||
type: FieldMetadataType.CURRENCY,
|
||||
label: 'Average cost of kibble per month',
|
||||
name: 'averageCostOfKibblePerMonth',
|
||||
},
|
||||
{
|
||||
type: FieldMetadataType.FULL_NAME,
|
||||
label: 'Makes its owner think of',
|
||||
name: 'makesOwnerThinkOf',
|
||||
},
|
||||
{
|
||||
type: FieldMetadataType.RATING,
|
||||
label: 'Sound swag (bark style, meow style, etc.)',
|
||||
name: 'soundSwag',
|
||||
},
|
||||
{
|
||||
type: FieldMetadataType.RICH_TEXT,
|
||||
label: 'Bio',
|
||||
name: 'bio',
|
||||
},
|
||||
{
|
||||
type: FieldMetadataType.ARRAY,
|
||||
label: 'Interesting facts',
|
||||
name: 'interestingFacts',
|
||||
},
|
||||
{
|
||||
type: FieldMetadataType.RAW_JSON,
|
||||
label: 'Extra data',
|
||||
name: 'extraData',
|
||||
},
|
||||
];
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
|
||||
import { NumberDataType } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata-settings.interface';
|
||||
|
||||
import { FieldMetadataDTO } from 'src/engine/metadata-modules/field-metadata/dtos/field-metadata.dto';
|
||||
import { FieldMetadataSeed } from 'src/engine/workspace-manager/dev-seeder/metadata/types/field-metadata-seed.type';
|
||||
|
||||
export const SURVEY_RESULT_CUSTOM_FIELD_SEEDS: FieldMetadataSeed[] = [
|
||||
{
|
||||
type: FieldMetadataType.NUMBER,
|
||||
label: 'Score (Float 3 decimals)',
|
||||
name: 'score',
|
||||
settings: {
|
||||
dataType: NumberDataType.FLOAT,
|
||||
decimals: 3,
|
||||
type: 'number',
|
||||
},
|
||||
} as FieldMetadataDTO<FieldMetadataType.NUMBER>,
|
||||
{
|
||||
type: FieldMetadataType.NUMBER,
|
||||
label: 'Percentage of completion (Float 3 decimals + percentage)',
|
||||
name: 'percentageOfCompletion',
|
||||
settings: {
|
||||
dataType: NumberDataType.FLOAT,
|
||||
decimals: 6,
|
||||
type: 'percentage',
|
||||
},
|
||||
} as FieldMetadataDTO<FieldMetadataType.NUMBER>,
|
||||
{
|
||||
type: FieldMetadataType.NUMBER,
|
||||
label: 'Participants (Int)',
|
||||
name: 'participants',
|
||||
settings: {
|
||||
dataType: NumberDataType.INT,
|
||||
type: 'number',
|
||||
},
|
||||
} as FieldMetadataDTO<FieldMetadataType.NUMBER>,
|
||||
{
|
||||
type: FieldMetadataType.NUMBER,
|
||||
label: 'Average estimated number of atoms in the universe (BigInt)',
|
||||
name: 'averageEstimatedNumberOfAtomsInTheUniverse',
|
||||
settings: {
|
||||
dataType: NumberDataType.BIGINT,
|
||||
type: 'number',
|
||||
},
|
||||
} as FieldMetadataDTO<FieldMetadataType.NUMBER>,
|
||||
{
|
||||
type: FieldMetadataType.TEXT,
|
||||
label: 'Comments (Max 5 rows)',
|
||||
name: 'comments',
|
||||
settings: {
|
||||
displayedMaxRows: 5,
|
||||
},
|
||||
} as FieldMetadataDTO<FieldMetadataType.TEXT>,
|
||||
{
|
||||
type: FieldMetadataType.TEXT,
|
||||
label: 'Short notes (Max 1 row)',
|
||||
name: 'shortNotes',
|
||||
settings: {
|
||||
displayedMaxRows: 1,
|
||||
},
|
||||
} as FieldMetadataDTO<FieldMetadataType.TEXT>,
|
||||
];
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import { ObjectMetadataSeed } from 'src/engine/workspace-manager/dev-seeder/metadata/types/object-metadata-seed.type';
|
||||
|
||||
export const PET_CUSTOM_OBJECT_SEED: ObjectMetadataSeed = {
|
||||
labelPlural: 'Pets',
|
||||
labelSingular: 'Pet',
|
||||
namePlural: 'pets',
|
||||
nameSingular: 'pet',
|
||||
icon: 'IconCat',
|
||||
};
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import { ObjectMetadataSeed } from 'src/engine/workspace-manager/dev-seeder/metadata/types/object-metadata-seed.type';
|
||||
|
||||
export const ROCKET_CUSTOM_OBJECT_SEED: ObjectMetadataSeed = {
|
||||
labelPlural: 'Rockets',
|
||||
labelSingular: 'Rocket',
|
||||
namePlural: 'rockets',
|
||||
nameSingular: 'rocket',
|
||||
icon: 'IconRocket',
|
||||
description: 'A rocket',
|
||||
isRemote: false,
|
||||
};
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import { ObjectMetadataSeed } from 'src/engine/workspace-manager/dev-seeder/metadata/types/object-metadata-seed.type';
|
||||
|
||||
export const SURVEY_RESULT_CUSTOM_OBJECT_SEED: ObjectMetadataSeed = {
|
||||
labelPlural: 'Survey results',
|
||||
labelSingular: 'Survey result',
|
||||
namePlural: 'surveyResults',
|
||||
nameSingular: 'surveyResult',
|
||||
icon: 'IconRulerMeasure',
|
||||
};
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { DataSourceEntity } from 'src/engine/metadata-modules/data-source/data-source.entity';
|
||||
import { FieldMetadataService } from 'src/engine/metadata-modules/field-metadata/field-metadata.service';
|
||||
import { ObjectMetadataService } from 'src/engine/metadata-modules/object-metadata/object-metadata.service';
|
||||
import { COMPANY_CUSTOM_FIELD_SEEDS } from 'src/engine/workspace-manager/dev-seeder/metadata/custom-fields/constants/company-custom-field-seeds.constant';
|
||||
import { PERSON_CUSTOM_FIELD_SEEDS } from 'src/engine/workspace-manager/dev-seeder/metadata/custom-fields/constants/person-custom-field-seeds.constant';
|
||||
import { PET_CUSTOM_FIELD_SEEDS } from 'src/engine/workspace-manager/dev-seeder/metadata/custom-fields/constants/pet-custom-field-seeds.constant';
|
||||
import { SURVEY_RESULT_CUSTOM_FIELD_SEEDS } from 'src/engine/workspace-manager/dev-seeder/metadata/custom-fields/constants/survey-results-field-seeds.constant';
|
||||
import { PET_CUSTOM_OBJECT_SEED } from 'src/engine/workspace-manager/dev-seeder/metadata/custom-objects/constants/pet-custom-object-seed.constant';
|
||||
import { ROCKET_CUSTOM_OBJECT_SEED } from 'src/engine/workspace-manager/dev-seeder/metadata/custom-objects/constants/rocket-custom-object-seed.constant';
|
||||
import { SURVEY_RESULT_CUSTOM_OBJECT_SEED } from 'src/engine/workspace-manager/dev-seeder/metadata/custom-objects/constants/survey-results-object-seed.constant';
|
||||
import { FieldMetadataSeed } from 'src/engine/workspace-manager/dev-seeder/metadata/types/field-metadata-seed.type';
|
||||
import { ObjectMetadataSeed } from 'src/engine/workspace-manager/dev-seeder/metadata/types/object-metadata-seed.type';
|
||||
|
||||
@Injectable()
|
||||
export class DevSeederMetadataService {
|
||||
constructor(
|
||||
private readonly objectMetadataService: ObjectMetadataService,
|
||||
private readonly fieldMetadataService: FieldMetadataService,
|
||||
) {}
|
||||
|
||||
public async seed({
|
||||
dataSourceMetadata,
|
||||
workspaceId,
|
||||
}: {
|
||||
dataSourceMetadata: DataSourceEntity;
|
||||
workspaceId: string;
|
||||
}) {
|
||||
await this.seedCustomObject({
|
||||
dataSourceId: dataSourceMetadata.id,
|
||||
workspaceId,
|
||||
objectMetadataSeed: ROCKET_CUSTOM_OBJECT_SEED,
|
||||
});
|
||||
|
||||
await this.seedCustomObject({
|
||||
dataSourceId: dataSourceMetadata.id,
|
||||
workspaceId,
|
||||
objectMetadataSeed: PET_CUSTOM_OBJECT_SEED,
|
||||
});
|
||||
|
||||
await this.seedCustomFields({
|
||||
workspaceId,
|
||||
objectMetadataNameSingular: PET_CUSTOM_OBJECT_SEED.nameSingular,
|
||||
fieldMetadataSeeds: PET_CUSTOM_FIELD_SEEDS,
|
||||
});
|
||||
|
||||
await this.seedCustomObject({
|
||||
dataSourceId: dataSourceMetadata.id,
|
||||
workspaceId,
|
||||
objectMetadataSeed: SURVEY_RESULT_CUSTOM_OBJECT_SEED,
|
||||
});
|
||||
|
||||
await this.seedCustomFields({
|
||||
workspaceId,
|
||||
objectMetadataNameSingular: SURVEY_RESULT_CUSTOM_OBJECT_SEED.nameSingular,
|
||||
fieldMetadataSeeds: SURVEY_RESULT_CUSTOM_FIELD_SEEDS,
|
||||
});
|
||||
|
||||
await this.seedCustomFields({
|
||||
workspaceId,
|
||||
objectMetadataNameSingular: 'company',
|
||||
fieldMetadataSeeds: COMPANY_CUSTOM_FIELD_SEEDS,
|
||||
});
|
||||
|
||||
await this.seedCustomFields({
|
||||
workspaceId,
|
||||
objectMetadataNameSingular: 'person',
|
||||
fieldMetadataSeeds: PERSON_CUSTOM_FIELD_SEEDS,
|
||||
});
|
||||
}
|
||||
|
||||
private async seedCustomObject({
|
||||
dataSourceId,
|
||||
workspaceId,
|
||||
objectMetadataSeed,
|
||||
}: {
|
||||
dataSourceId: string;
|
||||
workspaceId: string;
|
||||
objectMetadataSeed: ObjectMetadataSeed;
|
||||
}): Promise<void> {
|
||||
await this.objectMetadataService.createOne({
|
||||
...objectMetadataSeed,
|
||||
dataSourceId,
|
||||
workspaceId,
|
||||
});
|
||||
}
|
||||
|
||||
private async seedCustomFields({
|
||||
workspaceId,
|
||||
objectMetadataNameSingular,
|
||||
fieldMetadataSeeds,
|
||||
}: {
|
||||
workspaceId: string;
|
||||
objectMetadataNameSingular: string;
|
||||
fieldMetadataSeeds: FieldMetadataSeed[];
|
||||
}): Promise<void> {
|
||||
const objectMetadata =
|
||||
await this.objectMetadataService.findOneWithinWorkspace(workspaceId, {
|
||||
where: { nameSingular: objectMetadataNameSingular },
|
||||
});
|
||||
|
||||
if (!objectMetadata) {
|
||||
throw new Error('Object metadata not found');
|
||||
}
|
||||
|
||||
await this.fieldMetadataService.createMany(
|
||||
fieldMetadataSeeds.map((fieldMetadataSeed) => ({
|
||||
...fieldMetadataSeed,
|
||||
objectMetadataId: objectMetadata.id,
|
||||
workspaceId,
|
||||
})),
|
||||
);
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import { CreateFieldInput } from 'src/engine/metadata-modules/field-metadata/dtos/create-field.input';
|
||||
|
||||
export type FieldMetadataSeed = Omit<
|
||||
CreateFieldInput,
|
||||
'objectMetadataId' | 'workspaceId'
|
||||
>;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import { CreateObjectInput } from 'src/engine/metadata-modules/object-metadata/dtos/create-object.input';
|
||||
|
||||
export type ObjectMetadataSeed = Omit<
|
||||
CreateObjectInput,
|
||||
'workspaceId' | 'dataSourceId' | 'fields'
|
||||
>;
|
||||
Reference in New Issue
Block a user