Skip to content

Commit 9cafed5

Browse files
error message for invalid filter type (#484)
Signed-off-by: Mathieu DEHARBE <[email protected]>
1 parent 1f4a5f4 commit 9cafed5

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/components/filter/criteria-based/criteria-based-form.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import { useFormContext, useWatch } from 'react-hook-form';
1010
import { Grid } from '@mui/material';
1111
import SelectInput from '../../inputs/react-hook-form/select-inputs/select-input';
1212
import InputWithPopupConfirmation from '../../inputs/react-hook-form/select-inputs/input-with-popup-confirmation';
13-
import { FunctionComponent } from 'react';
13+
import { FunctionComponent, useEffect } from 'react';
1414
import { FormEquipment } from '../utils/filter-form-utils';
15+
import { useSnackMessage } from '../../../hooks/useSnackMessage';
1516

1617
export interface CriteriaBasedFormProps {
1718
equipments: Record<string, FormEquipment>;
@@ -23,11 +24,20 @@ const CriteriaBasedForm: FunctionComponent<CriteriaBasedFormProps> = ({
2324
defaultValues,
2425
}) => {
2526
const { getValues, setValue } = useFormContext();
27+
const { snackError } = useSnackMessage();
2628

2729
const watchEquipmentType = useWatch({
2830
name: FieldConstants.EQUIPMENT_TYPE,
2931
});
3032

33+
useEffect(() => {
34+
if (watchEquipmentType && !equipments[watchEquipmentType]) {
35+
snackError({
36+
headerId: 'obsoleteFilter',
37+
});
38+
}
39+
}, [snackError, equipments, watchEquipmentType]);
40+
3141
const openConfirmationPopup = () => {
3242
return (
3343
JSON.stringify(getValues(FieldConstants.CRITERIA_BASED)) !==
@@ -59,6 +69,7 @@ const CriteriaBasedForm: FunctionComponent<CriteriaBasedFormProps> = ({
5969
/>
6070
</Grid>
6171
{watchEquipmentType &&
72+
equipments[watchEquipmentType] &&
6273
equipments[watchEquipmentType].fields.map(
6374
(equipment: any, index: number) => {
6475
const EquipmentForm = equipment.renderer;

src/components/filter/explicit-naming/explicit-naming-filter-form.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { useSnackMessage } from '../../../hooks/useSnackMessage';
2727
import { ElementType } from '../../../utils/ElementType';
2828
import ModifyElementSelection from '../../dialogs/modify-element-selection';
2929
import { exportFilter } from '../../../services/study';
30+
import { EquipmentType } from '../../../utils/EquipmentType';
3031

3132
export const FILTER_EQUIPMENTS_ATTRIBUTES = 'filterEquipmentsAttributes';
3233

@@ -132,6 +133,17 @@ const ExplicitNamingFilterForm: FunctionComponent<
132133
name: FieldConstants.EQUIPMENT_TYPE,
133134
});
134135

136+
useEffect(() => {
137+
if (
138+
watchEquipmentType &&
139+
!((watchEquipmentType as EquipmentType) in FILTER_EQUIPMENTS)
140+
) {
141+
snackError({
142+
headerId: 'obsoleteFilter',
143+
});
144+
}
145+
}, [snackError, watchEquipmentType]);
146+
135147
const forGeneratorOrLoad = isGeneratorOrLoad(watchEquipmentType);
136148

137149
useEffect(() => {

src/components/translations/filter-en.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const filter_en = {
2222
isNotPartOf: 'is not part of',
2323
emptyRule: 'Filter contains an empty field',
2424
incorrectRule: 'Filter contains an incorrect field',
25+
obsoleteFilter:
26+
'This filter is no longer supported. Please remove it or change its equipment type.',
2527
betweenRule:
2628
"Left value of 'between' rule have to be lower than the right value",
2729
emptyGroup:

src/components/translations/filter-fr.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const filter_fr = {
2222
isNotPartOf: 'ne fait pas partie de',
2323
emptyRule: 'Le filtre contient un champ vide',
2424
incorrectRule: 'Le filtre contient un champ incorrect',
25+
obsoleteFilter:
26+
"Ce filtre n'est plus supporté. Veuillez le supprimer ou changer son type d'équipement.",
2527
betweenRule:
2628
"La valeur de gauche d'une règle 'entre' doit être inférieure à la valeur de droite",
2729
emptyGroup:

0 commit comments

Comments
 (0)