Skip to content

Commit

Permalink
Merge pull request #1711 from BLSQ/WC2-585-finish-launch-analysis-mod…
Browse files Browse the repository at this point in the history
…al-rename-duplicate-search-fields

WC2-585: [Web] Duplicate pair details: finish launch analysis modal and rename "duplicate search fields" on entity type
  • Loading branch information
hakifran authored Oct 17, 2024
2 parents 2e270ee + 0c03de1 commit c7c3e86
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 40 deletions.
2 changes: 1 addition & 1 deletion hat/assets/js/apps/Iaso/domains/app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
"iaso.entityTypes.dialog.deleteTitle": "Are you sure you want to delete this entity type?",
"iaso.entityTypes.errors.referenceForm": "Reference form is required",
"iaso.entityTypes.fieldsDetailInfoView": "Detail info fields",
"iaso.entityTypes.fieldsDuplicateSearch": "Duplicate search fields",
"iaso.entityTypes.fieldsDuplicateSearch": "Mobile: Entity search fields",
"iaso.entityTypes.fieldsListView": "List fields",
"iaso.entityTypes.label": "Beneficiary type",
"iaso.entityTypes.referenceForm": "Reference form",
Expand Down
2 changes: 1 addition & 1 deletion hat/assets/js/apps/Iaso/domains/app/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
"iaso.entityTypes.dialog.deleteTitle": "Êtes-vous certain de vouloir effacer ce type d'entité ?",
"iaso.entityTypes.errors.referenceForm": "Le formulaire de référence est un champs requis",
"iaso.entityTypes.fieldsDetailInfoView": "Champs détails",
"iaso.entityTypes.fieldsDuplicateSearch": "Champs de recherche de duplication",
"iaso.entityTypes.fieldsDuplicateSearch": "Mobile : champs de recherche d'entité",
"iaso.entityTypes.fieldsListView": "Champs liste",
"iaso.entityTypes.label": "Type de bénéficiaire",
"iaso.entityTypes.referenceForm": "Formulaire de référence",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import {
ConfirmCancelModal,
makeFullModal,
useSafeIntl,
} from 'bluesquare-components';
import { ConfirmCancelModal, makeFullModal } from 'bluesquare-components';
import React, {
FunctionComponent,
useCallback,
useEffect,
useState,
} from 'react';
import Alert from '@mui/lab/Alert';
import MESSAGES from '../messages';
import { AnalysisModalButton } from './AnalysisModalButton';
import InputComponent from '../../../../components/forms/InputComponent';
import { useGetBeneficiaryTypesDropdown } from '../../hooks/requests';
import { useStartAnalyse } from '../hooks/api/analyzes';
import { ALGORITHM_DROPDOWN } from '../../constants';
import { formatLabel } from '../../../instances/utils';
import { useGetFormForEntityType } from '../../entityTypes/hooks/requests/forms';

type Props = {
isOpen: boolean;
Expand All @@ -25,11 +22,9 @@ type Props = {
const AnalysisModal: FunctionComponent<Props> = ({ closeDialog, isOpen }) => {
const [entityType, setEntityType] = useState(null);
const [algorithm, setAlgorithm] = useState(null);
const [fields, setFields] = useState([]);
const [entityTypeFields, setEntityTypeFields] = useState([]);
const [referenceForm, setReferenceForm] = useState(undefined);
const [confirm, setConfirm] = useState(false);
const [errorMissingFields, setErrorMissingFields] = useState('');

const { formatMessage } = useSafeIntl();

const { data: entityTypesDropdown, isFetching: isFetchingEntityTypes } =
useGetBeneficiaryTypesDropdown();
Expand All @@ -39,42 +34,51 @@ const AnalysisModal: FunctionComponent<Props> = ({ closeDialog, isOpen }) => {
startAnalyse({
algorithm,
entity_type_id: entityType,
fields,
fields: entityTypeFields,
parameters: {},
});
}, [startAnalyse, algorithm, entityType, fields]);
}, [startAnalyse, algorithm, entityType, entityTypeFields]);

const handleChangeEntityType = value => {
const filteredEntityType = entityTypesDropdown?.find(
entityTypeItem => entityTypeItem.value === value,
);

setReferenceForm(filteredEntityType?.original?.reference_form);

setEntityType(value);
};

const handleChange = (keyValue, value) => {
if (keyValue === 'entity_type') {
const filteredEntityType = entityTypesDropdown?.find(
entityTypeItem => entityTypeItem.value === value,
);
const entityTypeFields =
filteredEntityType?.original?.fields_duplicate_search;
if (!entityTypeFields) {
setErrorMissingFields(
formatMessage(MESSAGES.messageErrorMissingFields),
);
} else {
setErrorMissingFields('');
setFields(entityTypeFields || []);
}
switch (keyValue) {
case 'entity_type':
handleChangeEntityType(value);
break;

setEntityType(value);
}
if (keyValue === 'algorithm') {
setAlgorithm(value);
case 'entity_type_fields':
setEntityTypeFields(value || []);
break;

case 'algorithm':
setAlgorithm(value);
break;

default:
break;
}
};

useEffect(() => {
if (algorithm && entityType && errorMissingFields === '') {
if (algorithm && entityType && entityTypeFields.length > 0) {
setConfirm(true);
} else {
setConfirm(false);
}
}, [algorithm, entityType, errorMissingFields]);

}, [algorithm, entityType, entityTypeFields]);
const { possibleFields, isFetchingForm } = useGetFormForEntityType({
formId: referenceForm,
enabled: isOpen,
});
return (
<ConfirmCancelModal
allowConfirm={confirm}
Expand All @@ -92,10 +96,6 @@ const AnalysisModal: FunctionComponent<Props> = ({ closeDialog, isOpen }) => {
onClose={() => null}
dataTestId=""
>
{errorMissingFields && (
<Alert severity="error">{errorMissingFields}</Alert>
)}

<InputComponent
type="select"
keyValue="entity_type"
Expand All @@ -113,6 +113,22 @@ const AnalysisModal: FunctionComponent<Props> = ({ closeDialog, isOpen }) => {
label={MESSAGES.algorithm}
options={ALGORITHM_DROPDOWN}
/>
<InputComponent
type="select"
multi
required
disabled={isFetchingForm || !referenceForm}
keyValue="entity_type_fields"
onChange={(key, value) =>
handleChange(key, value ? value.split(',') : null)
}
value={entityTypeFields}
label={MESSAGES.fields}
options={possibleFields.map(field => ({
value: field.name,
label: formatLabel(field),
}))}
/>
</ConfirmCancelModal>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const MESSAGES = defineMessages({
},
fieldsDuplicateSearch: {
id: 'iaso.entityTypes.fieldsDuplicateSearch',
defaultMessage: 'Duplicate search fields',
defaultMessage: 'Mobile: Entity search fields',
},
selectReferenceForm: {
id: 'iaso.entityTypes.selectReferenceForm',
Expand Down

0 comments on commit c7c3e86

Please sign in to comment.