Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix isLabelSyncedWithName toggle at object creation #8646

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ export const ObjectSettings = ({ objectMetadataItem }: ObjectSettingsProps) => {
description="Name in both singular (e.g., 'Invoice') and plural (e.g., 'Invoices') forms."
/>
<SettingsDataModelObjectAboutForm
disabled={!objectMetadataItem.isCustom}
disableNameEdit={!objectMetadataItem.isCustom}
disableEdition={!objectMetadataItem.isCustom}
objectMetadataItem={objectMetadataItem}
onBlur={() => {
formConfig.handleSubmit(handleSave)();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ type SettingsDataModelObjectAboutFormValues = z.infer<
>;

type SettingsDataModelObjectAboutFormProps = {
disabled?: boolean;
disableNameEdit?: boolean;
disableEdition?: boolean;
objectMetadataItem?: ObjectMetadataItem;
onBlur?: () => void;
};
Expand Down Expand Up @@ -92,16 +91,19 @@ const infoCircleElementId = 'info-circle-id';
export const IS_LABEL_SYNCED_WITH_NAME_LABEL = 'isLabelSyncedWithName';

export const SettingsDataModelObjectAboutForm = ({
disabled,
disableNameEdit,
disableEdition,
objectMetadataItem,
onBlur,
}: SettingsDataModelObjectAboutFormProps) => {
const { control, watch, setValue } =
useFormContext<SettingsDataModelObjectAboutFormValues>();
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 labelPlural = watch('labelPlural');
watch('nameSingular');
Expand Down Expand Up @@ -148,7 +150,7 @@ export const SettingsDataModelObjectAboutForm = ({
defaultValue={objectMetadataItem?.icon ?? 'IconListNumbers'}
render={({ field: { onChange, value } }) => (
<IconPicker
disabled={disabled}
disabled={disableEdition}
selectedIconKey={value}
onChange={({ iconKey }) => onChange(iconKey)}
/>
Expand All @@ -173,7 +175,7 @@ export const SettingsDataModelObjectAboutForm = ({
}
}}
onBlur={onBlur}
disabled={disabled || disableNameEdit}
disabled={disableEdition}
fullWidth
maxLength={OBJECT_NAME_MAXIMUM_LENGTH}
/>
Expand All @@ -195,7 +197,7 @@ export const SettingsDataModelObjectAboutForm = ({
fillNamePluralFromLabelPlural(value);
}
}}
disabled={disabled || disableNameEdit}
disabled={disableEdition}
fullWidth
maxLength={OBJECT_NAME_MAXIMUM_LENGTH}
/>
Expand All @@ -212,7 +214,7 @@ export const SettingsDataModelObjectAboutForm = ({
minRows={4}
value={value ?? undefined}
onChange={(nextValue) => onChange(nextValue ?? null)}
disabled={disabled}
disabled={disableEdition}
/>
)}
/>
Expand All @@ -226,17 +228,15 @@ export const SettingsDataModelObjectAboutForm = ({
fieldName: 'nameSingular' as const,
placeholder: 'listing',
defaultValue: objectMetadataItem?.nameSingular,
disabled:
disabled || disableNameEdit || isLabelSyncedWithName,
disableEdition: disableEdition || isLabelSyncedWithName,
tooltip: apiNameTooltipText,
},
{
label: 'API Name (Plural)',
fieldName: 'namePlural' as const,
placeholder: 'listings',
defaultValue: objectMetadataItem?.namePlural,
disabled:
disabled || disableNameEdit || isLabelSyncedWithName,
disableEdition: disableEdition || isLabelSyncedWithName,
tooltip: apiNameTooltipText,
},
].map(
Expand All @@ -245,7 +245,7 @@ export const SettingsDataModelObjectAboutForm = ({
fieldName,
label,
placeholder,
disabled,
disableEdition,
tooltip,
}) => (
<StyledInputContainer key={`object-${fieldName}-text-input`}>
Expand All @@ -260,7 +260,7 @@ export const SettingsDataModelObjectAboutForm = ({
placeholder={placeholder}
value={value}
onChange={onChange}
disabled={disabled}
disabled={disableEdition}
fullWidth
maxLength={OBJECT_NAME_MAXIMUM_LENGTH}
onBlur={onBlur}
Expand Down Expand Up @@ -303,7 +303,10 @@ export const SettingsDataModelObjectAboutForm = ({
title="Synchronize Objects Labels and API Names"
description="Should changing an object's label also change the API?"
checked={value ?? true}
disabled={!objectMetadataItem?.isCustom}
disabled={
Comment on lines 305 to +306
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: value ?? true is redundant since defaultValue is already set with the same fallback on line 298

isDefined(objectMetadataItem) &&
!objectMetadataItem.isCustom
}
advancedMode
onChange={(value) => {
onChange(value);
Expand Down
Loading