-
Notifications
You must be signed in to change notification settings - Fork 5
Moving the byFilterDeletion form gridstudy to commons-ui #3809
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,44 +6,33 @@ | |||||
| */ | ||||||
|
|
||||||
| import { yupResolver } from '@hookform/resolvers/yup'; | ||||||
| import yup from 'components/utils/yup-config'; | ||||||
| import { FILTERS, ID, NAME, TYPE } from '../../../../utils/field-constants'; | ||||||
| import { CustomFormProvider, snackWithFallback, useSnackMessage } from '@gridsuite/commons-ui'; | ||||||
| import { | ||||||
| ByFilterDeletionDto, | ||||||
| ByFilterDeletionForm, | ||||||
| ByFilterDeletionFormData, | ||||||
| byFilterDeletionDtoToForm, | ||||||
| byFilterDeletionFormSchema, | ||||||
| FieldConstants, | ||||||
| CustomFormProvider, | ||||||
| snackWithFallback, | ||||||
| useSnackMessage, | ||||||
| } from '@gridsuite/commons-ui'; | ||||||
| import { useForm } from 'react-hook-form'; | ||||||
| import { FunctionComponent, useCallback, useEffect } from 'react'; | ||||||
| import { ModificationDialog } from '../../../commons/modificationDialog'; | ||||||
| import { EQUIPMENT_TYPES } from 'components/utils/equipment-types'; | ||||||
| import { useOpenShortWaitFetching } from 'components/dialogs/commons/handle-modification-form'; | ||||||
| import { FORM_LOADING_DELAY } from 'components/network/constants'; | ||||||
| import { deleteEquipmentByFilter } from '../../../../../services/study/network-modifications'; | ||||||
| import { FetchStatus } from '../../../../../services/utils'; | ||||||
| import ByFilterDeletionForm from './by-filter-deletion-form'; | ||||||
| import { | ||||||
| ByFilterDeletionDialogProps, | ||||||
| ByFilterDeletionEditData, | ||||||
| ByFilterDeletionFormData, | ||||||
| } from './by-filter-deletion.type'; | ||||||
| import { NetworkModificationDialogProps } from '../../../../graph/menus/network-modifications/network-modification-menu.type'; | ||||||
|
|
||||||
| const formSchema = yup | ||||||
| .object() | ||||||
| .shape({ | ||||||
| [TYPE]: yup.mixed<keyof typeof EQUIPMENT_TYPES>().required(), | ||||||
| [FILTERS]: yup | ||||||
| .array() | ||||||
| .of( | ||||||
| yup.object().shape({ | ||||||
| [ID]: yup.string().required(), | ||||||
| [NAME]: yup.string().required(), | ||||||
| }) | ||||||
| ) | ||||||
| .required() | ||||||
| .min(1, 'FieldIsRequired'), | ||||||
| }) | ||||||
| .required(); | ||||||
| const emptyFormData: ByFilterDeletionFormData = { | ||||||
| [FieldConstants.TYPE]: null, | ||||||
| [FieldConstants.FILTERS]: [], | ||||||
| }; | ||||||
|
|
||||||
| const emptyFormData = { | ||||||
| [TYPE]: null, | ||||||
| [FILTERS]: [], | ||||||
| type ByFilterDeletionDialogProps = NetworkModificationDialogProps & { | ||||||
| editData: ByFilterDeletionDto; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
editData is optional (cf creation mode). and you can add uuid here (if you remove it from the DTO). |
||||||
| }; | ||||||
|
|
||||||
| /** | ||||||
|
|
@@ -69,17 +58,14 @@ | |||||
|
|
||||||
| const formMethods = useForm<ByFilterDeletionFormData>({ | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| defaultValues: emptyFormData, | ||||||
| resolver: yupResolver<ByFilterDeletionFormData>(formSchema), | ||||||
| resolver: yupResolver<ByFilterDeletionFormData>(byFilterDeletionFormSchema), | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| }); | ||||||
|
|
||||||
| const { reset } = formMethods; | ||||||
|
|
||||||
| const fromEditDataToFormValues = useCallback( | ||||||
| (editData: ByFilterDeletionEditData) => { | ||||||
| reset({ | ||||||
| [TYPE]: EQUIPMENT_TYPES[editData.equipmentType] as keyof typeof EQUIPMENT_TYPES, | ||||||
| [FILTERS]: editData.filters, | ||||||
| }); | ||||||
| (data: ByFilterDeletionDto) => { | ||||||
| reset(byFilterDeletionDtoToForm(data)); | ||||||
| }, | ||||||
| [reset] | ||||||
| ); | ||||||
|
|
@@ -95,8 +81,8 @@ | |||||
| deleteEquipmentByFilter( | ||||||
| studyUuid, | ||||||
| currentNodeUuid, | ||||||
| formData[TYPE], | ||||||
| formData[FILTERS], | ||||||
| formData[FieldConstants.TYPE], | ||||||
| formData[FieldConstants.FILTERS], | ||||||
| editData?.uuid | ||||||
|
Comment on lines
81
to
86
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should use: const dto = byFilterDeletionFormToDto(form); ex: #3815 |
||||||
| ).catch((error) => { | ||||||
| snackWithFallback(snackError, error, { headerId: 'UnableToDeleteEquipment' }); | ||||||
|
|
@@ -116,7 +102,7 @@ | |||||
| }); | ||||||
|
|
||||||
| return ( | ||||||
| <CustomFormProvider validationSchema={formSchema} {...formMethods}> | ||||||
| <CustomFormProvider validationSchema={byFilterDeletionFormSchema} {...formMethods}> | ||||||
| <ModificationDialog | ||||||
| fullWidth | ||||||
| maxWidth={'md'} | ||||||
|
|
||||||
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And we put it in commons-ui too