mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-22 19:41:53 +03:00
Reactive form preview (#8663)
## Description This PR fixes issues with field previews not updating immediately when settings are changed in the Data Model Editor. The changes affect number field types, ensuring that the preview updates in real-time as settings are modified. ### Fixed Issues - Number field preview not updating when changing decimals or number type (e.g., percentage) Recording https://www.loom.com/share/14a30f67266d4a08a694c759ae06b0f3?sid=c0de35ef-9982-438b-b822-94ed106f6891 ~~Fixes #8663~~ Fixes #8556 --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
parent
32fef06734
commit
e84176dc0d
@ -117,7 +117,7 @@ export const settingsDataModelFieldSettingsFormSchema = z.discriminatedUnion(
|
|||||||
type SettingsDataModelFieldSettingsFormCardProps = {
|
type SettingsDataModelFieldSettingsFormCardProps = {
|
||||||
fieldMetadataItem: Pick<
|
fieldMetadataItem: Pick<
|
||||||
FieldMetadataItem,
|
FieldMetadataItem,
|
||||||
'icon' | 'label' | 'type' | 'isCustom'
|
'icon' | 'label' | 'type' | 'isCustom' | 'settings'
|
||||||
> &
|
> &
|
||||||
Partial<Omit<FieldMetadataItem, 'icon' | 'label' | 'type'>>;
|
Partial<Omit<FieldMetadataItem, 'icon' | 'label' | 'type'>>;
|
||||||
} & Pick<SettingsDataModelFieldPreviewCardProps, 'objectMetadataItem'>;
|
} & Pick<SettingsDataModelFieldPreviewCardProps, 'objectMetadataItem'>;
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
SettingsDataModelFieldPreviewCard,
|
SettingsDataModelFieldPreviewCard,
|
||||||
SettingsDataModelFieldPreviewCardProps,
|
SettingsDataModelFieldPreviewCardProps,
|
||||||
} from '@/settings/data-model/fields/preview/components/SettingsDataModelFieldPreviewCard';
|
} from '@/settings/data-model/fields/preview/components/SettingsDataModelFieldPreviewCard';
|
||||||
|
import { useFormContext } from 'react-hook-form';
|
||||||
|
|
||||||
type SettingsDataModelFieldTextSettingsFormCardProps = {
|
type SettingsDataModelFieldTextSettingsFormCardProps = {
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
@ -26,11 +27,16 @@ export const SettingsDataModelFieldTextSettingsFormCard = ({
|
|||||||
fieldMetadataItem,
|
fieldMetadataItem,
|
||||||
objectMetadataItem,
|
objectMetadataItem,
|
||||||
}: SettingsDataModelFieldTextSettingsFormCardProps) => {
|
}: SettingsDataModelFieldTextSettingsFormCardProps) => {
|
||||||
|
const { watch } = useFormContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SettingsDataModelPreviewFormCard
|
<SettingsDataModelPreviewFormCard
|
||||||
preview={
|
preview={
|
||||||
<StyledFieldPreviewCard
|
<StyledFieldPreviewCard
|
||||||
fieldMetadataItem={fieldMetadataItem}
|
fieldMetadataItem={{
|
||||||
|
...fieldMetadataItem,
|
||||||
|
settings: watch('settings'),
|
||||||
|
}}
|
||||||
objectMetadataItem={objectMetadataItem}
|
objectMetadataItem={objectMetadataItem}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,13 @@ import {
|
|||||||
SettingsDataModelFieldPreviewCard,
|
SettingsDataModelFieldPreviewCard,
|
||||||
SettingsDataModelFieldPreviewCardProps,
|
SettingsDataModelFieldPreviewCardProps,
|
||||||
} from '@/settings/data-model/fields/preview/components/SettingsDataModelFieldPreviewCard';
|
} from '@/settings/data-model/fields/preview/components/SettingsDataModelFieldPreviewCard';
|
||||||
|
import { useFormContext } from 'react-hook-form';
|
||||||
|
|
||||||
type SettingsDataModelFieldNumberSettingsFormCardProps = {
|
type SettingsDataModelFieldNumberSettingsFormCardProps = {
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
fieldMetadataItem: Pick<
|
fieldMetadataItem: Pick<
|
||||||
FieldMetadataItem,
|
FieldMetadataItem,
|
||||||
'icon' | 'label' | 'type' | 'defaultValue'
|
'icon' | 'label' | 'type' | 'defaultValue' | 'settings'
|
||||||
>;
|
>;
|
||||||
} & Pick<SettingsDataModelFieldPreviewCardProps, 'objectMetadataItem'>;
|
} & Pick<SettingsDataModelFieldPreviewCardProps, 'objectMetadataItem'>;
|
||||||
|
|
||||||
@ -26,11 +27,18 @@ export const SettingsDataModelFieldNumberSettingsFormCard = ({
|
|||||||
fieldMetadataItem,
|
fieldMetadataItem,
|
||||||
objectMetadataItem,
|
objectMetadataItem,
|
||||||
}: SettingsDataModelFieldNumberSettingsFormCardProps) => {
|
}: SettingsDataModelFieldNumberSettingsFormCardProps) => {
|
||||||
|
const { watch } = useFormContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SettingsDataModelPreviewFormCard
|
<SettingsDataModelPreviewFormCard
|
||||||
preview={
|
preview={
|
||||||
<StyledFieldPreviewCard
|
<StyledFieldPreviewCard
|
||||||
fieldMetadataItem={fieldMetadataItem}
|
fieldMetadataItem={{
|
||||||
|
icon: watch('icon'),
|
||||||
|
label: watch('label') || 'New Field',
|
||||||
|
settings: watch('settings') || null,
|
||||||
|
type: fieldMetadataItem.type,
|
||||||
|
}}
|
||||||
objectMetadataItem={objectMetadataItem}
|
objectMetadataItem={objectMetadataItem}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
@ -227,6 +227,7 @@ export const SettingsObjectNewFieldConfigure = () => {
|
|||||||
fieldMetadataItem={{
|
fieldMetadataItem={{
|
||||||
icon: formConfig.watch('icon'),
|
icon: formConfig.watch('icon'),
|
||||||
label: formConfig.watch('label') || 'New Field',
|
label: formConfig.watch('label') || 'New Field',
|
||||||
|
settings: formConfig.watch('settings') || null,
|
||||||
type: fieldType as FieldMetadataType,
|
type: fieldType as FieldMetadataType,
|
||||||
}}
|
}}
|
||||||
objectMetadataItem={activeObjectMetadataItem}
|
objectMetadataItem={activeObjectMetadataItem}
|
||||||
|
Loading…
Reference in New Issue
Block a user