Skip to content

Commit

Permalink
Fix not possible to edit options (#6979)
Browse files Browse the repository at this point in the history
We have recently merged: #6700

However, this introduced a regression on field edition as we have
removed the type dropdown from the field edition page. This dropdown was
wrapped into a controller setting the type on the form. Without this
type, the form is considered as invalid and cannot be saved.

I'm setting the form values through useForm.

I'm unhappy with this PR for too reasons:
- usage of activeMetadataField?.icon ?? '' format because I cannot call
useForm conditionnally. This would imply splitting the component into
several components to avoid this issue
- usage of react hook form which is very hard to debug, we should remove
it from the project
  • Loading branch information
charlesBochet authored Sep 11, 2024
1 parent 846953b commit 425eb04
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { SettingsDataModelFieldDescriptionForm } from '@/settings/data-model/fie
import { SettingsDataModelFieldIconLabelForm } from '@/settings/data-model/fields/forms/components/SettingsDataModelFieldIconLabelForm';
import { SettingsDataModelFieldSettingsFormCard } from '@/settings/data-model/fields/forms/components/SettingsDataModelFieldSettingsFormCard';
import { settingsFieldFormSchema } from '@/settings/data-model/fields/forms/validation-schemas/settingsFieldFormSchema';
import { SettingsSupportedFieldType } from '@/settings/data-model/types/SettingsSupportedFieldType';
import { AppPath } from '@/types/AppPath';
import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar';
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
Expand Down Expand Up @@ -86,6 +87,12 @@ export const SettingsObjectFieldEdit = () => {
const formConfig = useForm<SettingsDataModelFieldEditFormValues>({
mode: 'onTouched',
resolver: zodResolver(settingsFieldFormSchema()),
values: {
icon: activeMetadataField?.icon ?? 'Icon123',
type: activeMetadataField?.type as SettingsSupportedFieldType,
label: activeMetadataField?.label ?? '',
description: activeMetadataField?.description,
},
});

useEffect(() => {
Expand All @@ -94,11 +101,11 @@ export const SettingsObjectFieldEdit = () => {
}
}, [activeMetadataField, activeObjectMetadataItem, navigate]);

if (!activeObjectMetadataItem || !activeMetadataField) return null;

const { isDirty, isValid, isSubmitting } = formConfig.formState;
const canSave = isDirty && isValid && !isSubmitting;

if (!activeObjectMetadataItem || !activeMetadataField) return null;

const isLabelIdentifier = isLabelIdentifierField({
fieldMetadataItem: activeMetadataField,
objectMetadataItem: activeObjectMetadataItem,
Expand Down

0 comments on commit 425eb04

Please sign in to comment.