@asteby/metacore-runtime-react 53.26.0 → 53.28.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 +20 -0
- package/dist/action-modal-dispatcher.d.ts.map +1 -1
- package/dist/action-modal-dispatcher.js +5 -0
- package/dist/business/customer-picker.d.ts +10 -1
- package/dist/business/customer-picker.d.ts.map +1 -1
- package/dist/business/customer-picker.js +3 -2
- package/dist/dialogs/create-record-dialog.d.ts +1 -1
- package/dist/dialogs/create-record-dialog.d.ts.map +1 -1
- package/dist/dialogs/create-record-dialog.js +2 -2
- package/dist/dialogs/dynamic-record.d.ts +13 -1
- package/dist/dialogs/dynamic-record.d.ts.map +1 -1
- package/dist/dialogs/dynamic-record.js +41 -23
- package/dist/dialogs/types.d.ts +2 -0
- package/dist/dialogs/types.d.ts.map +1 -1
- package/dist/dynamic-crud-page.d.ts.map +1 -1
- package/dist/dynamic-crud-page.js +3 -0
- package/dist/dynamic-form.d.ts.map +1 -1
- package/dist/dynamic-form.js +13 -5
- package/dist/dynamic-line-items.d.ts.map +1 -1
- package/dist/dynamic-line-items.js +5 -0
- package/dist/dynamic-multi-select-field.d.ts.map +1 -1
- package/dist/dynamic-multi-select-field.js +5 -5
- package/dist/field-widget-registry.d.ts +6 -0
- package/dist/field-widget-registry.d.ts.map +1 -1
- package/dist/host-api-client.d.ts +17 -0
- package/dist/host-api-client.d.ts.map +1 -1
- package/dist/host-api-client.js +10 -4
- package/dist/host-api.d.ts +14 -0
- package/dist/host-api.d.ts.map +1 -1
- package/dist/host-api.js +23 -3
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/model-labels.d.ts +26 -0
- package/dist/model-labels.d.ts.map +1 -1
- package/dist/model-labels.js +22 -5
- package/dist/record-picker-dialog.d.ts +4 -1
- package/dist/record-picker-dialog.d.ts.map +1 -1
- package/dist/record-picker-dialog.js +2 -2
- package/dist/record-picker.d.ts +11 -0
- package/dist/record-picker.d.ts.map +1 -1
- package/dist/record-picker.js +17 -4
- package/dist/searchable-select-field.d.ts +33 -0
- package/dist/searchable-select-field.d.ts.map +1 -0
- package/dist/searchable-select-field.js +50 -0
- package/dist/searchable-select.d.ts +45 -0
- package/dist/searchable-select.d.ts.map +1 -0
- package/dist/searchable-select.js +72 -0
- package/dist/types.d.ts +22 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/use-host-api-client.js +1 -1
- package/package.json +5 -5
- package/src/__tests__/dynamic-record-texts.test.tsx +22 -0
- package/src/__tests__/field-widget-set-values.test.tsx +65 -0
- package/src/__tests__/host-api-client.test.tsx +12 -0
- package/src/__tests__/host-api.test.ts +41 -0
- package/src/__tests__/model-labels.test.tsx +41 -1
- package/src/__tests__/record-picker-open-on-focus.test.tsx +49 -0
- package/src/__tests__/searchable-select.test.tsx +247 -0
- package/src/action-modal-dispatcher.tsx +16 -0
- package/src/business/customer-picker.tsx +13 -0
- package/src/dialogs/create-record-dialog.tsx +2 -0
- package/src/dialogs/dynamic-record.tsx +74 -26
- package/src/dialogs/types.ts +2 -0
- package/src/dynamic-crud-page.tsx +3 -0
- package/src/dynamic-form.tsx +26 -2
- package/src/dynamic-line-items.tsx +17 -0
- package/src/dynamic-multi-select-field.tsx +5 -4
- package/src/field-widget-registry.tsx +6 -0
- package/src/host-api-client.ts +24 -5
- package/src/host-api.ts +28 -3
- package/src/index.ts +4 -2
- package/src/model-labels.ts +45 -5
- package/src/record-picker-dialog.tsx +5 -0
- package/src/record-picker.tsx +42 -3
- package/src/searchable-select-field.tsx +134 -0
- package/src/searchable-select.ts +87 -0
- package/src/types.ts +22 -0
- package/src/use-host-api-client.ts +1 -1
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// the image-url resolver and the org IANA timezone — are passed as props so the
|
|
11
11
|
// SDK stays transport- and host-agnostic.
|
|
12
12
|
import { emitRecordMutation } from '../record-mutation-events'
|
|
13
|
+
import { modelVerbTitle, resolveModelNoun } from '../model-labels'
|
|
13
14
|
import { createContext, lazy, Suspense, useCallback, useContext, useEffect, useId, useMemo, useRef, useState } from 'react'
|
|
14
15
|
import { useTranslation } from 'react-i18next'
|
|
15
16
|
import type { ModelSchema } from './types'
|
|
@@ -54,6 +55,8 @@ import { useBranchCreateGate } from '../branch-create-gate'
|
|
|
54
55
|
import { toastServerError, extractFieldErrors, localizeFieldIssue, localizeFieldErrorMap } from '../server-error'
|
|
55
56
|
import { DynamicSelectField, OptionLead, OptionThumb } from '../dynamic-select-field'
|
|
56
57
|
import { RecordPicker } from '../record-picker'
|
|
58
|
+
import { SearchableSelectField } from '../searchable-select-field'
|
|
59
|
+
import { isSearchableSelect } from '../searchable-select'
|
|
57
60
|
import { DynamicMultiSelectField } from '../dynamic-multi-select-field'
|
|
58
61
|
import { UploadField, validateUploadFile } from '../upload-field'
|
|
59
62
|
import { DynamicRelations } from '../dynamic-relations'
|
|
@@ -117,6 +120,8 @@ export interface FieldOption {
|
|
|
117
120
|
color?: string
|
|
118
121
|
icon?: string
|
|
119
122
|
image?: string
|
|
123
|
+
/** Secondary text; also matched by the searchable select search box. */
|
|
124
|
+
description?: string
|
|
120
125
|
}
|
|
121
126
|
|
|
122
127
|
export interface FieldDef {
|
|
@@ -131,6 +136,14 @@ export interface FieldDef {
|
|
|
131
136
|
*/
|
|
132
137
|
nullable?: boolean
|
|
133
138
|
options?: FieldOption[]
|
|
139
|
+
/**
|
|
140
|
+
* Searchable select: `true` always renders the combobox with a search box,
|
|
141
|
+
* `false` always the flat select, unset = combobox when the field has more
|
|
142
|
+
* than SEARCHABLE_SELECT_THRESHOLD (8) options. Served by the kernel as
|
|
143
|
+
* `searchable`. `searchThreshold` overrides the 8.
|
|
144
|
+
*/
|
|
145
|
+
searchable?: boolean
|
|
146
|
+
searchThreshold?: number
|
|
134
147
|
defaultValue?: any
|
|
135
148
|
placeholder?: string
|
|
136
149
|
readonly?: boolean
|
|
@@ -274,6 +287,9 @@ interface ModalMetadata {
|
|
|
274
287
|
titleKey?: string
|
|
275
288
|
createTitle?: string
|
|
276
289
|
editTitle?: string
|
|
290
|
+
/** Backend-localized singular noun ("cliente"): feeds "Crear/Editar/Eliminar {noun}". Host i18n `models.<model>.singular` wins. */
|
|
291
|
+
singular_label?: string
|
|
292
|
+
singularLabel?: string
|
|
277
293
|
/**
|
|
278
294
|
* Optional per-model dialog texts. When present they replace the generic
|
|
279
295
|
* description / submit label of the mode; absent → the built-in texts.
|
|
@@ -322,13 +338,17 @@ interface ModalMetadata {
|
|
|
322
338
|
messages?: { created?: string; updated?: string; deleted?: string }
|
|
323
339
|
}
|
|
324
340
|
|
|
325
|
-
type TFn = (key: string) => string
|
|
341
|
+
type TFn = (key: string, opts?: Record<string, unknown>) => string
|
|
326
342
|
|
|
327
343
|
// localizedModelName resolves the (possibly addon-i18n) model name: prefer the
|
|
328
344
|
// translated titleKey, fall back to the backend-provided raw title.
|
|
329
|
-
function localizedModelName(meta: ModalMetadata, t: TFn): string {
|
|
330
|
-
|
|
331
|
-
|
|
345
|
+
function localizedModelName(meta: ModalMetadata, t: TFn, model = ''): string {
|
|
346
|
+
return resolveModelNoun(t, {
|
|
347
|
+
model,
|
|
348
|
+
singularLabel: meta.singular_label ?? meta.singularLabel,
|
|
349
|
+
titleKey: meta.titleKey,
|
|
350
|
+
title: meta.title,
|
|
351
|
+
})
|
|
332
352
|
}
|
|
333
353
|
|
|
334
354
|
export interface DynamicRecordDialogProps {
|
|
@@ -630,9 +650,9 @@ function modeTexts(
|
|
|
630
650
|
|
|
631
651
|
const MODE_CONFIG = {
|
|
632
652
|
create: {
|
|
633
|
-
getTitle: (meta: ModalMetadata, t: TFn) => {
|
|
634
|
-
const name = localizedModelName(meta, t)
|
|
635
|
-
return name ? `Crear ${name}` : (meta.createTitle || meta.title || 'Nuevo registro')
|
|
653
|
+
getTitle: (meta: ModalMetadata, t: TFn, model = '') => {
|
|
654
|
+
const name = localizedModelName(meta, t, model)
|
|
655
|
+
return name ? modelVerbTitle(t, 'create', name, `Crear ${name}`) : (meta.createTitle || meta.title || 'Nuevo registro')
|
|
636
656
|
},
|
|
637
657
|
description: 'Completa los campos para crear un nuevo registro.',
|
|
638
658
|
submitLabel: 'Crear',
|
|
@@ -640,9 +660,9 @@ const MODE_CONFIG = {
|
|
|
640
660
|
cancelLabel: 'Cancelar',
|
|
641
661
|
},
|
|
642
662
|
edit: {
|
|
643
|
-
getTitle: (meta: ModalMetadata, t: TFn) => {
|
|
644
|
-
const name = localizedModelName(meta, t)
|
|
645
|
-
return name ? `Editar ${name}` : (meta.editTitle || meta.title || 'Editar registro')
|
|
663
|
+
getTitle: (meta: ModalMetadata, t: TFn, model = '') => {
|
|
664
|
+
const name = localizedModelName(meta, t, model)
|
|
665
|
+
return name ? modelVerbTitle(t, 'edit', name, `Editar ${name}`) : (meta.editTitle || meta.title || 'Editar registro')
|
|
646
666
|
},
|
|
647
667
|
description: 'Modifica los campos y guarda los cambios.',
|
|
648
668
|
submitLabel: 'Guardar cambios',
|
|
@@ -650,7 +670,7 @@ const MODE_CONFIG = {
|
|
|
650
670
|
cancelLabel: 'Cancelar',
|
|
651
671
|
},
|
|
652
672
|
view: {
|
|
653
|
-
getTitle: (meta: ModalMetadata, t: TFn) => localizedModelName(meta, t) || meta.title || 'Ver registro',
|
|
673
|
+
getTitle: (meta: ModalMetadata, t: TFn, model = '') => localizedModelName(meta, t, model) || meta.title || 'Ver registro',
|
|
654
674
|
description: 'Información detallada del registro.',
|
|
655
675
|
submitLabel: '',
|
|
656
676
|
submittingLabel: '',
|
|
@@ -1302,14 +1322,21 @@ export function DynamicRecordDialog({
|
|
|
1302
1322
|
}
|
|
1303
1323
|
|
|
1304
1324
|
const title = modalMeta
|
|
1305
|
-
? config.getTitle(modalMeta, t)
|
|
1325
|
+
? config.getTitle(modalMeta, t, model)
|
|
1306
1326
|
: mode === 'create'
|
|
1307
1327
|
? 'Nuevo registro'
|
|
1308
1328
|
: mode === 'edit'
|
|
1309
1329
|
? 'Editar registro'
|
|
1310
1330
|
: 'Ver registro'
|
|
1311
1331
|
|
|
1312
|
-
|
|
1332
|
+
// Generic dialog texts go through the host's i18n (`dynamic.*`, es defaults) so an English host
|
|
1333
|
+
// gets English buttons without per-model metadata; per-model metadata texts still win.
|
|
1334
|
+
const texts = modeTexts(modalMeta, mode, {
|
|
1335
|
+
description: t(`dynamic.${mode}_description`, { defaultValue: config.description }),
|
|
1336
|
+
submitLabel: t(`dynamic.${mode}_submit`, { defaultValue: config.submitLabel }),
|
|
1337
|
+
})
|
|
1338
|
+
const submittingLabel = t(`dynamic.${mode}_submitting`, { defaultValue: config.submittingLabel })
|
|
1339
|
+
const cancelLabel = t(`dynamic.${mode}_cancel`, { defaultValue: config.cancelLabel })
|
|
1313
1340
|
|
|
1314
1341
|
const visibleFields = filterVisibleFields(modalMeta?.fields, mode, formValues, attributeClasses)
|
|
1315
1342
|
|
|
@@ -1339,6 +1366,7 @@ export function DynamicRecordDialog({
|
|
|
1339
1366
|
mode={mode}
|
|
1340
1367
|
locked={isCreate && !!lockedFields?.includes(field.key)}
|
|
1341
1368
|
error={fieldErrors[field.key]}
|
|
1369
|
+
setValues={patch => setFormValues((prev: Record<string, any>) => ({ ...prev, ...patch }))}
|
|
1342
1370
|
onChange={val => {
|
|
1343
1371
|
if (getDeriveFrom(field)) {
|
|
1344
1372
|
if (val === '' || val == null) manualDerived.current.delete(field.key)
|
|
@@ -1568,11 +1596,11 @@ export function DynamicRecordDialog({
|
|
|
1568
1596
|
on; the first step still shows Cancel. */}
|
|
1569
1597
|
{isSteps && clampedStep > 0 ? (
|
|
1570
1598
|
<Button variant="outline" onClick={goBackStep} disabled={saving || deleting}>
|
|
1571
|
-
Anterior
|
|
1599
|
+
{t('dynamic.previous', { defaultValue: 'Anterior' })}
|
|
1572
1600
|
</Button>
|
|
1573
1601
|
) : (
|
|
1574
1602
|
<Button variant="outline" onClick={() => onOpenChange(false)} disabled={saving || deleting}>
|
|
1575
|
-
{
|
|
1603
|
+
{cancelLabel}
|
|
1576
1604
|
</Button>
|
|
1577
1605
|
)}
|
|
1578
1606
|
{isView && onDelete && (
|
|
@@ -1582,12 +1610,12 @@ export function DynamicRecordDialog({
|
|
|
1582
1610
|
disabled={deleting || loading}
|
|
1583
1611
|
>
|
|
1584
1612
|
{deleting && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
|
1585
|
-
{deleting ? 'Eliminando...' : 'Eliminar'}
|
|
1613
|
+
{deleting ? t('dynamic.deleting', { defaultValue: 'Eliminando...' }) : t('dynamic.delete_confirm', { defaultValue: 'Eliminar' })}
|
|
1586
1614
|
</Button>
|
|
1587
1615
|
)}
|
|
1588
1616
|
{isView && onEdit && (
|
|
1589
1617
|
<Button onClick={onEdit} disabled={deleting || loading}>
|
|
1590
|
-
Editar
|
|
1618
|
+
{t('dynamic.edit', { defaultValue: 'Editar' })}
|
|
1591
1619
|
</Button>
|
|
1592
1620
|
)}
|
|
1593
1621
|
{/* Non-final wizard step → "Siguiente" validates the step
|
|
@@ -1595,7 +1623,7 @@ export function DynamicRecordDialog({
|
|
|
1595
1623
|
every non-wizard form) keeps the real submit button. */}
|
|
1596
1624
|
{isEditable && isSteps && !isLastStep && (
|
|
1597
1625
|
<Button type="button" onClick={goNextStep} disabled={saving || loading}>
|
|
1598
|
-
Siguiente
|
|
1626
|
+
{t('dynamic.next', { defaultValue: 'Siguiente' })}
|
|
1599
1627
|
</Button>
|
|
1600
1628
|
)}
|
|
1601
1629
|
{isEditable && (!isSteps || isLastStep) && (
|
|
@@ -1605,7 +1633,7 @@ export function DynamicRecordDialog({
|
|
|
1605
1633
|
disabled={saving || loading}
|
|
1606
1634
|
>
|
|
1607
1635
|
{saving && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
|
1608
|
-
{saving ?
|
|
1636
|
+
{saving ? submittingLabel : texts.submitLabel}
|
|
1609
1637
|
</Button>
|
|
1610
1638
|
)}
|
|
1611
1639
|
</div>
|
|
@@ -1635,6 +1663,8 @@ interface FieldRowProps {
|
|
|
1635
1663
|
value: any
|
|
1636
1664
|
mode: 'view' | 'edit' | 'create'
|
|
1637
1665
|
onChange: (val: any) => void
|
|
1666
|
+
/** Patches several form values at once (forwarded to host field widgets). */
|
|
1667
|
+
setValues?: (patch: Record<string, any>) => void
|
|
1638
1668
|
/** Localized validation error for this field, shown in red under the input. */
|
|
1639
1669
|
error?: string
|
|
1640
1670
|
/**
|
|
@@ -1646,7 +1676,7 @@ interface FieldRowProps {
|
|
|
1646
1676
|
locked?: boolean
|
|
1647
1677
|
}
|
|
1648
1678
|
|
|
1649
|
-
function FieldRow({ field, record, value, mode, onChange, error, locked }: FieldRowProps) {
|
|
1679
|
+
function FieldRow({ field, record, value, mode, onChange, setValues, error, locked }: FieldRowProps) {
|
|
1650
1680
|
// A `readonly` field is server/system-generated (e.g. the GitHub addon's
|
|
1651
1681
|
// `number`/`github_url`, filled by the API after the outbound create). On
|
|
1652
1682
|
// CREATE it is excluded from the form entirely (see `visibleFields`); on EDIT
|
|
@@ -1673,7 +1703,7 @@ function FieldRow({ field, record, value, mode, onChange, error, locked }: Field
|
|
|
1673
1703
|
) : isEditReadonly ? (
|
|
1674
1704
|
<ReadonlyEditField field={field} value={value} />
|
|
1675
1705
|
) : (
|
|
1676
|
-
<EditField field={field} value={value} onChange={onChange} record={record} invalid={!!error} error={error} labelId={labelId} />
|
|
1706
|
+
<EditField field={field} value={value} onChange={onChange} setValues={setValues} record={record} invalid={!!error} error={error} labelId={labelId} />
|
|
1677
1707
|
)}
|
|
1678
1708
|
|
|
1679
1709
|
{error && mode !== 'view' && (
|
|
@@ -2369,12 +2399,14 @@ function JsonObjectViewValue({ value }: { value: Record<string, unknown> }) {
|
|
|
2369
2399
|
)
|
|
2370
2400
|
}
|
|
2371
2401
|
|
|
2372
|
-
export function EditField({ field, value, onChange, record, invalid, error, labelId }: {
|
|
2402
|
+
export function EditField({ field, value, onChange, setValues, record, invalid, error, labelId }: {
|
|
2373
2403
|
field: FieldDef
|
|
2374
2404
|
/** id de la etiqueta visible (FieldRow); el control de tres estados la referencia. */
|
|
2375
2405
|
labelId?: string
|
|
2376
2406
|
value: any
|
|
2377
2407
|
onChange: (val: any) => void
|
|
2408
|
+
/** Patches several form values at once (forwarded to host field widgets). */
|
|
2409
|
+
setValues?: (patch: Record<string, any>) => void
|
|
2378
2410
|
/** The full record being edited — supplies FK relation siblings + line-items. */
|
|
2379
2411
|
record?: any
|
|
2380
2412
|
/** When true, paint the control with a destructive border (Laravel-style). */
|
|
@@ -2401,6 +2433,7 @@ export function EditField({ field, value, onChange, record, invalid, error, labe
|
|
|
2401
2433
|
field={field as unknown as ActionFieldDef}
|
|
2402
2434
|
value={value}
|
|
2403
2435
|
onChange={onChange}
|
|
2436
|
+
setValues={setValues}
|
|
2404
2437
|
error={error}
|
|
2405
2438
|
record={record}
|
|
2406
2439
|
/>
|
|
@@ -2587,10 +2620,24 @@ export function EditField({ field, value, onChange, record, invalid, error, labe
|
|
|
2587
2620
|
}
|
|
2588
2621
|
|
|
2589
2622
|
if (field.type === 'select' && field.options?.length) {
|
|
2623
|
+
// Long static list (or `searchable: true`): combobox with a search box.
|
|
2624
|
+
if (isSearchableSelect(field, field.options.length)) {
|
|
2625
|
+
return (
|
|
2626
|
+
<SearchableSelectField
|
|
2627
|
+
id={field.key}
|
|
2628
|
+
ariaLabel={field.label || field.key}
|
|
2629
|
+
options={field.options}
|
|
2630
|
+
value={value}
|
|
2631
|
+
onChange={onChange}
|
|
2632
|
+
required={!!field.required}
|
|
2633
|
+
invalid={invalid}
|
|
2634
|
+
/>
|
|
2635
|
+
)
|
|
2636
|
+
}
|
|
2590
2637
|
return (
|
|
2591
2638
|
<Select value={String(value ?? '')} onValueChange={onChange}>
|
|
2592
2639
|
<SelectTrigger className={cn("w-full", invalidCls)} aria-invalid={invalid || undefined}>
|
|
2593
|
-
<SelectValue placeholder=
|
|
2640
|
+
<SelectValue placeholder={t('dynamic.select_placeholder', { defaultValue: 'Seleccionar...' })} />
|
|
2594
2641
|
</SelectTrigger>
|
|
2595
2642
|
<SelectContent>
|
|
2596
2643
|
{field.options.map(opt => (
|
|
@@ -2648,7 +2695,7 @@ export function EditField({ field, value, onChange, record, invalid, error, labe
|
|
|
2648
2695
|
<CalendarIcon className="mr-2 h-4 w-4" />
|
|
2649
2696
|
{validDate
|
|
2650
2697
|
? format(validDate, 'PPP', { locale: es })
|
|
2651
|
-
:
|
|
2698
|
+
: t('dynamic.select_date', { defaultValue: 'Seleccionar fecha' })}
|
|
2652
2699
|
</Button>
|
|
2653
2700
|
</PopoverTrigger>
|
|
2654
2701
|
<PopoverContent className="w-auto p-0" align="start">
|
|
@@ -2875,6 +2922,7 @@ function extractArray(res: any): any[] {
|
|
|
2875
2922
|
const searchCache = new Map<string, any[]>()
|
|
2876
2923
|
|
|
2877
2924
|
function SearchField({ field, value, onChange }: { field: FieldDef; value: any; onChange: (val: any) => void }) {
|
|
2925
|
+
const { t } = useTranslation()
|
|
2878
2926
|
const api = useApi()
|
|
2879
2927
|
const [selectedLabel, setSelectedLabel] = useState('')
|
|
2880
2928
|
const ep = field.searchEndpoint!
|
|
@@ -2921,14 +2969,14 @@ function SearchField({ field, value, onChange }: { field: FieldDef; value: any;
|
|
|
2921
2969
|
selected={value ? { value, label: selectedLabel } : null}
|
|
2922
2970
|
renderValue={() => (
|
|
2923
2971
|
<span className={cn('min-w-0 flex-1 truncate', !selectedLabel && 'text-muted-foreground')}>
|
|
2924
|
-
{selectedLabel || `Seleccionar ${what}...`}
|
|
2972
|
+
{selectedLabel || t('dynamic.select_what', { what, defaultValue: `Seleccionar ${what}...` })}
|
|
2925
2973
|
</span>
|
|
2926
2974
|
)}
|
|
2927
2975
|
onSelect={(item) => {
|
|
2928
2976
|
onChange(itemValue(item))
|
|
2929
2977
|
setSelectedLabel(itemLabel(item))
|
|
2930
2978
|
}}
|
|
2931
|
-
searchPlaceholder={`Buscar ${what}...`}
|
|
2979
|
+
searchPlaceholder={t('dynamic.search_what', { what, defaultValue: `Buscar ${what}...` })}
|
|
2932
2980
|
emptyText="Sin resultados."
|
|
2933
2981
|
/>
|
|
2934
2982
|
)
|
package/src/dialogs/types.ts
CHANGED
|
@@ -113,6 +113,8 @@ export interface CreateRecordDialogProps extends RecordDialogProps {
|
|
|
113
113
|
* Ignored outside create mode.
|
|
114
114
|
*/
|
|
115
115
|
lockedFields?: string[]
|
|
116
|
+
/** Fields merged into the modal schema after load (see DynamicRecordDialog.ensureFields). */
|
|
117
|
+
ensureFields?: import('./dynamic-record').FieldDef[]
|
|
116
118
|
/** Notification when a create or update succeeds. */
|
|
117
119
|
onSaved?: () => void
|
|
118
120
|
}
|
|
@@ -192,6 +192,9 @@ export function DynamicCRUDPage(props: DynamicCRUDPageProps) {
|
|
|
192
192
|
model,
|
|
193
193
|
title: metadata?.title,
|
|
194
194
|
titleKey: metadata?.titleKey ?? metadata?.title_key,
|
|
195
|
+
singularLabel: metadata?.singular_label,
|
|
196
|
+
newLabelMeta: metadata?.new_label,
|
|
197
|
+
gender: metadata?.gender,
|
|
195
198
|
titleOverride: titleOverride ?? ext?.title,
|
|
196
199
|
newLabelOverride: newLabel ?? ext?.newLabel,
|
|
197
200
|
newPrefix: strings.newPrefix,
|
package/src/dynamic-form.tsx
CHANGED
|
@@ -34,6 +34,8 @@ import { getOptionFilter } from './option-filter'
|
|
|
34
34
|
import { useOptionsResolver, type ResolvedOption } from './use-options-resolver'
|
|
35
35
|
import { DynamicLineItems } from './dynamic-line-items'
|
|
36
36
|
import { DynamicSelectField } from './dynamic-select-field'
|
|
37
|
+
import { SearchableSelectField } from './searchable-select-field'
|
|
38
|
+
import { isSearchableSelect } from './searchable-select'
|
|
37
39
|
import { DynamicMultiSelectField } from './dynamic-multi-select-field'
|
|
38
40
|
import { DynamicDateField } from './dynamic-date-field'
|
|
39
41
|
import { UploadField } from './upload-field'
|
|
@@ -239,6 +241,8 @@ export function DynamicForm({
|
|
|
239
241
|
try { await onSubmit(data) } finally { setSubmitting(false) }
|
|
240
242
|
}
|
|
241
243
|
|
|
244
|
+
const patchValues = (patch: Record<string, any>) => setValues((prev: Record<string, any>) => ({ ...prev, ...patch }))
|
|
245
|
+
|
|
242
246
|
// Renders one group's fields into the responsive 2-column grid: scalar
|
|
243
247
|
// header fields flow through it; line-items grids (and textareas) span full
|
|
244
248
|
// width so the row table / memo gets room. Shared by every layout mode.
|
|
@@ -254,6 +258,7 @@ export function DynamicForm({
|
|
|
254
258
|
error={errors[field.key]}
|
|
255
259
|
initialValues={initialValues}
|
|
256
260
|
onFieldMeta={onFieldMeta}
|
|
261
|
+
setValues={patchValues}
|
|
257
262
|
/>
|
|
258
263
|
))}
|
|
259
264
|
</div>
|
|
@@ -374,6 +379,8 @@ interface FieldRendererProps {
|
|
|
374
379
|
onFieldMeta?: (key: string, meta: { width?: number; height?: number }) => void
|
|
375
380
|
/** id único (useId) de la etiqueta visible; el control de tres estados la referencia. */
|
|
376
381
|
labelId?: string
|
|
382
|
+
/** Patches several form values at once (forwarded to host field widgets). */
|
|
383
|
+
setValues?: (patch: Record<string, any>) => void
|
|
377
384
|
}
|
|
378
385
|
|
|
379
386
|
interface FieldRowProps extends FieldRendererProps {
|
|
@@ -384,7 +391,7 @@ interface FieldRowProps extends FieldRendererProps {
|
|
|
384
391
|
// component so a STATIC enum select whose options are all gated out by a sibling
|
|
385
392
|
// value (`when`) can hide the ENTIRE row (label included) and run its reset
|
|
386
393
|
// effect with valid hook ordering.
|
|
387
|
-
function FieldRow({ field, value, onChange, values, error, initialValues, onFieldMeta }: FieldRowProps) {
|
|
394
|
+
function FieldRow({ field, value, onChange, values, error, initialValues, onFieldMeta, setValues }: FieldRowProps) {
|
|
388
395
|
// Único por instancia: dos formularios montados con el mismo campo no chocan.
|
|
389
396
|
const labelId = `${useId()}-label`
|
|
390
397
|
const isStaticSelect =
|
|
@@ -425,6 +432,7 @@ function FieldRow({ field, value, onChange, values, error, initialValues, onFiel
|
|
|
425
432
|
error={error}
|
|
426
433
|
onFieldMeta={onFieldMeta}
|
|
427
434
|
labelId={labelId}
|
|
435
|
+
setValues={setValues}
|
|
428
436
|
/>
|
|
429
437
|
{error && <span className="text-red-500 text-sm" role="alert">{error}</span>}
|
|
430
438
|
</div>
|
|
@@ -468,13 +476,14 @@ function FieldRenderer({
|
|
|
468
476
|
error,
|
|
469
477
|
onFieldMeta,
|
|
470
478
|
labelId,
|
|
479
|
+
setValues,
|
|
471
480
|
}: FieldRendererProps & { effectiveOptions?: import('./types').OptionDef[]; error?: string }) {
|
|
472
481
|
// Host-registered widget (`widget: "<name>"`) wins over every built-in and
|
|
473
482
|
// type-based branch. Unregistered names fall through untouched.
|
|
474
483
|
useFieldWidgetRegistryVersion()
|
|
475
484
|
const HostWidget = getFieldWidget(field.widget)
|
|
476
485
|
if (HostWidget) {
|
|
477
|
-
return <HostWidget field={field} value={value} onChange={onChange} error={error} record={values} />
|
|
486
|
+
return <HostWidget field={field} value={value} onChange={onChange} error={error} record={values} setValues={setValues} />
|
|
478
487
|
}
|
|
479
488
|
// Repeatable line-items group → render the row grid. Its value is an array
|
|
480
489
|
// of row objects rather than a scalar.
|
|
@@ -538,6 +547,21 @@ function FieldRenderer({
|
|
|
538
547
|
)
|
|
539
548
|
case 'select': {
|
|
540
549
|
const opts = effectiveOptions ?? field.options
|
|
550
|
+
// Long static list (or `searchable: true`): combobox with a search box
|
|
551
|
+
// instead of a flat dropdown the user has to scroll.
|
|
552
|
+
if (isSearchableSelect(field, opts?.length ?? 0)) {
|
|
553
|
+
return (
|
|
554
|
+
<SearchableSelectField
|
|
555
|
+
id={field.key}
|
|
556
|
+
ariaLabel={field.label || field.key}
|
|
557
|
+
options={opts ?? []}
|
|
558
|
+
value={value}
|
|
559
|
+
onChange={onChange}
|
|
560
|
+
placeholder={field.placeholder || undefined}
|
|
561
|
+
required={!!field.required}
|
|
562
|
+
/>
|
|
563
|
+
)
|
|
564
|
+
}
|
|
541
565
|
return (
|
|
542
566
|
<Select value={value || ''} onValueChange={guardEmptySelect(value, onChange, (opts ?? []).map((o) => o.value))}>
|
|
543
567
|
<SelectTrigger className="w-full"><SelectValue placeholder={field.placeholder || 'Seleccionar...'} /></SelectTrigger>
|
|
@@ -38,6 +38,8 @@ import {
|
|
|
38
38
|
applyOptionWhen,
|
|
39
39
|
} from './dynamic-form-schema'
|
|
40
40
|
import { DynamicSelectField, DEFAULT_DEPENDS_HINT } from './dynamic-select-field'
|
|
41
|
+
import { SearchableSelectField } from './searchable-select-field'
|
|
42
|
+
import { isSearchableSelect } from './searchable-select'
|
|
41
43
|
import { getOptionFilter } from './option-filter'
|
|
42
44
|
import { useOptionsResolver, type ResolvedOption } from './use-options-resolver'
|
|
43
45
|
|
|
@@ -503,6 +505,21 @@ function CellRenderer({ field, value, onChange, onPick, disabled, formValues, ro
|
|
|
503
505
|
const opts = effectiveOptions ?? field.options
|
|
504
506
|
// No option applies under the current sibling value → hide the cell.
|
|
505
507
|
if (effectiveOptions && effectiveOptions.length === 0) return null
|
|
508
|
+
if (isSearchableSelect(field, opts?.length ?? 0)) {
|
|
509
|
+
return (
|
|
510
|
+
<SearchableSelectField
|
|
511
|
+
id={field.key}
|
|
512
|
+
ariaLabel={field.label || field.key}
|
|
513
|
+
options={opts ?? []}
|
|
514
|
+
value={value}
|
|
515
|
+
onChange={onChange}
|
|
516
|
+
placeholder={field.placeholder || undefined}
|
|
517
|
+
required={!!field.required}
|
|
518
|
+
disabled={off}
|
|
519
|
+
invalid={invalid}
|
|
520
|
+
/>
|
|
521
|
+
)
|
|
522
|
+
}
|
|
506
523
|
return (
|
|
507
524
|
<Select value={value || ''} onValueChange={onChange} disabled={off}>
|
|
508
525
|
<SelectTrigger className={'w-full' + (invalidCls ? ` ${invalidCls}` : '')} aria-invalid={invalid || undefined}>
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
// with ONE `?ids=` lookup (useResolveOptionIds): a chip reads "Cargando…" while
|
|
23
23
|
// it resolves and "(registro eliminado)" when the record is gone — never the id.
|
|
24
24
|
import { useMemo, useState } from 'react'
|
|
25
|
+
import { filterSearchableOptions } from './searchable-select'
|
|
25
26
|
import { getOptionFilter } from './option-filter'
|
|
26
27
|
import { RecordPicker } from './record-picker'
|
|
27
28
|
import { OptionLead } from './record-picker-option'
|
|
@@ -89,10 +90,9 @@ export function DynamicMultiSelectField({ field, value, onChange, staticOptions
|
|
|
89
90
|
const label = useStatic ? id : !r ? 'Cargando…' : r.status === 'missing' ? DELETED_RECORD_LABEL : id
|
|
90
91
|
return { id, value: id, label, name: label }
|
|
91
92
|
})
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}, [options, query])
|
|
93
|
+
// Case/accent-insensitive, by label, code and description (shared with the
|
|
94
|
+
// single searchable select); order kept inside each relevance rank.
|
|
95
|
+
const shown = useMemo(() => filterSearchableOptions(options, query), [options, query])
|
|
96
96
|
|
|
97
97
|
const toggle = (o: ResolvedOption) => {
|
|
98
98
|
const id = String(o.id)
|
|
@@ -110,6 +110,7 @@ export function DynamicMultiSelectField({ field, value, onChange, staticOptions
|
|
|
110
110
|
getLabel={(o) => o.label}
|
|
111
111
|
renderLead={(o) => <OptionLead option={o} size={20} />}
|
|
112
112
|
getDescription={(o) => o.description}
|
|
113
|
+
highlightQuery
|
|
113
114
|
value={selected}
|
|
114
115
|
selected={selectedItems}
|
|
115
116
|
onSelect={toggle}
|
|
@@ -37,6 +37,12 @@ export interface FieldWidgetProps {
|
|
|
37
37
|
* record dialog (`EditField`) it is the loaded/edited record.
|
|
38
38
|
*/
|
|
39
39
|
record?: Record<string, any>
|
|
40
|
+
/**
|
|
41
|
+
* Merge several sibling fields into the form at once. For widgets that fill
|
|
42
|
+
* the form from an external source (a scanned document, a lookup) instead of
|
|
43
|
+
* editing their own value. Absent where the host form cannot patch siblings.
|
|
44
|
+
*/
|
|
45
|
+
setValues?: (patch: Record<string, any>) => void
|
|
40
46
|
}
|
|
41
47
|
|
|
42
48
|
export type FieldWidgetComponent = React.ComponentType<FieldWidgetProps>
|
package/src/host-api-client.ts
CHANGED
|
@@ -28,11 +28,26 @@ export interface HostRequestConfig {
|
|
|
28
28
|
* and the other headers it owns; they can never be overridden from here.
|
|
29
29
|
*/
|
|
30
30
|
headers?: Record<string, string>
|
|
31
|
+
/**
|
|
32
|
+
* Per-call timeout (ms) for slow operations; overrides `defaultTimeout`.
|
|
33
|
+
* Finite number >= 0, else ignored. The host clamps it to its ceiling, so
|
|
34
|
+
* `0` means that ceiling (never unlimited unless the host allows it).
|
|
35
|
+
* A timeout rejects the call but the server may still have applied it.
|
|
36
|
+
*/
|
|
37
|
+
timeout?: number
|
|
38
|
+
/**
|
|
39
|
+
* `'network'`: never serve this read from the host's offline cache (use for
|
|
40
|
+
* money-critical reads). Rejects on network failure. Enforced only by hosts
|
|
41
|
+
* that honor it (ops does not yet unless it reads `metacoreFreshness`).
|
|
42
|
+
*/
|
|
43
|
+
freshness?: 'network'
|
|
31
44
|
}
|
|
32
45
|
|
|
33
46
|
export interface HostApiClientOptions {
|
|
34
47
|
/** Headers sent on every call; per-call `headers` win over them. */
|
|
35
48
|
defaultHeaders?: Record<string, string>
|
|
49
|
+
/** Timeout (ms) for every call; a per-call `timeout` wins. */
|
|
50
|
+
defaultTimeout?: number
|
|
36
51
|
}
|
|
37
52
|
|
|
38
53
|
/** Minimal axios-like surface (what DynamicSelectField & co. call). */
|
|
@@ -64,7 +79,7 @@ export interface HostApiClient {
|
|
|
64
79
|
path: string,
|
|
65
80
|
file: File | Blob | FormData,
|
|
66
81
|
fields?: Record<string, string>,
|
|
67
|
-
opts?: { fileField?: string; signal?: AbortSignal },
|
|
82
|
+
opts?: { fileField?: string; signal?: AbortSignal; timeout?: number; headers?: Record<string, string> },
|
|
68
83
|
): Promise<T>
|
|
69
84
|
/**
|
|
70
85
|
* Axios-like adapter for runtime-react fields that expect `{ data }` with
|
|
@@ -96,10 +111,14 @@ function toApiError(e: unknown, signal?: AbortSignal): Error {
|
|
|
96
111
|
/** Build the client over the host-injected {@link HostApi}. */
|
|
97
112
|
export function createHostApiClient(api: HostApi, options: HostApiClientOptions = {}): HostApiClient {
|
|
98
113
|
const defaults = options.defaultHeaders
|
|
99
|
-
|
|
114
|
+
const defaultTimeout = options.defaultTimeout
|
|
115
|
+
// Additive: without defaults or per-call options the config is untouched.
|
|
100
116
|
const cfg = <C extends HostRequestConfig | undefined>(c: C): C => {
|
|
101
|
-
if (!defaults) return c
|
|
102
|
-
|
|
117
|
+
if (!defaults && defaultTimeout === undefined) return c
|
|
118
|
+
const out: HostRequestConfig = { ...(c ?? {}) }
|
|
119
|
+
if (defaults) out.headers = { ...defaults, ...(c?.headers ?? {}) }
|
|
120
|
+
if (defaultTimeout !== undefined && c?.timeout === undefined) out.timeout = defaultTimeout
|
|
121
|
+
return out as C
|
|
103
122
|
}
|
|
104
123
|
const run = async <R,>(p: () => Promise<R>, signal?: AbortSignal): Promise<R> => {
|
|
105
124
|
try {
|
|
@@ -130,7 +149,7 @@ export function createHostApiClient(api: HostApi, options: HostApiClientOptions
|
|
|
130
149
|
form.append(opts?.fileField ?? 'file', file as Blob)
|
|
131
150
|
for (const [k, v] of Object.entries(fields ?? {})) form.append(k, v)
|
|
132
151
|
}
|
|
133
|
-
return body(() => api.post(path, form, cfg(opts?.signal ? { signal: opts.signal } : undefined)), opts?.signal)
|
|
152
|
+
return body(() => api.post(path, form, cfg(opts?.signal || opts?.timeout !== undefined || opts?.headers ? { signal: opts.signal, timeout: opts.timeout, headers: opts.headers } : undefined)), opts?.signal)
|
|
134
153
|
},
|
|
135
154
|
axiosLike: () => {
|
|
136
155
|
// Envelope kept (the runtime-react fields unwrap it themselves),
|
package/src/host-api.ts
CHANGED
|
@@ -33,6 +33,12 @@ export interface CreateHostApiOptions {
|
|
|
33
33
|
* batches.
|
|
34
34
|
*/
|
|
35
35
|
batchGets?: boolean
|
|
36
|
+
/**
|
|
37
|
+
* Ceiling (ms) for a remote's per-call `timeout`. Default 600000 (10 min).
|
|
38
|
+
* A remote asking for more, or for `0`, gets this ceiling. `0` here means
|
|
39
|
+
* the host admits no ceiling (remote `0` = no limit).
|
|
40
|
+
*/
|
|
41
|
+
maxTimeoutMs?: number
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
type AxiosLikeError = {
|
|
@@ -127,12 +133,30 @@ export function sanitizeRemoteHeaders(
|
|
|
127
133
|
return Object.keys(out).length ? out : undefined
|
|
128
134
|
}
|
|
129
135
|
|
|
130
|
-
|
|
136
|
+
export const DEFAULT_MAX_TIMEOUT_MS = 600_000
|
|
137
|
+
|
|
138
|
+
/** Request-config key the host transport reads to bypass its offline cache. */
|
|
139
|
+
export const HOST_FRESHNESS_KEY = 'metacoreFreshness'
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Validate a requested timeout: finite number >= 0 else `undefined` (ignored);
|
|
143
|
+
* clamp to `max` (0 or above max => max; `max === 0` => no ceiling).
|
|
144
|
+
*/
|
|
145
|
+
export function normalizeTimeout(t: unknown, max: number = DEFAULT_MAX_TIMEOUT_MS): number | undefined {
|
|
146
|
+
if (typeof t !== 'number' || !Number.isFinite(t) || t < 0) return undefined
|
|
147
|
+
if (max > 0 && (t === 0 || t > max)) return max
|
|
148
|
+
return t
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function toConfig(opts?: HostApiRequestOptions, maxTimeoutMs?: number): Record<string, unknown> | undefined {
|
|
131
152
|
if (!opts) return undefined
|
|
132
153
|
const config: Record<string, unknown> = {}
|
|
133
154
|
if (opts.params) config.params = opts.params
|
|
134
155
|
if (opts.signal) config.signal = opts.signal
|
|
135
156
|
if (opts.responseType === 'blob') config.responseType = 'blob'
|
|
157
|
+
const timeout = normalizeTimeout(opts.timeout, maxTimeoutMs)
|
|
158
|
+
if (timeout !== undefined) config.timeout = timeout
|
|
159
|
+
if (opts.freshness === 'network') config[HOST_FRESHNESS_KEY] = 'network'
|
|
136
160
|
const headers = sanitizeRemoteHeaders(opts.headers)
|
|
137
161
|
if (headers) config.headers = headers
|
|
138
162
|
return config
|
|
@@ -174,7 +198,7 @@ async function bodyOf<T>(p: Promise<{ data: unknown }>, opts?: HostApiRequestOpt
|
|
|
174
198
|
export function createHostApi(client: ApiClient, options: CreateHostApiOptions = {}): HostApi {
|
|
175
199
|
const capabilityPath = options.capabilityPath ?? '/capabilities/query'
|
|
176
200
|
const withConfig = <A extends unknown[]>(args: A, opts?: HostApiRequestOptions) => {
|
|
177
|
-
const config = toConfig(opts)
|
|
201
|
+
const config = toConfig(opts, options.maxTimeoutMs)
|
|
178
202
|
return config ? ([...args, config] as unknown[]) : (args as unknown[])
|
|
179
203
|
}
|
|
180
204
|
const patch = (client as ApiClient & {
|
|
@@ -184,7 +208,8 @@ export function createHostApi(client: ApiClient, options: CreateHostApiOptions =
|
|
|
184
208
|
get: <T,>(path: string, opts?: HostApiRequestOptions) => {
|
|
185
209
|
const args = withConfig([path], opts) as [string, { params?: Record<string, unknown> }?]
|
|
186
210
|
// A GET with per-call headers cannot share a POST /q: it goes on its own.
|
|
187
|
-
const batch = options.batchGets && opts?.responseType !== 'blob' && !sanitizeRemoteHeaders(opts?.headers)
|
|
211
|
+
const batch = options.batchGets && opts?.responseType !== 'blob' && !sanitizeRemoteHeaders(opts?.headers) &&
|
|
212
|
+
opts?.timeout === undefined && opts?.freshness !== 'network'
|
|
188
213
|
return bodyOf<T>(batch ? batchGet(client, ...args) : client.get(...args), opts)
|
|
189
214
|
},
|
|
190
215
|
post: <T,>(path: string, body?: unknown, opts?: HostApiRequestOptions) =>
|
package/src/index.ts
CHANGED
|
@@ -304,7 +304,7 @@ export {
|
|
|
304
304
|
type PageChromeState,
|
|
305
305
|
type PageChromeStore,
|
|
306
306
|
} from './addon-page-host'
|
|
307
|
-
export { createHostApi, toHostApiError, sanitizeRemoteHeaders, PROTECTED_HOST_HEADERS, type CreateHostApiOptions } from './host-api'
|
|
307
|
+
export { createHostApi, toHostApiError, sanitizeRemoteHeaders, PROTECTED_HOST_HEADERS, normalizeTimeout, DEFAULT_MAX_TIMEOUT_MS, HOST_FRESHNESS_KEY, type CreateHostApiOptions } from './host-api'
|
|
308
308
|
export { HostApiProvider, type HostApiProviderProps } from './host-api-context'
|
|
309
309
|
export {
|
|
310
310
|
createHostApiClient,
|
|
@@ -586,6 +586,8 @@ export { DynamicRecordDialog, ViewValue } from './dialogs/dynamic-record'
|
|
|
586
586
|
export { normalizeRefFieldsForSubmit } from './dialogs/normalize-submit'
|
|
587
587
|
export type { DynamicRecordDialogProps, FieldDef, FieldOption, GetImageUrl } from './dialogs/dynamic-record'
|
|
588
588
|
export { CreateRecordDialog } from './dialogs/create-record-dialog'
|
|
589
|
+
export { useInfiniteScrollSentinel, dedupeById } from './use-infinite-scroll'
|
|
590
|
+
export type { UseInfiniteScrollOptions, InfiniteScrollRefs } from './use-infinite-scroll'
|
|
589
591
|
export { EntitySelect } from './entity-select'
|
|
590
592
|
export type { EntitySelectProps, EntitySelectOption } from './entity-select'
|
|
591
593
|
// RecordPicker — the ONE "pick a related record" control (search, single /
|
|
@@ -912,5 +914,5 @@ export type { BatchLog as BulkImageBatchLog } from './bulk-image-import'
|
|
|
912
914
|
export * from './attention'
|
|
913
915
|
export * from './view-system'
|
|
914
916
|
|
|
915
|
-
export { useModelLabels, resolveModelLabels, defaultSingular } from './model-labels'
|
|
917
|
+
export { useModelLabels, resolveModelLabels, resolveModelNoun, modelVerbTitle, defaultSingular } from './model-labels'
|
|
916
918
|
export type { ModelLabels, ModelLabelInput, ModelLabelT } from './model-labels'
|