Fallback to field metadata (#19131)
Rely on the field metadata items to always display all object's fields in the fields widget configuration editor. If fields are missing in the returned view fields, we add the missing fields through object metadata. https://github.com/user-attachments/assets/3c4d45e8-05d0-4943-be4b-bcf1e310155c
This commit is contained in:
committed by
GitHub
parent
5bbfce7789
commit
c11e4ece39
+7
-16
@@ -217,7 +217,7 @@ describe('computeFieldsWidgetViewFieldsAndGroupsToCreate', () => {
|
||||
expect(result.flatViewFieldsToCreate).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should exclude id field unless it is the label identifier', () => {
|
||||
it('should always exclude id field even when it is the label identifier', () => {
|
||||
const idUid = v4();
|
||||
|
||||
const fields = [
|
||||
@@ -244,7 +244,7 @@ describe('computeFieldsWidgetViewFieldsAndGroupsToCreate', () => {
|
||||
|
||||
expect(resultWithout.flatViewFieldsToCreate).toHaveLength(1);
|
||||
|
||||
// With label identifier match: id included
|
||||
// With id as label identifier: id still excluded (label identifier fields are excluded)
|
||||
const resultWith = computeFieldsWidgetViewFieldsAndGroupsToCreate({
|
||||
objectFlatFieldMetadatas: fields,
|
||||
viewUniversalIdentifier,
|
||||
@@ -252,7 +252,7 @@ describe('computeFieldsWidgetViewFieldsAndGroupsToCreate', () => {
|
||||
labelIdentifierFieldMetadataUniversalIdentifier: idUid,
|
||||
});
|
||||
|
||||
expect(resultWith.flatViewFieldsToCreate).toHaveLength(2);
|
||||
expect(resultWith.flatViewFieldsToCreate).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should set correct applicationUniversalIdentifier on all entities', () => {
|
||||
@@ -339,24 +339,15 @@ describe('computeFieldsWidgetViewFieldsAndGroupsToCreate', () => {
|
||||
labelIdentifierFieldMetadataUniversalIdentifier: labelUid,
|
||||
});
|
||||
|
||||
expect(result.flatViewFieldsToCreate).toHaveLength(3);
|
||||
// Label identifier field is excluded by isFieldMetadataEligibleForFieldsWidget
|
||||
expect(result.flatViewFieldsToCreate).toHaveLength(2);
|
||||
|
||||
// The label identifier field must be at the lowest position
|
||||
// The label identifier field should not be in the results
|
||||
const labelField = result.flatViewFieldsToCreate.find(
|
||||
(vf) => vf.fieldMetadataUniversalIdentifier === labelUid,
|
||||
);
|
||||
|
||||
expect(labelField).toBeDefined();
|
||||
expect(labelField!.position).toBe(0);
|
||||
|
||||
// Other fields should have higher positions
|
||||
const otherPositions = result.flatViewFieldsToCreate
|
||||
.filter((vf) => vf.fieldMetadataUniversalIdentifier !== labelUid)
|
||||
.map((vf) => vf.position);
|
||||
|
||||
otherPositions.forEach((pos) => {
|
||||
expect(pos).toBeGreaterThan(0);
|
||||
});
|
||||
expect(labelField).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should make RELATION and MORPH_RELATION fields invisible by default', () => {
|
||||
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
|
||||
import { isFieldMetadataEligibleForFieldsWidget } from 'twenty-shared/utils';
|
||||
|
||||
describe('isFieldMetadataEligibleForFieldsWidget', () => {
|
||||
it('should exclude deletedAt field', () => {
|
||||
expect(
|
||||
isFieldMetadataEligibleForFieldsWidget({
|
||||
fieldName: 'deletedAt',
|
||||
fieldType: FieldMetadataType.DATE_TIME,
|
||||
isLabelIdentifierField: false,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('should exclude TS_VECTOR fields', () => {
|
||||
expect(
|
||||
isFieldMetadataEligibleForFieldsWidget({
|
||||
fieldName: 'searchVector',
|
||||
fieldType: FieldMetadataType.TS_VECTOR,
|
||||
isLabelIdentifierField: false,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('should exclude POSITION fields', () => {
|
||||
expect(
|
||||
isFieldMetadataEligibleForFieldsWidget({
|
||||
fieldName: 'position',
|
||||
fieldType: FieldMetadataType.POSITION,
|
||||
isLabelIdentifierField: false,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('should exclude id field when it is not the label identifier', () => {
|
||||
expect(
|
||||
isFieldMetadataEligibleForFieldsWidget({
|
||||
fieldName: 'id',
|
||||
fieldType: FieldMetadataType.UUID,
|
||||
isLabelIdentifierField: false,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('should exclude id field even when it is the label identifier', () => {
|
||||
expect(
|
||||
isFieldMetadataEligibleForFieldsWidget({
|
||||
fieldName: 'id',
|
||||
fieldType: FieldMetadataType.UUID,
|
||||
isLabelIdentifierField: true,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('should include a normal field', () => {
|
||||
expect(
|
||||
isFieldMetadataEligibleForFieldsWidget({
|
||||
fieldName: 'name',
|
||||
fieldType: FieldMetadataType.TEXT,
|
||||
isLabelIdentifierField: false,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('should include createdAt field', () => {
|
||||
expect(
|
||||
isFieldMetadataEligibleForFieldsWidget({
|
||||
fieldName: 'createdAt',
|
||||
fieldType: FieldMetadataType.DATE_TIME,
|
||||
isLabelIdentifierField: false,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
+8
-7
@@ -6,6 +6,7 @@ import { DEFAULT_VIEW_FIELD_SIZE } from 'src/engine/metadata-modules/flat-view-f
|
||||
import { type UniversalFlatFieldMetadata } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-field-metadata.type';
|
||||
import { type UniversalFlatViewFieldGroup } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-view-field-group.type';
|
||||
import { type UniversalFlatViewField } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-view-field.type';
|
||||
import { isFieldMetadataEligibleForFieldsWidget } from 'twenty-shared/utils';
|
||||
|
||||
export const computeFieldsWidgetViewFieldsAndGroupsToCreate = ({
|
||||
objectFlatFieldMetadatas,
|
||||
@@ -24,14 +25,14 @@ export const computeFieldsWidgetViewFieldsAndGroupsToCreate = ({
|
||||
const createdAt = new Date().toISOString();
|
||||
const applicationUniversalIdentifier = flatApplication.universalIdentifier;
|
||||
|
||||
const eligibleFields = objectFlatFieldMetadatas.filter(
|
||||
(field) =>
|
||||
field.name !== 'deletedAt' &&
|
||||
field.type !== FieldMetadataType.TS_VECTOR &&
|
||||
field.type !== FieldMetadataType.POSITION &&
|
||||
(field.name !== 'id' ||
|
||||
const eligibleFields = objectFlatFieldMetadatas.filter((field) =>
|
||||
isFieldMetadataEligibleForFieldsWidget({
|
||||
fieldName: field.name,
|
||||
fieldType: field.type,
|
||||
isLabelIdentifierField:
|
||||
field.universalIdentifier ===
|
||||
labelIdentifierFieldMetadataUniversalIdentifier),
|
||||
labelIdentifierFieldMetadataUniversalIdentifier,
|
||||
}),
|
||||
);
|
||||
|
||||
const standardFields = eligibleFields.filter((field) => !field.isCustom);
|
||||
|
||||
Reference in New Issue
Block a user