@rsuci/shared-form-components 1.0.57 → 1.0.58

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.
@@ -65,9 +65,9 @@ const GroupeInstanceTabs = ({ groupe, currentInstanceIndex, responses, onInstanc
65
65
  // Fonction pour obtenir l'icône et la couleur selon l'état
66
66
  const getInstanceDisplay = (instance, isActive) => {
67
67
  const state = getInstanceState(instance);
68
- const baseClasses = `
69
- flex items-center justify-center min-w-[3rem] h-10 px-3 rounded-lg font-medium text-sm
70
- transition-all duration-200 cursor-pointer border-2
68
+ const baseClasses = `
69
+ flex items-center justify-center min-w-[3rem] h-10 px-3 rounded-lg font-medium text-sm
70
+ transition-all duration-200 cursor-pointer border-2
71
71
  `;
72
72
  let stateClasses = '';
73
73
  let icon = null;
@@ -1 +1 @@
1
- {"version":3,"file":"GeographicCascadeInput.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/GeographicCascadeInput.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAmD,MAAM,OAAO,CAAC;AAWxE;;GAEG;AACH,UAAU,SAAS;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAWD,UAAU,2BAA2B;IACnC,QAAQ,EAAE,GAAG,CAAC;IACd,KAAK,EAAE,GAAG,CAAC;IACX,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,KAAK,IAAI,CAAC;IAC5C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,2BAA2B,CA0NxE,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
1
+ {"version":3,"file":"GeographicCascadeInput.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/GeographicCascadeInput.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAA4D,MAAM,OAAO,CAAC;AAWjF;;GAEG;AACH,UAAU,SAAS;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAWD,UAAU,2BAA2B;IACnC,QAAQ,EAAE,GAAG,CAAC;IACd,KAAK,EAAE,GAAG,CAAC;IACX,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,KAAK,IAAI,CAAC;IAC5C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,2BAA2B,CAkPxE,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
@@ -5,7 +5,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
5
  * Gère la cascade via le champ variable.valeur (ex: "${G_01}")
6
6
  * Utilise SearchableSelect pour une meilleure UX avec recherche intégrée
7
7
  */
8
- import { useEffect, useState, useCallback, useRef } from 'react';
8
+ import { useEffect, useState, useCallback, useRef, useMemo } from 'react';
9
9
  import SearchableSelect from './SearchableSelect';
10
10
  import { extractVariableCode, resolveParentValue, getApiEndpoint, getParentLabel, requiresParent } from '../../utils/variableDependencyResolver';
11
11
  import { isComponentReadonly } from '../../utils/componentStateUtils';
@@ -21,11 +21,11 @@ export const GeographicCascadeInput = ({ variable, value, onChange, reponses, di
21
21
  console.log('[GeographicCascade] Debug:', {
22
22
  variableCode: variable.code,
23
23
  variableType: variable.typeCode,
24
- variableValeur: variable.valeur,
24
+ valueProp: value,
25
+ valueType: typeof value,
25
26
  variableValeurDefaut: variable.valeurDefaut,
26
27
  needsParent,
27
28
  parentCode: extractVariableCode(variable),
28
- parentReponse: reponses?.[extractVariableCode(variable) || ''],
29
29
  parentValue,
30
30
  reponsesKeys: Object.keys(reponses || {})
31
31
  });
@@ -147,13 +147,35 @@ export const GeographicCascadeInput = ({ variable, value, onChange, reponses, di
147
147
  code: item.code,
148
148
  designation: item.designation
149
149
  }));
150
- // 11. Convertir la valeur actuelle en SelectOption
151
- const currentValue = value ? {
152
- id: value.id,
153
- code: value.code,
154
- designation: value.designation
150
+ // 11. Parser la valeur si c'est une chaîne JSON (cas édition d'enquête existante)
151
+ const parsedValue = useMemo(() => {
152
+ if (!value)
153
+ return null;
154
+ // Si c'est déjà un objet avec les propriétés attendues
155
+ if (typeof value === 'object' && value !== null && 'id' in value) {
156
+ return value;
157
+ }
158
+ // Si c'est une chaîne JSON, la parser
159
+ if (typeof value === 'string') {
160
+ try {
161
+ const parsed = JSON.parse(value);
162
+ if (parsed && typeof parsed === 'object' && 'id' in parsed) {
163
+ return parsed;
164
+ }
165
+ }
166
+ catch {
167
+ // Ignorer les erreurs de parsing (valeur non-JSON)
168
+ }
169
+ }
170
+ return null;
171
+ }, [value]);
172
+ // 12. Convertir la valeur parsée en SelectOption
173
+ const currentValue = parsedValue ? {
174
+ id: parsedValue.id,
175
+ code: parsedValue.code,
176
+ designation: parsedValue.designation
155
177
  } : null;
156
- // 12. Rendu du composant
178
+ // 13. Rendu du composant
157
179
  return (_jsxs("div", { className: "w-full", children: [_jsx(SearchableSelect, { options: options, value: currentValue, onChange: handleChange, placeholder: getPlaceholder(), searchPlaceholder: "Rechercher...", disabled: isDisabled, required: required, loading: loading, error: error || undefined, className: className, noOptionsMessage: needsParent && !parentValue
158
180
  ? `Veuillez d'abord sélectionner ${getParentLabel(variable.typeCode)}`
159
181
  : `Aucun(e) ${variable.designation?.toLowerCase() || 'élément'} disponible`, formatOptionLabel: (option) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsuci/shared-form-components",
3
- "version": "1.0.57",
3
+ "version": "1.0.58",
4
4
  "description": "Composants partagés de rendu de formulaires RSU v2 - Package local pour frontend Admin et Public",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",