Fix isLabelSyncedWithName toggle at object creation (#8646)
+ remove useless disableNameEdit prop (always has same value as disabled prop)
This commit is contained in:
@ -186,8 +186,7 @@ export const ObjectSettings = ({ objectMetadataItem }: ObjectSettingsProps) => {
|
|||||||
description="Name in both singular (e.g., 'Invoice') and plural (e.g., 'Invoices') forms."
|
description="Name in both singular (e.g., 'Invoice') and plural (e.g., 'Invoices') forms."
|
||||||
/>
|
/>
|
||||||
<SettingsDataModelObjectAboutForm
|
<SettingsDataModelObjectAboutForm
|
||||||
disabled={!objectMetadataItem.isCustom}
|
disableEdition={!objectMetadataItem.isCustom}
|
||||||
disableNameEdit={!objectMetadataItem.isCustom}
|
|
||||||
objectMetadataItem={objectMetadataItem}
|
objectMetadataItem={objectMetadataItem}
|
||||||
onBlur={() => {
|
onBlur={() => {
|
||||||
formConfig.handleSubmit(handleSave)();
|
formConfig.handleSubmit(handleSave)();
|
||||||
|
|||||||
@ -43,8 +43,7 @@ type SettingsDataModelObjectAboutFormValues = z.infer<
|
|||||||
>;
|
>;
|
||||||
|
|
||||||
type SettingsDataModelObjectAboutFormProps = {
|
type SettingsDataModelObjectAboutFormProps = {
|
||||||
disabled?: boolean;
|
disableEdition?: boolean;
|
||||||
disableNameEdit?: boolean;
|
|
||||||
objectMetadataItem?: ObjectMetadataItem;
|
objectMetadataItem?: ObjectMetadataItem;
|
||||||
onBlur?: () => void;
|
onBlur?: () => void;
|
||||||
};
|
};
|
||||||
@ -92,8 +91,7 @@ const infoCircleElementId = 'info-circle-id';
|
|||||||
export const IS_LABEL_SYNCED_WITH_NAME_LABEL = 'isLabelSyncedWithName';
|
export const IS_LABEL_SYNCED_WITH_NAME_LABEL = 'isLabelSyncedWithName';
|
||||||
|
|
||||||
export const SettingsDataModelObjectAboutForm = ({
|
export const SettingsDataModelObjectAboutForm = ({
|
||||||
disabled,
|
disableEdition,
|
||||||
disableNameEdit,
|
|
||||||
objectMetadataItem,
|
objectMetadataItem,
|
||||||
onBlur,
|
onBlur,
|
||||||
}: SettingsDataModelObjectAboutFormProps) => {
|
}: SettingsDataModelObjectAboutFormProps) => {
|
||||||
@ -101,7 +99,11 @@ export const SettingsDataModelObjectAboutForm = ({
|
|||||||
useFormContext<SettingsDataModelObjectAboutFormValues>();
|
useFormContext<SettingsDataModelObjectAboutFormValues>();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
const isLabelSyncedWithName = watch(IS_LABEL_SYNCED_WITH_NAME_LABEL);
|
const isLabelSyncedWithName =
|
||||||
|
watch(IS_LABEL_SYNCED_WITH_NAME_LABEL) ??
|
||||||
|
(isDefined(objectMetadataItem)
|
||||||
|
? objectMetadataItem.isLabelSyncedWithName
|
||||||
|
: true);
|
||||||
const labelSingular = watch('labelSingular');
|
const labelSingular = watch('labelSingular');
|
||||||
const labelPlural = watch('labelPlural');
|
const labelPlural = watch('labelPlural');
|
||||||
watch('nameSingular');
|
watch('nameSingular');
|
||||||
@ -148,7 +150,7 @@ export const SettingsDataModelObjectAboutForm = ({
|
|||||||
defaultValue={objectMetadataItem?.icon ?? 'IconListNumbers'}
|
defaultValue={objectMetadataItem?.icon ?? 'IconListNumbers'}
|
||||||
render={({ field: { onChange, value } }) => (
|
render={({ field: { onChange, value } }) => (
|
||||||
<IconPicker
|
<IconPicker
|
||||||
disabled={disabled}
|
disabled={disableEdition}
|
||||||
selectedIconKey={value}
|
selectedIconKey={value}
|
||||||
onChange={({ iconKey }) => onChange(iconKey)}
|
onChange={({ iconKey }) => onChange(iconKey)}
|
||||||
/>
|
/>
|
||||||
@ -173,7 +175,7 @@ export const SettingsDataModelObjectAboutForm = ({
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onBlur={onBlur}
|
onBlur={onBlur}
|
||||||
disabled={disabled || disableNameEdit}
|
disabled={disableEdition}
|
||||||
fullWidth
|
fullWidth
|
||||||
maxLength={OBJECT_NAME_MAXIMUM_LENGTH}
|
maxLength={OBJECT_NAME_MAXIMUM_LENGTH}
|
||||||
/>
|
/>
|
||||||
@ -195,7 +197,7 @@ export const SettingsDataModelObjectAboutForm = ({
|
|||||||
fillNamePluralFromLabelPlural(value);
|
fillNamePluralFromLabelPlural(value);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
disabled={disabled || disableNameEdit}
|
disabled={disableEdition}
|
||||||
fullWidth
|
fullWidth
|
||||||
maxLength={OBJECT_NAME_MAXIMUM_LENGTH}
|
maxLength={OBJECT_NAME_MAXIMUM_LENGTH}
|
||||||
/>
|
/>
|
||||||
@ -212,7 +214,7 @@ export const SettingsDataModelObjectAboutForm = ({
|
|||||||
minRows={4}
|
minRows={4}
|
||||||
value={value ?? undefined}
|
value={value ?? undefined}
|
||||||
onChange={(nextValue) => onChange(nextValue ?? null)}
|
onChange={(nextValue) => onChange(nextValue ?? null)}
|
||||||
disabled={disabled}
|
disabled={disableEdition}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
@ -226,8 +228,7 @@ export const SettingsDataModelObjectAboutForm = ({
|
|||||||
fieldName: 'nameSingular' as const,
|
fieldName: 'nameSingular' as const,
|
||||||
placeholder: 'listing',
|
placeholder: 'listing',
|
||||||
defaultValue: objectMetadataItem?.nameSingular,
|
defaultValue: objectMetadataItem?.nameSingular,
|
||||||
disabled:
|
disableEdition: disableEdition || isLabelSyncedWithName,
|
||||||
disabled || disableNameEdit || isLabelSyncedWithName,
|
|
||||||
tooltip: apiNameTooltipText,
|
tooltip: apiNameTooltipText,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -235,8 +236,7 @@ export const SettingsDataModelObjectAboutForm = ({
|
|||||||
fieldName: 'namePlural' as const,
|
fieldName: 'namePlural' as const,
|
||||||
placeholder: 'listings',
|
placeholder: 'listings',
|
||||||
defaultValue: objectMetadataItem?.namePlural,
|
defaultValue: objectMetadataItem?.namePlural,
|
||||||
disabled:
|
disableEdition: disableEdition || isLabelSyncedWithName,
|
||||||
disabled || disableNameEdit || isLabelSyncedWithName,
|
|
||||||
tooltip: apiNameTooltipText,
|
tooltip: apiNameTooltipText,
|
||||||
},
|
},
|
||||||
].map(
|
].map(
|
||||||
@ -245,7 +245,7 @@ export const SettingsDataModelObjectAboutForm = ({
|
|||||||
fieldName,
|
fieldName,
|
||||||
label,
|
label,
|
||||||
placeholder,
|
placeholder,
|
||||||
disabled,
|
disableEdition,
|
||||||
tooltip,
|
tooltip,
|
||||||
}) => (
|
}) => (
|
||||||
<StyledInputContainer key={`object-${fieldName}-text-input`}>
|
<StyledInputContainer key={`object-${fieldName}-text-input`}>
|
||||||
@ -260,7 +260,7 @@ export const SettingsDataModelObjectAboutForm = ({
|
|||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
value={value}
|
value={value}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
disabled={disabled}
|
disabled={disableEdition}
|
||||||
fullWidth
|
fullWidth
|
||||||
maxLength={OBJECT_NAME_MAXIMUM_LENGTH}
|
maxLength={OBJECT_NAME_MAXIMUM_LENGTH}
|
||||||
onBlur={onBlur}
|
onBlur={onBlur}
|
||||||
@ -303,7 +303,10 @@ export const SettingsDataModelObjectAboutForm = ({
|
|||||||
title="Synchronize Objects Labels and API Names"
|
title="Synchronize Objects Labels and API Names"
|
||||||
description="Should changing an object's label also change the API?"
|
description="Should changing an object's label also change the API?"
|
||||||
checked={value ?? true}
|
checked={value ?? true}
|
||||||
disabled={!objectMetadataItem?.isCustom}
|
disabled={
|
||||||
|
isDefined(objectMetadataItem) &&
|
||||||
|
!objectMetadataItem.isCustom
|
||||||
|
}
|
||||||
advancedMode
|
advancedMode
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
onChange(value);
|
onChange(value);
|
||||||
|
|||||||
Reference in New Issue
Block a user