@asteby/metacore-runtime-react 37.0.2 → 37.0.4
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 +12 -0
- package/dist/addon-loader.d.ts.map +1 -1
- package/dist/addon-loader.js +18 -10
- package/dist/dialogs/dynamic-record.d.ts +10 -2
- package/dist/dialogs/dynamic-record.d.ts.map +1 -1
- package/dist/dialogs/dynamic-record.js +67 -36
- package/dist/dynamic-form-schema.d.ts +27 -0
- package/dist/dynamic-form-schema.d.ts.map +1 -1
- package/dist/dynamic-form-schema.js +79 -0
- package/dist/dynamic-select-field.d.ts +3 -1
- package/dist/dynamic-select-field.d.ts.map +1 -1
- package/dist/dynamic-select-field.js +3 -2
- package/dist/dynamic-table.d.ts +1 -8
- package/dist/dynamic-table.d.ts.map +1 -1
- package/dist/dynamic-table.js +100 -20
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/types.d.ts +7 -6
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/dynamic-record-field-validation.test.tsx +110 -0
- package/src/__tests__/visible-when.test.ts +41 -1
- package/src/addon-loader.tsx +22 -10
- package/src/dialogs/dynamic-record.tsx +86 -32
- package/src/dynamic-form-schema.ts +81 -0
- package/src/dynamic-select-field.tsx +8 -1
- package/src/dynamic-table.tsx +89 -27
- package/src/index.ts +3 -0
- package/src/types.ts +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @asteby/metacore-runtime-react
|
|
2
2
|
|
|
3
|
+
## 37.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0396b95: DynamicRecordDialog: unique form ids (nested create), Laravel-style validateValues on submit, destructive borders on invalid fields, toast descriptions for errors on non-rendered fields, and `ensureFields` to inject host scope keys into the modal schema.
|
|
8
|
+
|
|
9
|
+
## 37.0.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 46a9505: List/board honor Column.visible_when against locked defaultFilters / URL scope (CxC hides Proveedor); AddonLoader retries transient remoteEntry 502s.
|
|
14
|
+
|
|
3
15
|
## 37.0.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addon-loader.d.ts","sourceRoot":"","sources":["../src/addon-loader.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAc3E,MAAM,WAAW,gBAAgB;IAC7B,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAA;IACb,+EAA+E;IAC/E,GAAG,EAAE,MAAM,CAAA;IACX,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,+DAA+D;IAC/D,GAAG,EAAE,QAAQ,CAAA;IACb;;;;OAIG;IACH,YAAY,CAAC,EAAE,QAAQ,CAAA;IACvB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,wCAAwC;IACxC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,iFAAiF;IACjF,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,+BAA+B;IAC/B,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAA;IAC9B;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC7B;
|
|
1
|
+
{"version":3,"file":"addon-loader.d.ts","sourceRoot":"","sources":["../src/addon-loader.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAc3E,MAAM,WAAW,gBAAgB;IAC7B,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAA;IACb,+EAA+E;IAC/E,GAAG,EAAE,MAAM,CAAA;IACX,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,+DAA+D;IAC/D,GAAG,EAAE,QAAQ,CAAA;IACb;;;;OAIG;IACH,YAAY,CAAC,EAAE,QAAQ,CAAA;IACvB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,wCAAwC;IACxC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,iFAAiF;IACjF,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,+BAA+B;IAC/B,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAA;IAC9B;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC7B;AAwED,wBAAgB,WAAW,CAAC,EACxB,KAAK,EACL,GAAG,EACH,MAAqB,EACrB,GAAG,EACH,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,QAAe,EACf,OAAO,EACP,OAAO,EACP,MAAM,EACN,QAAQ,GACX,EAAE,gBAAgB,sCAmElB"}
|
package/dist/addon-loader.js
CHANGED
|
@@ -33,20 +33,28 @@ function isRuntimeNotReady(e) {
|
|
|
33
33
|
const msg = e instanceof Error ? e.message : String(e);
|
|
34
34
|
return msg.includes('#RUNTIME-009') || msg.includes('call createInstance');
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
/** Transient network / gateway failures while the host API is restarting. */
|
|
37
|
+
function isTransientRemoteLoadError(e) {
|
|
38
|
+
if (isRuntimeNotReady(e))
|
|
39
|
+
return true;
|
|
40
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
41
|
+
return (/failed to fetch|networkerror|load failed|502|503|504|ERR_CONNECTION_REFUSED|ECONNREFUSED|Outdated Optimize Dep/i.test(msg) ||
|
|
42
|
+
// MF wraps fetch failures variously
|
|
43
|
+
/ScriptExternalLoadError|Loading script failed|remoteEntry/i.test(msg));
|
|
44
|
+
}
|
|
45
|
+
// Retry host-boot races (RUNTIME-009) and brief API blips (502 while backend
|
|
46
|
+
// SyncAll is still running). Permanent errors (404, missing register) fail fast.
|
|
47
|
+
async function withRemoteLoadRetry(op) {
|
|
48
|
+
const maxAttempts = 8;
|
|
42
49
|
for (let attempt = 1;; attempt++) {
|
|
43
50
|
try {
|
|
44
51
|
return await op();
|
|
45
52
|
}
|
|
46
53
|
catch (e) {
|
|
47
|
-
if (!
|
|
54
|
+
if (!isTransientRemoteLoadError(e) || attempt >= maxAttempts)
|
|
48
55
|
throw e;
|
|
49
|
-
|
|
56
|
+
// 80, 160, 320… capped — ~3s worst case for API restart
|
|
57
|
+
await sleep(Math.min(80 * 2 ** (attempt - 1), 800));
|
|
50
58
|
}
|
|
51
59
|
}
|
|
52
60
|
}
|
|
@@ -55,10 +63,10 @@ async function loadAddon(scope, url, module) {
|
|
|
55
63
|
// fetches the new remoteEntry. `force: true` wipes that remote's module
|
|
56
64
|
// cache — without it, loadRemote would keep serving the previous bundle.
|
|
57
65
|
if (shouldReregisterRemote(scope, url)) {
|
|
58
|
-
await
|
|
66
|
+
await withRemoteLoadRetry(() => registerRemotes([{ name: scope, entry: url, type: 'module' }], { force: true }));
|
|
59
67
|
markRemoteRegistered(scope, url);
|
|
60
68
|
}
|
|
61
|
-
return
|
|
69
|
+
return withRemoteLoadRetry(() => loadRemote(remoteId(scope, module)));
|
|
62
70
|
}
|
|
63
71
|
export function AddonLoader({ scope, url, module = './register', api, hostRegistry, addonKey, unbindKey, fallback = null, onReady, onError, layout, children, }) {
|
|
64
72
|
const [status, setStatus] = useState('loading');
|
|
@@ -100,6 +100,12 @@ export interface DynamicRecordDialogProps {
|
|
|
100
100
|
* lets it close while the depth lock is held.
|
|
101
101
|
*/
|
|
102
102
|
nestedInlineCreateSelf?: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Fields merged into the modal schema after load (by key). Existing keys are
|
|
105
|
+
* shallow-merged; missing keys are prepended. Hosts use this to inject
|
|
106
|
+
* required scope fields (e.g. branch_id) omitted from compiled DefineModal.
|
|
107
|
+
*/
|
|
108
|
+
ensureFields?: FieldDef[];
|
|
103
109
|
mode: 'view' | 'edit' | 'create';
|
|
104
110
|
model: string;
|
|
105
111
|
recordId?: string | null;
|
|
@@ -198,7 +204,7 @@ export declare function fkSeedOption(field: FieldDef, value: any, record: any):
|
|
|
198
204
|
export declare function isMoneyField(field: FieldDef, value: any): boolean;
|
|
199
205
|
export declare function filterVisibleFields(fields: FieldDef[] | undefined, mode: 'view' | 'edit' | 'create', formValues?: Record<string, any>): FieldDef[];
|
|
200
206
|
export declare function stripHiddenFieldValues(values: Record<string, any>, fields: FieldDef[] | undefined, mode: 'view' | 'edit' | 'create'): Record<string, any>;
|
|
201
|
-
export declare function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf, mode, model, recordId, endpoint, onSaved, onCreate, onUpdate, defaults, lockedFields, schema, onDelete, onEdit, onOpenFullPage, initialRecord, getImageUrl, timeZone, currency, onChange, }: DynamicRecordDialogProps): import("react").JSX.Element;
|
|
207
|
+
export declare function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf, ensureFields, mode, model, recordId, endpoint, onSaved, onCreate, onUpdate, defaults, lockedFields, schema, onDelete, onEdit, onOpenFullPage, initialRecord, getImageUrl, timeZone, currency, onChange, }: DynamicRecordDialogProps): import("react").JSX.Element;
|
|
202
208
|
export declare function ReadonlyEditField({ field, value }: {
|
|
203
209
|
field: FieldDef;
|
|
204
210
|
value: any;
|
|
@@ -214,11 +220,13 @@ export declare function ViewValue({ field, value: rawValue, record, getImageUrl:
|
|
|
214
220
|
/** Optional override; when omitted falls back to the nearest provider. */
|
|
215
221
|
currency?: string;
|
|
216
222
|
}): import("react").JSX.Element;
|
|
217
|
-
export declare function EditField({ field, value, onChange, record }: {
|
|
223
|
+
export declare function EditField({ field, value, onChange, record, invalid }: {
|
|
218
224
|
field: FieldDef;
|
|
219
225
|
value: any;
|
|
220
226
|
onChange: (val: any) => void;
|
|
221
227
|
/** The full record being edited — supplies FK relation siblings + line-items. */
|
|
222
228
|
record?: any;
|
|
229
|
+
/** When true, paint the control with a destructive border (Laravel-style). */
|
|
230
|
+
invalid?: boolean;
|
|
223
231
|
}): import("react").JSX.Element;
|
|
224
232
|
//# sourceMappingURL=dynamic-record.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-record.d.ts","sourceRoot":"","sources":["../../src/dialogs/dynamic-record.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AA6C1C,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAEjF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"dynamic-record.d.ts","sourceRoot":"","sources":["../../src/dialogs/dynamic-record.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AA6C1C,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAEjF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAoB3C,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAEnE,OAAO,EAAqC,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAK1F,YAAY,EAAE,WAAW,EAAE,CAAA;AAE3B,MAAM,WAAW,WAAW;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,KAA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I,CAAA;IAC5B,iFAAiF;IACjF,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ,8EAA8E;IAC9E,OAAO,CAAC,EAAE,OAAO,CAAA;CACpB,+BAiNA"}
|
|
@@ -10,7 +10,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
10
10
|
// flows through <ApiProvider> from runtime-react. Host-specific runtime values —
|
|
11
11
|
// the image-url resolver and the org IANA timezone — are passed as props so the
|
|
12
12
|
// SDK stays transport- and host-agnostic.
|
|
13
|
-
import { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';
|
|
13
|
+
import { createContext, useCallback, useContext, useEffect, useId, useRef, useState } from 'react';
|
|
14
14
|
import { useTranslation } from 'react-i18next';
|
|
15
15
|
/** Model key of the open create/edit dialog — used to hide "+" on self-FK pickers
|
|
16
16
|
* (e.g. Customer.parent_id) so they don't nest another "Crear Cliente" modal. */
|
|
@@ -23,7 +23,7 @@ import { es } from 'date-fns/locale';
|
|
|
23
23
|
import { ExternalLink, Loader2, CalendarIcon, ChevronDown, Check, Upload, X as XIcon, ScanLine } from 'lucide-react';
|
|
24
24
|
import { BarcodeScanner } from '../barcode-scanner';
|
|
25
25
|
import { useApi } from '../api-context';
|
|
26
|
-
import { toastServerError, extractFieldErrors, localizeFieldIssue } from '../server-error';
|
|
26
|
+
import { toastServerError, extractFieldErrors, localizeFieldIssue, localizeFieldErrorMap } from '../server-error';
|
|
27
27
|
import { DynamicSelectField, OptionLead, OptionThumb } from '../dynamic-select-field';
|
|
28
28
|
import { DynamicRelations } from '../dynamic-relations';
|
|
29
29
|
import { useOptionsResolver } from '../use-options-resolver';
|
|
@@ -33,6 +33,7 @@ import { FieldSection, WizardProgress } from '../form-layout-ui';
|
|
|
33
33
|
import { FieldCell } from '../field-grid';
|
|
34
34
|
import { isNilUuid, normalizeNilUuid } from '../nil-uuid';
|
|
35
35
|
import { normalizeRefFieldsForSubmit } from './normalize-submit';
|
|
36
|
+
import { validateValues, bagHasErrors } from '../validator';
|
|
36
37
|
import { DynamicIcon, isLucideIconName } from '../dynamic-icon';
|
|
37
38
|
import { IconPickerField } from '../icon-picker-field';
|
|
38
39
|
import { humanizeToken } from '../dynamic-columns-helpers';
|
|
@@ -299,7 +300,24 @@ export function stripHiddenFieldValues(values, fields, mode) {
|
|
|
299
300
|
}
|
|
300
301
|
return out;
|
|
301
302
|
}
|
|
302
|
-
|
|
303
|
+
function applyEnsureFields(meta, ensureFields) {
|
|
304
|
+
if (!meta)
|
|
305
|
+
return meta ?? null;
|
|
306
|
+
if (!ensureFields?.length)
|
|
307
|
+
return meta;
|
|
308
|
+
const fields = Array.isArray(meta.fields) ? [...meta.fields] : [];
|
|
309
|
+
for (const ensure of ensureFields) {
|
|
310
|
+
const idx = fields.findIndex((f) => f?.key === ensure.key);
|
|
311
|
+
if (idx >= 0) {
|
|
312
|
+
fields[idx] = { ...fields[idx], ...ensure };
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
fields.unshift(ensure);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return { ...meta, fields };
|
|
319
|
+
}
|
|
320
|
+
export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf, ensureFields, mode, model, recordId, endpoint, onSaved, onCreate, onUpdate, defaults, lockedFields, schema, onDelete, onEdit, onOpenFullPage, initialRecord, getImageUrl = identityImageUrl, timeZone, currency, onChange, }) {
|
|
303
321
|
const api = useApi();
|
|
304
322
|
const { t } = useTranslation();
|
|
305
323
|
const [modalMeta, setModalMeta] = useState(schema ? schema : null);
|
|
@@ -310,6 +328,9 @@ export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf
|
|
|
310
328
|
// inline under each input; populated from a 422 `errors` map or the client
|
|
311
329
|
// required-field check, cleared per-field on change and wholesale on reopen.
|
|
312
330
|
const [fieldErrors, setFieldErrors] = useState({});
|
|
331
|
+
// Unique form id per dialog instance — nested create must not share
|
|
332
|
+
// id={formId} or the child footer submits the parent.
|
|
333
|
+
const formId = useId();
|
|
313
334
|
const [loading, setLoading] = useState(false);
|
|
314
335
|
const [saving, setSaving] = useState(false);
|
|
315
336
|
const [deleting, setDeleting] = useState(false);
|
|
@@ -367,6 +388,7 @@ export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf
|
|
|
367
388
|
return;
|
|
368
389
|
meta = metaRes.data?.data ?? metaRes.data;
|
|
369
390
|
}
|
|
391
|
+
meta = applyEnsureFields(meta, ensureFields);
|
|
370
392
|
setModalMeta(meta);
|
|
371
393
|
if (isCreate) {
|
|
372
394
|
const initial = {};
|
|
@@ -415,7 +437,7 @@ export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf
|
|
|
415
437
|
// initialRecord intentionally omitted: the row identity is captured per open
|
|
416
438
|
// via recordId; re-seeding mid-open would clobber edits.
|
|
417
439
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
418
|
-
}, [open, recordId, model, endpoint, isCreate, schema]);
|
|
440
|
+
}, [open, recordId, model, endpoint, isCreate, schema, ensureFields]);
|
|
419
441
|
// Reset when closed
|
|
420
442
|
useEffect(() => {
|
|
421
443
|
if (!open) {
|
|
@@ -509,7 +531,12 @@ export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf
|
|
|
509
531
|
next[key] = localizeFieldIssue(issues[0], labelForKey(key), t);
|
|
510
532
|
}
|
|
511
533
|
setFieldErrors(next);
|
|
512
|
-
|
|
534
|
+
const visibleKeys = new Set(filterVisibleFields(modalMeta?.fields ?? [], mode, formValues).map(f => f.key));
|
|
535
|
+
const orphans = Object.entries(next).filter(([k]) => !visibleKeys.has(k));
|
|
536
|
+
const description = orphans.length
|
|
537
|
+
? orphans.map(([k, msg]) => `${labelForKey(k)}: ${msg}`).join(' · ')
|
|
538
|
+
: undefined;
|
|
539
|
+
toast.error(t('dynamic.validation_failed', { defaultValue: 'Revisa los campos marcados' }), description ? { description } : undefined);
|
|
513
540
|
return;
|
|
514
541
|
}
|
|
515
542
|
toastServerError(err, { t, fallback: t('dynamic.save_error', { defaultValue: 'No se pudo guardar' }) });
|
|
@@ -519,20 +546,22 @@ export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf
|
|
|
519
546
|
if (!modalMeta)
|
|
520
547
|
return;
|
|
521
548
|
if (isEditable) {
|
|
522
|
-
//
|
|
523
|
-
//
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
549
|
+
// Laravel-style: collect every issue from the shared validator
|
|
550
|
+
// (required + rule strings / min/max / email…) on visible fields only.
|
|
551
|
+
const visible = filterVisibleFields(modalMeta.fields, mode, formValues);
|
|
552
|
+
const bag = validateValues(visible, formValues);
|
|
553
|
+
if (bagHasErrors(bag)) {
|
|
554
|
+
const labels = {};
|
|
555
|
+
for (const f of visible)
|
|
556
|
+
labels[f.key] = f.label;
|
|
557
|
+
const next = localizeFieldErrorMap(bag, t, { labels });
|
|
558
|
+
setFieldErrors(next);
|
|
559
|
+
const visibleKeys = new Set(visible.map(f => f.key));
|
|
560
|
+
const orphans = Object.entries(next).filter(([k]) => !visibleKeys.has(k));
|
|
561
|
+
const description = orphans.length
|
|
562
|
+
? orphans.map(([k, msg]) => `${labelForKey(k)}: ${msg}`).join(' · ')
|
|
563
|
+
: undefined;
|
|
564
|
+
toast.error(t('dynamic.validation_failed', { defaultValue: 'Revisa los campos marcados' }), description ? { description } : undefined);
|
|
536
565
|
return;
|
|
537
566
|
}
|
|
538
567
|
}
|
|
@@ -653,14 +682,13 @@ export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf
|
|
|
653
682
|
// then advance. Mirrors handleSubmit's required check but scoped to the step.
|
|
654
683
|
const goNextStep = () => {
|
|
655
684
|
const step = groups[clampedStep];
|
|
656
|
-
const
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
setFieldErrors(missing);
|
|
685
|
+
const stepFields = step?.fields ?? [];
|
|
686
|
+
const bag = validateValues(stepFields, formValues);
|
|
687
|
+
if (bagHasErrors(bag)) {
|
|
688
|
+
const labels = {};
|
|
689
|
+
for (const f of stepFields)
|
|
690
|
+
labels[f.key] = f.label;
|
|
691
|
+
setFieldErrors(localizeFieldErrorMap(bag, t, { labels }));
|
|
664
692
|
toast.error(t('dynamic.validation_failed', { defaultValue: 'Revisa los campos marcados' }));
|
|
665
693
|
return;
|
|
666
694
|
}
|
|
@@ -668,7 +696,7 @@ export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf
|
|
|
668
696
|
setStepIndex(Math.min(clampedStep + 1, groups.length - 1));
|
|
669
697
|
};
|
|
670
698
|
const goBackStep = () => setStepIndex(Math.max(clampedStep - 1, 0));
|
|
671
|
-
return (_jsx(RecordDialogModelContext.Provider, { value: model, children: _jsx(Dialog, { open: open, onOpenChange: onOpenChange, nestedInlineCreateSelf: nestedInlineCreateSelf, children: _jsxs(DialogContent, { className: "sm:max-w-2xl max-h-[90dvh] flex flex-col p-0 gap-0 overflow-hidden", style: { maxHeight: '90dvh' }, children: [_jsxs(DialogHeader, { className: "p-6 pb-4 border-b shrink-0", children: [_jsx(DialogTitle, { children: title }), _jsx(DialogDescription, { children: config.description })] }), _jsx("div", { className: "flex-1 overflow-y-auto p-6", children: loading ? (_jsx(LoadingSkeleton, {})) : modalMeta ? (_jsx(ModelContext.Provider, { value: model, children: _jsx(ImageUrlContext.Provider, { value: getImageUrl, children: _jsx(TimeZoneContext.Provider, { value: timeZone, children: _jsxs(CurrencyContext.Provider, { value: currency, children: [_jsxs("form", { id:
|
|
699
|
+
return (_jsx(RecordDialogModelContext.Provider, { value: model, children: _jsx(Dialog, { open: open, onOpenChange: onOpenChange, nestedInlineCreateSelf: nestedInlineCreateSelf, children: _jsxs(DialogContent, { className: "sm:max-w-2xl max-h-[90dvh] flex flex-col p-0 gap-0 overflow-hidden", style: { maxHeight: '90dvh' }, children: [_jsxs(DialogHeader, { className: "p-6 pb-4 border-b shrink-0", children: [_jsx(DialogTitle, { children: title }), _jsx(DialogDescription, { children: config.description })] }), _jsx("div", { className: "flex-1 overflow-y-auto p-6", children: loading ? (_jsx(LoadingSkeleton, {})) : modalMeta ? (_jsx(ModelContext.Provider, { value: model, children: _jsx(ImageUrlContext.Provider, { value: getImageUrl, children: _jsx(TimeZoneContext.Provider, { value: timeZone, children: _jsxs(CurrencyContext.Provider, { value: currency, children: [_jsxs("form", { id: formId, onSubmit: handleSubmit, className: "grid gap-y-4", children: [isSteps && (_jsx(WizardProgress, { groups: groups, stepIndex: clampedStep })), (isSteps ? [groups[clampedStep]] : groups).map(group => (_jsx(FieldSection, { group: group, children: _jsx("div", { className: "grid grid-cols-1 gap-x-6 gap-y-4 sm:grid-cols-2", children: renderFields(group.fields) }) }, group.key))), record?.external_url && (_jsx("div", { className: "grid grid-cols-1 sm:grid-cols-2", children: _jsx("div", { className: "sm:col-span-2 min-w-0", children: _jsxs("a", { href: record.external_url, target: "_blank", rel: "noreferrer", className: "inline-flex items-center gap-1.5 text-sm text-primary hover:underline mt-1", children: [_jsx(ExternalLink, { className: "h-3.5 w-3.5" }), "Ver en ", record.external_provider ?? 'proveedor externo'] }) }) }))] }), !isCreate && record && relations.length > 0 && (_jsx("div", { className: "mt-6", children: _jsx(DynamicRelations, { record: record, relations: relations, lineSubtable: true, embedOnly: true, canCreate: mode === 'edit', canEdit: mode === 'edit', canDelete: mode === 'edit', onChange: handleChildChange }) }))] }) }) }) })) : null }), _jsxs(DialogFooter, { className: "p-4 border-t shrink-0 sm:justify-between", children: [isView && onOpenFullPage ? (_jsxs(Button, { variant: "ghost", size: "sm", className: "text-muted-foreground", onClick: () => { onOpenChange(false); onOpenFullPage(); }, children: [_jsx(ExternalLink, { className: "mr-1.5 h-3.5 w-3.5" }), "Ver p\u00E1gina completa"] })) : _jsx("span", {}), _jsxs("div", { className: "flex items-center gap-2", children: [isSteps && clampedStep > 0 ? (_jsx(Button, { variant: "outline", onClick: goBackStep, disabled: saving || deleting, children: "Anterior" })) : (_jsx(Button, { variant: "outline", onClick: () => onOpenChange(false), disabled: saving || deleting, children: config.cancelLabel })), isView && onDelete && (_jsxs(Button, { variant: "destructive", onClick: handleDelete, disabled: deleting || loading, children: [deleting && _jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }), deleting ? 'Eliminando...' : 'Eliminar'] })), isView && onEdit && (_jsx(Button, { onClick: onEdit, disabled: deleting || loading, children: "Editar" })), isEditable && isSteps && !isLastStep && (_jsx(Button, { type: "button", onClick: goNextStep, disabled: saving || loading, children: "Siguiente" })), isEditable && (!isSteps || isLastStep) && (_jsxs(Button, { type: "submit", form: formId, disabled: saving || loading, children: [saving && _jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }), saving ? config.submittingLabel : config.submitLabel] }))] })] })] }) }) }));
|
|
672
700
|
}
|
|
673
701
|
function LoadingSkeleton() {
|
|
674
702
|
return (_jsx("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-4", children: Array.from({ length: 6 }).map((_, i) => (_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Skeleton, { className: "h-3.5 w-24" }), _jsx(Skeleton, { className: "h-9 w-full" })] }, i))) }));
|
|
@@ -682,7 +710,7 @@ function FieldRow({ field, record, value, mode, onChange, error, locked }) {
|
|
|
682
710
|
// the rich read-only renderer. `locked` forces the same disabled rendering on
|
|
683
711
|
// CREATE for a caller-specified field (see `lockedFields`).
|
|
684
712
|
const isEditReadonly = (mode === 'edit' && !!field.readonly) || !!locked;
|
|
685
|
-
return (_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsxs(Label, { className: "text-xs font-medium text-muted-foreground uppercase tracking-wide", children: [field.label, field.required && mode !== 'view' && !isEditReadonly && (_jsx("span", { className: "text-destructive ml-0.5", children: "*" }))] }), mode === 'view' ? (_jsx(ViewValue, { field: field, value: value, record: record })) : isEditReadonly ? (_jsx(ReadonlyEditField, { field: field, value: value })) : (_jsx(EditField, { field: field, value: value, onChange: onChange, record: record })), error && mode !== 'view' && (_jsx("p", { className: "text-destructive text-xs mt-1", children: error }))] }));
|
|
713
|
+
return (_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsxs(Label, { className: "text-xs font-medium text-muted-foreground uppercase tracking-wide", children: [field.label, field.required && mode !== 'view' && !isEditReadonly && (_jsx("span", { className: "text-destructive ml-0.5", children: "*" }))] }), mode === 'view' ? (_jsx(ViewValue, { field: field, value: value, record: record })) : isEditReadonly ? (_jsx(ReadonlyEditField, { field: field, value: value })) : (_jsx(EditField, { field: field, value: value, onChange: onChange, record: record, invalid: !!error })), error && mode !== 'view' && (_jsx("p", { className: "text-destructive text-xs mt-1", children: error }))] }));
|
|
686
714
|
}
|
|
687
715
|
// ReadonlyEditField — the edit-mode rendering of a `readonly` (system-generated)
|
|
688
716
|
// field: a disabled, muted input that shows the current value without allowing
|
|
@@ -1047,7 +1075,10 @@ function JsonObjectViewValue({ value }) {
|
|
|
1047
1075
|
return (_jsxs("div", { className: "min-w-0", children: [_jsx("dt", { className: "text-[11px] font-medium uppercase tracking-wide text-muted-foreground", children: label }), _jsx("dd", { className: "mt-0.5 break-words text-foreground", children: isNest ? (_jsx("pre", { className: "max-h-48 overflow-auto rounded-md bg-muted/40 p-2 text-[11px] leading-relaxed whitespace-pre-wrap", children: JSON.stringify(raw, null, 2) })) : raw === null || raw === '' ? (_jsx("span", { className: "text-muted-foreground", children: "\u2014" })) : (String(raw)) })] }, key));
|
|
1048
1076
|
}) }));
|
|
1049
1077
|
}
|
|
1050
|
-
export function EditField({ field, value, onChange, record }) {
|
|
1078
|
+
export function EditField({ field, value, onChange, record, invalid }) {
|
|
1079
|
+
const invalidCls = invalid
|
|
1080
|
+
? 'border-destructive ring-1 ring-destructive/30 focus-visible:ring-destructive aria-invalid:border-destructive'
|
|
1081
|
+
: undefined;
|
|
1051
1082
|
const { t, i18n } = useTranslation();
|
|
1052
1083
|
const editFieldImageUrl = useContext(ImageUrlContext);
|
|
1053
1084
|
const dialogModel = useContext(RecordDialogModelContext);
|
|
@@ -1062,7 +1093,7 @@ export function EditField({ field, value, onChange, record }) {
|
|
|
1062
1093
|
return (_jsxs("div", { className: "flex items-center gap-2 py-1", children: [_jsx(Switch, { checked: !!value, onCheckedChange: onChange }), _jsx("span", { className: "text-sm text-muted-foreground", children: value ? 'Sí' : 'No' })] }));
|
|
1063
1094
|
}
|
|
1064
1095
|
if (field.type === 'textarea') {
|
|
1065
|
-
return (_jsx(Textarea, { value: value ?? '', onChange: (e) => onChange(e.target.value), placeholder: field.placeholder, rows: 4 }));
|
|
1096
|
+
return (_jsx(Textarea, { value: value ?? '', onChange: (e) => onChange(e.target.value), placeholder: field.placeholder, rows: 4, "aria-invalid": invalid || undefined, className: invalidCls }));
|
|
1066
1097
|
}
|
|
1067
1098
|
// Icon picker: the kernel serves `type: 'icon'` (or an explicit
|
|
1068
1099
|
// `widget: 'icon'`) when the manifest column declares `widget: "icon"`.
|
|
@@ -1103,7 +1134,7 @@ export function EditField({ field, value, onChange, record }) {
|
|
|
1103
1134
|
// backend-injected FK sibling, key without `_id`) so an existing
|
|
1104
1135
|
// selection shows the label, not the raw uuid — without waiting
|
|
1105
1136
|
// for the popover to open and fetch a page.
|
|
1106
|
-
seedOption: fkSeedOption(field, value, record), hideCreate: hideSelfCreate }));
|
|
1137
|
+
seedOption: fkSeedOption(field, value, record), hideCreate: hideSelfCreate, invalid: invalid }));
|
|
1107
1138
|
}
|
|
1108
1139
|
if (field.type === 'search' && field.searchEndpoint) {
|
|
1109
1140
|
return _jsx(SearchField, { field: field, value: value, onChange: onChange });
|
|
@@ -1112,7 +1143,7 @@ export function EditField({ field, value, onChange, record }) {
|
|
|
1112
1143
|
return _jsx(SearchField, { field: { ...field, type: 'search' }, value: value, onChange: onChange });
|
|
1113
1144
|
}
|
|
1114
1145
|
if (field.type === 'select' && field.options?.length) {
|
|
1115
|
-
return (_jsxs(Select, { value: String(value ?? ''), onValueChange: onChange, children: [_jsx(SelectTrigger, { className: "w-full", children: _jsx(SelectValue, { placeholder: "Seleccionar..." }) }), _jsx(SelectContent, { children: field.options.map(opt => (_jsx(SelectItem, { value: opt.value, children: opt.label }, opt.value))) })] }));
|
|
1146
|
+
return (_jsxs(Select, { value: String(value ?? ''), onValueChange: onChange, children: [_jsx(SelectTrigger, { className: cn("w-full", invalidCls), "aria-invalid": invalid || undefined, children: _jsx(SelectValue, { placeholder: "Seleccionar..." }) }), _jsx(SelectContent, { children: field.options.map(opt => (_jsx(SelectItem, { value: opt.value, children: opt.label }, opt.value))) })] }));
|
|
1116
1147
|
}
|
|
1117
1148
|
if (field.type === 'color') {
|
|
1118
1149
|
return (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("input", { type: "color", value: value || '#6366f1', onChange: (e) => onChange(e.target.value), className: "h-9 w-14 cursor-pointer rounded-md border p-1" }), _jsx(Input, { value: value || '', onChange: (e) => onChange(e.target.value), placeholder: "#6366f1", className: "flex-1 h-9" })] }));
|
|
@@ -1133,7 +1164,7 @@ export function EditField({ field, value, onChange, record }) {
|
|
|
1133
1164
|
: field.type === 'email'
|
|
1134
1165
|
? 'email'
|
|
1135
1166
|
: 'text';
|
|
1136
|
-
return _jsx(ScannableRecordInput, { field: field, value: value, onChange: onChange, inputType: inputType });
|
|
1167
|
+
return _jsx(ScannableRecordInput, { field: field, value: value, onChange: onChange, inputType: inputType, invalid: invalid, className: invalidCls });
|
|
1137
1168
|
}
|
|
1138
1169
|
/**
|
|
1139
1170
|
* Input de texto/número del modal de crear/editar registro con opción de ESCANEO
|
|
@@ -1146,14 +1177,14 @@ export function EditField({ field, value, onChange, record }) {
|
|
|
1146
1177
|
* eso el escaneo se cablea también acá (si no, el auto-CRUD de crear producto
|
|
1147
1178
|
* nunca mostraba el botón).
|
|
1148
1179
|
*/
|
|
1149
|
-
function ScannableRecordInput({ field, value, onChange, inputType, }) {
|
|
1180
|
+
function ScannableRecordInput({ field, value, onChange, inputType, invalid, className, }) {
|
|
1150
1181
|
const [scanOpen, setScanOpen] = useState(false);
|
|
1151
1182
|
// El botón de escaneo aparece siempre que el campo declara `scan` (como el
|
|
1152
1183
|
// POS), sin esconderse por `isCameraScanSupported()`. El BarcodeScanner ya
|
|
1153
1184
|
// muestra un mensaje amable cuando el navegador no tiene cámara.
|
|
1154
1185
|
const scanEnabled = !!(field.scan ??
|
|
1155
1186
|
field.scannable);
|
|
1156
|
-
const input = (_jsx(Input, { type: inputType, value: value ?? '', onChange: (e) => onChange(inputType === 'number' ? (e.target.value === '' ? '' : Number(e.target.value)) : e.target.value), placeholder: field.placeholder }));
|
|
1187
|
+
const input = (_jsx(Input, { type: inputType, value: value ?? '', onChange: (e) => onChange(inputType === 'number' ? (e.target.value === '' ? '' : Number(e.target.value)) : e.target.value), placeholder: field.placeholder, "aria-invalid": invalid || undefined, className: className }));
|
|
1157
1188
|
if (!scanEnabled)
|
|
1158
1189
|
return input;
|
|
1159
1190
|
return (_jsxs("div", { className: "flex w-full min-w-0 items-center gap-1.5", children: [_jsx("div", { className: "min-w-0 flex-1", children: input }), _jsx(Button, { type: "button", variant: "outline", size: "icon", className: "size-9 shrink-0", onClick: () => setScanOpen(true), title: "Escanear con la c\u00E1mara", "aria-label": "Escanear c\u00F3digo de barras con la c\u00E1mara", children: _jsx(ScanLine, { className: "size-4" }) }), _jsx(BarcodeScanner, { open: scanOpen, onClose: () => setScanOpen(false), onDetected: (code) => onChange(code),
|
|
@@ -122,6 +122,33 @@ export declare function getVisibleWhen(field: {
|
|
|
122
122
|
* `getVisibleWhen` to normalize first.
|
|
123
123
|
*/
|
|
124
124
|
export declare function evaluateVisibleWhen(cond: VisibleWhen | null | undefined, formValues: Record<string, any> | null | undefined): boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Strip a DynamicTable / URL filter token down to the comparable scalar the
|
|
127
|
+
* kernel `visible_when.equals` / `.in` predicates expect.
|
|
128
|
+
*
|
|
129
|
+
* `eq:customer` → `customer`, bare `customer` stays, `in:a,b` keeps the raw
|
|
130
|
+
* multi-value (list-scope only gates on known single-eq scopes today).
|
|
131
|
+
*/
|
|
132
|
+
export declare function scopeValueFromFilterToken(raw: unknown): string;
|
|
133
|
+
/**
|
|
134
|
+
* Flat "known field → value" map for list/board surfaces. Built from locked
|
|
135
|
+
* `defaultFilters` (nav / branch scope) plus active `dynamicFilters`. Only
|
|
136
|
+
* fields present here are considered known — see
|
|
137
|
+
* `evaluateVisibleWhenForListScope`.
|
|
138
|
+
*/
|
|
139
|
+
export declare function buildListScopeValues(defaultFilters?: Record<string, unknown> | null, dynamicFilters?: Record<string, string[] | undefined> | null): Record<string, string>;
|
|
140
|
+
/**
|
|
141
|
+
* List/board variant of `evaluateVisibleWhen`.
|
|
142
|
+
*
|
|
143
|
+
* Forms always have a live sibling value (or ''). Lists often do not — a
|
|
144
|
+
* mixed AccountStatement table has no single `party_type`. Hiding every
|
|
145
|
+
* `visible_when` column when the governing field is unknown would wipe both
|
|
146
|
+
* Cliente and Proveedor on the unscoped view. Rule: if the governing field is
|
|
147
|
+
* not in `scope` (or is empty), keep the column; once the scope pins it
|
|
148
|
+
* (sidebar locked_scope / defaultFilters / a single-eq chip), apply the same
|
|
149
|
+
* predicate as the form.
|
|
150
|
+
*/
|
|
151
|
+
export declare function evaluateVisibleWhenForListScope(cond: VisibleWhen | null | undefined, scope: Record<string, any> | null | undefined): boolean;
|
|
125
152
|
/**
|
|
126
153
|
* Reads a field's enriched options-resolution config, tolerating the camelCase
|
|
127
154
|
* `optionsConfig` (authored SDK shape) and the snake_case `options_config` 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,cA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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"}
|
|
@@ -355,6 +355,85 @@ export function evaluateVisibleWhen(cond, formValues) {
|
|
|
355
355
|
// Named a field but declared no comparison → nothing to gate on.
|
|
356
356
|
return true;
|
|
357
357
|
}
|
|
358
|
+
/**
|
|
359
|
+
* Strip a DynamicTable / URL filter token down to the comparable scalar the
|
|
360
|
+
* kernel `visible_when.equals` / `.in` predicates expect.
|
|
361
|
+
*
|
|
362
|
+
* `eq:customer` → `customer`, bare `customer` stays, `in:a,b` keeps the raw
|
|
363
|
+
* multi-value (list-scope only gates on known single-eq scopes today).
|
|
364
|
+
*/
|
|
365
|
+
export function scopeValueFromFilterToken(raw) {
|
|
366
|
+
if (raw == null)
|
|
367
|
+
return '';
|
|
368
|
+
const s = String(raw);
|
|
369
|
+
const i = s.indexOf(':');
|
|
370
|
+
if (i <= 0)
|
|
371
|
+
return s;
|
|
372
|
+
const op = s.slice(0, i).toLowerCase();
|
|
373
|
+
const rest = s.slice(i + 1);
|
|
374
|
+
if (op === 'eq' ||
|
|
375
|
+
op === 'neq' ||
|
|
376
|
+
op === 'gt' ||
|
|
377
|
+
op === 'gte' ||
|
|
378
|
+
op === 'lt' ||
|
|
379
|
+
op === 'lte' ||
|
|
380
|
+
op === 'like' ||
|
|
381
|
+
op === 'ilike' ||
|
|
382
|
+
op === 'contains') {
|
|
383
|
+
return rest;
|
|
384
|
+
}
|
|
385
|
+
return s;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Flat "known field → value" map for list/board surfaces. Built from locked
|
|
389
|
+
* `defaultFilters` (nav / branch scope) plus active `dynamicFilters`. Only
|
|
390
|
+
* fields present here are considered known — see
|
|
391
|
+
* `evaluateVisibleWhenForListScope`.
|
|
392
|
+
*/
|
|
393
|
+
export function buildListScopeValues(defaultFilters, dynamicFilters) {
|
|
394
|
+
const out = {};
|
|
395
|
+
if (defaultFilters) {
|
|
396
|
+
for (const [key, value] of Object.entries(defaultFilters)) {
|
|
397
|
+
const v = scopeValueFromFilterToken(value);
|
|
398
|
+
if (v !== '')
|
|
399
|
+
out[key] = v;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
if (dynamicFilters) {
|
|
403
|
+
for (const [key, values] of Object.entries(dynamicFilters)) {
|
|
404
|
+
if (defaultFilters && key in defaultFilters)
|
|
405
|
+
continue;
|
|
406
|
+
if (!values || values.length !== 1)
|
|
407
|
+
continue;
|
|
408
|
+
const v = scopeValueFromFilterToken(values[0]);
|
|
409
|
+
if (v !== '')
|
|
410
|
+
out[key] = v;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return out;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* List/board variant of `evaluateVisibleWhen`.
|
|
417
|
+
*
|
|
418
|
+
* Forms always have a live sibling value (or ''). Lists often do not — a
|
|
419
|
+
* mixed AccountStatement table has no single `party_type`. Hiding every
|
|
420
|
+
* `visible_when` column when the governing field is unknown would wipe both
|
|
421
|
+
* Cliente and Proveedor on the unscoped view. Rule: if the governing field is
|
|
422
|
+
* not in `scope` (or is empty), keep the column; once the scope pins it
|
|
423
|
+
* (sidebar locked_scope / defaultFilters / a single-eq chip), apply the same
|
|
424
|
+
* predicate as the form.
|
|
425
|
+
*/
|
|
426
|
+
export function evaluateVisibleWhenForListScope(cond, scope) {
|
|
427
|
+
if (!cond || typeof cond.field !== 'string' || cond.field.trim() === '')
|
|
428
|
+
return true;
|
|
429
|
+
const key = cond.field.trim();
|
|
430
|
+
if (!scope || !(key in scope))
|
|
431
|
+
return true;
|
|
432
|
+
const raw = scope[key];
|
|
433
|
+
if (raw == null || String(raw) === '')
|
|
434
|
+
return true;
|
|
435
|
+
return evaluateVisibleWhen(cond, scope);
|
|
436
|
+
}
|
|
358
437
|
/**
|
|
359
438
|
* Reads a field's enriched options-resolution config, tolerating the camelCase
|
|
360
439
|
* `optionsConfig` (authored SDK shape) and the snake_case `options_config` the
|
|
@@ -88,7 +88,9 @@ export interface DynamicSelectFieldProps {
|
|
|
88
88
|
* host's create modal renders them locked. Pairs with `createDefaults`.
|
|
89
89
|
*/
|
|
90
90
|
createLockedFields?: string[];
|
|
91
|
+
/** Paint trigger with destructive border when validation failed. */
|
|
92
|
+
invalid?: boolean;
|
|
91
93
|
}
|
|
92
|
-
export declare function DynamicSelectField({ field, value, onChange, seedOption, dependsValue, dependsHint, readonly, staticOptions, descriptionAsBadge, hideCreate, createDefaults, createLockedFields, }: DynamicSelectFieldProps): import("react").JSX.Element;
|
|
94
|
+
export declare function DynamicSelectField({ field, value, onChange, seedOption, dependsValue, dependsHint, readonly, staticOptions, descriptionAsBadge, hideCreate, createDefaults, createLockedFields, invalid, }: DynamicSelectFieldProps): import("react").JSX.Element;
|
|
93
95
|
export default DynamicSelectField;
|
|
94
96
|
//# sourceMappingURL=dynamic-select-field.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-select-field.d.ts","sourceRoot":"","sources":["../src/dynamic-select-field.tsx"],"names":[],"mappings":"AA4CA,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAEhF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,gDAAgD,CAAA;AAEjF;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,EACxB,KAAK,EACL,IAAI,EACJ,IAAS,GACZ,EAAE;IACC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,IAAI,C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gB,kBAAkB,CAAC,EAC/B,KAAK,EACL,KAAK,EACL,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,WAAW,EACX,QAAgB,EAChB,aAAoB,EACpB,kBAA0B,EAC1B,UAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,OAAe,GAClB,EAAE,uBAAuB,+BA0TzB;AAED,eAAe,kBAAkB,CAAA"}
|
|
@@ -88,7 +88,7 @@ export function OptionLead({ option, size = 20, }) {
|
|
|
88
88
|
function useDebounced(value, ms) {
|
|
89
89
|
return useDebouncedValue(value, ms);
|
|
90
90
|
}
|
|
91
|
-
export function DynamicSelectField({ field, value, onChange, seedOption, dependsValue, dependsHint, readonly = false, staticOptions = null, descriptionAsBadge = false, hideCreate = false, createDefaults, createLockedFields, }) {
|
|
91
|
+
export function DynamicSelectField({ field, value, onChange, seedOption, dependsValue, dependsHint, readonly = false, staticOptions = null, descriptionAsBadge = false, hideCreate = false, createDefaults, createLockedFields, invalid = false, }) {
|
|
92
92
|
const { t } = useTranslation();
|
|
93
93
|
const ph = (fallback) => field.placeholder ? t(field.placeholder, { defaultValue: field.placeholder }) : fallback;
|
|
94
94
|
const [open, setOpen] = useState(false);
|
|
@@ -221,7 +221,8 @@ export function DynamicSelectField({ field, value, onChange, seedOption, depends
|
|
|
221
221
|
// (the long empty-state placeholder) and overflows the column, pushing the
|
|
222
222
|
// "+" off-screen — it only "fit" once a short value was selected.
|
|
223
223
|
return (_jsxs("div", { className: "flex w-full min-w-0 items-center gap-1.5", children: [_jsxs(Popover, { open: open && !blockedByDependency, onOpenChange: (o) => { if (!blockedByDependency)
|
|
224
|
-
setOpen(o); }, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs(Button, { type: "button", variant: "outline", role: "combobox", "aria-expanded": open, id: field.key, disabled: blockedByDependency,
|
|
224
|
+
setOpen(o); }, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs(Button, { type: "button", variant: "outline", role: "combobox", "aria-expanded": open, id: field.key, disabled: blockedByDependency, "aria-invalid": invalid || undefined, className: 'min-w-0 flex-1 justify-between font-normal' +
|
|
225
|
+
(invalid ? ' border-destructive ring-1 ring-destructive/30' : ''), "data-empty": !value, "data-depends-blocked": blockedByDependency ? '' : undefined, children: [_jsxs("span", { className: "flex min-w-0 flex-1 items-center gap-2 text-left", children: [value && selectedOption ? (_jsx(OptionLead, { option: selectedOption, size: 20 })) : null, _jsx("span", { className: 'min-w-0 flex-1 truncate ' + (selectedLabel ? '' : 'text-muted-foreground'), children: blockedByDependency
|
|
225
226
|
? (dependsHint || DEFAULT_DEPENDS_HINT)
|
|
226
227
|
: selectedLabel || ph('Buscar…') }), descriptionAsBadge && selectedOption?.description ? (_jsx(Badge, { variant: "secondary", className: "shrink-0 font-normal tabular-nums", children: selectedOption.description })) : null] }), _jsx(ChevronsUpDown, { className: "ml-2 size-4 shrink-0 opacity-50" })] }) }), _jsx(PopoverContent, { className: "p-0", align: "start",
|
|
227
228
|
// Match the trigger width without an arbitrary Tailwind class
|
package/dist/dynamic-table.d.ts
CHANGED
|
@@ -40,13 +40,6 @@ export interface DynamicTableProps {
|
|
|
40
40
|
*/
|
|
41
41
|
onRowClick?: (row: any) => void;
|
|
42
42
|
refreshTrigger?: any;
|
|
43
|
-
/**
|
|
44
|
-
* Refetch when the host's realtime client reports a data event for this
|
|
45
|
-
* model (created/updated/deleted by anyone in the org, or a `resync`).
|
|
46
|
-
* Off by default; `<RealtimeProvider defaultRealtime>` turns it on for
|
|
47
|
-
* every table, and an explicit prop always wins. No-op without a client.
|
|
48
|
-
*/
|
|
49
|
-
realtime?: boolean;
|
|
50
43
|
defaultFilters?: Record<string, any>;
|
|
51
44
|
extraColumns?: ColumnDef<any>[];
|
|
52
45
|
/**
|
|
@@ -91,5 +84,5 @@ export interface DynamicTableProps {
|
|
|
91
84
|
*/
|
|
92
85
|
infiniteScroll?: boolean;
|
|
93
86
|
}
|
|
94
|
-
export declare function DynamicTable({ model, endpoint, mutationEndpoint, enableUrlSync, hideImport, hideExport, hiddenColumns, allowedActionKeys, onAction, onRowClick, refreshTrigger,
|
|
87
|
+
export declare function DynamicTable({ model, endpoint, mutationEndpoint, enableUrlSync, hideImport, hideExport, hiddenColumns, allowedActionKeys, onAction, onRowClick, refreshTrigger, defaultFilters, extraColumns, getDynamicColumns, timeZone, currency, pagination: paginationMode, infiniteScroll: infiniteScrollProp, }: DynamicTableProps): import("react").JSX.Element;
|
|
95
88
|
//# sourceMappingURL=dynamic-table.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-table.d.ts","sourceRoot":"","sources":["../src/dynamic-table.tsx"],"names":[],"mappings":"AAgBA,OAAO,EAKH,KAAK,SAAS,EAajB,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"dynamic-table.d.ts","sourceRoot":"","sources":["../src/dynamic-table.tsx"],"names":[],"mappings":"AAgBA,OAAO,EAKH,KAAK,SAAS,EAajB,MAAM,uBAAuB,CAAA;AAgC9B,OAAO,KAAK,EAAsB,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAkGnF,MAAM,WAAW,iBAAiB;IAC9B,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,6DAA6D;IAC7D,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;IACxB;;;;;;;;;OASG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC5B,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,IAAI,CAAA;IAC7C;;;;;OAKG;IACH,UAAU,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IA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