@rsuci/shared-form-components 1.0.84 → 1.0.85

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":"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"}
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,CAwPxE,CAAC;AAEF,eAAe,sBAAsB,CAAC"}
@@ -15,6 +15,10 @@ export const GeographicCascadeInput = ({ variable, value, onChange, reponses, di
15
15
  const [error, setError] = useState(null);
16
16
  // 1. Déterminer si ce type nécessite un parent
17
17
  const needsParent = requiresParent(variable.typeCode);
18
+ // 1b. Vérifier si un parent est CONFIGURÉ dans la variable (valeur non vide)
19
+ const hasParentConfigured = !!extractVariableCode(variable);
20
+ // Le champ a besoin d'un parent SEULEMENT si le type le requiert ET qu'un parent est configuré
21
+ const effectiveNeedsParent = needsParent && hasParentConfigured;
18
22
  // 2. Résoudre la valeur du parent depuis les réponses
19
23
  const parentValue = resolveParentValue(variable, reponses);
20
24
  // Debug temporaire - À SUPPRIMER après validation
@@ -34,11 +38,11 @@ export const GeographicCascadeInput = ({ variable, value, onChange, reponses, di
34
38
  ? (variable.valeur || 'CIV')
35
39
  : undefined;
36
40
  // 4. Déterminer l'endpoint API à appeler
37
- const apiEndpoint = getApiEndpoint(variable.typeCode, parentValue, countryCode);
41
+ const apiEndpoint = getApiEndpoint(variable.typeCode, parentValue, countryCode, hasParentConfigured);
38
42
  // 4. Fonction pour charger les données
39
43
  const fetchData = useCallback(async () => {
40
- // Si un parent est requis mais absent, ne rien charger
41
- if (needsParent && !parentValue) {
44
+ // Si un parent est requis (configuré) mais absent, ne rien charger
45
+ if (effectiveNeedsParent && !parentValue) {
42
46
  setItems([]);
43
47
  setLoading(false);
44
48
  setError(null);
@@ -90,7 +94,7 @@ export const GeographicCascadeInput = ({ variable, value, onChange, reponses, di
90
94
  finally {
91
95
  setLoading(false);
92
96
  }
93
- }, [apiEndpoint, needsParent, parentValue, variable.type, variable.libelle]);
97
+ }, [apiEndpoint, effectiveNeedsParent, parentValue, variable.type, variable.libelle]);
94
98
  // 5. Charger les données quand l'endpoint ou le parent change
95
99
  useEffect(() => {
96
100
  fetchData();
@@ -98,8 +102,8 @@ export const GeographicCascadeInput = ({ variable, value, onChange, reponses, di
98
102
  // 6. Réinitialiser la valeur si le parent change
99
103
  const previousParentRef = useRef(undefined);
100
104
  useEffect(() => {
101
- // Si un parent est requis et que la valeur du parent a changé
102
- if (needsParent) {
105
+ // Si un parent est requis (configuré) et que la valeur du parent a changé
106
+ if (effectiveNeedsParent) {
103
107
  // Premier rendu : initialiser la référence sans réinitialiser
104
108
  if (previousParentRef.current === undefined) {
105
109
  previousParentRef.current = parentValue;
@@ -111,7 +115,7 @@ export const GeographicCascadeInput = ({ variable, value, onChange, reponses, di
111
115
  }
112
116
  previousParentRef.current = parentValue;
113
117
  }
114
- }, [parentValue, needsParent, value, onChange]);
118
+ }, [parentValue, effectiveNeedsParent, value, onChange]);
115
119
  // 7. Gérer le changement de valeur
116
120
  const handleChange = (option) => {
117
121
  if (!option) {
@@ -128,12 +132,12 @@ export const GeographicCascadeInput = ({ variable, value, onChange, reponses, di
128
132
  };
129
133
  // 8. Déterminer si le champ est désactivé (select ne supporte pas readonly, on utilise disabled)
130
134
  const isReadonly = isComponentReadonly(variable, isConsultationMode);
131
- const isDisabled = disabled || isReadonly || loading || (needsParent && !parentValue);
135
+ const isDisabled = disabled || isReadonly || loading || (effectiveNeedsParent && !parentValue);
132
136
  // 9. Déterminer le message du placeholder
133
137
  const getPlaceholder = () => {
134
138
  if (loading)
135
139
  return 'Chargement...';
136
- if (needsParent && !parentValue) {
140
+ if (effectiveNeedsParent && !parentValue) {
137
141
  return `Sélectionnez d'abord ${getParentLabel(variable.typeCode)}`;
138
142
  }
139
143
  if (items.length === 0 && !loading) {
@@ -176,11 +180,11 @@ export const GeographicCascadeInput = ({ variable, value, onChange, reponses, di
176
180
  designation: parsedValue.designation
177
181
  } : null;
178
182
  // 13. Rendu du composant
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
183
+ 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: effectiveNeedsParent && !parentValue
180
184
  ? `Veuillez d'abord sélectionner ${getParentLabel(variable.typeCode)}`
181
185
  : `Aucun(e) ${variable.designation?.toLowerCase() || 'élément'} disponible`, formatOptionLabel: (option) => {
182
186
  // Afficher uniquement la désignation
183
187
  return option.designation;
184
- } }), needsParent && !parentValue && !loading && !error && (_jsxs("p", { className: "mt-1 text-sm text-gray-500 flex items-center", children: [_jsx("svg", { className: "w-4 h-4 mr-1", fill: "currentColor", viewBox: "0 0 20 20", children: _jsx("path", { fillRule: "evenodd", d: "M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z", clipRule: "evenodd" }) }), "Veuillez d'abord s\u00E9lectionner ", getParentLabel(variable.typeCode)] })), loading && (_jsxs("p", { className: "mt-1 text-sm text-blue-600 flex items-center", children: [_jsxs("svg", { className: "animate-spin h-4 w-4 mr-1", fill: "none", viewBox: "0 0 24 24", children: [_jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }), _jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })] }), "Chargement des donn\u00E9es..."] }))] }));
188
+ } }), effectiveNeedsParent && !parentValue && !loading && !error && (_jsxs("p", { className: "mt-1 text-sm text-gray-500 flex items-center", children: [_jsx("svg", { className: "w-4 h-4 mr-1", fill: "currentColor", viewBox: "0 0 20 20", children: _jsx("path", { fillRule: "evenodd", d: "M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z", clipRule: "evenodd" }) }), "Veuillez d'abord s\u00E9lectionner ", getParentLabel(variable.typeCode)] })), loading && (_jsxs("p", { className: "mt-1 text-sm text-blue-600 flex items-center", children: [_jsxs("svg", { className: "animate-spin h-4 w-4 mr-1", fill: "none", viewBox: "0 0 24 24", children: [_jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }), _jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })] }), "Chargement des donn\u00E9es..."] }))] }));
185
189
  };
186
190
  export default GeographicCascadeInput;
@@ -40,7 +40,7 @@ export declare function resolveParentValue(variable: any, reponses: Record<strin
40
40
  * getApiEndpoint('REGION', 1) // Returns: '/api/v1/Regions/1/select'
41
41
  * getApiEndpoint('REGION') // Returns: null (parent requis mais absent)
42
42
  */
43
- export declare function getApiEndpoint(variableType: string, parentId?: number | null, defaultCountryCode?: string): string | null;
43
+ export declare function getApiEndpoint(variableType: string, parentId?: number | null, defaultCountryCode?: string, hasParentConfigured?: boolean): string | null;
44
44
  /**
45
45
  * Détermine le libellé du parent selon le type de variable
46
46
  * @param variableType - Type de la variable
@@ -1 +1 @@
1
- {"version":3,"file":"variableDependencyResolver.d.ts","sourceRoot":"","sources":["../../src/utils/variableDependencyResolver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,gBAAgB,EAAE,MAAM,GAAG,GAAG,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAmCpG;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,GAAG,EACb,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC5B,MAAM,GAAG,IAAI,CA+Cf;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAC5B,YAAY,EAAE,MAAM,EACpB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,EACxB,kBAAkB,GAAE,MAAc,GACjC,MAAM,GAAG,IAAI,CA2Bf;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAa3D;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAW5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAY9D"}
1
+ {"version":3,"file":"variableDependencyResolver.d.ts","sourceRoot":"","sources":["../../src/utils/variableDependencyResolver.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAgB,mBAAmB,CAAC,gBAAgB,EAAE,MAAM,GAAG,GAAG,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAmCpG;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,GAAG,EACb,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC5B,MAAM,GAAG,IAAI,CA+Cf;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAC5B,YAAY,EAAE,MAAM,EACpB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,EACxB,kBAAkB,GAAE,MAAc,EAClC,mBAAmB,GAAE,OAAc,GAClC,MAAM,GAAG,IAAI,CA+Bf;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAa3D;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAW5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAY9D"}
@@ -114,23 +114,32 @@ export function resolveParentValue(variable, reponses) {
114
114
  * getApiEndpoint('REGION', 1) // Returns: '/api/v1/Regions/1/select'
115
115
  * getApiEndpoint('REGION') // Returns: null (parent requis mais absent)
116
116
  */
117
- export function getApiEndpoint(variableType, parentId, defaultCountryCode = 'CIV') {
117
+ export function getApiEndpoint(variableType, parentId, defaultCountryCode = 'CIV', hasParentConfigured = true) {
118
118
  const type = variableType?.toUpperCase();
119
119
  switch (type) {
120
120
  case 'DISTRICT':
121
- // Pour DISTRICT, pas besoin de code pays dans l'URL
122
121
  return `/api/v1/Districts/select`;
123
122
  case 'REGION':
124
- return parentId ? `/api/v1/Regions/${parentId}/select` : null;
123
+ if (parentId)
124
+ return `/api/v1/Regions/${parentId}/select`;
125
+ return hasParentConfigured ? null : `/api/v1/Regions/select`;
125
126
  case 'DEPARTEMENT':
126
- return parentId ? `/api/v1/Departements/${parentId}/select` : null;
127
+ if (parentId)
128
+ return `/api/v1/Departements/${parentId}/select`;
129
+ return hasParentConfigured ? null : `/api/v1/Departements/select`;
127
130
  case 'SOUS_PREFECTURE':
128
131
  case 'SOUSPREFECTURE':
129
- return parentId ? `/api/v1/SousPrefectures/${parentId}/select` : null;
132
+ if (parentId)
133
+ return `/api/v1/SousPrefectures/${parentId}/select`;
134
+ return hasParentConfigured ? null : `/api/v1/SousPrefectures/select`;
130
135
  case 'QUARTIER':
131
- return parentId ? `/api/v1/Quartiers/${parentId}/select` : null;
136
+ if (parentId)
137
+ return `/api/v1/Quartiers/${parentId}/select`;
138
+ return hasParentConfigured ? null : `/api/v1/Quartiers/select`;
132
139
  case 'VILLAGE':
133
- return parentId ? `/api/v1/Villages/${parentId}/select` : null;
140
+ if (parentId)
141
+ return `/api/v1/Villages/${parentId}/select`;
142
+ return hasParentConfigured ? null : `/api/v1/Villages/select`;
134
143
  default:
135
144
  return null;
136
145
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsuci/shared-form-components",
3
- "version": "1.0.84",
3
+ "version": "1.0.85",
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",