4ecc9c622d
# Introduction
Initial motivation here was to migrate the object related records logic
from v1 to v2, please note that now in v2 views aren't records anymore
but core engine entities
## What's done
- Added specific label identifier targeting view field logic
- Handled side effects on viewField creation with lowest position on
object label identifier mutation
- Added viewField relations in field metadate entity + handled
optimistic in builder v2
- Added view relations in object metadata entity + handled optimistic in
builder v2
- Added integration tests covering the side effects and new validation
exceptions
- Sandardized cache computation
- Coverage on object metadata creation side effect on views and view
fields
## Coverage
```ts
PASS test/integration/graphql/suites/view/view-field/object-identifier-update-side-effect-on-view-field.integration-spec.ts
View Field Resolver - Successful object metadata identifier update side effect on view field
✓ should create a view field on label identifier object metadata update if it does not exist on view (7 ms)
✓ Should not allow deleting a label identifier view field (17 ms)
✓ Should not allow destroying a label identifier view field (6 ms)
✓ Should not allow updating a label identifier view field visibility to false (8 ms)
✓ Should not allow creating a view field with a position lower than the label idenfitier view field (180 ms)
✓ Should not allow updated labelIdentifier view field with a position higher than existing other view field (346 ms)
✓ Should allow updated labelIdentifier view field with a position higher than existing other view field (434 ms)
Test Suites: 1 passed, 1 total
Tests: 7 passed, 7 total
Snapshots: 5 passed, 5 total
Time: 4.571 s, estimated 5 s
```
close https://github.com/twentyhq/core-team-issues/issues/1664
170 lines
4.7 KiB
TypeScript
170 lines
4.7 KiB
TypeScript
import {
|
|
Column,
|
|
CreateDateColumn,
|
|
Entity,
|
|
JoinColumn,
|
|
ManyToOne,
|
|
OneToMany,
|
|
PrimaryGeneratedColumn,
|
|
Relation,
|
|
Unique,
|
|
UpdateDateColumn,
|
|
} from 'typeorm';
|
|
|
|
import { type WorkspaceEntityDuplicateCriteria } from 'src/engine/api/graphql/workspace-query-builder/types/workspace-entity-duplicate-criteria.type';
|
|
import { ApplicationEntity } from 'src/engine/core-modules/application/application.entity';
|
|
import { ViewEntity } from 'src/engine/core-modules/view/entities/view.entity';
|
|
import { DataSourceEntity } from 'src/engine/metadata-modules/data-source/data-source.entity';
|
|
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
|
import { IndexMetadataEntity } from 'src/engine/metadata-modules/index-metadata/index-metadata.entity';
|
|
import { type ObjectStandardOverridesDTO } from 'src/engine/metadata-modules/object-metadata/dtos/object-standard-overrides.dto';
|
|
import { FieldPermissionEntity } from 'src/engine/metadata-modules/object-permission/field-permission/field-permission.entity';
|
|
import { ObjectPermissionEntity } from 'src/engine/metadata-modules/object-permission/object-permission.entity';
|
|
|
|
@Entity('objectMetadata')
|
|
@Unique('IDX_OBJECT_METADATA_NAME_SINGULAR_WORKSPACE_ID_UNIQUE', [
|
|
'nameSingular',
|
|
'workspaceId',
|
|
])
|
|
@Unique('IDX_OBJECT_METADATA_NAME_PLURAL_WORKSPACE_ID_UNIQUE', [
|
|
'namePlural',
|
|
'workspaceId',
|
|
])
|
|
export class ObjectMetadataEntity implements Required<ObjectMetadataEntity> {
|
|
@PrimaryGeneratedColumn('uuid')
|
|
id: string;
|
|
|
|
@Column({ nullable: true, type: 'uuid' })
|
|
standardId: string | null;
|
|
|
|
@Column({ nullable: true, type: 'uuid' })
|
|
applicationId: string | null;
|
|
|
|
@Column({ nullable: false, type: 'uuid' })
|
|
dataSourceId: string;
|
|
|
|
@Column({ nullable: false })
|
|
nameSingular: string;
|
|
|
|
@Column({ nullable: false })
|
|
namePlural: string;
|
|
|
|
@Column({ nullable: false })
|
|
labelSingular: string;
|
|
|
|
@Column({ nullable: false })
|
|
labelPlural: string;
|
|
|
|
@Column({ nullable: true, type: 'text' })
|
|
description: string | null;
|
|
|
|
@Column({ nullable: true, type: 'varchar' })
|
|
icon: string | null;
|
|
|
|
@Column({ type: 'jsonb', nullable: true })
|
|
standardOverrides: ObjectStandardOverridesDTO | null;
|
|
|
|
/**
|
|
* @deprecated
|
|
*/
|
|
@Column({ nullable: false })
|
|
targetTableName: string;
|
|
|
|
@Column({ default: false })
|
|
isCustom: boolean;
|
|
|
|
@Column({ default: false })
|
|
isRemote: boolean;
|
|
|
|
@Column({ default: false })
|
|
isActive: boolean;
|
|
|
|
@Column({ default: false })
|
|
isSystem: boolean;
|
|
|
|
@Column({ default: false })
|
|
isUIReadOnly: boolean;
|
|
|
|
@Column({ default: true })
|
|
isAuditLogged: boolean;
|
|
|
|
@Column({ default: false })
|
|
isSearchable: boolean;
|
|
|
|
@Column({ type: 'jsonb', nullable: true })
|
|
duplicateCriteria: WorkspaceEntityDuplicateCriteria[] | null;
|
|
|
|
@Column({ nullable: true, type: 'varchar' })
|
|
shortcut: string | null;
|
|
|
|
// TODO: This should not be nullable - legacy field introduced when label identifier was nullable
|
|
@Column({ nullable: true, type: 'uuid' })
|
|
labelIdentifierFieldMetadataId: string | null;
|
|
|
|
@Column({ nullable: true, type: 'uuid' })
|
|
imageIdentifierFieldMetadataId: string | null;
|
|
|
|
@Column({ default: false })
|
|
isLabelSyncedWithName: boolean;
|
|
|
|
@Column({ nullable: false, type: 'uuid' })
|
|
workspaceId: string;
|
|
|
|
@OneToMany(() => FieldMetadataEntity, (field) => field.object, {
|
|
cascade: true,
|
|
})
|
|
fields: Relation<FieldMetadataEntity[]>;
|
|
|
|
@OneToMany(() => IndexMetadataEntity, (index) => index.objectMetadata, {
|
|
cascade: true,
|
|
})
|
|
indexMetadatas: Relation<IndexMetadataEntity[]>;
|
|
|
|
@OneToMany(
|
|
() => FieldMetadataEntity,
|
|
(field) => field.relationTargetObjectMetadataId,
|
|
)
|
|
targetRelationFields: Relation<FieldMetadataEntity[]>;
|
|
|
|
@ManyToOne(() => DataSourceEntity, (dataSource) => dataSource.objects, {
|
|
onDelete: 'CASCADE',
|
|
})
|
|
dataSource: Relation<DataSourceEntity>;
|
|
|
|
@CreateDateColumn({ type: 'timestamptz' })
|
|
createdAt: Date;
|
|
|
|
@UpdateDateColumn({ type: 'timestamptz' })
|
|
updatedAt: Date;
|
|
|
|
@ManyToOne(() => ApplicationEntity, (application) => application.objects, {
|
|
onDelete: 'CASCADE',
|
|
nullable: true,
|
|
})
|
|
@JoinColumn({ name: 'applicationId' })
|
|
application: Relation<ApplicationEntity> | null;
|
|
|
|
@OneToMany(
|
|
() => ObjectPermissionEntity,
|
|
(objectPermission) => objectPermission.objectMetadata,
|
|
{
|
|
cascade: true,
|
|
},
|
|
)
|
|
objectPermissions: Relation<ObjectPermissionEntity[]>;
|
|
|
|
@OneToMany(
|
|
() => FieldPermissionEntity,
|
|
(fieldPermission) => fieldPermission.objectMetadata,
|
|
{
|
|
cascade: true,
|
|
},
|
|
)
|
|
fieldPermissions: Relation<FieldPermissionEntity[]>;
|
|
|
|
@OneToMany(() => ViewEntity, (view) => view.objectMetadata, {
|
|
cascade: true,
|
|
})
|
|
views: Relation<ViewEntity[]>;
|
|
}
|