@asteby/metacore-runtime-react 53.13.1 → 53.15.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 +1 -1
- package/dist/action-modal-dispatcher.d.ts.map +1 -1
- package/dist/action-modal-dispatcher.js +31 -6
- package/dist/dialogs/dynamic-record.d.ts +8 -1
- package/dist/dialogs/dynamic-record.d.ts.map +1 -1
- package/dist/dialogs/dynamic-record.js +34 -4
- package/dist/dynamic-columns.d.ts.map +1 -1
- package/dist/dynamic-columns.js +4 -0
- package/dist/dynamic-form-schema.d.ts.map +1 -1
- package/dist/dynamic-form-schema.js +5 -1
- package/dist/dynamic-form.d.ts.map +1 -1
- package/dist/dynamic-form.js +28 -3
- package/dist/dynamic-kanban.d.ts.map +1 -1
- package/dist/dynamic-kanban.js +33 -1
- package/dist/dynamic-line-items.d.ts.map +1 -1
- package/dist/dynamic-line-items.js +9 -1
- package/dist/dynamic-table.d.ts.map +1 -1
- package/dist/dynamic-table.js +7 -0
- package/dist/field-grid.d.ts +3 -1
- package/dist/field-grid.d.ts.map +1 -1
- package/dist/field-grid.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/nullable-boolean.d.ts +48 -0
- package/dist/nullable-boolean.d.ts.map +1 -0
- package/dist/nullable-boolean.js +80 -0
- package/dist/slots/addon-slot.d.ts +91 -0
- package/dist/slots/addon-slot.d.ts.map +1 -0
- package/dist/slots/addon-slot.js +219 -0
- package/dist/slots/index.d.ts +3 -0
- package/dist/slots/index.d.ts.map +1 -0
- package/dist/slots/index.js +2 -0
- package/dist/slots/sdk-range.d.ts +6 -0
- package/dist/slots/sdk-range.d.ts.map +1 -0
- package/dist/slots/sdk-range.js +92 -0
- package/dist/tri-state-boolean-impl.d.ts +24 -0
- package/dist/tri-state-boolean-impl.d.ts.map +1 -0
- package/dist/tri-state-boolean-impl.js +35 -0
- package/dist/tri-state-boolean.d.ts +15 -0
- package/dist/tri-state-boolean.d.ts.map +1 -0
- package/dist/tri-state-boolean.js +24 -0
- package/dist/use-dynamic-filters.d.ts.map +1 -1
- package/dist/use-dynamic-filters.js +10 -0
- package/package.json +5 -5
- package/src/__tests__/addon-slot.test.tsx +280 -0
- package/src/__tests__/nullable-boolean.test.tsx +458 -0
- package/src/__tests__/slot-legacy.test.tsx +34 -0
- package/src/action-modal-dispatcher.tsx +32 -6
- package/src/dialogs/dynamic-record.tsx +53 -5
- package/src/dynamic-columns.tsx +3 -0
- package/src/dynamic-form-schema.ts +4 -1
- package/src/dynamic-form.tsx +31 -2
- package/src/dynamic-kanban.tsx +6 -1
- package/src/dynamic-line-items.tsx +9 -1
- package/src/dynamic-table.tsx +5 -0
- package/src/field-grid.tsx +4 -0
- package/src/index.ts +1 -0
- package/src/nullable-boolean.ts +96 -0
- package/src/slots/addon-slot.tsx +452 -0
- package/src/slots/index.ts +18 -0
- package/src/slots/sdk-range.ts +86 -0
- package/src/tri-state-boolean-impl.tsx +71 -0
- package/src/tri-state-boolean.tsx +39 -0
- package/src/use-dynamic-filters.ts +8 -0
|
@@ -68,6 +68,8 @@ import { FieldSection, WizardProgress } from '../form-layout-ui'
|
|
|
68
68
|
import { AssistInterview } from '../assist-interview'
|
|
69
69
|
import { RecordPrefillBar } from '../record-prefill-bar'
|
|
70
70
|
import { FieldCell } from '../field-grid'
|
|
71
|
+
import { isNullableBooleanField, omitUntouchedNullBooleans, usesTriState } from '../nullable-boolean'
|
|
72
|
+
import { NullBooleanMark, TriStateBooleanField } from '../tri-state-boolean'
|
|
71
73
|
import { isNilUuid, normalizeNilUuid } from '../nil-uuid'
|
|
72
74
|
import { normalizeRefFieldsForSubmit } from './normalize-submit'
|
|
73
75
|
import { validateValues, bagHasErrors, exemptUnchangedRuleIssues } from '../validator'
|
|
@@ -115,6 +117,11 @@ export interface FieldDef {
|
|
|
115
117
|
type: 'text' | 'textarea' | 'select' | 'search' | 'number' | 'date' | 'email' | 'url' | 'boolean' | 'image'
|
|
116
118
|
| 'password' | 'phone' | 'tel' | 'checkbox' | 'time' | 'hidden' | 'multiselect' | 'file' | string
|
|
117
119
|
required?: boolean
|
|
120
|
+
/**
|
|
121
|
+
* Contrato de nulabilidad del kernel (`nullable = !required`). En un
|
|
122
|
+
* booleano decide el control de tres estados (Sí / No / Sin definir).
|
|
123
|
+
*/
|
|
124
|
+
nullable?: boolean
|
|
118
125
|
options?: FieldOption[]
|
|
119
126
|
defaultValue?: any
|
|
120
127
|
placeholder?: string
|
|
@@ -235,7 +242,9 @@ export function pickDeclaredFieldValues(
|
|
|
235
242
|
const out: Record<string, any> = {}
|
|
236
243
|
for (const f of fields ?? []) {
|
|
237
244
|
if (f.key in values) {
|
|
238
|
-
|
|
245
|
+
// Un booleano opcional en null viaja null («Sin definir»): '' lo
|
|
246
|
+
// descartaría el kernel y no podría volver a NULL.
|
|
247
|
+
out[f.key] = values[f.key] === null && isNullableBooleanField(f) ? null : values[f.key] ?? ''
|
|
239
248
|
} else if (!getVisibleWhen(f) && !f.hidden && f.type !== 'hidden' && !f.readonly) {
|
|
240
249
|
out[f.key] = ''
|
|
241
250
|
}
|
|
@@ -856,9 +865,16 @@ export function DynamicRecordDialog({
|
|
|
856
865
|
const seedForm = (meta: ModalMetadata, rec: any) => {
|
|
857
866
|
const initial: Record<string, any> = {}
|
|
858
867
|
for (const field of meta.fields ?? []) {
|
|
868
|
+
const v = resolvePath(rec, field.key)
|
|
869
|
+
// Booleano opcional en NULL: se queda null («Sin definir»). Si
|
|
870
|
+
// cayera al default o a '' el PUT lo convertiría en otro valor.
|
|
871
|
+
if (v === null && isNullableBooleanField(field)) {
|
|
872
|
+
initial[field.key] = null
|
|
873
|
+
continue
|
|
874
|
+
}
|
|
859
875
|
initial[field.key] = isPasswordField(field)
|
|
860
876
|
? ''
|
|
861
|
-
:
|
|
877
|
+
: v ?? field.defaultValue ?? ''
|
|
862
878
|
}
|
|
863
879
|
// En edición, un destino derivado ya guardado no se pisa: cuenta como manual.
|
|
864
880
|
if (!isCreate) {
|
|
@@ -1118,6 +1134,10 @@ export function DynamicRecordDialog({
|
|
|
1118
1134
|
normalizeRefFieldsForSubmit(submittedValues, modalMeta.fields),
|
|
1119
1135
|
modalMeta.fields,
|
|
1120
1136
|
)
|
|
1137
|
+
// Edición: un booleano NULL que nadie tocó no viaja (conserva el NULL).
|
|
1138
|
+
if (mode === 'edit' && record) {
|
|
1139
|
+
payload = omitUntouchedNullBooleans(payload, modalMeta.fields, (k) => resolvePath(record, k))
|
|
1140
|
+
}
|
|
1121
1141
|
|
|
1122
1142
|
if (
|
|
1123
1143
|
isCreate &&
|
|
@@ -1525,10 +1545,12 @@ function FieldRow({ field, record, value, mode, onChange, error, locked }: Field
|
|
|
1525
1545
|
// CREATE for a caller-specified field (see `lockedFields`).
|
|
1526
1546
|
const isEditReadonly = (mode === 'edit' && !!field.readonly) || !!locked
|
|
1527
1547
|
const { t } = useTranslation()
|
|
1548
|
+
// Único por instancia (dos diálogos abiertos con el mismo campo no chocan).
|
|
1549
|
+
const labelId = `${useId()}-label`
|
|
1528
1550
|
|
|
1529
1551
|
return (
|
|
1530
1552
|
<div className="flex flex-col gap-1.5" data-aby-field={field.key}>
|
|
1531
|
-
<Label className="text-sm font-medium text-foreground/80">
|
|
1553
|
+
<Label id={labelId} className="text-sm font-medium text-foreground/80">
|
|
1532
1554
|
{localizeFieldLabel(field.label, t)}
|
|
1533
1555
|
{field.required && mode !== 'view' && !isEditReadonly && (
|
|
1534
1556
|
<span className="text-destructive ml-0.5">*</span>
|
|
@@ -1540,7 +1562,7 @@ function FieldRow({ field, record, value, mode, onChange, error, locked }: Field
|
|
|
1540
1562
|
) : isEditReadonly ? (
|
|
1541
1563
|
<ReadonlyEditField field={field} value={value} />
|
|
1542
1564
|
) : (
|
|
1543
|
-
<EditField field={field} value={value} onChange={onChange} record={record} invalid={!!error} error={error} />
|
|
1565
|
+
<EditField field={field} value={value} onChange={onChange} record={record} invalid={!!error} error={error} labelId={labelId} />
|
|
1544
1566
|
)}
|
|
1545
1567
|
|
|
1546
1568
|
{error && mode !== 'view' && (
|
|
@@ -1564,6 +1586,13 @@ export function ReadonlyEditField({ field, value }: { field: FieldDef; value: an
|
|
|
1564
1586
|
return <HostWidget field={field as unknown as ActionFieldDef} value={value} onChange={noopChange} disabled />
|
|
1565
1587
|
}
|
|
1566
1588
|
if (field.type === 'boolean' || field.type === 'checkbox' || typeof value === 'boolean') {
|
|
1589
|
+
if (value === null || value === undefined || value === '') {
|
|
1590
|
+
return (
|
|
1591
|
+
<div className="flex items-center gap-2 py-1">
|
|
1592
|
+
<NullBooleanMark className="text-sm text-muted-foreground" />
|
|
1593
|
+
</div>
|
|
1594
|
+
)
|
|
1595
|
+
}
|
|
1567
1596
|
return (
|
|
1568
1597
|
<div className="flex items-center gap-2 py-1">
|
|
1569
1598
|
<Switch checked={!!value} disabled />
|
|
@@ -1801,6 +1830,10 @@ export function ViewValue({
|
|
|
1801
1830
|
}
|
|
1802
1831
|
|
|
1803
1832
|
if (field.type === 'boolean' || field.type === 'checkbox' || typeof value === 'boolean') {
|
|
1833
|
+
// NULL no es «No»: se pinta «—» (misma convención que formatDisplayValue).
|
|
1834
|
+
if (value === null || value === undefined || value === '') {
|
|
1835
|
+
return <p className="text-sm py-1"><NullBooleanMark /></p>
|
|
1836
|
+
}
|
|
1804
1837
|
return (
|
|
1805
1838
|
<div className="flex items-center gap-2 py-1">
|
|
1806
1839
|
<Switch checked={!!value} disabled />
|
|
@@ -2225,8 +2258,10 @@ function JsonObjectViewValue({ value }: { value: Record<string, unknown> }) {
|
|
|
2225
2258
|
)
|
|
2226
2259
|
}
|
|
2227
2260
|
|
|
2228
|
-
export function EditField({ field, value, onChange, record, invalid, error }: {
|
|
2261
|
+
export function EditField({ field, value, onChange, record, invalid, error, labelId }: {
|
|
2229
2262
|
field: FieldDef
|
|
2263
|
+
/** id de la etiqueta visible (FieldRow); el control de tres estados la referencia. */
|
|
2264
|
+
labelId?: string
|
|
2230
2265
|
value: any
|
|
2231
2266
|
onChange: (val: any) => void
|
|
2232
2267
|
/** The full record being edited — supplies FK relation siblings + line-items. */
|
|
@@ -2285,6 +2320,19 @@ export function EditField({ field, value, onChange, record, invalid, error }: {
|
|
|
2285
2320
|
)
|
|
2286
2321
|
}
|
|
2287
2322
|
|
|
2323
|
+
// Booleano opcional (nullable): Sí / No / Sin definir. Nunca convierte un
|
|
2324
|
+
// NULL en `false` sin que el usuario lo elija.
|
|
2325
|
+
if (
|
|
2326
|
+
(field.type === 'boolean' || field.type === 'checkbox') &&
|
|
2327
|
+
usesTriState(field, record ? resolvePath(record, field.key) : undefined)
|
|
2328
|
+
) {
|
|
2329
|
+
return (
|
|
2330
|
+
<div className="py-1">
|
|
2331
|
+
<TriStateBooleanField id={field.key} value={value} onChange={onChange} label={localizeFieldLabel(field.label, t)} labelledBy={labelId} invalid={invalid} />
|
|
2332
|
+
</div>
|
|
2333
|
+
)
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2288
2336
|
if (field.type === 'boolean') {
|
|
2289
2337
|
return (
|
|
2290
2338
|
<div className="flex items-center gap-2 py-1">
|
package/src/dynamic-columns.tsx
CHANGED
|
@@ -60,6 +60,7 @@ import { useOptionsResolver } from './use-options-resolver'
|
|
|
60
60
|
import { RowActionsMenu } from './row-actions-menu'
|
|
61
61
|
import type { TableMetadata, ColumnDefinition } from './types'
|
|
62
62
|
import { isColumnVisibleInTable } from './column-visibility'
|
|
63
|
+
import { NullBooleanMark } from './tri-state-boolean'
|
|
63
64
|
import type {
|
|
64
65
|
ColumnFilterConfig,
|
|
65
66
|
GetDynamicColumns,
|
|
@@ -1546,6 +1547,8 @@ export function makeDefaultGetDynamicColumns(
|
|
|
1546
1547
|
}
|
|
1547
1548
|
|
|
1548
1549
|
case 'boolean': {
|
|
1550
|
+
// NULL (booleano opcional sin definir) no es «No».
|
|
1551
|
+
if (value === null || value === undefined) return <NullBooleanMark />
|
|
1549
1552
|
const showText = styleCfg(col, 'show_text', 'showText') !== false
|
|
1550
1553
|
return (
|
|
1551
1554
|
<span className="inline-flex items-center gap-1.5">
|
|
@@ -6,6 +6,7 @@ import type { ActionFieldDef, FieldOptionsConfig, OptionDef, VisibleWhen } from
|
|
|
6
6
|
import { fieldValidationOf } from './validator'
|
|
7
7
|
import { applyOptionWhen, getDependsOn } from './option-when'
|
|
8
8
|
import { resolveValidatorToken } from './use-org-config-bridge'
|
|
9
|
+
import { isNullableBooleanField } from './nullable-boolean'
|
|
9
10
|
|
|
10
11
|
// Viven en option-when.ts (el validador también los usa); se re-exportan aquí
|
|
11
12
|
// para no romper a quien los importaba de este módulo.
|
|
@@ -307,7 +308,9 @@ function fieldToZod(field: ActionFieldDef): ZodTypeAny {
|
|
|
307
308
|
|
|
308
309
|
if (isBool) {
|
|
309
310
|
const base = z.boolean()
|
|
310
|
-
|
|
311
|
+
if (field.required) return base
|
|
312
|
+
// Booleano opcional: acepta null («Sin definir», kernel >= v0.248.4).
|
|
313
|
+
return isNullableBooleanField(field) ? base.nullable().optional() : base.optional()
|
|
311
314
|
}
|
|
312
315
|
|
|
313
316
|
if (isNumeric) {
|
package/src/dynamic-form.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Minimal standalone DynamicForm. Factored from the dynamic-record-dialog
|
|
2
2
|
// pattern + ActionFieldDef renderer so callers can reuse the form layout
|
|
3
3
|
// outside the full record-edit modal.
|
|
4
|
-
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
4
|
+
import { useEffect, useId, useMemo, useRef, useState } from 'react'
|
|
5
5
|
import { groupFieldsBySection, type FormLayout } from './form-layout'
|
|
6
6
|
import { FieldSection, WizardProgress } from './form-layout-ui'
|
|
7
7
|
import { AssistInterview } from './assist-interview'
|
|
@@ -40,6 +40,8 @@ import { UploadField } from './upload-field'
|
|
|
40
40
|
import { IconPickerField } from './icon-picker-field'
|
|
41
41
|
import { ColorPickerField } from './color-picker-field'
|
|
42
42
|
import { getFieldWidget, useFieldWidgetRegistryVersion } from './field-widget-registry'
|
|
43
|
+
import { isBooleanField, isNullableBooleanField, usesTriState } from './nullable-boolean'
|
|
44
|
+
import { TriStateBooleanField } from './tri-state-boolean'
|
|
43
45
|
|
|
44
46
|
export { buildZodSchema, resolveWidget }
|
|
45
47
|
export { DynamicLineItems } from './dynamic-line-items'
|
|
@@ -92,6 +94,18 @@ function seedValues(fields: ActionFieldDef[], initialValues?: Record<string, any
|
|
|
92
94
|
defaults[f.key] = initialValues?.[f.key] ?? f.defaultValue ?? []
|
|
93
95
|
continue
|
|
94
96
|
}
|
|
97
|
+
// Booleano opcional que el registro trae en NULL: se queda en null
|
|
98
|
+
// («Sin definir»), nunca cae al default ni a `false`. El default sólo
|
|
99
|
+
// aplica cuando la llave no viene (alta).
|
|
100
|
+
if (
|
|
101
|
+
initialValues &&
|
|
102
|
+
initialValues[f.key] === null &&
|
|
103
|
+
Object.prototype.hasOwnProperty.call(initialValues, f.key) &&
|
|
104
|
+
isNullableBooleanField(f)
|
|
105
|
+
) {
|
|
106
|
+
defaults[f.key] = null
|
|
107
|
+
continue
|
|
108
|
+
}
|
|
95
109
|
defaults[f.key] = initialValues?.[f.key] ?? f.defaultValue ?? (f.type === 'boolean' ? false : '')
|
|
96
110
|
}
|
|
97
111
|
return defaults
|
|
@@ -214,6 +228,12 @@ export function DynamicForm({
|
|
|
214
228
|
if (touched.current.has(f.key)) continue
|
|
215
229
|
if (data[f.key] === '' || data[f.key] == null) delete data[f.key]
|
|
216
230
|
}
|
|
231
|
+
// Un booleano NULL que nadie tocó no viaja: el update parcial
|
|
232
|
+
// conserva el NULL del registro en vez de pisarlo.
|
|
233
|
+
for (const f of visibleFields) {
|
|
234
|
+
if (!isBooleanField(f) || touched.current.has(f.key)) continue
|
|
235
|
+
if (data[f.key] == null) delete data[f.key]
|
|
236
|
+
}
|
|
217
237
|
}
|
|
218
238
|
setSubmitting(true)
|
|
219
239
|
try { await onSubmit(data) } finally { setSubmitting(false) }
|
|
@@ -352,6 +372,8 @@ interface FieldRendererProps {
|
|
|
352
372
|
*/
|
|
353
373
|
values?: Record<string, any>
|
|
354
374
|
onFieldMeta?: (key: string, meta: { width?: number; height?: number }) => void
|
|
375
|
+
/** id único (useId) de la etiqueta visible; el control de tres estados la referencia. */
|
|
376
|
+
labelId?: string
|
|
355
377
|
}
|
|
356
378
|
|
|
357
379
|
interface FieldRowProps extends FieldRendererProps {
|
|
@@ -363,6 +385,8 @@ interface FieldRowProps extends FieldRendererProps {
|
|
|
363
385
|
// value (`when`) can hide the ENTIRE row (label included) and run its reset
|
|
364
386
|
// effect with valid hook ordering.
|
|
365
387
|
function FieldRow({ field, value, onChange, values, error, initialValues, onFieldMeta }: FieldRowProps) {
|
|
388
|
+
// Único por instancia: dos formularios montados con el mismo campo no chocan.
|
|
389
|
+
const labelId = `${useId()}-label`
|
|
366
390
|
const isStaticSelect =
|
|
367
391
|
resolveWidget(field) === 'select' && !field.ref && Array.isArray(field.options)
|
|
368
392
|
const effectiveOptions = isStaticSelect
|
|
@@ -387,7 +411,7 @@ function FieldRow({ field, value, onChange, values, error, initialValues, onFiel
|
|
|
387
411
|
resolveWidget(field) === 'richtext'
|
|
388
412
|
return (
|
|
389
413
|
<div className={'grid gap-2 ' + (fullWidth ? 'sm:col-span-2' : '')}>
|
|
390
|
-
<Label htmlFor={field.key}>
|
|
414
|
+
<Label id={labelId} htmlFor={field.key}>
|
|
391
415
|
{field.label}
|
|
392
416
|
{field.required && <span className="text-red-500 ml-1">*</span>}
|
|
393
417
|
</Label>
|
|
@@ -400,6 +424,7 @@ function FieldRow({ field, value, onChange, values, error, initialValues, onFiel
|
|
|
400
424
|
effectiveOptions={effectiveOptions}
|
|
401
425
|
error={error}
|
|
402
426
|
onFieldMeta={onFieldMeta}
|
|
427
|
+
labelId={labelId}
|
|
403
428
|
/>
|
|
404
429
|
{error && <span className="text-red-500 text-sm" role="alert">{error}</span>}
|
|
405
430
|
</div>
|
|
@@ -442,6 +467,7 @@ function FieldRenderer({
|
|
|
442
467
|
effectiveOptions,
|
|
443
468
|
error,
|
|
444
469
|
onFieldMeta,
|
|
470
|
+
labelId,
|
|
445
471
|
}: FieldRendererProps & { effectiveOptions?: import('./types').OptionDef[]; error?: string }) {
|
|
446
472
|
// Host-registered widget (`widget: "<name>"`) wins over every built-in and
|
|
447
473
|
// type-based branch. Unregistered names fall through untouched.
|
|
@@ -522,6 +548,9 @@ function FieldRenderer({
|
|
|
522
548
|
)
|
|
523
549
|
}
|
|
524
550
|
case 'switch':
|
|
551
|
+
if (usesTriState(field, initialValues?.[field.key])) {
|
|
552
|
+
return <TriStateBooleanField id={field.key} value={value} onChange={onChange} label={field.label} labelledBy={labelId} />
|
|
553
|
+
}
|
|
525
554
|
return <Switch id={field.key} checked={!!value} onCheckedChange={onChange} />
|
|
526
555
|
case 'number':
|
|
527
556
|
return <Input id={field.key} type="number" value={value ?? ''} onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
package/src/dynamic-kanban.tsx
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
// Transitions: when the metadata carries `transitions[]`, a card may only be
|
|
25
25
|
// dropped into a lane reachable from its current stage. Disallowed lanes dim
|
|
26
26
|
// while dragging and reject the drop.
|
|
27
|
+
import { BOOLEAN_UNSET_FILTER_VALUE } from './nullable-boolean'
|
|
27
28
|
import * as React from 'react'
|
|
28
29
|
import {
|
|
29
30
|
useCallback,
|
|
@@ -723,8 +724,12 @@ export function cardMatchesLaneFunnel(
|
|
|
723
724
|
filter: { field?: string; values?: string[]; text?: string } | undefined,
|
|
724
725
|
): boolean {
|
|
725
726
|
if (!filter?.field) return true
|
|
726
|
-
const
|
|
727
|
+
const value = card?.[filter.field]
|
|
728
|
+
const raw = String(value ?? '')
|
|
727
729
|
if (filter.values && filter.values.length > 0) {
|
|
730
|
+
// «Sin definir» de un booleano (valor de filtro NULL) casa sólo con null
|
|
731
|
+
// explícito: una tarjeta sin la columna o con '' no es «Sin definir».
|
|
732
|
+
if (value === null && filter.values.includes(BOOLEAN_UNSET_FILTER_VALUE)) return true
|
|
728
733
|
return filter.values.includes(raw)
|
|
729
734
|
}
|
|
730
735
|
if (filter.text?.trim()) {
|
|
@@ -18,8 +18,10 @@ import {
|
|
|
18
18
|
SelectTrigger,
|
|
19
19
|
SelectValue,
|
|
20
20
|
} from '@asteby/metacore-ui/primitives'
|
|
21
|
-
import { useEffect, useRef } from 'react'
|
|
21
|
+
import { useEffect, useRef, useState } from 'react'
|
|
22
22
|
import { Plus, Trash2, Check } from 'lucide-react'
|
|
23
|
+
import { usesTriState } from './nullable-boolean'
|
|
24
|
+
import { TriStateBooleanField } from './tri-state-boolean'
|
|
23
25
|
import type { ActionFieldDef } from './types'
|
|
24
26
|
import {
|
|
25
27
|
resolveWidget,
|
|
@@ -407,6 +409,9 @@ interface CellRendererProps {
|
|
|
407
409
|
// a scalar widget).
|
|
408
410
|
function CellRenderer({ field, value, onChange, onPick, disabled, formValues, rowValues, invalid }: CellRendererProps) {
|
|
409
411
|
const widget = resolveWidget(field)
|
|
412
|
+
// Un booleano opcional que llegó en NULL conserva el control de tres
|
|
413
|
+
// estados aunque el usuario elija Sí/No (puede volver a «Sin definir»).
|
|
414
|
+
const [seededNull] = useState(() => value === null)
|
|
410
415
|
const invalidCls = invalid
|
|
411
416
|
? 'border-destructive ring-1 ring-destructive/30 focus-visible:ring-destructive'
|
|
412
417
|
: ''
|
|
@@ -514,6 +519,9 @@ function CellRenderer({ field, value, onChange, onPick, disabled, formValues, ro
|
|
|
514
519
|
)
|
|
515
520
|
}
|
|
516
521
|
case 'switch':
|
|
522
|
+
if (usesTriState(field, seededNull ? null : value)) {
|
|
523
|
+
return <TriStateBooleanField value={value} onChange={onChange} disabled={off} label={field.label} invalid={invalid} />
|
|
524
|
+
}
|
|
517
525
|
return <Switch checked={!!value} onCheckedChange={onChange} disabled={off} />
|
|
518
526
|
case 'number':
|
|
519
527
|
return (
|
package/src/dynamic-table.tsx
CHANGED
|
@@ -74,6 +74,7 @@ import type { ColumnFilterConfig, GetDynamicColumns, RowActionPredicate } from '
|
|
|
74
74
|
import { defaultGetDynamicColumns, DATE_CELL_TYPES, aggregateOf, formatAggregateTotal } from './dynamic-columns'
|
|
75
75
|
import { useFacetLoaders, isLongTextColumn } from './use-facet-loaders'
|
|
76
76
|
import { translateOptionLabels } from './filter-chips'
|
|
77
|
+
import { withBooleanUnsetOption } from './nullable-boolean'
|
|
77
78
|
import { applyColumnFilterFields } from './column-filter-field'
|
|
78
79
|
import { dedupeById, useInfiniteScrollSentinel } from './use-infinite-scroll'
|
|
79
80
|
import {
|
|
@@ -1376,6 +1377,8 @@ export function DynamicTable({
|
|
|
1376
1377
|
// package has no i18n) so header filters, chips and value summaries show
|
|
1377
1378
|
// localized text. A raw value with no key falls through via defaultValue.
|
|
1378
1379
|
const tr = (label: string) => t(label, { defaultValue: label })
|
|
1380
|
+
// «Sin definir» del filtro booleano (NULL), ver withBooleanUnsetOption.
|
|
1381
|
+
const unsetLabel = t('common.unset', { defaultValue: 'Sin definir' })
|
|
1379
1382
|
const stageOptions = (metadata.stages ?? []).map((s) => ({
|
|
1380
1383
|
label: s.label,
|
|
1381
1384
|
value: s.key,
|
|
@@ -1418,6 +1421,7 @@ export function DynamicTable({
|
|
|
1418
1421
|
}
|
|
1419
1422
|
}
|
|
1420
1423
|
if (fType === 'select' && options.length === 0 && !f.searchEndpoint) continue
|
|
1424
|
+
if (fType === 'boolean') options = withBooleanUnsetOption(options, unsetLabel)
|
|
1421
1425
|
map.set(f.key, {
|
|
1422
1426
|
filterType: fType,
|
|
1423
1427
|
filterKey: f.column || f.key,
|
|
@@ -1471,6 +1475,7 @@ export function DynamicTable({
|
|
|
1471
1475
|
? filterOptionsMap.get(c.searchEndpoint!) || []
|
|
1472
1476
|
: []
|
|
1473
1477
|
if (isStageColumn) options = stageOptions
|
|
1478
|
+
if (filterType === 'boolean') options = withBooleanUnsetOption(options, unsetLabel)
|
|
1474
1479
|
|
|
1475
1480
|
// (B) Upgrade a plain text filter to a facet value-picker unless it's
|
|
1476
1481
|
// a long-text/body column (too many unique values to enumerate).
|
package/src/field-grid.tsx
CHANGED
|
@@ -40,11 +40,14 @@ export function FieldCell({
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export function FieldLabel({
|
|
43
|
+
id,
|
|
43
44
|
htmlFor,
|
|
44
45
|
required,
|
|
45
46
|
tone = 'sentence',
|
|
46
47
|
children,
|
|
47
48
|
}: {
|
|
49
|
+
/** Lets a non-labelable control (a radiogroup) point `aria-labelledby` here. */
|
|
50
|
+
id?: string
|
|
48
51
|
htmlFor?: string
|
|
49
52
|
required?: boolean
|
|
50
53
|
/**
|
|
@@ -58,6 +61,7 @@ export function FieldLabel({
|
|
|
58
61
|
}) {
|
|
59
62
|
return (
|
|
60
63
|
<Label
|
|
64
|
+
id={id}
|
|
61
65
|
htmlFor={htmlFor}
|
|
62
66
|
className={
|
|
63
67
|
tone === 'sentence'
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Booleanos opcionales con tres estados: Sí / No / Sin definir.
|
|
2
|
+
//
|
|
3
|
+
// El kernel (>= v0.248.4) conserva NULL en los booleanos opcionales del CRUD
|
|
4
|
+
// dinámico y Get/List devuelven `null` cuando la columna es NULL. Ese NULL
|
|
5
|
+
// significa algo («modo desconocido» en `mp_payments.sandbox`), así que el SDK
|
|
6
|
+
// no puede pintarlo como «No» ni convertirlo en `false` al guardar: un pago de
|
|
7
|
+
// prueba pasaría a parecer real.
|
|
8
|
+
//
|
|
9
|
+
// Regla: un booleano NO requerido (sin `required` y sin
|
|
10
|
+
// `nullable: false` explícito) acepta NULL — es el contrato del kernel, que
|
|
11
|
+
// sirve `nullable = !required`. Esos campos se editan con este control de tres
|
|
12
|
+
// estados; los requeridos siguen con su switch/checkbox de dos estados.
|
|
13
|
+
|
|
14
|
+
type BoolFieldLike = {
|
|
15
|
+
type?: string
|
|
16
|
+
required?: boolean
|
|
17
|
+
nullable?: boolean
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const BOOL_TYPES = new Set(['boolean', 'checkbox'])
|
|
21
|
+
|
|
22
|
+
/** El campo es booleano (tipo `boolean` o `checkbox`). */
|
|
23
|
+
export function isBooleanField(field: BoolFieldLike | undefined | null): boolean {
|
|
24
|
+
return !!field && BOOL_TYPES.has(String(field.type ?? '').toLowerCase())
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* El campo es un booleano que admite NULL: no es requerido y no trae
|
|
29
|
+
* `nullable: false`. Un booleano requerido devuelve false (dos estados).
|
|
30
|
+
*/
|
|
31
|
+
export function isNullableBooleanField(field: BoolFieldLike | undefined | null): boolean {
|
|
32
|
+
if (!isBooleanField(field)) return false
|
|
33
|
+
if (field!.required) return false
|
|
34
|
+
if (field!.nullable === false) return false
|
|
35
|
+
return true
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* ¿Se edita con el control de tres estados? Sólo un booleano que admite NULL y,
|
|
40
|
+
* además, (a) el servidor lo declara `nullable: true` (el kernel lo sirve en los
|
|
41
|
+
* campos del CRUD) o (b) el registro lo trae en NULL. Así un flag opcional de una
|
|
42
|
+
* acción («notificar al cliente») sigue siendo un switch, y un NULL real nunca se
|
|
43
|
+
* pinta como «No».
|
|
44
|
+
*/
|
|
45
|
+
export function usesTriState(
|
|
46
|
+
field: BoolFieldLike | undefined | null,
|
|
47
|
+
original: unknown,
|
|
48
|
+
): boolean {
|
|
49
|
+
if (!isNullableBooleanField(field)) return false
|
|
50
|
+
return field!.nullable === true || original === null
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Valor de filtro «Sin definir» de un booleano: el dialecto de filtros de ops
|
|
55
|
+
* del kernel (`query.ParseOpsFilterValue`) lee `f_<col>=NULL` como `IS NULL`
|
|
56
|
+
* (OpNull). No hay OR entre operadores, así que el filtro booleano es de una
|
|
57
|
+
* sola opción: Sí (`= true`), No (`= false`, excluye NULL) o Sin definir
|
|
58
|
+
* (`IS NULL`).
|
|
59
|
+
*/
|
|
60
|
+
export const BOOLEAN_UNSET_FILTER_VALUE = 'NULL'
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Agrega la opción «Sin definir» a las opciones de un filtro booleano (Sí/No
|
|
64
|
+
* que sirve el host). Sin opciones o si ya está, las devuelve igual.
|
|
65
|
+
*/
|
|
66
|
+
export function withBooleanUnsetOption<T extends { label: string; value: string }>(
|
|
67
|
+
options: T[],
|
|
68
|
+
label: string,
|
|
69
|
+
): T[] {
|
|
70
|
+
if (options.length === 0) return options
|
|
71
|
+
if (options.some((o) => String(o.value).toUpperCase() === BOOLEAN_UNSET_FILTER_VALUE)) return options
|
|
72
|
+
return [...options, { label, value: BOOLEAN_UNSET_FILTER_VALUE } as T]
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Contrato de payload (ops #2252 / kernel v0.248.4): un booleano que no se tocó
|
|
77
|
+
* NO viaja. Quita del payload las llaves booleanas que siguen en NULL igual que
|
|
78
|
+
* en el registro original (el usuario no eligió nada). Un `null` elegido a
|
|
79
|
+
* propósito («Sin definir» sobre un Sí/No guardado) sí viaja como `null` JSON.
|
|
80
|
+
* Nunca convierte a `false`, a `""` ni al texto `"null"`.
|
|
81
|
+
*/
|
|
82
|
+
export function omitUntouchedNullBooleans<T extends Record<string, unknown>>(
|
|
83
|
+
payload: T,
|
|
84
|
+
fields: ReadonlyArray<BoolFieldLike & { key: string }> | undefined,
|
|
85
|
+
original: (key: string) => unknown,
|
|
86
|
+
): T {
|
|
87
|
+
let out: T | undefined
|
|
88
|
+
for (const f of fields ?? []) {
|
|
89
|
+
if (!isBooleanField(f) || !(f.key in payload)) continue
|
|
90
|
+
if (payload[f.key] === null && original(f.key) === null) {
|
|
91
|
+
out ??= { ...payload }
|
|
92
|
+
delete out[f.key]
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return out ?? payload
|
|
96
|
+
}
|