- Remove the label identifier field for all standard objects as it's a first-class citizen that is displayed specifically in the app; it doesn't make a lot of sense to display it in the Fields widgets - Disable logic that made the label identifier required and in first position - Add all fields for all standard objects in record page layout view fields - Do not include position and ts vector fields in custom objects > [!IMPORTANT] > The command will create Field widgets for all relations. It is consistent to the way the frontend dynamically generates them as of today. We will have to decide which relations we pin as individual Field widgets before the release. (This will likely land in this command or in another one.)
73 lines
3.0 KiB
TypeScript
73 lines
3.0 KiB
TypeScript
import { v4 } from 'uuid';
|
|
|
|
import { type FlatApplication } from 'src/engine/core-modules/application/types/flat-application.type';
|
|
import { DEFAULT_VIEW_FIELD_SIZE } from 'src/engine/metadata-modules/flat-view-field/constants/default-view-field-size.constant';
|
|
import { type UniversalFlatFieldMetadata } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-field-metadata.type';
|
|
import { type UniversalFlatViewField } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-view-field.type';
|
|
import { FieldMetadataType } from 'twenty-shared/types';
|
|
|
|
export const computeFlatViewFieldsToCreate = ({
|
|
objectFlatFieldMetadatas,
|
|
viewUniversalIdentifier,
|
|
flatApplication,
|
|
labelIdentifierFieldMetadataUniversalIdentifier,
|
|
excludeLabelIdentifier = false,
|
|
}: {
|
|
flatApplication: FlatApplication;
|
|
objectFlatFieldMetadatas: UniversalFlatFieldMetadata[];
|
|
viewUniversalIdentifier: string;
|
|
labelIdentifierFieldMetadataUniversalIdentifier: string | null;
|
|
excludeLabelIdentifier?: boolean;
|
|
}): UniversalFlatViewField[] => {
|
|
const createdAt = new Date().toISOString();
|
|
const defaultViewFields = objectFlatFieldMetadatas
|
|
.filter(
|
|
(field) =>
|
|
field.name !== 'deletedAt' &&
|
|
field.type !== FieldMetadataType.TS_VECTOR &&
|
|
field.type !== FieldMetadataType.POSITION &&
|
|
field.type !== FieldMetadataType.MORPH_RELATION &&
|
|
field.type !== FieldMetadataType.RELATION &&
|
|
// Include 'id' only if it's the label identifier (e.g., for junction tables)
|
|
(field.name !== 'id' ||
|
|
field.universalIdentifier ===
|
|
labelIdentifierFieldMetadataUniversalIdentifier) &&
|
|
// Exclude label identifier field when requested (e.g., for FIELDS_WIDGET views)
|
|
(!excludeLabelIdentifier ||
|
|
field.universalIdentifier !==
|
|
labelIdentifierFieldMetadataUniversalIdentifier),
|
|
)
|
|
.sort((a, b) => {
|
|
const aIsLabelIdentifierFieldMetadata =
|
|
a.universalIdentifier ===
|
|
labelIdentifierFieldMetadataUniversalIdentifier;
|
|
const bIsLabelIdentifierFieldMetadata =
|
|
b.universalIdentifier ===
|
|
labelIdentifierFieldMetadataUniversalIdentifier;
|
|
|
|
if (aIsLabelIdentifierFieldMetadata && !bIsLabelIdentifierFieldMetadata)
|
|
return -1;
|
|
if (!aIsLabelIdentifierFieldMetadata && bIsLabelIdentifierFieldMetadata)
|
|
return 1;
|
|
|
|
return 0;
|
|
})
|
|
.map<UniversalFlatViewField>((field, index) => ({
|
|
fieldMetadataUniversalIdentifier: field.universalIdentifier,
|
|
viewUniversalIdentifier,
|
|
viewFieldGroupUniversalIdentifier: null,
|
|
createdAt,
|
|
updatedAt: createdAt,
|
|
deletedAt: null,
|
|
universalIdentifier: v4(),
|
|
isVisible: true,
|
|
size: DEFAULT_VIEW_FIELD_SIZE,
|
|
position: index,
|
|
aggregateOperation: null,
|
|
universalOverrides: null,
|
|
applicationUniversalIdentifier: flatApplication.universalIdentifier,
|
|
}));
|
|
|
|
return defaultViewFields;
|
|
};
|