From 0140385415a742a322076fb2a25f187aa0d5290d Mon Sep 17 00:00:00 2001 From: Tristan Chuine Date: Mon, 12 Aug 2024 20:26:48 +0200 Subject: [PATCH] deduplicate yup --- .../contingency-list-creation-dialog.jsx | 4 ++-- .../criteria-based-edition-dialog.jsx | 4 ++-- .../explicit-naming-edition-dialog.jsx | 5 ++-- .../edition/script/script-edition-dialog.jsx | 5 ++-- .../explicit-naming/explicit-naming-form.jsx | 9 ++++++-- .../dialogs/copy-to-script-dialog.tsx | 3 +-- .../create-case-dialog-utils.ts | 3 +-- .../create-case-dialog/create-case-dialog.tsx | 2 +- .../create-study-dialog-utils.js | 3 +-- .../create-study-dialog.jsx | 2 +- src/components/utils/yup-config.js | 23 ------------------- 11 files changed, 20 insertions(+), 43 deletions(-) delete mode 100644 src/components/utils/yup-config.js diff --git a/src/components/dialogs/contingency-list/creation/contingency-list-creation-dialog.jsx b/src/components/dialogs/contingency-list/creation/contingency-list-creation-dialog.jsx index c8e54a223..29da8d516 100644 --- a/src/components/dialogs/contingency-list/creation/contingency-list-creation-dialog.jsx +++ b/src/components/dialogs/contingency-list/creation/contingency-list-creation-dialog.jsx @@ -12,12 +12,12 @@ import { getCriteriaBasedSchema, PARAM_LANGUAGE, useSnackMessage, + yup, } from '@gridsuite/commons-ui'; import { useForm } from 'react-hook-form'; -import { yupResolver } from '@hookform/resolvers/yup/dist/yup'; +import { yupResolver } from '@hookform/resolvers/yup'; import ContingencyListCreationForm from './contingency-list-creation-form'; import { getContingencyListEmptyFormData, getFormContent } from '../contingency-list-utils'; -import yup from '../../../utils/yup-config'; import { getExplicitNamingSchema } from '../explicit-naming/explicit-naming-form'; import { ContingencyListType } from '../../../../utils/elementType'; import { useParameterState } from '../../parameters-dialog'; diff --git a/src/components/dialogs/contingency-list/edition/criteria-based/criteria-based-edition-dialog.jsx b/src/components/dialogs/contingency-list/edition/criteria-based/criteria-based-edition-dialog.jsx index b86297eff..8dedf57db 100644 --- a/src/components/dialogs/contingency-list/edition/criteria-based/criteria-based-edition-dialog.jsx +++ b/src/components/dialogs/contingency-list/edition/criteria-based/criteria-based-edition-dialog.jsx @@ -11,15 +11,15 @@ import { getCriteriaBasedSchema, PARAM_LANGUAGE, useSnackMessage, + yup, } from '@gridsuite/commons-ui'; import { useForm } from 'react-hook-form'; -import { yupResolver } from '@hookform/resolvers/yup/dist/yup'; +import { yupResolver } from '@hookform/resolvers/yup'; import { useEffect, useState } from 'react'; import { getContingencyListEmptyFormData, getCriteriaBasedFormDataFromFetchedElement, } from '../../contingency-list-utils'; -import yup from 'components/utils/yup-config'; import CriteriaBasedEditionForm from './criteria-based-edition-form'; import { useDispatch, useSelector } from 'react-redux'; import { noSelectionForCopy } from 'utils/constants'; diff --git a/src/components/dialogs/contingency-list/edition/explicit-naming/explicit-naming-edition-dialog.jsx b/src/components/dialogs/contingency-list/edition/explicit-naming/explicit-naming-edition-dialog.jsx index 341cc237e..4774266e1 100644 --- a/src/components/dialogs/contingency-list/edition/explicit-naming/explicit-naming-edition-dialog.jsx +++ b/src/components/dialogs/contingency-list/edition/explicit-naming/explicit-naming-edition-dialog.jsx @@ -5,15 +5,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { CustomMuiDialog, FieldConstants, useSnackMessage } from '@gridsuite/commons-ui'; +import { CustomMuiDialog, FieldConstants, useSnackMessage, yup } from '@gridsuite/commons-ui'; import { useForm } from 'react-hook-form'; -import { yupResolver } from '@hookform/resolvers/yup/dist/yup'; +import { yupResolver } from '@hookform/resolvers/yup'; import { useEffect, useState } from 'react'; import { getContingencyListEmptyFormData, getExplicitNamingFormDataFromFetchedElement, } from '../../contingency-list-utils'; -import yup from 'components/utils/yup-config'; import { getExplicitNamingEditSchema } from '../../explicit-naming/explicit-naming-form'; import ExplicitNamingEditionForm from './explicit-naming-edition-form'; import { prepareContingencyListForBackend } from 'components/dialogs/contingency-list-helper'; diff --git a/src/components/dialogs/contingency-list/edition/script/script-edition-dialog.jsx b/src/components/dialogs/contingency-list/edition/script/script-edition-dialog.jsx index d814a21f4..fcc788232 100644 --- a/src/components/dialogs/contingency-list/edition/script/script-edition-dialog.jsx +++ b/src/components/dialogs/contingency-list/edition/script/script-edition-dialog.jsx @@ -5,12 +5,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { CustomMuiDialog, FieldConstants, useSnackMessage } from '@gridsuite/commons-ui'; +import { CustomMuiDialog, FieldConstants, useSnackMessage, yup } from '@gridsuite/commons-ui'; import { useForm } from 'react-hook-form'; -import { yupResolver } from '@hookform/resolvers/yup/dist/yup'; +import { yupResolver } from '@hookform/resolvers/yup'; import { useEffect, useState } from 'react'; import { getContingencyListEmptyFormData, getScriptFormDataFromFetchedElement } from '../../contingency-list-utils'; -import yup from 'components/utils/yup-config'; import ScriptEditionForm from './script-edition-form'; import { useDispatch, useSelector } from 'react-redux'; import { noSelectionForCopy } from 'utils/constants'; diff --git a/src/components/dialogs/contingency-list/explicit-naming/explicit-naming-form.jsx b/src/components/dialogs/contingency-list/explicit-naming/explicit-naming-form.jsx index 0852d8faa..cf6e6b071 100644 --- a/src/components/dialogs/contingency-list/explicit-naming/explicit-naming-form.jsx +++ b/src/components/dialogs/contingency-list/explicit-naming/explicit-naming-form.jsx @@ -7,12 +7,17 @@ import { useIntl } from 'react-intl'; import React, { useCallback, useMemo } from 'react'; -import yup from '../../../utils/yup-config'; import { makeDefaultRowData } from '../contingency-list-utils'; import ChipsArrayEditor from '../../../utils/rhf-inputs/ag-grid-table-rhf/cell-editors/chips-array-editor'; import { ContingencyListType } from 'utils/elementType'; import { v4 as uuid4 } from 'uuid'; -import { FieldConstants, gridItem, CustomAgGridTable, ROW_DRAGGING_SELECTION_COLUMN_DEF } from '@gridsuite/commons-ui'; +import { + CustomAgGridTable, + FieldConstants, + gridItem, + ROW_DRAGGING_SELECTION_COLUMN_DEF, + yup, +} from '@gridsuite/commons-ui'; export const getExplicitNamingSchema = (id) => { return { diff --git a/src/components/dialogs/copy-to-script-dialog.tsx b/src/components/dialogs/copy-to-script-dialog.tsx index fba7b6af9..8440c7744 100644 --- a/src/components/dialogs/copy-to-script-dialog.tsx +++ b/src/components/dialogs/copy-to-script-dialog.tsx @@ -6,11 +6,10 @@ */ import { FunctionComponent, useCallback, useEffect, useState } from 'react'; import { useIntl } from 'react-intl'; -import yup from 'components/utils/yup-config'; import { useForm } from 'react-hook-form'; import { yupResolver } from '@hookform/resolvers/yup'; import { CircularProgress, Grid } from '@mui/material'; -import { CustomMuiDialog, ElementType, FieldConstants, UniqueNameInput } from '@gridsuite/commons-ui'; +import { CustomMuiDialog, ElementType, FieldConstants, UniqueNameInput, yup } from '@gridsuite/commons-ui'; import { useSelector } from 'react-redux'; import { UUID } from 'crypto'; import { AppState } from '../../redux/reducer'; diff --git a/src/components/dialogs/create-case-dialog/create-case-dialog-utils.ts b/src/components/dialogs/create-case-dialog/create-case-dialog-utils.ts index 78f01fc60..a1d50b57a 100644 --- a/src/components/dialogs/create-case-dialog/create-case-dialog-utils.ts +++ b/src/components/dialogs/create-case-dialog/create-case-dialog-utils.ts @@ -5,8 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import yup from '../../utils/yup-config'; -import { FieldConstants } from '@gridsuite/commons-ui'; +import { FieldConstants, yup } from '@gridsuite/commons-ui'; export const getCreateCaseDialogFormValidationDefaultValues = () => ({ [FieldConstants.CASE_NAME]: '', diff --git a/src/components/dialogs/create-case-dialog/create-case-dialog.tsx b/src/components/dialogs/create-case-dialog/create-case-dialog.tsx index 747f528c0..33fcd87c9 100644 --- a/src/components/dialogs/create-case-dialog/create-case-dialog.tsx +++ b/src/components/dialogs/create-case-dialog/create-case-dialog.tsx @@ -12,7 +12,7 @@ import { Grid } from '@mui/material'; import { addUploadingElement, removeUploadingElement } from '../../../redux/actions'; import UploadNewCase from '../commons/upload-new-case'; import { useForm } from 'react-hook-form'; -import { yupResolver } from '@hookform/resolvers/yup/dist/yup'; +import { yupResolver } from '@hookform/resolvers/yup'; import { createCaseDialogFormValidationSchema, getCreateCaseDialogFormValidationDefaultValues, diff --git a/src/components/dialogs/create-study-dialog/create-study-dialog-utils.js b/src/components/dialogs/create-study-dialog/create-study-dialog-utils.js index bd425dbe1..313769d1d 100644 --- a/src/components/dialogs/create-study-dialog/create-study-dialog-utils.js +++ b/src/components/dialogs/create-study-dialog/create-study-dialog-utils.js @@ -5,8 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import yup from '../../utils/yup-config'; -import { FieldConstants } from '@gridsuite/commons-ui'; +import { FieldConstants, yup } from '@gridsuite/commons-ui'; export const getCreateStudyDialogFormDefaultValues = ({ directory = '', diff --git a/src/components/dialogs/create-study-dialog/create-study-dialog.jsx b/src/components/dialogs/create-study-dialog/create-study-dialog.jsx index 61ed02e6a..e1b29d3c6 100644 --- a/src/components/dialogs/create-study-dialog/create-study-dialog.jsx +++ b/src/components/dialogs/create-study-dialog/create-study-dialog.jsx @@ -29,7 +29,7 @@ import { createStudyDialogFormValidationSchema, getCreateStudyDialogFormDefaultValues, } from './create-study-dialog-utils'; -import { yupResolver } from '@hookform/resolvers/yup/dist/yup'; +import { yupResolver } from '@hookform/resolvers/yup'; import PrefilledNameInput from '../commons/prefilled-name-input'; import { handleMaxElementsExceededError } from '../../utils/rest-errors'; import { caseSrv, exploreSrv, networkConversionSrv } from '../../../services'; diff --git a/src/components/utils/yup-config.js b/src/components/utils/yup-config.js deleted file mode 100644 index 4209b421b..000000000 --- a/src/components/utils/yup-config.js +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (c) 2023, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -import * as yup from 'yup'; - -yup.setLocale({ - mixed: { - required: 'YupRequired', - notType: ({ type }) => { - if (type === 'number') { - return 'YupNotTypeNumber'; - } else { - return 'YupNotTypeDefault'; - } - }, - }, -}); - -export default yup;