From c4fb29ea23c63a1bfa2a9cff3968d6bfd5e52402 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 12 Apr 2022 10:02:39 +0200 Subject: [PATCH] (bug) open only selected mapping modal --- .../data-mapping-form.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/frontend/src/javascript/components/authentication-provider/data-mapping-form.tsx b/app/frontend/src/javascript/components/authentication-provider/data-mapping-form.tsx index cdb1bd7da..5bbb68fba 100644 --- a/app/frontend/src/javascript/components/authentication-provider/data-mapping-form.tsx +++ b/app/frontend/src/javascript/components/authentication-provider/data-mapping-form.tsx @@ -9,6 +9,7 @@ import { FormInput } from '../form/form-input'; import { useTranslation } from 'react-i18next'; import { FabButton } from '../base/fab-button'; import { TypeMappingModal } from './type-mapping-modal'; +import { useImmer } from 'use-immer'; export interface DataMappingFormProps { register: UseFormRegister, @@ -23,7 +24,7 @@ type selectModelFieldOption = { value: string, label: string }; export const DataMappingForm = ({ register, control }: DataMappingFormProps) => { const { t } = useTranslation('shared'); const [dataMapping, setDataMapping] = useState(null); - const [isOpenTypeMappingModal, setIsOpenTypeMappingModal] = useState(false); + const [isOpenTypeMappingModal, updateIsOpenTypeMappingModal] = useImmer>(new Map()); const { fields, append, remove } = useFieldArray({ control, name: 'auth_provider_mappings_attributes' as ArrayPath }); const output = useWatch({ name: 'auth_provider_mappings_attributes' as Path, control }); @@ -78,10 +79,12 @@ export const DataMappingForm = { - setIsOpenTypeMappingModal(!isOpenTypeMappingModal); + const toggleTypeMappingModal = (index: number): () => void => { + return () => { + updateIsOpenTypeMappingModal(draft => draft.set(index, !draft.get(index))); + }; }; // fetch the mapping data from the API on mount @@ -133,13 +136,13 @@ export const DataMappingForm =
- } onClick={toggleTypeMappingModal} disabled={getField(output, index) === undefined} tooltip={t('app.shared.authentication.data_mapping')} /> + } onClick={toggleTypeMappingModal(index)} disabled={getField(output, index) === undefined} tooltip={t('app.shared.authentication.data_mapping')} /> } onClick={() => remove(index)} className="delete-button" />