Skip to content

Commit

Permalink
delete criteria filter (#648)
Browse files Browse the repository at this point in the history
* delete criteria filter

Signed-off-by: basseche <[email protected]>
  • Loading branch information
basseche authored Dec 18, 2024
1 parent 58f7bbd commit 8bbc4b3
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 793 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ReactElement, useEffect } from 'react';
import { FieldConstants } from '../../../utils/constants/fieldConstants';
import { SelectInput } from '../../inputs/reactHookForm/selectInputs/SelectInput';
import { InputWithPopupConfirmation } from '../../inputs/reactHookForm/selectInputs/InputWithPopupConfirmation';
import { FormEquipment, FormField } from '../utils/filterFormUtils';
import { FormEquipment, FormField } from '../../filter/utils/filterFormUtils';
import { useSnackMessage } from '../../../hooks/useSnackMessage';
import { unscrollableDialogStyles } from '../../dialogs';

Expand Down
62 changes: 62 additions & 0 deletions src/components/contingencyList/criteriaBased/criteriaBasedUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Copyright (c) 2021, 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 { type ObjectSchema } from 'yup';
import { FieldConstants } from '../../../utils/constants/fieldConstants';
import yup from '../../../utils/yupConfig';
import {
DEFAULT_RANGE_VALUE,
getRangeInputSchema,
type RangeInputData,
} from '../../inputs/reactHookForm/numbers/RangeInput';

export type CriteriaBasedData = {
[FieldConstants.COUNTRIES]?: string[];
[FieldConstants.COUNTRIES_1]?: string[];
[FieldConstants.COUNTRIES_2]?: string[];
[FieldConstants.NOMINAL_VOLTAGE]?: RangeInputData | null;
[FieldConstants.NOMINAL_VOLTAGE_1]?: RangeInputData | null;
[FieldConstants.NOMINAL_VOLTAGE_2]?: RangeInputData | null;
[FieldConstants.NOMINAL_VOLTAGE_3]?: RangeInputData | null;
[key: string]: any;
};

export function getCriteriaBasedSchema(extraFields: Record<string, yup.AnyObject | null> = {}) {
return {
[FieldConstants.CRITERIA_BASED]: yup.object().shape({
[FieldConstants.COUNTRIES]: yup.array().of(yup.string().required()),
[FieldConstants.COUNTRIES_1]: yup.array().of(yup.string().required()),
[FieldConstants.COUNTRIES_2]: yup.array().of(yup.string().required()),
...getRangeInputSchema(FieldConstants.NOMINAL_VOLTAGE),
...getRangeInputSchema(FieldConstants.NOMINAL_VOLTAGE_1),
...getRangeInputSchema(FieldConstants.NOMINAL_VOLTAGE_2),
...getRangeInputSchema(FieldConstants.NOMINAL_VOLTAGE_3),
...extraFields,
}),
} as const satisfies Record<FieldConstants.CRITERIA_BASED, ObjectSchema<CriteriaBasedData>>;
}

export function getCriteriaBasedFormData(
criteriaValues?: Record<string, any>,
extraFields: Record<string, yup.AnyObject | null> = {}
) {
return {
[FieldConstants.CRITERIA_BASED]: {
[FieldConstants.COUNTRIES]: criteriaValues?.[FieldConstants.COUNTRIES] ?? [],
[FieldConstants.COUNTRIES_1]: criteriaValues?.[FieldConstants.COUNTRIES_1] ?? [],
[FieldConstants.COUNTRIES_2]: criteriaValues?.[FieldConstants.COUNTRIES_2] ?? [],
[FieldConstants.NOMINAL_VOLTAGE]: criteriaValues?.[FieldConstants.NOMINAL_VOLTAGE] ?? DEFAULT_RANGE_VALUE,
[FieldConstants.NOMINAL_VOLTAGE_1]:
criteriaValues?.[FieldConstants.NOMINAL_VOLTAGE_1] ?? DEFAULT_RANGE_VALUE,
[FieldConstants.NOMINAL_VOLTAGE_2]:
criteriaValues?.[FieldConstants.NOMINAL_VOLTAGE_2] ?? DEFAULT_RANGE_VALUE,
[FieldConstants.NOMINAL_VOLTAGE_3]:
criteriaValues?.[FieldConstants.NOMINAL_VOLTAGE_3] ?? DEFAULT_RANGE_VALUE,
...extraFields,
},
} as const;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
* 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/.
*/
export * from './CriteriaBasedFilterEditionDialog';
export * from './CriteriaBasedFilterForm';

export * from './CriteriaBasedForm';
export * from './FilterFreeProperties';
export * from './FilterProperties';
export * from './FilterProperty';
export * from './criteriaBasedFilterUtils';
export * from './criteriaBasedUtils';
11 changes: 1 addition & 10 deletions src/components/filter/FilterCreationDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import { useCallback } from 'react';
import { FieldValues, Resolver, useForm } from 'react-hook-form';
import { yupResolver } from '@hookform/resolvers/yup';
import { UUID } from 'crypto';
import { saveCriteriaBasedFilter, saveExpertFilter, saveExplicitNamingFilter } from './utils/filterApi';
import { saveExpertFilter, saveExplicitNamingFilter } from './utils/filterApi';
import { useSnackMessage } from '../../hooks/useSnackMessage';
import { CustomMuiDialog } from '../dialogs/customMuiDialog/CustomMuiDialog';
import { criteriaBasedFilterEmptyFormData, criteriaBasedFilterSchema } from './criteriaBased/CriteriaBasedFilterForm';
import {
explicitNamingFilterSchema,
FILTER_EQUIPMENTS_ATTRIBUTES,
Expand All @@ -30,7 +29,6 @@ const emptyFormData = {
[FieldConstants.DESCRIPTION]: '',
[FieldConstants.FILTER_TYPE]: FilterType.EXPERT.id,
[FieldConstants.EQUIPMENT_TYPE]: null,
...criteriaBasedFilterEmptyFormData,
...getExplicitNamingFilterEmptyFormData(),
...getExpertFilterEmptyFormData(),
};
Expand All @@ -43,7 +41,6 @@ const formSchema = yup
[FieldConstants.DESCRIPTION]: yup.string().max(500, 'descriptionLimitError'),
[FieldConstants.FILTER_TYPE]: yup.string().required(),
[FieldConstants.EQUIPMENT_TYPE]: yup.string().required(),
...criteriaBasedFilterSchema,
...explicitNamingFilterSchema,
...expertFilterSchema,
})
Expand Down Expand Up @@ -101,12 +98,6 @@ export function FilterCreationDialog({
onClose,
activeDirectory
);
} else if (filterForm[FieldConstants.FILTER_TYPE] === FilterType.CRITERIA_BASED.id) {
saveCriteriaBasedFilter(filterForm, activeDirectory, onClose, (error?: string) => {
snackError({
messageTxt: error,
});
});
} else if (filterForm[FieldConstants.FILTER_TYPE] === FilterType.EXPERT.id) {
saveExpertFilter(
null,
Expand Down
2 changes: 0 additions & 2 deletions src/components/filter/FilterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { useFormContext, useWatch } from 'react-hook-form';
import React, { useEffect } from 'react';
import { HeaderFilterForm, FilterFormProps } from './HeaderFilterForm';
import { FieldConstants } from '../../utils/constants/fieldConstants';
import { CriteriaBasedFilterForm } from './criteriaBased/CriteriaBasedFilterForm';
import { ExplicitNamingFilterForm } from './explicitNaming/ExplicitNamingFilterForm';
import { ExpertFilterForm } from './expert/ExpertFilterForm';
import { FilterType } from './constants/FilterConstants';
Expand Down Expand Up @@ -48,7 +47,6 @@ export function FilterForm({
handleFilterTypeChange={handleFilterTypeChange}
/>
</Box>
{filterType === FilterType.CRITERIA_BASED.id && <CriteriaBasedFilterForm />}
{filterType === FilterType.EXPLICIT_NAMING.id && (
<ExplicitNamingFilterForm
sourceFilterForExplicitNamingConversion={sourceFilterForExplicitNamingConversion}
Expand Down
1 change: 0 additions & 1 deletion src/components/filter/constants/FilterConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { ItemSelectionForCopy } from '../filter.type';
export const DISTRIBUTION_KEY = 'distributionKey';

export const FilterType = {
CRITERIA_BASED: { id: 'CRITERIA', label: 'filter.criteriaBased' },
EXPLICIT_NAMING: { id: 'IDENTIFIER_LIST', label: 'filter.explicitNaming' },
EXPERT: { id: 'EXPERT', label: 'filter.expert' },
};
Expand Down

This file was deleted.

35 changes: 0 additions & 35 deletions src/components/filter/criteriaBased/CriteriaBasedFilterForm.tsx

This file was deleted.

Loading

0 comments on commit 8bbc4b3

Please sign in to comment.