Allow to edit labels of standard objects (#10922)
Fixes #10793 This PR is a work in progress. **Still left to fix:** - [x] When disabling synchronization of labels / api names, the edited labels should be set to the English version. Currently the client just send the localized versions together with the `isLabelSyncedWithName` change. Could be an easy fix. - [ ] Sometimes flipping the switch don't trigger the update function, may be a regression as it seems to affect the custom objects too. - [ ] There is a frontend problem where the labels inputs don't reflect the changes made. When enabling back synchronisation after editing labels, they are correctly back to their base values (backend, navigation breadcrumb, etc) but the label inputs still have the old values (switching pages will put them back to normal). I suspect this could be linked to the above problem. - [ ] API names are still displayed for standard objects per (kept them for debugging, trivial fix) - [ ] `SettingsDataModelObjectAboutForm` have a `disableEdition` parameter which is now used only for a few fields, not sure if it's worth keeping because it's a bit misleading since it doesn't "disable" much? - [ ] I don't know what these do, but I have seen "Remote" object types. Not sure if they work with my patch or not (I don't know how to test them) - [ ] Make it work with metadata synchronisation **What should work:** - Disabling synchronization of standard objects should work, label inputs should no longer be disabled - Modifying labels should work - Enabling back synchronization should reset back the labels to the base value and disable the label inputs again (minus the mentioned display bug) - The synchronisation switch should still work as expected for custom objects - Creating custom objects should still work (it uses the same form) --------- Signed-off-by: AFCMS <afcm.contact@gmail.com> Co-authored-by: Félix Malfait <felix@twenty.com> Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
import { AdvancedSettingsWrapper } from '@/settings/components/AdvancedSettingsWrapper';
|
||||
import { SettingsOptionCardContentToggle } from '@/settings/components/SettingsOptions/SettingsOptionCardContentToggle';
|
||||
import { SETTINGS_OBJECT_MODEL_IS_LABEL_SYNCED_WITH_NAME_LABEL_DEFAULT_VALUE } from '@/settings/constants/SettingsObjectModel';
|
||||
import { OBJECT_NAME_MAXIMUM_LENGTH } from '@/settings/data-model/constants/ObjectNameMaximumLength';
|
||||
import { SettingsDataModelObjectAboutFormValues } from '@/settings/data-model/validation-schemas/settingsDataModelObjectAboutFormSchema';
|
||||
import { IconPicker } from '@/ui/input/components/IconPicker';
|
||||
@ -12,6 +11,7 @@ import styled from '@emotion/styled';
|
||||
import { useLingui } from '@lingui/react/macro';
|
||||
import { plural } from 'pluralize';
|
||||
import { Controller, useFormContext } from 'react-hook-form';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import {
|
||||
AppTooltip,
|
||||
Card,
|
||||
@ -21,7 +21,6 @@ import {
|
||||
} from 'twenty-ui';
|
||||
import { StringKeyOf } from 'type-fest';
|
||||
import { computeMetadataNameFromLabel } from '~/pages/settings/data-model/utils/compute-metadata-name-from-label.utils';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
type SettingsDataModelObjectAboutFormProps = {
|
||||
disableEdition?: boolean;
|
||||
@ -69,8 +68,6 @@ const StyledLabel = styled.span`
|
||||
|
||||
const infoCircleElementId = 'info-circle-id';
|
||||
|
||||
export const IS_LABEL_SYNCED_WITH_NAME_LABEL = 'isLabelSyncedWithName';
|
||||
|
||||
export const SettingsDataModelObjectAboutForm = ({
|
||||
disableEdition = false,
|
||||
onNewDirtyField,
|
||||
@ -81,20 +78,20 @@ export const SettingsDataModelObjectAboutForm = ({
|
||||
const { t } = useLingui();
|
||||
const theme = useTheme();
|
||||
|
||||
const isLabelSyncedWithName =
|
||||
watch(IS_LABEL_SYNCED_WITH_NAME_LABEL) ??
|
||||
(isDefined(objectMetadataItem)
|
||||
? objectMetadataItem.isLabelSyncedWithName
|
||||
: SETTINGS_OBJECT_MODEL_IS_LABEL_SYNCED_WITH_NAME_LABEL_DEFAULT_VALUE);
|
||||
const isLabelSyncedWithName = watch('isLabelSyncedWithName');
|
||||
const labelSingular = watch('labelSingular');
|
||||
const labelPlural = watch('labelPlural');
|
||||
watch('nameSingular');
|
||||
watch('namePlural');
|
||||
watch('description');
|
||||
watch('icon');
|
||||
const apiNameTooltipText = isLabelSyncedWithName
|
||||
? t`Deactivate "Synchronize Objects Labels and API Names" to set a custom API name`
|
||||
: t`Input must be in camel case and cannot start with a number`;
|
||||
|
||||
const apiNameTooltipText =
|
||||
!isDefined(objectMetadataItem) || objectMetadataItem.isCustom
|
||||
? isLabelSyncedWithName
|
||||
? t`Deactivate "Synchronize Objects Labels and API Names" to set a custom API name`
|
||||
: t`Input must be in camel case and cannot start with a number`
|
||||
: t`Can't change API names for standard objects`;
|
||||
|
||||
const fillLabelPlural = (labelSingular: string | undefined) => {
|
||||
if (!isDefined(labelSingular)) return;
|
||||
@ -103,9 +100,6 @@ export const SettingsDataModelObjectAboutForm = ({
|
||||
setValue('labelPlural', labelPluralFromSingularLabel, {
|
||||
shouldDirty: true,
|
||||
});
|
||||
if (isLabelSyncedWithName === true) {
|
||||
fillNamePluralFromLabelPlural(labelPluralFromSingularLabel);
|
||||
}
|
||||
};
|
||||
|
||||
const fillNameSingularFromLabelSingular = (
|
||||
@ -137,7 +131,6 @@ export const SettingsDataModelObjectAboutForm = ({
|
||||
defaultValue={objectMetadataItem?.icon ?? 'IconListNumbers'}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<IconPicker
|
||||
disabled={disableEdition}
|
||||
selectedIconKey={value}
|
||||
onChange={({ iconKey }) => {
|
||||
onChange(iconKey);
|
||||
@ -168,7 +161,7 @@ export const SettingsDataModelObjectAboutForm = ({
|
||||
}
|
||||
}}
|
||||
onBlur={() => onNewDirtyField?.()}
|
||||
disabled={disableEdition}
|
||||
disabled={!objectMetadataItem?.isCustom && isLabelSyncedWithName}
|
||||
fullWidth
|
||||
maxLength={OBJECT_NAME_MAXIMUM_LENGTH}
|
||||
/>
|
||||
@ -194,7 +187,7 @@ export const SettingsDataModelObjectAboutForm = ({
|
||||
}
|
||||
}}
|
||||
onBlur={() => onNewDirtyField?.()}
|
||||
disabled={disableEdition}
|
||||
disabled={!objectMetadataItem?.isCustom && isLabelSyncedWithName}
|
||||
fullWidth
|
||||
maxLength={OBJECT_NAME_MAXIMUM_LENGTH}
|
||||
/>
|
||||
@ -210,7 +203,6 @@ export const SettingsDataModelObjectAboutForm = ({
|
||||
minRows={4}
|
||||
value={value ?? undefined}
|
||||
onChange={(nextValue) => onChange(nextValue ?? null)}
|
||||
disabled={disableEdition}
|
||||
onBlur={() => onNewDirtyField?.()}
|
||||
/>
|
||||
)}
|
||||
@ -303,12 +295,9 @@ export const SettingsDataModelObjectAboutForm = ({
|
||||
)}
|
||||
<AdvancedSettingsWrapper>
|
||||
<Controller
|
||||
name={IS_LABEL_SYNCED_WITH_NAME_LABEL}
|
||||
name="isLabelSyncedWithName"
|
||||
control={control}
|
||||
defaultValue={
|
||||
objectMetadataItem?.isLabelSyncedWithName ??
|
||||
SETTINGS_OBJECT_MODEL_IS_LABEL_SYNCED_WITH_NAME_LABEL_DEFAULT_VALUE
|
||||
}
|
||||
defaultValue={objectMetadataItem?.isLabelSyncedWithName}
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<Card rounded>
|
||||
<SettingsOptionCardContentToggle
|
||||
@ -316,18 +305,19 @@ export const SettingsDataModelObjectAboutForm = ({
|
||||
title={t`Synchronize Objects Labels and API Names`}
|
||||
description={t`Should changing an object's label also change the API?`}
|
||||
checked={value ?? true}
|
||||
disabled={
|
||||
isDefined(objectMetadataItem) &&
|
||||
!objectMetadataItem.isCustom
|
||||
}
|
||||
advancedMode
|
||||
onChange={(value) => {
|
||||
onChange(value);
|
||||
if (value === true) {
|
||||
onNewDirtyField?.();
|
||||
|
||||
if (
|
||||
value === true &&
|
||||
isDefined(objectMetadataItem) &&
|
||||
objectMetadataItem.isCustom
|
||||
) {
|
||||
fillNamePluralFromLabelPlural(labelPlural);
|
||||
fillNameSingularFromLabelSingular(labelSingular);
|
||||
}
|
||||
onNewDirtyField?.();
|
||||
}}
|
||||
/>
|
||||
</Card>
|
||||
|
||||
Reference in New Issue
Block a user