fix: fix several field bugs (#5339)
After discussing with @charlesBochet, several fixes are needed on fields: - [x] Disable Boolean field `defaultValue` edition for now (On `defaultValue` update, newly created records are not taking the updated `defaultValue` into account. Setting the `defaultValue` on creation is fine.) - [x] Disable Phone field creation for now - [x] For the Person object, display the "Phone" field as a field of type Phone (right now its type is Text; later we'll migrate it to a proper Phone field). - [x] Fix RawJson field display (displaying `[object Object]` in Record Table cells). - [x] In Settings/Data Model, on Relation field creation/edition, "Object destination" select is not working properly if an object was not manually selected (displays Companies by default but creates a relation to another random object than Companies).
This commit is contained in:
@ -1,9 +1,8 @@
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { useEffect } from 'react';
|
||||
import { FormProvider, useForm } from 'react-hook-form';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import styled from '@emotion/styled';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import omit from 'lodash.omit';
|
||||
import pick from 'lodash.pick';
|
||||
import { IconArchive, IconSettings } from 'twenty-ui';
|
||||
@ -33,6 +32,7 @@ import { SubMenuTopBarContainer } from '@/ui/layout/page/SubMenuTopBarContainer'
|
||||
import { Section } from '@/ui/layout/section/components/Section';
|
||||
import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
|
||||
type SettingsDataModelFieldEditFormValues = z.infer<
|
||||
typeof settingsFieldFormSchema
|
||||
@ -72,15 +72,6 @@ export const SettingsObjectFieldEdit = () => {
|
||||
);
|
||||
|
||||
const getRelationMetadata = useGetRelationMetadata();
|
||||
const { relationFieldMetadataItem } =
|
||||
useMemo(
|
||||
() =>
|
||||
activeMetadataField
|
||||
? getRelationMetadata({ fieldMetadataItem: activeMetadataField })
|
||||
: null,
|
||||
[activeMetadataField, getRelationMetadata],
|
||||
) ?? {};
|
||||
|
||||
const { updateOneFieldMetadataItem } = useUpdateOneFieldMetadataItem();
|
||||
|
||||
const formConfig = useForm<SettingsDataModelFieldEditFormValues>({
|
||||
@ -111,13 +102,19 @@ export const SettingsObjectFieldEdit = () => {
|
||||
if (
|
||||
formValues.type === FieldMetadataType.Relation &&
|
||||
'relation' in formValues &&
|
||||
'relation' in dirtyFields &&
|
||||
isNonEmptyString(relationFieldMetadataItem?.id)
|
||||
'relation' in dirtyFields
|
||||
) {
|
||||
await updateOneFieldMetadataItem({
|
||||
fieldMetadataIdToUpdate: relationFieldMetadataItem.id,
|
||||
updatePayload: formValues.relation.field,
|
||||
});
|
||||
const { relationFieldMetadataItem } =
|
||||
getRelationMetadata({
|
||||
fieldMetadataItem: activeMetadataField,
|
||||
}) ?? {};
|
||||
|
||||
if (isDefined(relationFieldMetadataItem)) {
|
||||
await updateOneFieldMetadataItem({
|
||||
fieldMetadataIdToUpdate: relationFieldMetadataItem.id,
|
||||
updatePayload: formValues.relation.field,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const otherDirtyFields = omit(dirtyFields, 'relation');
|
||||
@ -202,7 +199,6 @@ export const SettingsObjectFieldEdit = () => {
|
||||
disableCurrencyForm
|
||||
fieldMetadataItem={activeMetadataField}
|
||||
objectMetadataItem={activeObjectMetadataItem}
|
||||
relationFieldMetadataItem={relationFieldMetadataItem}
|
||||
/>
|
||||
</Section>
|
||||
{!isLabelIdentifier && (
|
||||
|
||||
@ -271,6 +271,7 @@ export const SettingsObjectNewFieldStep2 = () => {
|
||||
FieldMetadataType.Numeric,
|
||||
FieldMetadataType.Probability,
|
||||
FieldMetadataType.Uuid,
|
||||
FieldMetadataType.Phone,
|
||||
];
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user