@rsuci/shared-form-components 1.0.110 → 1.0.112
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormRenderer.d.ts","sourceRoot":"","sources":["../../../src/components/form-renderer/FormRenderer.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAA4D,MAAM,OAAO,CAAC;AACjF,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,cAAc,EAIf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAuBlF;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,6BAA6B;IAC7B,UAAU,EAAE,iBAAiB,CAAC;IAC9B,6DAA6D;IAC7D,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,yBAAyB;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAClD,oCAAoC;IACpC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,iCAAiC;IACjC,SAAS,EAAE,qBAAqB,CAAC;IACjC,wBAAwB;IACxB,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IAChC,wCAAwC;IACxC,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,iCAAiC;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iCAAiC;IACjC,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;
|
|
1
|
+
{"version":3,"file":"FormRenderer.d.ts","sourceRoot":"","sources":["../../../src/components/form-renderer/FormRenderer.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAA4D,MAAM,OAAO,CAAC;AACjF,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,cAAc,EAIf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EAEtB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAuBlF;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,6BAA6B;IAC7B,UAAU,EAAE,iBAAiB,CAAC;IAC9B,6DAA6D;IAC7D,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,yBAAyB;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAClD,oCAAoC;IACpC,MAAM,EAAE,kBAAkB,CAAC;IAC3B,iCAAiC;IACjC,SAAS,EAAE,qBAAqB,CAAC;IACjC,wBAAwB;IACxB,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IAChC,wCAAwC;IACxC,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,iCAAiC;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,iCAAiC;IACjC,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AA0gCD;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAgBpD,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -243,9 +243,21 @@ const FormRendererInner = () => {
|
|
|
243
243
|
const handleFillFormFromEnquete = useCallback((enqueteData) => {
|
|
244
244
|
if (!enqueteData?.reponses)
|
|
245
245
|
return;
|
|
246
|
+
// Collecter les codes des variables des groupes contenant MENAGE ou ENQUETE
|
|
247
|
+
// Ces groupes ne doivent pas être écrasés par le chargement de données
|
|
248
|
+
const excludedCodes = new Set();
|
|
249
|
+
for (const groupe of (formulaire.groupes || [])) {
|
|
250
|
+
if (groupe.variables?.some((v) => v.typeCode === 'MENAGE' || v.typeCode === 'ENQUETE')) {
|
|
251
|
+
for (const v of (groupe.variables || [])) {
|
|
252
|
+
excludedCodes.add(v.code);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
246
256
|
const allVariables = formulaire.variables ||
|
|
247
257
|
formulaire.groupes?.flatMap((g) => g.variables || []) || [];
|
|
248
258
|
for (const reponse of enqueteData.reponses) {
|
|
259
|
+
if (excludedCodes.has(reponse.variableCode))
|
|
260
|
+
continue;
|
|
249
261
|
const variable = allVariables.find((v) => v.code === reponse.variableCode);
|
|
250
262
|
if (variable) {
|
|
251
263
|
updateResponse(variable.code, reponse.valeur, variable, reponse.numeroMembre);
|
|
@@ -447,6 +459,46 @@ const FormRendererInner = () => {
|
|
|
447
459
|
navigation.goToPreviousGroup();
|
|
448
460
|
}
|
|
449
461
|
};
|
|
462
|
+
// Nettoyer les réponses avant sauvegarde : supprimer les valeurs des variables masquées (hideMe/showMe/jump)
|
|
463
|
+
// Gère correctement les instances : une variable masquée pour l'instance 2 mais visible pour l'instance 1
|
|
464
|
+
// n'est effacée que pour l'instance 2
|
|
465
|
+
const cleanResponsesForSave = useCallback((responsesToClean) => {
|
|
466
|
+
const keysToRemove = new Set();
|
|
467
|
+
for (const groupe of groupes) {
|
|
468
|
+
if (!groupe.variables)
|
|
469
|
+
continue;
|
|
470
|
+
if (groupe.estMultiple && groupe.instances) {
|
|
471
|
+
// Groupes multiples : vérifier la visibilité par instance
|
|
472
|
+
for (const instance of groupe.instances) {
|
|
473
|
+
const visibleCodes = new Set(getVisibleVariablesForInstance(groupe.code, instance.numeroInstance)
|
|
474
|
+
.map(v => v.code));
|
|
475
|
+
for (const variable of groupe.variables) {
|
|
476
|
+
if (!visibleCodes.has(variable.code)) {
|
|
477
|
+
keysToRemove.add(`${variable.code}_${instance.numeroInstance}`);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
// Groupes simples : vérifier la visibilité globale
|
|
484
|
+
const visibleCodes = new Set(getVisibleVariables(groupe.code).map(v => v.code));
|
|
485
|
+
for (const variable of groupe.variables) {
|
|
486
|
+
if (!visibleCodes.has(variable.code)) {
|
|
487
|
+
keysToRemove.add(variable.code);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
if (keysToRemove.size === 0)
|
|
493
|
+
return responsesToClean;
|
|
494
|
+
const cleaned = {};
|
|
495
|
+
for (const [key, reponse] of Object.entries(responsesToClean)) {
|
|
496
|
+
if (!keysToRemove.has(key)) {
|
|
497
|
+
cleaned[key] = reponse;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
return cleaned;
|
|
501
|
+
}, [groupes, getVisibleVariables, getVisibleVariablesForInstance]);
|
|
450
502
|
// Handler pour la soumission
|
|
451
503
|
const handleSubmit = async () => {
|
|
452
504
|
if (effectiveDisabled || isSubmitting || isSubmittingForm)
|
|
@@ -526,7 +578,7 @@ const FormRendererInner = () => {
|
|
|
526
578
|
}
|
|
527
579
|
setIsSubmittingForm(true);
|
|
528
580
|
try {
|
|
529
|
-
await callbacks.onSubmit(responses);
|
|
581
|
+
await callbacks.onSubmit(cleanResponsesForSave(responses));
|
|
530
582
|
}
|
|
531
583
|
finally {
|
|
532
584
|
setIsSubmittingForm(false);
|
|
@@ -538,7 +590,7 @@ const FormRendererInner = () => {
|
|
|
538
590
|
return;
|
|
539
591
|
setIsSavingDraft(true);
|
|
540
592
|
try {
|
|
541
|
-
await callbacks.onSaveDraft(responses);
|
|
593
|
+
await callbacks.onSaveDraft(cleanResponsesForSave(responses));
|
|
542
594
|
draftJustSavedRef.current = true;
|
|
543
595
|
setHasUnsavedChanges(false);
|
|
544
596
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioInput.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/RadioInput.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,
|
|
1
|
+
{"version":3,"file":"RadioInput.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/RadioInput.tsx"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAoB,MAAM,OAAO,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAKxE,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,kBAAkB,GAAG;QAAE,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAC;IACrD,KAAK,EAAE,aAAa,CAAC;IACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IACzC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,QAAA,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CA2DzC,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
'use client';
|
|
6
6
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { useEffect } from 'react';
|
|
7
8
|
import { VariableValueConverter } from '../../lib/utils/variableValueConverter';
|
|
8
9
|
import { applyComponentStyle } from '../../utils/styleUtils';
|
|
9
10
|
import { isComponentReadonly } from '../../utils/componentStateUtils';
|
|
@@ -17,9 +18,19 @@ const RadioInput = ({ variable, value, onChange, onBlur, error, disabled, isCons
|
|
|
17
18
|
const options = typeof optionsSource === 'string'
|
|
18
19
|
? VariableValueConverter.parseOptionsFromProperty(optionsSource)
|
|
19
20
|
: [];
|
|
21
|
+
// Sélectionner automatiquement la 1ere option si aucune n'est sélectionnée
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (options.length > 0 && (value === null || value === undefined || value === '')) {
|
|
24
|
+
onChange(options[0].code);
|
|
25
|
+
}
|
|
26
|
+
}, [options.length]);
|
|
20
27
|
const handleChange = (selectedValue) => {
|
|
21
28
|
onChange(selectedValue || null);
|
|
22
29
|
};
|
|
23
|
-
return (_jsxs("div", { className: "space-y-2", style: containerStyle, children: [_jsx("div", { className: "space-y-2", children: options.map((option) =>
|
|
30
|
+
return (_jsxs("div", { className: "space-y-2", style: containerStyle, children: [_jsx("div", { className: "space-y-2", children: options.map((option) => {
|
|
31
|
+
const isSelected = value === option.code;
|
|
32
|
+
return (_jsxs("label", { className: `flex items-center space-x-3 ${effectiveDisabled ? 'cursor-not-allowed' : 'cursor-pointer'}`, children: [_jsx("input", { type: "radio", name: `radio-${variable.code}`, value: option.code, checked: isSelected, onChange: (e) => handleChange(e.target.value), onClick: () => { if (isSelected)
|
|
33
|
+
handleChange(option.code); }, onBlur: onBlur, disabled: effectiveDisabled, className: "h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 disabled:opacity-50" }), _jsx("span", { className: `text-sm ${effectiveDisabled ? 'text-gray-400' : 'text-gray-900'}`, style: textStyle, children: option.designation })] }, option.code));
|
|
34
|
+
}) }), options.length === 0 && (_jsx("p", { className: "text-sm text-gray-500", children: "Aucune option disponible" })), error && (_jsx("p", { className: "text-sm text-red-600", children: error }))] }));
|
|
24
35
|
};
|
|
25
36
|
export default RadioInput;
|
package/package.json
CHANGED