@asteby/metacore-runtime-react 49.2.1 → 49.3.0
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.
- package/CHANGELOG.md +24 -0
- package/dist/action-modal-dispatcher.d.ts.map +1 -1
- package/dist/action-modal-dispatcher.js +12 -3
- package/dist/business/document-editor-model.d.ts +12 -1
- package/dist/business/document-editor-model.d.ts.map +1 -1
- package/dist/business/document-editor-model.js +49 -3
- package/dist/business/document-editor.d.ts.map +1 -1
- package/dist/business/document-editor.js +14 -5
- package/dist/dynamic-form-schema.d.ts +3 -26
- package/dist/dynamic-form-schema.d.ts.map +1 -1
- package/dist/dynamic-form-schema.js +4 -56
- package/dist/option-when.d.ts +27 -0
- package/dist/option-when.d.ts.map +1 -0
- package/dist/option-when.js +56 -0
- package/dist/validator.d.ts.map +1 -1
- package/dist/validator.js +17 -7
- package/package.json +1 -1
- package/src/__tests__/document-editor-model.test.ts +14 -1
- package/src/__tests__/document-editor.test.tsx +23 -1
- package/src/__tests__/invoice-document-editor.test.tsx +4 -3
- package/src/__tests__/option-when-validation.test.tsx +87 -0
- package/src/__tests__/r6-editor-option-when.test.tsx +104 -0
- package/src/action-modal-dispatcher.tsx +14 -5
- package/src/business/document-editor-model.ts +48 -3
- package/src/business/document-editor.tsx +15 -4
- package/src/dynamic-form-schema.ts +5 -55
- package/src/option-when.ts +61 -0
- package/src/validator.ts +17 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @asteby/metacore-runtime-react
|
|
2
2
|
|
|
3
|
+
## 49.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 12b6d10: DocumentEditor «Cargar desde…»: al precargar solo lo pendiente de un renglón, el descuento en importe (`discount_mode: amount`) se prorratea a esa cantidad (cotización de 6 piezas con $1,200 de descuento y 4 pendientes → $800), en vez de arrastrar el importe completo y chocar con «El descuento no puede superar el importe». Un descuento en porcentaje no cambia. Avisos de carga en español más claro («con lo que falta · ya completos (omitidos)», «Documento de origen»).
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 0a64839: DocumentEditor: los selects con opciones condicionadas (`options[].when`) solo ofrecen las que aplican y ajustan solos un valor que dejó de aplicar.
|
|
12
|
+
|
|
13
|
+
Con método de pago PPD, la forma de pago pasa sola a «99 · Por definir» (la única que aplica) y el alta de la factura lleva los dos valores; al volver a PUE regresa al default del campo. Vale igual si el cambio viene de la contraparte o de «Cargar desde…».
|
|
14
|
+
|
|
15
|
+
- 0a64839: DocumentEditor: «Cargar desde» venta, OT o cotización deja el cliente elegido y los selectores muestran nombre o folio, no el UUID.
|
|
16
|
+
|
|
17
|
+
- La cabecera del origen (`sources[].header`, p. ej. `customer_id`, y `link_field`) se carga antes que los renglones, así que el cliente y su tarjeta llegan aunque los renglones del origen fallen.
|
|
18
|
+
- Los selectores que el editor llena por código (cliente, documento origen, «Factura a abonar» de la NC) se siembran con la etiqueta que ya conoce: el objeto hermano `{value,label}` que sirve el host, el nombre de la contraparte cargada o el folio del origen. El selector «Cargar desde…» también muestra el folio.
|
|
19
|
+
- La vista previa local muestra esas etiquetas, y un campo con `options` en objeto ya no rompe el resumen.
|
|
20
|
+
|
|
21
|
+
## 49.2.2
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- 4915386: `options[].when` también valida, no solo filtra el formulario genérico. El validador del cliente (`validateValues`) marca como `invalid_option` una opción que su `when` descarta con el valor actual del campo hermano (forma de pago «99» con método PUE, o PPD con una forma distinta de «99»), igual que el kernel al guardar. Las celdas de renglón se evalúan contra su renglón y el encabezado. `renderField` —el render compartido del DocumentEditor, del diálogo de document_forms y de los modales de acción— solo ofrece las opciones que aplican y marca en el acto un valor ya elegido que dejó de aplicar. `applyOptionWhen` y `getDependsOn` pasan a `option-when.ts` (se siguen exportando desde `dynamic-form-schema`).
|
|
26
|
+
|
|
3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5D,MAAM,WAAW,mBAAmB;IAChC,gFAAgF;IAChF,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,qBAAqB;IACrB,GAAG,CAAC,EAAE,IAAI,CAAA;CACb;AAID;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,GAAE,mBAAwB,GAAG,OAAO,CASjG;AAKD,wBAAgB,kBAAkB,CAC9B,MAAM,EAAE,cAAc,EAAE,EACxB,MAAM,EAAE,GAAG,EACX,KAAK,CAAC,EAAE,MAAM,EACd,GAAG,GAAE,mBAAwB,GAC9B,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAoBrB;AAwPD,wBAAgB,oBAAoB,CAChC,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,GAAG,EACV,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC7B,OAAO,wBAAwB,EAAE,cAAc,GAAG,SAAS,CAuB7D;AAED,oGAAoG;AACpG,wBAAgB,WAAW,CACvB,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,GAAG,EACV,QAAQ,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,EAK9B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC5B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,+BAiFvC"}
|
|
@@ -39,7 +39,7 @@ import { DynamicRelations } from './dynamic-relations';
|
|
|
39
39
|
import { DynamicSelectField } from './dynamic-select-field';
|
|
40
40
|
import { DynamicDateField } from './dynamic-date-field';
|
|
41
41
|
import { UploadField } from './upload-field';
|
|
42
|
-
import { isLineItemsField, resolveWidget, resolveDependsValue, getDependsOn, getFieldRef } from './dynamic-form-schema';
|
|
42
|
+
import { isLineItemsField, resolveWidget, resolveDependsValue, getDependsOn, getFieldRef, applyOptionWhen } from './dynamic-form-schema';
|
|
43
43
|
import { FieldGrid, FieldCell, FieldLabel } from './field-grid';
|
|
44
44
|
import { useMetadataCache } from './metadata-cache';
|
|
45
45
|
import { ViewValue, objectLabel, relationSiblingValue, isLineItemsField as isRecordLineItemsField, } from './dialogs/dynamic-record';
|
|
@@ -1194,8 +1194,17 @@ formValues, record, fieldErrors) {
|
|
|
1194
1194
|
switch (widget) {
|
|
1195
1195
|
case 'textarea':
|
|
1196
1196
|
return _jsx(Textarea, { id: field.key, value: value || '', onChange: (e) => onChange(e.target.value), placeholder: field.placeholder, "aria-invalid": invalid || undefined, className: invalidCls || undefined });
|
|
1197
|
-
case 'select':
|
|
1198
|
-
|
|
1197
|
+
case 'select': {
|
|
1198
|
+
// Opciones condicionadas por un campo hermano (`options[].when`, p. ej.
|
|
1199
|
+
// forma de pago «99» solo con método PPD): solo se ofrecen las que
|
|
1200
|
+
// aplican, y un valor ya elegido que dejó de aplicar se marca en el
|
|
1201
|
+
// acto (el validador y el kernel lo rechazan como invalid_option).
|
|
1202
|
+
const options = formValues ? applyOptionWhen(field.options, formValues, getDependsOn(field)) : field.options ?? [];
|
|
1203
|
+
const stale = !!value && !options.some((o) => String(o.value) === String(value));
|
|
1204
|
+
const selectInvalid = invalid || stale;
|
|
1205
|
+
const selectCls = selectInvalid ? 'border-destructive ring-1 ring-destructive/30 focus-visible:ring-destructive' : '';
|
|
1206
|
+
return (_jsxs(Select, { value: stale ? '' : value || '', onValueChange: onChange, children: [_jsx(SelectTrigger, { className: 'w-full' + (selectCls ? ` ${selectCls}` : ''), "aria-invalid": selectInvalid || undefined, "data-stale-option": stale || undefined, children: _jsx(SelectValue, { placeholder: field.placeholder || 'Seleccionar...' }) }), _jsx(SelectContent, { children: options.map((opt) => _jsx(SelectItem, { value: opt.value, children: opt.label }, opt.value)) })] }));
|
|
1207
|
+
}
|
|
1199
1208
|
case 'switch':
|
|
1200
1209
|
return _jsx(Switch, { id: field.key, checked: !!value, onCheckedChange: onChange });
|
|
1201
1210
|
case 'number':
|
|
@@ -44,6 +44,16 @@ export declare function splitEditorFields(fields: readonly ActionFieldDef[], opt
|
|
|
44
44
|
export declare function friendlyOptionLabel(label: string): string;
|
|
45
45
|
/** El mismo campo con sus opciones en formato «texto · código». */
|
|
46
46
|
export declare function withFriendlyOptions(f: ActionFieldDef): ActionFieldDef;
|
|
47
|
+
/** Opciones del select que aplican con los valores actuales (`options[].when`). */
|
|
48
|
+
export declare function gatedOptions(f: ActionFieldDef, values: Record<string, unknown>): ActionFieldDef;
|
|
49
|
+
/**
|
|
50
|
+
* Selects con opciones condicionadas (`options[].when`, p. ej. forma de pago
|
|
51
|
+
* «99» solo con método PPD): cuando el valor actual deja de aplicar —o está
|
|
52
|
+
* vacío y solo queda una opción— devuelve el que toca. Una sola opción
|
|
53
|
+
* permitida se elige sola; si hay varias, el default del campo si aplica; si
|
|
54
|
+
* no, vacío. Sin cambios devuelve `{}`, así que aplicarlo converge.
|
|
55
|
+
*/
|
|
56
|
+
export declare function gatedOptionFixes(fields: readonly ActionFieldDef[], values: Record<string, unknown>): Record<string, unknown>;
|
|
47
57
|
/**
|
|
48
58
|
* Defaults del encabezado que salen de la contraparte: los campos de extensión
|
|
49
59
|
* con la MISMA clave en ambos modelos (p. ej. `fiscal_data.uso_cfdi` de Customer
|
|
@@ -80,7 +90,8 @@ export declare function creditStatus(party: Record<string, any> | null, cols: {
|
|
|
80
90
|
*
|
|
81
91
|
* Con `remaining_quantity` (lo sirve el host: cantidad − lo ya facturado o
|
|
82
92
|
* devuelto) la cantidad sugerida y el tope son lo pendiente y los renglones ya
|
|
83
|
-
* cubiertos se omiten
|
|
93
|
+
* cubiertos se omiten; un descuento en importe se prorratea a lo pendiente (un
|
|
94
|
+
* porcentaje no cambia). Cada línea guarda `source_line_id` para el vínculo.
|
|
84
95
|
*/
|
|
85
96
|
export declare function linesFromSource(rows: unknown, map?: Record<string, string>, opts?: {
|
|
86
97
|
kind?: DocumentFormLines['kind'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document-editor-model.d.ts","sourceRoot":"","sources":["../../src/business/document-editor-model.ts"],"names":[],"mappings":"AAMA,OAAO,EAA2B,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"document-editor-model.d.ts","sourceRoot":"","sources":["../../src/business/document-editor-model.ts"],"names":[],"mappings":"AAMA,OAAO,EAA2B,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;AAIrE,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACzF,OAAO,KAAK,EACR,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,yBAAyB,EACzB,qBAAqB,EACrB,gBAAgB,EACnB,MAAM,UAAU,CAAA;AAEjB,eAAO,MAAM,gBAAgB,iBAAiB,CAAA;AAK9C,MAAM,MAAM,iBAAiB,GAAG,iBAAiB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAErE,yEAAyE;AACzE,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,gBAAgB,EAAE,QAAQ,GAAG,SAAS,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAI7G;AAED,qEAAqE;AACrE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,IAAI,CAAC,qBAAqB,EAAE,aAAa,CAAC,GAAG,iBAAiB,GAAG,SAAS,CAK1I;AAeD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,cAAc,EAAE,aAAa,GAAE,WAAW,CAAC,MAAM,CAAa,GAAG,OAAO,CAM1G;AAED,MAAM,WAAW,iBAAiB;IAC9B,iFAAiF;IACjF,KAAK,CAAC,EAAE,cAAc,CAAA;IACtB,8CAA8C;IAC9C,SAAS,EAAE,cAAc,EAAE,CAAA;IAC3B,uCAAuC;IACvC,QA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,EAAE,EAAE,IAAI,GAAE;IAAE,YAAY,CAAC,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,WAAW,EAAE,CA0BzH;AAID,8EAA8E;AAC9E,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,yBAAyB,EAAE,QAAQ,EAAE,MAAM,GAAG,YAAY,EAAE,CA0B/G;AAED,wFAAwF;AACxF,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEhG;AAED,iGAAiG;AACjG,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,SAAS,UAAU,EAAE,EAAE,GAAG,EAAE,yBAAyB,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAEpI;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,GAAG,MAAM,GAAG,SAAS,CAK3F;AAUD,gFAAgF;AAChF,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS,eAAe,EAAE,EAAE,IAAI,EAAE,SAAS,YAAY,EAAE,GAAG,WAAW,EAAE,CAUxH;AAED,4FAA4F;AAC5F,wBAAgB,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,EAAE,KAAK,GAAE,IAAiB,GAAG,MAAM,CAM/F"}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { roundMoney, toAmount } from './format';
|
|
7
7
|
import { computeTotals, makeLine } from './line-items';
|
|
8
8
|
import { optionPassesRule, getOptionFilter } from '../option-filter';
|
|
9
|
+
import { applyOptionWhen, getDependsOn } from '../dynamic-form-schema';
|
|
9
10
|
export const EXTENSION_PREFIX = 'fiscal_data.';
|
|
10
11
|
/** Secciones de campo que el editor pliega en «Opciones fiscales». */
|
|
11
12
|
const ADVANCED_SECTIONS = new Set(['fiscal', 'advanced']);
|
|
@@ -93,6 +94,42 @@ export function withFriendlyOptions(f) {
|
|
|
93
94
|
return f;
|
|
94
95
|
return { ...f, options: f.options.map((o) => ({ ...o, label: friendlyOptionLabel(String(o.label ?? o.value)) })) };
|
|
95
96
|
}
|
|
97
|
+
/** Select estático con alguna opción condicionada por otro campo (`options[].when`). */
|
|
98
|
+
function isGatedSelect(f) {
|
|
99
|
+
return Array.isArray(f.options) && f.options.some((o) => !!o?.when);
|
|
100
|
+
}
|
|
101
|
+
/** Opciones del select que aplican con los valores actuales (`options[].when`). */
|
|
102
|
+
export function gatedOptions(f, values) {
|
|
103
|
+
if (!isGatedSelect(f))
|
|
104
|
+
return f;
|
|
105
|
+
return { ...f, options: applyOptionWhen(f.options, values, getDependsOn(f)) };
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Selects con opciones condicionadas (`options[].when`, p. ej. forma de pago
|
|
109
|
+
* «99» solo con método PPD): cuando el valor actual deja de aplicar —o está
|
|
110
|
+
* vacío y solo queda una opción— devuelve el que toca. Una sola opción
|
|
111
|
+
* permitida se elige sola; si hay varias, el default del campo si aplica; si
|
|
112
|
+
* no, vacío. Sin cambios devuelve `{}`, así que aplicarlo converge.
|
|
113
|
+
*/
|
|
114
|
+
export function gatedOptionFixes(fields, values) {
|
|
115
|
+
const out = {};
|
|
116
|
+
for (const f of fields) {
|
|
117
|
+
if (!isGatedSelect(f))
|
|
118
|
+
continue;
|
|
119
|
+
const allowed = applyOptionWhen(f.options, values, getDependsOn(f));
|
|
120
|
+
const cur = values[f.key];
|
|
121
|
+
const ok = (v) => hasValue(v) && allowed.some((o) => String(o.value) === String(v));
|
|
122
|
+
if (ok(cur))
|
|
123
|
+
continue;
|
|
124
|
+
if (!hasValue(cur) && allowed.length !== 1)
|
|
125
|
+
continue;
|
|
126
|
+
const def = declaredDefault(f);
|
|
127
|
+
const next = allowed.length === 1 ? allowed[0].value : ok(def) ? def : '';
|
|
128
|
+
if (String(next ?? '') !== String(cur ?? ''))
|
|
129
|
+
out[f.key] = next;
|
|
130
|
+
}
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
96
133
|
/**
|
|
97
134
|
* Defaults del encabezado que salen de la contraparte: los campos de extensión
|
|
98
135
|
* con la MISMA clave en ambos modelos (p. ej. `fiscal_data.uso_cfdi` de Customer
|
|
@@ -159,7 +196,8 @@ export function creditStatus(party, cols, documentTotal) {
|
|
|
159
196
|
*
|
|
160
197
|
* Con `remaining_quantity` (lo sirve el host: cantidad − lo ya facturado o
|
|
161
198
|
* devuelto) la cantidad sugerida y el tope son lo pendiente y los renglones ya
|
|
162
|
-
* cubiertos se omiten
|
|
199
|
+
* cubiertos se omiten; un descuento en importe se prorratea a lo pendiente (un
|
|
200
|
+
* porcentaje no cambia). Cada línea guarda `source_line_id` para el vínculo.
|
|
163
201
|
*/
|
|
164
202
|
export function linesFromSource(rows, map = {}, opts = {}) {
|
|
165
203
|
if (!Array.isArray(rows))
|
|
@@ -193,8 +231,16 @@ export function linesFromSource(rows, map = {}, opts = {}) {
|
|
|
193
231
|
});
|
|
194
232
|
// El descuento del origen se lee en la unidad del documento (importe en
|
|
195
233
|
// modelos cuyo subtotal resta un monto).
|
|
196
|
-
if (opts.discountMode === 'amount')
|
|
234
|
+
if (opts.discountMode === 'amount') {
|
|
197
235
|
line.discount_kind = 'amount';
|
|
236
|
+
// Un importe es de TODO el renglón de origen: al cargar solo lo
|
|
237
|
+
// pendiente se prorratea a esa cantidad (4 llantas con $400 de
|
|
238
|
+
// descuento, 1 pendiente → $100), si no superaría el importe.
|
|
239
|
+
const sourceQty = toAmount(r.source_quantity ?? get('quantity'));
|
|
240
|
+
if (pending != null && sourceQty > 0 && pending < sourceQty) {
|
|
241
|
+
line.discount = roundMoney((toAmount(line.discount) * pending) / sourceQty);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
198
244
|
if (pending != null)
|
|
199
245
|
line.max_quantity = pending;
|
|
200
246
|
else if (opts.kind === 'credit')
|
|
@@ -323,7 +369,7 @@ export function localIssues(lines, opts = {}) {
|
|
|
323
369
|
issues.push({
|
|
324
370
|
field: `lines.${i}`,
|
|
325
371
|
severity: 'error',
|
|
326
|
-
message: `Renglón ${i + 1}: la cantidad excede lo pendiente del documento origen (${l.max_quantity}).`,
|
|
372
|
+
message: `Renglón ${i + 1}: la cantidad excede lo pendiente del documento origen (quedan ${l.max_quantity}).`,
|
|
327
373
|
});
|
|
328
374
|
}
|
|
329
375
|
if (opts.requireTax && toAmount(l.tax_rate) === 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document-editor.d.ts","sourceRoot":"","sources":["../../src/business/document-editor.tsx"],"names":[],"mappings":"AA4BA,OAAO,EAAqB,KAAK,sBAAsB,EAAwB,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"document-editor.d.ts","sourceRoot":"","sources":["../../src/business/document-editor.tsx"],"names":[],"mappings":"AA4BA,OAAO,EAAqB,KAAK,sBAAsB,EAAwB,MAAM,qBAAqB,CAAA;AAkD1G,OAAO,KAAK,EAAsC,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAA;AAE3G,MAAM,WAAW,mBAAmB;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,qBAAqB,CAAA;IAC5B,IAAI,EAAE,gBAAgB,CAAA;IACtB,sFAAsF;IACtF,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC5B,oEAAoE;IACpE,aAAa,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAA;IAC3C,OAAO,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;IACpC,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,cAAc,CAAC,EAAE,sBAAsB,CAAC,QAAQ,CAAC,CAAA;IACjD,+EAA+E;IAC/E,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,6DAA6D;IAC7D,KAAK,CAAC,EAAE,IAAI,CAAA;IACZ;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;CACvB;AAID,wBAAgB,cAAc,CAAC,EAC3B,KAAK,EACL,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,MAAM,EACN,aAAa,EACb,OAAO,EACP,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,KAAK,EACL,UAAkB,GACrB,EAAE,mBAAmB,+BAwuBrB"}
|
|
@@ -31,7 +31,7 @@ import { DocumentLinesGrid } from './line-items-editor';
|
|
|
31
31
|
import { computeTotals, serializeLineItems, taxBreakdown } from './line-items';
|
|
32
32
|
import { roundMoney, toAmount, useFormatter } from './format';
|
|
33
33
|
import { createCatalogProductSearch } from './catalog-product-search';
|
|
34
|
-
import { allocationAmountField, allocationIssueMessages, allocationPayload, creditStatus, editorLinesConfig, linesFromSource, localIssues, sourceLoadSummary, sourceTracksRemaining, partyDefaults, partySummaryRows, recordLabel, seedRecord, sourceHeaderSeeds, splitEditorFields, toOpenDocuments, friendlyOptionLabel, withFriendlyOptions, } from './document-editor-model';
|
|
34
|
+
import { allocationAmountField, allocationIssueMessages, allocationPayload, creditStatus, editorLinesConfig, linesFromSource, localIssues, sourceLoadSummary, sourceTracksRemaining, partyDefaults, partySummaryRows, recordLabel, seedRecord, sourceHeaderSeeds, splitEditorFields, toOpenDocuments, friendlyOptionLabel, gatedOptionFixes, gatedOptions, withFriendlyOptions, } from './document-editor-model';
|
|
35
35
|
import { CollapsibleSection, DraftPreview, EditorSection, PartyCard, PreviewPanel, TotalsPanel, ValidationChecklist, } from './document-editor-panels';
|
|
36
36
|
import { PaymentAllocator } from './payment-allocator';
|
|
37
37
|
import { actionErrorBannerMessage, buildFieldDefaults, prefillFromFieldRelationRequest, renderField } from '../action-modal-dispatcher';
|
|
@@ -119,6 +119,15 @@ export function DocumentEditor({ model, endpoint, forms, type, record, initialSo
|
|
|
119
119
|
const allFields = useMemo(() => [...(groups.party ? [groups.party] : []), ...groups.essential, ...groups.advanced, ...groups.notes], [groups]);
|
|
120
120
|
const fieldKeys = useRef([]);
|
|
121
121
|
fieldKeys.current = allFields.map((f) => f.key);
|
|
122
|
+
// Opciones condicionadas (`options[].when`): al cambiar el campo del que
|
|
123
|
+
// dependen —a mano, por la contraparte o por «Cargar desde…»— el valor que
|
|
124
|
+
// dejó de aplicar se ajusta solo (método PPD → forma de pago 99) y viaja así
|
|
125
|
+
// en el alta, no solo en el diálogo de timbrado.
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
const fixes = gatedOptionFixes(allFields, header);
|
|
128
|
+
if (Object.keys(fixes).length > 0)
|
|
129
|
+
setHeader((h) => ({ ...h, ...gatedOptionFixes(allFields, h) }));
|
|
130
|
+
}, [allFields, header]);
|
|
122
131
|
// Contraparte: tarjeta + defaults de las extensiones con la misma clave.
|
|
123
132
|
const partyId = type.party ? header[type.party.field] : undefined;
|
|
124
133
|
useEffect(() => {
|
|
@@ -334,11 +343,11 @@ export function DocumentEditor({ model, endpoint, forms, type, record, initialSo
|
|
|
334
343
|
setLinesFromSourceDoc(kind === 'credit');
|
|
335
344
|
setSourceNote(loaded.length === 0 && covered > 0
|
|
336
345
|
? t('documentEditor.source_all_covered', {
|
|
337
|
-
defaultValue: '
|
|
346
|
+
defaultValue: 'Ese documento ya se registró completo; no queda nada pendiente.',
|
|
338
347
|
})
|
|
339
348
|
: covered > 0
|
|
340
349
|
? t('documentEditor.source_loaded_partial', {
|
|
341
|
-
defaultValue: '{{count}} renglones con lo
|
|
350
|
+
defaultValue: '{{count}} renglones con lo que falta · {{covered}} ya completos (omitidos)',
|
|
342
351
|
count: loaded.length,
|
|
343
352
|
covered,
|
|
344
353
|
})
|
|
@@ -473,7 +482,7 @@ export function DocumentEditor({ model, endpoint, forms, type, record, initialSo
|
|
|
473
482
|
setFieldErrors((prev) => clearFieldErrorTree(prev, key));
|
|
474
483
|
};
|
|
475
484
|
const fieldRecord = useMemo(() => seedRecord(seeds, record), [seeds, record]);
|
|
476
|
-
const fieldCell = (field, fullWidth = false) => visible(field) ? (_jsxs(FieldCell, { fullWidth: fullWidth, children: [_jsx(FieldLabel, { htmlFor: field.key, required: field.required, children: tl(field.label) }), renderField(withFriendlyOptions(field), header[field.key], (v) => updateField(field.key, v), header, fieldRecord, fieldErrors), fieldErrors[field.key] && _jsx("p", { className: "mt-1 text-xs text-destructive", children: fieldErrors[field.key] })] }, field.key)) : null;
|
|
485
|
+
const fieldCell = (field, fullWidth = false) => visible(field) ? (_jsxs(FieldCell, { fullWidth: fullWidth, children: [_jsx(FieldLabel, { htmlFor: field.key, required: field.required, children: tl(field.label) }), renderField(withFriendlyOptions(gatedOptions(field, header)), header[field.key], (v) => updateField(field.key, v), header, fieldRecord, fieldErrors), fieldErrors[field.key] && _jsx("p", { className: "mt-1 text-xs text-destructive", children: fieldErrors[field.key] })] }, field.key)) : null;
|
|
477
486
|
const summaryRows = partySummaryRows(party, type.party?.summary, {
|
|
478
487
|
...Object.fromEntries(Object.entries(partyLabels).map(([k, v]) => [k, tl(v)])),
|
|
479
488
|
...Object.fromEntries(allFields.map((f) => [f.key, tl(f.label)])),
|
|
@@ -517,7 +526,7 @@ export function DocumentEditor({ model, endpoint, forms, type, record, initialSo
|
|
|
517
526
|
// la suya local (encabezado, renglones y totales): sin borrador ni red.
|
|
518
527
|
const localPreview = !previewEnabled && !type.preview && !!lineCfg && !isAllocation && kind !== 'credit';
|
|
519
528
|
const essentials = (_jsxs(EditorSection, { slot: "editor-essentials", children: [_jsxs(FieldGrid, { children: [groups.party && fieldCell(groups.party), groups.essential.map((f) => fieldCell(f))] }), party && (_jsx(PartyCard, { name: party.name ?? party.legal_name, rows: summaryRows, credit: credit, fmt: fmt, children: partyContribs.map(({ id, component: C }) => (_jsx(C, { ...contribProps }, id))) }))] }));
|
|
520
|
-
const loadFrom = sources.length > 0 && !isAllocation && (_jsx(EditorSection, { slot: "load-from-source", title: t('documentEditor.load_from', { defaultValue: 'Cargar desde…' }), hint: busy === 'source' ? t('documentEditor.loading_source', { defaultValue: 'Cargando…' }) : sourceNote, children: _jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [sources.length > 1 && (_jsx("div", { role: "radiogroup", "aria-label": t('documentEditor.source_kind', { defaultValue: '
|
|
529
|
+
const loadFrom = sources.length > 0 && !isAllocation && (_jsx(EditorSection, { slot: "load-from-source", title: t('documentEditor.load_from', { defaultValue: 'Cargar desde…' }), hint: busy === 'source' ? t('documentEditor.loading_source', { defaultValue: 'Cargando…' }) : sourceNote, children: _jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [sources.length > 1 && (_jsx("div", { role: "radiogroup", "aria-label": t('documentEditor.source_kind', { defaultValue: 'Documento de origen' }), className: "inline-flex flex-wrap gap-1 rounded-md border p-1", children: sources.map((s) => (_jsx("button", { type: "button", role: "radio", "aria-checked": s.key === sourceKey, "data-source-kind": s.key, onClick: () => {
|
|
521
530
|
setSourceKey(s.key);
|
|
522
531
|
setSourceId('');
|
|
523
532
|
}, className: `rounded px-3 py-1.5 text-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring ${s.key === sourceKey ? 'bg-primary/10 font-medium text-primary' : 'text-muted-foreground hover:bg-accent'}`, children: tl(s.label) }, s.key))) })), activeSource && (_jsx(SourcePicker, { source: activeSource, value: sourceId, seed: sourceSeed, header: header, label: tl(activeSource.label), onPick: (id) => {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import type { ActionFieldDef, FieldOptionsConfig,
|
|
2
|
+
import type { ActionFieldDef, FieldOptionsConfig, VisibleWhen } from './types';
|
|
3
|
+
import { applyOptionWhen, getDependsOn } from './option-when';
|
|
4
|
+
export { applyOptionWhen, getDependsOn };
|
|
3
5
|
/**
|
|
4
6
|
* Apps register validator implementations by slug. The slug is the value
|
|
5
7
|
* `OrgConfig.validators[<key>]` returns for a $org.<key> reference.
|
|
@@ -81,14 +83,6 @@ export declare function resolveWidget(field: ActionFieldDef): string;
|
|
|
81
83
|
export declare function getFieldRef(field: ActionFieldDef): string | undefined;
|
|
82
84
|
/** True when a field declares an FK target the SDK can resolve options against. */
|
|
83
85
|
export declare function fieldHasRef(field: ActionFieldDef): boolean;
|
|
84
|
-
/**
|
|
85
|
-
* Resolves a field's cascade dependency — the key of another form field whose
|
|
86
|
-
* current value scopes this picker's options (`filter_value`). Tolerates the
|
|
87
|
-
* camelCase `dependsOn` (authored SDK shape) and the snake_case `depends_on`
|
|
88
|
-
* the kernel manifest serves. Returns the trimmed field key, or `undefined`
|
|
89
|
-
* when the field declares no dependency.
|
|
90
|
-
*/
|
|
91
|
-
export declare function getDependsOn(field: ActionFieldDef): string | undefined;
|
|
92
86
|
/**
|
|
93
87
|
* Resolves the cascade `filter_value` for a field from the surrounding form
|
|
94
88
|
* context. The depended-on key is matched against the current row first (a
|
|
@@ -98,23 +92,6 @@ export declare function getDependsOn(field: ActionFieldDef): string | undefined;
|
|
|
98
92
|
* field has no dependency or the depended-on value is empty/unset.
|
|
99
93
|
*/
|
|
100
94
|
export declare function resolveDependsValue(field: ActionFieldDef, formValues?: Record<string, any> | null, rowValues?: Record<string, any> | null): string;
|
|
101
|
-
/**
|
|
102
|
-
* Filters a STATIC enum's `options[]` by each option's `when` gate against the
|
|
103
|
-
* current form values. Pure — no React, no side effects.
|
|
104
|
-
*
|
|
105
|
-
* Rule per option:
|
|
106
|
-
* - No `when` → always included (retrocompat; existing enums untouched).
|
|
107
|
-
* - With `when`: the gating field is `when.field ?? dependsOn`. If neither is
|
|
108
|
-
* present the option is included (nothing to gate on). Otherwise the form's
|
|
109
|
-
* value for that field is compared AS STRING: included when (no `in`, or
|
|
110
|
-
* value ∈ `in`) AND (no `not_in`, or value ∉ `not_in`). Tolerates the
|
|
111
|
-
* snake_case `not_in` the kernel serves alongside camelCase `notIn`.
|
|
112
|
-
*
|
|
113
|
-
* `formValues` is the flat map of the surrounding form/row values the gating
|
|
114
|
-
* field is read from; `dependsOn` is the containing field's declared dependency
|
|
115
|
-
* used as the default gating field.
|
|
116
|
-
*/
|
|
117
|
-
export declare function applyOptionWhen(options: OptionDef[] | undefined, formValues: Record<string, any> | null | undefined, dependsOn?: string): OptionDef[];
|
|
118
95
|
/**
|
|
119
96
|
* Reads a field's `visible_when` predicate, tolerating the camelCase alias
|
|
120
97
|
* (`visibleWhen`) an app may author and the snake_case (`visible_when`) the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-form-schema.d.ts","sourceRoot":"","sources":["../src/dynamic-form-schema.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAmB,MAAM,KAAK,CAAA;AACxC,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"dynamic-form-schema.d.ts","sourceRoot":"","sources":["../src/dynamic-form-schema.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAmB,MAAM,KAAK,CAAA;AACxC,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAa,WAAW,EAAE,MAAM,SAAS,CAAA;AAEzF,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAK7D,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,CAAA;AAgBxC;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,SAAS,GAAG,IAAI,CAEzF;AAcD,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,EAAE;;kBAMtD;AAED;;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E,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EAC/C,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,GAAG,IAAI,GAC7D,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAiBxB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,+BAA+B,CAC3C,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,EACpC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,GAC9C,OAAO,CAQT;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,cAAc,GAAG,kBAAkB,GAAG,SAAS,CAGtF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,cAAc,GAAG;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;CACnB,CAQA;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,cAAc,GAAG;IACpD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;CACvB,CAaA"}
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
// metacore-ui primitives.
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { fieldValidationOf } from './validator';
|
|
6
|
+
import { applyOptionWhen, getDependsOn } from './option-when';
|
|
6
7
|
import { resolveValidatorToken } from './use-org-config-bridge';
|
|
8
|
+
// Viven en option-when.ts (el validador también los usa); se re-exportan aquí
|
|
9
|
+
// para no romper a quien los importaba de este módulo.
|
|
10
|
+
export { applyOptionWhen, getDependsOn };
|
|
7
11
|
/**
|
|
8
12
|
* Built-in validators the SDK knows how to apply by symbolic name. Apps
|
|
9
13
|
* that wire `OrgConfigProvider` map `$org.<key>` references to one of
|
|
@@ -364,19 +368,6 @@ export function getFieldRef(field) {
|
|
|
364
368
|
export function fieldHasRef(field) {
|
|
365
369
|
return getFieldRef(field) !== undefined;
|
|
366
370
|
}
|
|
367
|
-
/**
|
|
368
|
-
* Resolves a field's cascade dependency — the key of another form field whose
|
|
369
|
-
* current value scopes this picker's options (`filter_value`). Tolerates the
|
|
370
|
-
* camelCase `dependsOn` (authored SDK shape) and the snake_case `depends_on`
|
|
371
|
-
* the kernel manifest serves. Returns the trimmed field key, or `undefined`
|
|
372
|
-
* when the field declares no dependency.
|
|
373
|
-
*/
|
|
374
|
-
export function getDependsOn(field) {
|
|
375
|
-
const dep = field.dependsOn ?? field.depends_on;
|
|
376
|
-
if (typeof dep === 'string' && dep.trim() !== '')
|
|
377
|
-
return dep.trim();
|
|
378
|
-
return undefined;
|
|
379
|
-
}
|
|
380
371
|
/**
|
|
381
372
|
* Resolves the cascade `filter_value` for a field from the surrounding form
|
|
382
373
|
* context. The depended-on key is matched against the current row first (a
|
|
@@ -395,49 +386,6 @@ export function resolveDependsValue(field, formValues, rowValues) {
|
|
|
395
386
|
return '';
|
|
396
387
|
return String(raw);
|
|
397
388
|
}
|
|
398
|
-
/**
|
|
399
|
-
* Filters a STATIC enum's `options[]` by each option's `when` gate against the
|
|
400
|
-
* current form values. Pure — no React, no side effects.
|
|
401
|
-
*
|
|
402
|
-
* Rule per option:
|
|
403
|
-
* - No `when` → always included (retrocompat; existing enums untouched).
|
|
404
|
-
* - With `when`: the gating field is `when.field ?? dependsOn`. If neither is
|
|
405
|
-
* present the option is included (nothing to gate on). Otherwise the form's
|
|
406
|
-
* value for that field is compared AS STRING: included when (no `in`, or
|
|
407
|
-
* value ∈ `in`) AND (no `not_in`, or value ∉ `not_in`). Tolerates the
|
|
408
|
-
* snake_case `not_in` the kernel serves alongside camelCase `notIn`.
|
|
409
|
-
*
|
|
410
|
-
* `formValues` is the flat map of the surrounding form/row values the gating
|
|
411
|
-
* field is read from; `dependsOn` is the containing field's declared dependency
|
|
412
|
-
* used as the default gating field.
|
|
413
|
-
*/
|
|
414
|
-
export function applyOptionWhen(options, formValues, dependsOn) {
|
|
415
|
-
if (!Array.isArray(options))
|
|
416
|
-
return [];
|
|
417
|
-
return options.filter((opt) => {
|
|
418
|
-
const when = opt?.when;
|
|
419
|
-
if (!when)
|
|
420
|
-
return true;
|
|
421
|
-
const gate = (typeof when.field === 'string' && when.field.trim() !== '')
|
|
422
|
-
? when.field.trim()
|
|
423
|
-
: dependsOn;
|
|
424
|
-
if (!gate)
|
|
425
|
-
return true;
|
|
426
|
-
const raw = formValues ? formValues[gate] : undefined;
|
|
427
|
-
const current = raw == null ? '' : String(raw);
|
|
428
|
-
const inList = when.in;
|
|
429
|
-
const notIn = when.notIn ?? when.not_in;
|
|
430
|
-
if (Array.isArray(inList) && inList.length > 0) {
|
|
431
|
-
if (!inList.some((v) => String(v) === current))
|
|
432
|
-
return false;
|
|
433
|
-
}
|
|
434
|
-
if (Array.isArray(notIn) && notIn.length > 0) {
|
|
435
|
-
if (notIn.some((v) => String(v) === current))
|
|
436
|
-
return false;
|
|
437
|
-
}
|
|
438
|
-
return true;
|
|
439
|
-
});
|
|
440
|
-
}
|
|
441
389
|
/**
|
|
442
390
|
* Reads a field's `visible_when` predicate, tolerating the camelCase alias
|
|
443
391
|
* (`visibleWhen`) an app may author and the snake_case (`visible_when`) the
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ActionFieldDef, OptionDef } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves a field's cascade dependency — the key of another form field whose
|
|
4
|
+
* current value scopes this picker's options (`filter_value`). Tolerates the
|
|
5
|
+
* camelCase `dependsOn` (authored SDK shape) and the snake_case `depends_on`
|
|
6
|
+
* the kernel manifest serves. Returns the trimmed field key, or `undefined`
|
|
7
|
+
* when the field declares no dependency.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getDependsOn(field: ActionFieldDef): string | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Filters a STATIC enum's `options[]` by each option's `when` gate against the
|
|
12
|
+
* current form values. Pure — no React, no side effects.
|
|
13
|
+
*
|
|
14
|
+
* Rule per option:
|
|
15
|
+
* - No `when` → always included (retrocompat; existing enums untouched).
|
|
16
|
+
* - With `when`: the gating field is `when.field ?? dependsOn`. If neither is
|
|
17
|
+
* present the option is included (nothing to gate on). Otherwise the form's
|
|
18
|
+
* value for that field is compared AS STRING: included when (no `in`, or
|
|
19
|
+
* value ∈ `in`) AND (no `not_in`, or value ∉ `not_in`). Tolerates the
|
|
20
|
+
* snake_case `not_in` the kernel serves alongside camelCase `notIn`.
|
|
21
|
+
*
|
|
22
|
+
* `formValues` is the flat map of the surrounding form/row values the gating
|
|
23
|
+
* field is read from; `dependsOn` is the containing field's declared dependency
|
|
24
|
+
* used as the default gating field.
|
|
25
|
+
*/
|
|
26
|
+
export declare function applyOptionWhen(options: OptionDef[] | undefined, formValues: Record<string, any> | null | undefined, dependsOn?: string): OptionDef[];
|
|
27
|
+
//# sourceMappingURL=option-when.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"option-when.d.ts","sourceRoot":"","sources":["../src/option-when.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAExD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,GAAG,SAAS,CAItE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAC3B,OAAO,EAAE,SAAS,EAAE,GAAG,SAAS,EAChC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,EAClD,SAAS,CAAC,EAAE,MAAM,GACnB,SAAS,EAAE,CAqBb"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves a field's cascade dependency — the key of another form field whose
|
|
3
|
+
* current value scopes this picker's options (`filter_value`). Tolerates the
|
|
4
|
+
* camelCase `dependsOn` (authored SDK shape) and the snake_case `depends_on`
|
|
5
|
+
* the kernel manifest serves. Returns the trimmed field key, or `undefined`
|
|
6
|
+
* when the field declares no dependency.
|
|
7
|
+
*/
|
|
8
|
+
export function getDependsOn(field) {
|
|
9
|
+
const dep = field.dependsOn ?? field.depends_on;
|
|
10
|
+
if (typeof dep === 'string' && dep.trim() !== '')
|
|
11
|
+
return dep.trim();
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Filters a STATIC enum's `options[]` by each option's `when` gate against the
|
|
16
|
+
* current form values. Pure — no React, no side effects.
|
|
17
|
+
*
|
|
18
|
+
* Rule per option:
|
|
19
|
+
* - No `when` → always included (retrocompat; existing enums untouched).
|
|
20
|
+
* - With `when`: the gating field is `when.field ?? dependsOn`. If neither is
|
|
21
|
+
* present the option is included (nothing to gate on). Otherwise the form's
|
|
22
|
+
* value for that field is compared AS STRING: included when (no `in`, or
|
|
23
|
+
* value ∈ `in`) AND (no `not_in`, or value ∉ `not_in`). Tolerates the
|
|
24
|
+
* snake_case `not_in` the kernel serves alongside camelCase `notIn`.
|
|
25
|
+
*
|
|
26
|
+
* `formValues` is the flat map of the surrounding form/row values the gating
|
|
27
|
+
* field is read from; `dependsOn` is the containing field's declared dependency
|
|
28
|
+
* used as the default gating field.
|
|
29
|
+
*/
|
|
30
|
+
export function applyOptionWhen(options, formValues, dependsOn) {
|
|
31
|
+
if (!Array.isArray(options))
|
|
32
|
+
return [];
|
|
33
|
+
return options.filter((opt) => {
|
|
34
|
+
const when = opt?.when;
|
|
35
|
+
if (!when)
|
|
36
|
+
return true;
|
|
37
|
+
const gate = (typeof when.field === 'string' && when.field.trim() !== '')
|
|
38
|
+
? when.field.trim()
|
|
39
|
+
: dependsOn;
|
|
40
|
+
if (!gate)
|
|
41
|
+
return true;
|
|
42
|
+
const raw = formValues ? formValues[gate] : undefined;
|
|
43
|
+
const current = raw == null ? '' : String(raw);
|
|
44
|
+
const inList = when.in;
|
|
45
|
+
const notIn = when.notIn ?? when.not_in;
|
|
46
|
+
if (Array.isArray(inList) && inList.length > 0) {
|
|
47
|
+
if (!inList.some((v) => String(v) === current))
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
if (Array.isArray(notIn) && notIn.length > 0) {
|
|
51
|
+
if (notIn.some((v) => String(v) === current))
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
});
|
|
56
|
+
}
|
package/dist/validator.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAMhD,MAAM,WAAW,cAAc;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CACrB;AAQD,iFAAiF;AACjF,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,cAAc,CAyCzD;AAqCD,gFAAgF;AAChF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,eAAe,CAUlG;AAiCD,4EAA4E;AAC5E,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,GAAG,UAAU,EAAE,CAmC7E;AAyDD;+DAC+D;AAC/D,wBAAgB,cAAc,CAC1B,MAAM,EAAE,SAAS,cAAc,EAAE,EACjC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAI9B;AAgCD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,GAAG,OAAO,CAEvE;AAYD;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CACrC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,EACjC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,GACtD,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAY9B"}
|
package/dist/validator.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { applyOptionWhen, getDependsOn } from './option-when';
|
|
1
2
|
const NIL_UUID = '00000000-0000-0000-0000-000000000000';
|
|
2
3
|
const NUMERIC_TYPES = new Set(['int', 'integer', 'bigint', 'decimal', 'numeric', 'number', 'float', 'double']);
|
|
3
4
|
const RULE_NAMES = new Set([
|
|
@@ -203,7 +204,13 @@ function checkBuiltin(slug, value) {
|
|
|
203
204
|
return undefined;
|
|
204
205
|
}
|
|
205
206
|
}
|
|
206
|
-
|
|
207
|
+
/**
|
|
208
|
+
* `context` son los valores hermanos contra los que se evalúa el `when` de
|
|
209
|
+
* cada opción: una opción que su `when` descarta con el valor actual (forma de
|
|
210
|
+
* pago «99» con método PUE) es `invalid_option`, igual que una fuera de catálogo
|
|
211
|
+
* — y como la rechaza el kernel al guardar.
|
|
212
|
+
*/
|
|
213
|
+
function specFromField(field, context) {
|
|
207
214
|
const v = fieldValidationOf(field);
|
|
208
215
|
const spec = {
|
|
209
216
|
required: !!field.required,
|
|
@@ -213,8 +220,10 @@ function specFromField(field) {
|
|
|
213
220
|
max: v.max,
|
|
214
221
|
custom: v.custom,
|
|
215
222
|
};
|
|
216
|
-
if (field.options?.length)
|
|
217
|
-
|
|
223
|
+
if (field.options?.length) {
|
|
224
|
+
const applicable = context ? applyOptionWhen(field.options, context, getDependsOn(field)) : field.options;
|
|
225
|
+
spec.options = applicable.map(o => String(o.value));
|
|
226
|
+
}
|
|
218
227
|
return spec;
|
|
219
228
|
}
|
|
220
229
|
function isLineItems(field) {
|
|
@@ -229,10 +238,10 @@ function itemFieldsOf(field) {
|
|
|
229
238
|
* field issue, dotted keys for line-items (`items.0.qty`). */
|
|
230
239
|
export function validateValues(fields, values) {
|
|
231
240
|
const bag = {};
|
|
232
|
-
walk(fields, values ?? {}, '', bag);
|
|
241
|
+
walk(fields, values ?? {}, '', bag, values ?? {});
|
|
233
242
|
return bag;
|
|
234
243
|
}
|
|
235
|
-
function walk(fields, values, prefix, bag) {
|
|
244
|
+
function walk(fields, values, prefix, bag, context) {
|
|
236
245
|
for (const field of fields) {
|
|
237
246
|
const key = field.key;
|
|
238
247
|
if (!key)
|
|
@@ -247,11 +256,12 @@ function walk(fields, values, prefix, bag) {
|
|
|
247
256
|
}
|
|
248
257
|
rows.forEach((row, i) => {
|
|
249
258
|
const obj = row && typeof row === 'object' ? row : {};
|
|
250
|
-
|
|
259
|
+
// Una celda puede depender de otra del renglón o del encabezado.
|
|
260
|
+
walk(itemFieldsOf(field), obj, `${path}.${i}`, bag, { ...context, ...obj });
|
|
251
261
|
});
|
|
252
262
|
continue;
|
|
253
263
|
}
|
|
254
|
-
const issues = checkValue(raw, specFromField(field));
|
|
264
|
+
const issues = checkValue(raw, specFromField(field, context));
|
|
255
265
|
if (issues.length)
|
|
256
266
|
bag[path] = issues;
|
|
257
267
|
}
|