Skip to content

Commit

Permalink
error message for invalid filter type (#484)
Browse files Browse the repository at this point in the history
Signed-off-by: Mathieu DEHARBE <[email protected]>
  • Loading branch information
Mathieu-Deharbe authored Jul 5, 2024
1 parent 1f4a5f4 commit 9cafed5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/components/filter/criteria-based/criteria-based-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import { useFormContext, useWatch } from 'react-hook-form';
import { Grid } from '@mui/material';
import SelectInput from '../../inputs/react-hook-form/select-inputs/select-input';
import InputWithPopupConfirmation from '../../inputs/react-hook-form/select-inputs/input-with-popup-confirmation';
import { FunctionComponent } from 'react';
import { FunctionComponent, useEffect } from 'react';
import { FormEquipment } from '../utils/filter-form-utils';
import { useSnackMessage } from '../../../hooks/useSnackMessage';

export interface CriteriaBasedFormProps {
equipments: Record<string, FormEquipment>;
Expand All @@ -23,11 +24,20 @@ const CriteriaBasedForm: FunctionComponent<CriteriaBasedFormProps> = ({
defaultValues,
}) => {
const { getValues, setValue } = useFormContext();
const { snackError } = useSnackMessage();

const watchEquipmentType = useWatch({
name: FieldConstants.EQUIPMENT_TYPE,
});

useEffect(() => {
if (watchEquipmentType && !equipments[watchEquipmentType]) {
snackError({
headerId: 'obsoleteFilter',
});
}
}, [snackError, equipments, watchEquipmentType]);

const openConfirmationPopup = () => {
return (
JSON.stringify(getValues(FieldConstants.CRITERIA_BASED)) !==
Expand Down Expand Up @@ -59,6 +69,7 @@ const CriteriaBasedForm: FunctionComponent<CriteriaBasedFormProps> = ({
/>
</Grid>
{watchEquipmentType &&
equipments[watchEquipmentType] &&
equipments[watchEquipmentType].fields.map(
(equipment: any, index: number) => {
const EquipmentForm = equipment.renderer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { useSnackMessage } from '../../../hooks/useSnackMessage';
import { ElementType } from '../../../utils/ElementType';
import ModifyElementSelection from '../../dialogs/modify-element-selection';
import { exportFilter } from '../../../services/study';
import { EquipmentType } from '../../../utils/EquipmentType';

export const FILTER_EQUIPMENTS_ATTRIBUTES = 'filterEquipmentsAttributes';

Expand Down Expand Up @@ -132,6 +133,17 @@ const ExplicitNamingFilterForm: FunctionComponent<
name: FieldConstants.EQUIPMENT_TYPE,
});

useEffect(() => {
if (
watchEquipmentType &&
!((watchEquipmentType as EquipmentType) in FILTER_EQUIPMENTS)
) {
snackError({
headerId: 'obsoleteFilter',
});
}
}, [snackError, watchEquipmentType]);

const forGeneratorOrLoad = isGeneratorOrLoad(watchEquipmentType);

useEffect(() => {
Expand Down
2 changes: 2 additions & 0 deletions src/components/translations/filter-en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const filter_en = {
isNotPartOf: 'is not part of',
emptyRule: 'Filter contains an empty field',
incorrectRule: 'Filter contains an incorrect field',
obsoleteFilter:
'This filter is no longer supported. Please remove it or change its equipment type.',
betweenRule:
"Left value of 'between' rule have to be lower than the right value",
emptyGroup:
Expand Down
2 changes: 2 additions & 0 deletions src/components/translations/filter-fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const filter_fr = {
isNotPartOf: 'ne fait pas partie de',
emptyRule: 'Le filtre contient un champ vide',
incorrectRule: 'Le filtre contient un champ incorrect',
obsoleteFilter:
"Ce filtre n'est plus supporté. Veuillez le supprimer ou changer son type d'équipement.",
betweenRule:
"La valeur de gauche d'une règle 'entre' doit être inférieure à la valeur de droite",
emptyGroup:
Expand Down

0 comments on commit 9cafed5

Please sign in to comment.