Fix storybook / chromatic tests flakyness and integration tests (#11687)
## Storybook flakyness ### Actor Display image flakyness <img width="1512" alt="image" src="https://github.com/user-attachments/assets/875c0738-5e31-4aba-9231-4ba5f78d1355" /> **Fix:** stop using a random usage ### Task Groups broken <img width="1512" alt="image" src="https://github.com/user-attachments/assets/c67e47a1-a027-43f1-9601-68d61a8052b4" /> **Fix:** add missing TabListComponentInstance ## Flaky dates Add https://github.com/k35o/storybook-addon-mock-date ## Integration tests Fix broken tests due to relation refactoring
This commit is contained in:
@ -37,11 +37,6 @@ export class WorkspaceSchemaFactory {
|
||||
return new GraphQLSchema({});
|
||||
}
|
||||
|
||||
const cachedIsNewRelationEnabled =
|
||||
await this.workspaceCacheStorageService.getIsNewRelationEnabled(
|
||||
authContext.workspace.id,
|
||||
);
|
||||
|
||||
const isNewRelationEnabled = await this.featureFlagService.isFeatureEnabled(
|
||||
FeatureFlagKey.IsNewRelationEnabled,
|
||||
authContext.workspace.id,
|
||||
@ -79,35 +74,6 @@ export class WorkspaceSchemaFactory {
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: remove this after the feature flag is droped
|
||||
if (
|
||||
(isNewRelationEnabled && cachedIsNewRelationEnabled === undefined) ||
|
||||
(isNewRelationEnabled !== cachedIsNewRelationEnabled &&
|
||||
cachedIsNewRelationEnabled !== undefined)
|
||||
) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(
|
||||
chalk.yellow('Recomputing due to new relation feature flag'),
|
||||
{
|
||||
isNewRelationEnabled,
|
||||
},
|
||||
);
|
||||
|
||||
await this.workspaceCacheStorageService.setIsNewRelationEnabled(
|
||||
authContext.workspace.id,
|
||||
isNewRelationEnabled,
|
||||
);
|
||||
|
||||
await this.workspaceMetadataCacheService.recomputeMetadataCache({
|
||||
workspaceId: authContext.workspace.id,
|
||||
});
|
||||
|
||||
throw new GraphqlQueryRunnerException(
|
||||
'Metadata cache recomputation required due to relation feature flag change',
|
||||
GraphqlQueryRunnerExceptionCode.METADATA_CACHE_FEATURE_FLAG_RECOMPUTATION_REQUIRED,
|
||||
);
|
||||
}
|
||||
|
||||
const objectMetadataMaps =
|
||||
await this.workspaceCacheStorageService.getObjectMetadataMaps(
|
||||
authContext.workspace.id,
|
||||
|
||||
@ -24,6 +24,7 @@ import { IsFieldMetadataOptions } from 'src/engine/metadata-modules/field-metada
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { ObjectMetadataModule } from 'src/engine/metadata-modules/object-metadata/object-metadata.module';
|
||||
import { PermissionsModule } from 'src/engine/metadata-modules/permissions/permissions.module';
|
||||
import { RelationMetadataEntity } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
|
||||
import { WorkspaceMetadataVersionModule } from 'src/engine/metadata-modules/workspace-metadata-version/workspace-metadata-version.module';
|
||||
import { WorkspaceMigrationModule } from 'src/engine/metadata-modules/workspace-migration/workspace-migration.module';
|
||||
import { WorkspaceCacheStorageModule } from 'src/engine/workspace-cache-storage/workspace-cache-storage.module';
|
||||
@ -41,7 +42,7 @@ import { UpdateFieldInput } from './dtos/update-field.input';
|
||||
NestjsQueryGraphQLModule.forFeature({
|
||||
imports: [
|
||||
NestjsQueryTypeOrmModule.forFeature(
|
||||
[FieldMetadataEntity, ObjectMetadataEntity],
|
||||
[FieldMetadataEntity, ObjectMetadataEntity, RelationMetadataEntity],
|
||||
'metadata',
|
||||
),
|
||||
WorkspaceMigrationModule,
|
||||
|
||||
@ -161,12 +161,6 @@ export class FieldMetadataResolver {
|
||||
throw new ValidationError("Active fields can't be deleted");
|
||||
}
|
||||
|
||||
if (fieldMetadata.type === FieldMetadataType.RELATION) {
|
||||
throw new ValidationError(
|
||||
"Relation fields can't be deleted, you need to delete the RelationMetadata instead",
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.fieldMetadataService.deleteOneField(input, workspaceId);
|
||||
} catch (error) {
|
||||
|
||||
@ -10,6 +10,8 @@ import { isDefined } from 'twenty-shared/utils';
|
||||
import { DataSource, FindOneOptions, In, Repository } from 'typeorm';
|
||||
import { v4 as uuidV4, v4 } from 'uuid';
|
||||
|
||||
import { RelationType } from 'src/engine/metadata-modules/field-metadata/interfaces/relation-type.interface';
|
||||
|
||||
import { TypeORMService } from 'src/database/typeorm/typeorm.service';
|
||||
import { settings } from 'src/engine/constants/settings';
|
||||
import { generateMessageId } from 'src/engine/core-modules/i18n/utils/generateMessageId';
|
||||
@ -81,6 +83,8 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
|
||||
private readonly fieldMetadataRepository: Repository<FieldMetadataEntity>,
|
||||
@InjectRepository(ObjectMetadataEntity, 'metadata')
|
||||
private readonly objectMetadataRepository: Repository<ObjectMetadataEntity>,
|
||||
@InjectRepository(RelationMetadataEntity, 'metadata')
|
||||
private readonly relationMetadataRepository: Repository<RelationMetadataEntity>,
|
||||
private readonly workspaceMigrationFactory: WorkspaceMigrationFactory,
|
||||
private readonly workspaceMigrationService: WorkspaceMigrationService,
|
||||
private readonly workspaceMigrationRunnerService: WorkspaceMigrationRunnerService,
|
||||
@ -350,9 +354,48 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
|
||||
fieldMetadataId: fieldMetadata.id,
|
||||
});
|
||||
|
||||
await fieldMetadataRepository.delete(fieldMetadata.id);
|
||||
if (fieldMetadata.type === FieldMetadataType.RELATION) {
|
||||
const isManyToManyRelation =
|
||||
(fieldMetadata as FieldMetadataEntity<FieldMetadataType.RELATION>)
|
||||
.settings?.relationType === RelationType.MANY_TO_ONE;
|
||||
|
||||
if (isCompositeFieldMetadataType(fieldMetadata.type)) {
|
||||
const targetFieldMetadata =
|
||||
await this.fieldMetadataRepository.findOneBy({
|
||||
id: fieldMetadata.relationTargetFieldMetadataId,
|
||||
});
|
||||
|
||||
if (targetFieldMetadata) {
|
||||
await this.relationMetadataRepository.delete({
|
||||
fromFieldMetadataId: In([fieldMetadata.id, targetFieldMetadata.id]),
|
||||
});
|
||||
await this.relationMetadataRepository.delete({
|
||||
toFieldMetadataId: In([fieldMetadata.id, targetFieldMetadata.id]),
|
||||
});
|
||||
await fieldMetadataRepository.delete({
|
||||
id: In([fieldMetadata.id, targetFieldMetadata.id]),
|
||||
});
|
||||
|
||||
await this.workspaceMigrationService.createCustomMigration(
|
||||
generateMigrationName(`delete-${fieldMetadata.name}`),
|
||||
workspaceId,
|
||||
[
|
||||
{
|
||||
name: computeObjectTargetTable(objectMetadata),
|
||||
action: WorkspaceMigrationTableActionType.ALTER,
|
||||
columns: [
|
||||
{
|
||||
action: WorkspaceMigrationColumnActionType.DROP,
|
||||
columnName: isManyToManyRelation
|
||||
? `${(fieldMetadata as FieldMetadataEntity<FieldMetadataType.RELATION>).settings?.joinColumnName}`
|
||||
: `${(targetFieldMetadata as FieldMetadataEntity<FieldMetadataType.RELATION>).settings?.joinColumnName}`,
|
||||
} satisfies WorkspaceMigrationColumnDrop,
|
||||
],
|
||||
} satisfies WorkspaceMigrationTableAction,
|
||||
],
|
||||
);
|
||||
}
|
||||
} else if (isCompositeFieldMetadataType(fieldMetadata.type)) {
|
||||
await fieldMetadataRepository.delete(fieldMetadata.id);
|
||||
const compositeType = compositeTypeDefinitions.get(fieldMetadata.type);
|
||||
|
||||
if (!compositeType) {
|
||||
@ -383,6 +426,7 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
|
||||
],
|
||||
);
|
||||
} else {
|
||||
await fieldMetadataRepository.delete(fieldMetadata.id);
|
||||
await this.workspaceMigrationService.createCustomMigration(
|
||||
generateMigrationName(`delete-${fieldMetadata.name}`),
|
||||
workspaceId,
|
||||
|
||||
@ -310,17 +310,17 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
||||
|
||||
const updatedObject = await super.updateOne(inputId, inputPayload);
|
||||
|
||||
const isNewRelationEnabled = await this.featureFlagService.isFeatureEnabled(
|
||||
FeatureFlagKey.IsNewRelationEnabled,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
await this.handleObjectNameAndLabelUpdates(
|
||||
existingObjectMetadata,
|
||||
existingObjectMetadataCombinedWithUpdateInput,
|
||||
inputPayload,
|
||||
);
|
||||
|
||||
const isNewRelationEnabled = await this.featureFlagService.isFeatureEnabled(
|
||||
FeatureFlagKey.IsNewRelationEnabled,
|
||||
workspaceId,
|
||||
);
|
||||
|
||||
if (inputPayload.isActive !== undefined) {
|
||||
// For new relation system, the active status is stitched to the field metadata
|
||||
if (!isNewRelationEnabled) {
|
||||
|
||||
@ -6,6 +6,7 @@ import { capitalize } from 'twenty-shared/utils';
|
||||
import { Repository } from 'typeorm';
|
||||
import { v4 as uuidV4 } from 'uuid';
|
||||
|
||||
import { FieldMetadataDefaultSettings } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata-settings.interface';
|
||||
import { RelationType } from 'src/engine/metadata-modules/field-metadata/interfaces/relation-type.interface';
|
||||
|
||||
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
@ -165,15 +166,30 @@ export class ObjectMetadataFieldRelationService {
|
||||
objectMetadataId: targetObjectMetadata.id,
|
||||
workspaceId: workspaceId,
|
||||
});
|
||||
|
||||
const isTargetFieldMetadataManyToOneRelation =
|
||||
(
|
||||
targetFieldMetadataToUpdate as FieldMetadataEntity<FieldMetadataType.RELATION>
|
||||
).settings?.relationType === RelationType.MANY_TO_ONE;
|
||||
|
||||
const targetFieldMetadata = await this.fieldMetadataRepository.save({
|
||||
id: targetFieldMetadataToUpdate.id,
|
||||
...targetFieldMetadataUpdateData,
|
||||
settings: {
|
||||
...(targetFieldMetadataToUpdate.settings as FieldMetadataDefaultSettings),
|
||||
...(isTargetFieldMetadataManyToOneRelation
|
||||
? {
|
||||
joinColumnName: `${sourceObjectMetadata.nameSingular}Id`,
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
});
|
||||
|
||||
const sourceFieldMetadataUpdateData = this.updateSourceFieldMetadata(
|
||||
sourceObjectMetadata,
|
||||
targetObjectMetadata,
|
||||
);
|
||||
|
||||
const sourceFieldMetadataToUpdate =
|
||||
await this.fieldMetadataRepository.findOneByOrFail({
|
||||
standardId:
|
||||
@ -181,9 +197,23 @@ export class ObjectMetadataFieldRelationService {
|
||||
objectMetadataId: sourceObjectMetadata.id,
|
||||
workspaceId: workspaceId,
|
||||
});
|
||||
|
||||
const isSourceFieldMetadataManyToOneRelation =
|
||||
(
|
||||
sourceFieldMetadataToUpdate as FieldMetadataEntity<FieldMetadataType.RELATION>
|
||||
).settings?.relationType === RelationType.MANY_TO_ONE;
|
||||
|
||||
const sourceFieldMetadata = await this.fieldMetadataRepository.save({
|
||||
id: sourceFieldMetadataToUpdate.id,
|
||||
...sourceFieldMetadataUpdateData,
|
||||
settings: {
|
||||
...(sourceFieldMetadataToUpdate.settings as FieldMetadataDefaultSettings),
|
||||
...(isSourceFieldMetadataManyToOneRelation
|
||||
? {
|
||||
joinColumnName: `${targetObjectMetadata.nameSingular}Id`,
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@ -276,7 +276,7 @@ export class ObjectMetadataMigrationService {
|
||||
relationToDelete.toFieldMetadataId,
|
||||
]);
|
||||
|
||||
if (relationToDelete.direction === 'from') {
|
||||
if (relationToDelete.direction === 'from' && !isNewRelationEnabled) {
|
||||
await this.workspaceMigrationService.createCustomMigration(
|
||||
generateMigrationName(
|
||||
`delete-${RELATION_MIGRATION_PRIORITY_PREFIX}-${relationToDelete.fromObjectName}-${relationToDelete.toObjectName}`,
|
||||
|
||||
Reference in New Issue
Block a user