From b6f7d183eebfd83d8a7ac171755f63faed03998b Mon Sep 17 00:00:00 2001 From: Mihoub Date: Tue, 5 Nov 2024 14:45:54 +0100 Subject: [PATCH] fix(mandate): add possibility to search with acronym of relation type --- src/components/forms/mandate/index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/forms/mandate/index.js b/src/components/forms/mandate/index.js index 473a78ff..204d690e 100644 --- a/src/components/forms/mandate/index.js +++ b/src/components/forms/mandate/index.js @@ -61,9 +61,7 @@ export default function MandateForm({ id, resourceType, relatedObjectTypes, data const relationTypeUrl = (relatedObjectTypes.length > 1) ? `/relation-types?limit=500&filters[for][$in]=${relatedObjectTypes.join('&filters[for][$in]=')}` : `/relation-types?limit=500&filters[for]=${relatedObjectTypes[0]}`; - const { data: relationTypes } = useFetch(relationTypeUrl); - const [showErrors, setShowErrors] = useState(false); const [relatedObjectQuery, setRelatedObjectQuery] = useState(''); @@ -173,14 +171,18 @@ export default function MandateForm({ id, resourceType, relatedObjectTypes, data return onSave(body, id); }; - const relationTypesOptions = (relationTypes?.data) + const relationTypesOptions = (Array.isArray(relationTypes?.data)) ? [ { label: 'Appartient à la liste', value: null }, ...relationTypes.data - .map((element) => ({ label: element.name, value: element.id })) - .sort((a, b) => a.label > b.label), + .map((element) => ({ + label: `${element?.name ?? 'Nom inconnu'}${element?.acronym ? ` (${element.acronym})` : ''}`, + value: element?.id ?? null, + })) + .sort((a, b) => a.label.localeCompare(b.label)), ] : [{ label: 'Appartient à la liste', value: null }]; + return (