Skip to content

Commit

Permalink
fix: harmonize types on SelectionForCopy
Browse files Browse the repository at this point in the history
Signed-off-by: Joris Mancini <joris.mancini_externe@rte-france.com>
  • Loading branch information
TheMaskedTurtle committed Sep 25, 2024
1 parent 5c55d74 commit e87da0d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 42 deletions.
11 changes: 11 additions & 0 deletions src/components/filter/constants/FilterConstants.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
};
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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()
Expand All @@ -53,8 +40,8 @@ export interface CriteriaBasedFilterEditionDialogProps {
onClose: () => void;
broadcastChannel: BroadcastChannel;
getFilterById: (id: string) => Promise<any>;
selectionForCopy: SelectionCopy;
setSelelectionForCopy: (selection: SelectionCopy) => Dispatch<SetStateAction<SelectionCopy>>;
selectionForCopy: SelectionForCopy;
setSelectionForCopy: (selection: SelectionForCopy) => void;
activeDirectory?: UUID;
elementExists?: ElementExistsType;
language?: string;
Expand All @@ -69,7 +56,7 @@ function CriteriaBasedFilterEditionDialog({
broadcastChannel,
getFilterById,
selectionForCopy,
setSelelectionForCopy,
setSelectionForCopy,
activeDirectory,
elementExists,
language,
Expand Down Expand Up @@ -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,
});
}
})
Expand All @@ -130,7 +117,7 @@ function CriteriaBasedFilterEditionDialog({
});
});
},
[broadcastChannel, id, selectionForCopy.sourceItemUuid, snackError, setSelelectionForCopy]
[broadcastChannel, id, selectionForCopy.sourceItemUuid, snackError, setSelectionForCopy]
);

const isDataReady = dataFetchStatus === FetchStatus.FETCH_SUCCESS;
Expand Down
12 changes: 6 additions & 6 deletions src/components/filter/expert/ExpertFilterEditionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ 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';
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()
Expand All @@ -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;
Expand Down Expand Up @@ -120,9 +120,9 @@ function ExpertFilterEditionDialog({
}
);
if (selectionForCopy.sourceItemUuid === id) {
setSelectionForCopy(noSelectionForCopy);
setSelectionForCopy(NO_SELECTION_FOR_COPY);
broadcastChannel.postMessage({
noSelectionForCopy,
NO_SELECTION_FOR_COPY,
});
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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<any>;
activeDirectory?: UUID;
elementExists?: ElementExistsType;
Expand Down Expand Up @@ -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,
});
}
},
Expand Down
8 changes: 8 additions & 0 deletions src/components/filter/filter.type.ts
Original file line number Diff line number Diff line change
@@ -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;
};
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
7 changes: 0 additions & 7 deletions src/utils/types/equipmentTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,3 @@ export const Substation = {
label: 'Substations',
type: 'SUBSTATION',
};

export const noSelectionForCopy = {
sourceCaseUuid: null,
name: null,
description: null,
parentDirectoryUuid: null,
};

0 comments on commit e87da0d

Please sign in to comment.