diff --git a/src/components/filter/constants/FilterConstants.ts b/src/components/filter/constants/FilterConstants.ts index 664b4767c..1098855ec 100644 --- a/src/components/filter/constants/FilterConstants.ts +++ b/src/components/filter/constants/FilterConstants.ts @@ -1,3 +1,5 @@ +import { SelectionForCopy } from '../filter.type'; + /** * Copyright (c) 2024, RTE (http://www.rte-france.com) * This Source Code Form is subject to the terms of the Mozilla Public @@ -11,3 +13,12 @@ export const FilterType = { EXPLICIT_NAMING: { id: 'IDENTIFIER_LIST', label: 'filter.explicitNaming' }, EXPERT: { id: 'EXPERT', label: 'filter.expert' }, }; + +export const NO_SELECTION_FOR_COPY: SelectionForCopy = { + sourceItemUuid: null, + nameItem: null, + descriptionItem: null, + parentDirectoryUuid: null, + typeItem: null, + specificTypeItem: null, +}; diff --git a/src/components/filter/criteriaBased/CriteriaBasedFilterEditionDialog.tsx b/src/components/filter/criteriaBased/CriteriaBasedFilterEditionDialog.tsx index 267d21b1a..e65f737fa 100644 --- a/src/components/filter/criteriaBased/CriteriaBasedFilterEditionDialog.tsx +++ b/src/components/filter/criteriaBased/CriteriaBasedFilterEditionDialog.tsx @@ -5,7 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { Dispatch, SetStateAction, useCallback, useEffect, useState } from 'react'; +import { useCallback, useEffect, useState } from 'react'; import { useForm } from 'react-hook-form'; import { yupResolver } from '@hookform/resolvers/yup'; import { UUID } from 'crypto'; @@ -15,25 +15,12 @@ import CustomMuiDialog from '../../dialogs/customMuiDialog/CustomMuiDialog'; import { useSnackMessage } from '../../../hooks/useSnackMessage'; import { criteriaBasedFilterSchema } from './CriteriaBasedFilterForm'; import yup from '../../../utils/yupConfig'; -import { FilterType } from '../constants/FilterConstants'; +import { FilterType, NO_SELECTION_FOR_COPY } from '../constants/FilterConstants'; import FetchStatus from '../../../utils/constants/fetchStatus'; import { saveFilter } from '../../../services/explore'; import { ElementExistsType } from '../../../utils/types/elementType'; import FilterForm from '../FilterForm'; - -export type SelectionCopy = { - sourceItemUuid: UUID | null; - name: string | null; - description: string | null; - parentDirectoryUuid: UUID | null; -}; - -export const noSelectionForCopy: SelectionCopy = { - sourceItemUuid: null, - name: null, - description: null, - parentDirectoryUuid: null, -}; +import { SelectionForCopy } from '../filter.type'; const formSchema = yup .object() @@ -53,8 +40,8 @@ export interface CriteriaBasedFilterEditionDialogProps { onClose: () => void; broadcastChannel: BroadcastChannel; getFilterById: (id: string) => Promise; - selectionForCopy: SelectionCopy; - setSelelectionForCopy: (selection: SelectionCopy) => Dispatch>; + selectionForCopy: SelectionForCopy; + setSelectionForCopy: (selection: SelectionForCopy) => void; activeDirectory?: UUID; elementExists?: ElementExistsType; language?: string; @@ -69,7 +56,7 @@ function CriteriaBasedFilterEditionDialog({ broadcastChannel, getFilterById, selectionForCopy, - setSelelectionForCopy, + setSelectionForCopy, activeDirectory, elementExists, language, @@ -118,9 +105,9 @@ function CriteriaBasedFilterEditionDialog({ saveFilter(frontToBackTweak(id, filterForm), filterForm[FieldConstants.NAME]) .then(() => { if (selectionForCopy.sourceItemUuid === id) { - setSelelectionForCopy(noSelectionForCopy); + setSelectionForCopy(NO_SELECTION_FOR_COPY); broadcastChannel.postMessage({ - noSelectionForCopy, + NO_SELECTION_FOR_COPY, }); } }) @@ -130,7 +117,7 @@ function CriteriaBasedFilterEditionDialog({ }); }); }, - [broadcastChannel, id, selectionForCopy.sourceItemUuid, snackError, setSelelectionForCopy] + [broadcastChannel, id, selectionForCopy.sourceItemUuid, snackError, setSelectionForCopy] ); const isDataReady = dataFetchStatus === FetchStatus.FETCH_SUCCESS; diff --git a/src/components/filter/expert/ExpertFilterEditionDialog.tsx b/src/components/filter/expert/ExpertFilterEditionDialog.tsx index 671c58be3..88ff9e450 100644 --- a/src/components/filter/expert/ExpertFilterEditionDialog.tsx +++ b/src/components/filter/expert/ExpertFilterEditionDialog.tsx @@ -10,7 +10,6 @@ import { useForm } from 'react-hook-form'; import { yupResolver } from '@hookform/resolvers/yup'; import { UUID } from 'crypto'; import FieldConstants from '../../../utils/constants/fieldConstants'; -import { noSelectionForCopy } from '../../../utils/types/equipmentTypes'; import { useSnackMessage } from '../../../hooks/useSnackMessage'; import CustomMuiDialog from '../../dialogs/customMuiDialog/CustomMuiDialog'; import yup from '../../../utils/yupConfig'; @@ -18,9 +17,10 @@ import FilterForm from '../FilterForm'; import { EXPERT_FILTER_QUERY, expertFilterSchema } from './ExpertFilterForm'; import { saveExpertFilter } from '../utils/filterApi'; import { importExpertRules } from './expertFilterUtils'; -import { FilterType } from '../constants/FilterConstants'; +import { FilterType, NO_SELECTION_FOR_COPY } from '../constants/FilterConstants'; import FetchStatus from '../../../utils/constants/fetchStatus'; import { ElementExistsType } from '../../../utils/types/elementType'; +import { SelectionForCopy } from '../filter.type'; const formSchema = yup .object() @@ -40,9 +40,9 @@ export interface ExpertFilterEditionDialogProps { onClose: () => void; broadcastChannel: BroadcastChannel; - selectionForCopy: any; + selectionForCopy: SelectionForCopy; getFilterById: (id: string) => Promise<{ [prop: string]: any }>; - setSelectionForCopy: (selection: any) => void; + setSelectionForCopy: (selection: SelectionForCopy) => void; activeDirectory?: UUID; elementExists?: ElementExistsType; language?: string; @@ -120,9 +120,9 @@ function ExpertFilterEditionDialog({ } ); if (selectionForCopy.sourceItemUuid === id) { - setSelectionForCopy(noSelectionForCopy); + setSelectionForCopy(NO_SELECTION_FOR_COPY); broadcastChannel.postMessage({ - noSelectionForCopy, + NO_SELECTION_FOR_COPY, }); } }, diff --git a/src/components/filter/explicitNaming/ExplicitNamingFilterEditionDialog.tsx b/src/components/filter/explicitNaming/ExplicitNamingFilterEditionDialog.tsx index e5c1abbad..6b85a7f0c 100644 --- a/src/components/filter/explicitNaming/ExplicitNamingFilterEditionDialog.tsx +++ b/src/components/filter/explicitNaming/ExplicitNamingFilterEditionDialog.tsx @@ -19,10 +19,10 @@ import { explicitNamingFilterSchema, FILTER_EQUIPMENTS_ATTRIBUTES } from './Expl import FieldConstants from '../../../utils/constants/fieldConstants'; import FilterForm from '../FilterForm'; -import { noSelectionForCopy } from '../../../utils/types/equipmentTypes'; -import { FilterType } from '../constants/FilterConstants'; +import { FilterType, NO_SELECTION_FOR_COPY } from '../constants/FilterConstants'; import FetchStatus from '../../../utils/constants/fetchStatus'; import { ElementExistsType } from '../../../utils/types/elementType'; +import { SelectionForCopy } from '../filter.type'; const formSchema = yup .object() @@ -41,8 +41,8 @@ export interface ExplicitNamingFilterEditionDialogProps { open: boolean; onClose: () => void; broadcastChannel: BroadcastChannel; - selectionForCopy: any; - setSelectionForCopy: (selection: any) => void; + selectionForCopy: SelectionForCopy; + setSelectionForCopy: (selection: SelectionForCopy) => void; getFilterById: (id: string) => Promise; activeDirectory?: UUID; elementExists?: ElementExistsType; @@ -122,9 +122,9 @@ function ExplicitNamingFilterEditionDialog({ onClose ); if (selectionForCopy.sourceItemUuid === id) { - setSelectionForCopy(noSelectionForCopy); + setSelectionForCopy(NO_SELECTION_FOR_COPY); broadcastChannel.postMessage({ - noSelectionForCopy, + NO_SELECTION_FOR_COPY, }); } }, diff --git a/src/components/filter/filter.type.ts b/src/components/filter/filter.type.ts new file mode 100644 index 000000000..32aa052f7 --- /dev/null +++ b/src/components/filter/filter.type.ts @@ -0,0 +1,8 @@ +export type SelectionForCopy = { + sourceItemUuid: unknown | null; + typeItem: unknown | null; + nameItem: unknown | null; + descriptionItem: unknown | null; + parentDirectoryUuid: unknown | null; + specificTypeItem: unknown | null; +}; diff --git a/src/index.ts b/src/index.ts index 926e77e66..9a1458645 100644 --- a/src/index.ts +++ b/src/index.ts @@ -65,9 +65,10 @@ export { ShuntCompensator, VoltageLevel, Substation, - noSelectionForCopy, } from './utils/types/equipmentTypes'; +export { NO_SELECTION_FOR_COPY as noSelectionForCopy } from './components/filter/constants/FilterConstants'; + export { default as FieldConstants } from './utils/constants/fieldConstants'; export { fields as EXPERT_FILTER_FIELDS } from './components/filter/expert/expertFilterConstants'; diff --git a/src/utils/types/equipmentTypes.ts b/src/utils/types/equipmentTypes.ts index 1724b1b7d..245201908 100644 --- a/src/utils/types/equipmentTypes.ts +++ b/src/utils/types/equipmentTypes.ts @@ -44,10 +44,3 @@ export const Substation = { label: 'Substations', type: 'SUBSTATION', }; - -export const noSelectionForCopy = { - sourceCaseUuid: null, - name: null, - description: null, - parentDirectoryUuid: null, -};