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

Allow standard field default value and settings editing (#7104) #8559

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 @@ -5,7 +5,6 @@ import { z } from 'zod';
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
import { SettingsOptionCardContentSelect } from '@/settings/components/SettingsOptions/SettingsOptionCardContentSelect';
import { useBooleanSettingsFormInitialValues } from '@/settings/data-model/fields/forms/boolean/hooks/useBooleanSettingsFormInitialValues';
import { isDefined } from '~/utils/isDefined';

export const settingsDataModelFieldBooleanFormSchema = z.object({
defaultValue: z.boolean(),
Expand All @@ -26,7 +25,6 @@ export const SettingsDataModelFieldBooleanForm = ({
}: SettingsDataModelFieldBooleanFormProps) => {
const { control } = useFormContext<SettingsDataModelFieldBooleanFormValues>();

const isEditMode = isDefined(fieldMetadataItem?.defaultValue);
const { initialDefaultValue } = useBooleanSettingsFormInitialValues({
fieldMetadataItem,
});
Expand All @@ -44,9 +42,6 @@ export const SettingsDataModelFieldBooleanForm = ({
value={value}
onChange={onChange}
selectClassName={className}
// TODO: temporary fix - disabling edition because after editing the defaultValue,
// newly created records are not taking into account the updated defaultValue properly.
Copy link
Contributor Author

@ad-elias ad-elias Nov 18, 2024

Choose a reason for hiding this comment

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

Could not replicate this issue so removed the comment

disabled={isEditMode}
dropdownId="object-field-default-value-select-boolean"
options={[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export const settingsDataModelFieldSettingsFormSchema = z.discriminatedUnion(
);

type SettingsDataModelFieldSettingsFormCardProps = {
isCreatingField?: boolean;
fieldMetadataItem: Pick<
FieldMetadataItem,
'icon' | 'label' | 'type' | 'isCustom'
Expand Down Expand Up @@ -124,7 +123,6 @@ const previewableTypes = [
];

export const SettingsDataModelFieldSettingsFormCard = ({
isCreatingField,
fieldMetadataItem,
objectMetadataItem,
}: SettingsDataModelFieldSettingsFormCardProps) => {
Expand All @@ -144,7 +142,6 @@ export const SettingsDataModelFieldSettingsFormCard = ({
if (fieldMetadataItem.type === FieldMetadataType.Currency) {
return (
<SettingsDataModelFieldCurrencySettingsFormCard
disabled={!isCreatingField}
fieldMetadataItem={fieldMetadataItem}
objectMetadataItem={objectMetadataItem}
/>
Expand All @@ -157,7 +154,6 @@ export const SettingsDataModelFieldSettingsFormCard = ({
) {
return (
<SettingsDataModelFieldDateSettingsFormCard
disabled={!isCreatingField}
fieldMetadataItem={fieldMetadataItem}
objectMetadataItem={objectMetadataItem}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { useFieldMetadataItem } from '@/object-metadata/hooks/useFieldMetadataIt
import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilteredObjectMetadataItems';
import { useGetRelationMetadata } from '@/object-metadata/hooks/useGetRelationMetadata';
import { useUpdateOneFieldMetadataItem } from '@/object-metadata/hooks/useUpdateOneFieldMetadataItem';
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
import { formatFieldMetadataItemInput } from '@/object-metadata/utils/formatFieldMetadataItemInput';
import { getFieldSlug } from '@/object-metadata/utils/getFieldSlug';
import { isLabelIdentifierField } from '@/object-metadata/utils/isLabelIdentifierField';
Expand Down Expand Up @@ -47,16 +46,6 @@ type SettingsDataModelFieldEditFormValues = z.infer<
> &
any;

const canPersistFieldMetadataItemUpdate = (
fieldMetadataItem: FieldMetadataItem,
) => {
return (
fieldMetadataItem.isCustom ||
fieldMetadataItem.type === FieldMetadataType.Select ||
fieldMetadataItem.type === FieldMetadataType.MultiSelect
);
};

export const SettingsObjectFieldEdit = () => {
const navigate = useNavigate();
const { enqueueSnackBar } = useSnackBar();
Expand Down Expand Up @@ -179,9 +168,6 @@ export const SettingsObjectFieldEdit = () => {
navigate(`/settings/objects/${objectSlug}`);
};

const shouldDisplaySaveAndCancel =
canPersistFieldMetadataItemUpdate(fieldMetadataItem);

return (
<RecordFieldValueSelectorContextProvider>
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
Expand All @@ -206,14 +192,12 @@ export const SettingsObjectFieldEdit = () => {
},
]}
actionButton={
shouldDisplaySaveAndCancel && (
<SaveAndCancelButtons
isSaveDisabled={!canSave}
isCancelDisabled={isSubmitting}
onCancel={() => navigate(`/settings/objects/${objectSlug}`)}
onSave={formConfig.handleSubmit(handleSave)}
/>
)
<SaveAndCancelButtons
isSaveDisabled={!canSave}
isCancelDisabled={isSubmitting}
onCancel={() => navigate(`/settings/objects/${objectSlug}`)}
onSave={formConfig.handleSubmit(handleSave)}
/>
}
Comment on lines 194 to 201
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Removing the restriction on standard field editing could have unintended consequences. Consider adding validation to prevent critical system fields from being modified.

>
<SettingsPageContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ export const SettingsObjectNewFieldConfigure = () => {
<Section>
<H2Title title="Values" description="The values of this field" />
<SettingsDataModelFieldSettingsFormCard
isCreatingField
fieldMetadataItem={{
icon: formConfig.watch('icon'),
label: formConfig.watch('label') || 'New Field',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,23 +632,25 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
fieldMetadataInput: UpdateFieldInput,
existingFieldMetadata: FieldMetadataEntity,
) {
let fieldMetadataInputOverrided = {};

fieldMetadataInputOverrided = {
const defaultUpdatableStandardFieldInput: UpdateFieldInput = {
id: fieldMetadataInput.id,
isActive: fieldMetadataInput.isActive,
workspaceId: fieldMetadataInput.workspaceId,
defaultValue: fieldMetadataInput.defaultValue,
settings: fieldMetadataInput.settings,
};

if (existingFieldMetadata.type === FieldMetadataType.SELECT) {
fieldMetadataInputOverrided = {
...fieldMetadataInputOverrided,
if (
existingFieldMetadata.type === FieldMetadataType.SELECT ||
existingFieldMetadata.type === FieldMetadataType.MULTI_SELECT
) {
return {
...defaultUpdatableStandardFieldInput,
options: fieldMetadataInput.options,
};
}

return fieldMetadataInputOverrided as UpdateFieldInput;
return defaultUpdatableStandardFieldInput;
}

public async getRelationDefinitionFromRelationMetadata(
Expand Down
Loading