@asteby/metacore-runtime-react 49.12.0 → 50.0.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 +29 -0
- package/dist/dialogs/dynamic-record.d.ts +41 -0
- package/dist/dialogs/dynamic-record.d.ts.map +1 -1
- package/dist/dialogs/dynamic-record.js +134 -11
- package/dist/dialogs/types.d.ts +5 -0
- package/dist/dialogs/types.d.ts.map +1 -1
- package/dist/dynamic-table.d.ts +17 -1
- package/dist/dynamic-table.d.ts.map +1 -1
- package/dist/dynamic-table.js +66 -9
- package/dist/icon-picker-field.d.ts +8 -1
- package/dist/icon-picker-field.d.ts.map +1 -1
- package/dist/icon-picker-field.js +8 -4
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/upload-field.d.ts +21 -0
- package/dist/upload-field.d.ts.map +1 -1
- package/dist/upload-field.js +51 -3
- package/package.json +3 -3
- package/src/__tests__/dynamic-record-edit-payload-upload.test.tsx +231 -0
- package/src/__tests__/dynamic-record-texts.test.tsx +75 -0
- package/src/__tests__/dynamic-table-bulk-delete-reasons.test.tsx +224 -0
- package/src/__tests__/icon-picker-icon-only.test.tsx +49 -0
- package/src/dialogs/dynamic-record.tsx +224 -35
- package/src/dialogs/types.ts +5 -0
- package/src/dynamic-table.tsx +84 -7
- package/src/icon-picker-field.tsx +27 -4
- package/src/types.ts +6 -0
- package/src/upload-field.tsx +57 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @asteby/metacore-runtime-react
|
|
2
2
|
|
|
3
|
+
## 50.0.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- b1954cd: DynamicRecordDialog: tres mejoras opcionales y retrocompatibles (sin las opciones nuevas el comportamiento es idéntico).
|
|
8
|
+
|
|
9
|
+
- `ModalMetadata.editPayload?: 'all' | 'declared'` (alias `edit_payload`). En `mode='edit'`, `'declared'` envía en el PUT solo las claves de los campos declarados en la metadata del modal (un campo declarado vacío va como `''`, para poder borrar valores; los ocultos por `visible_when` siguen fuera). El id solo viaja en la URL / como primer argumento de `onUpdate`. Default `'all'` = hoy. Nota: el formulario ya se siembra solo con los campos declarados, así que `'declared'` además excluye claves añadidas por `onApply` y garantiza el `''`; para NO enviar un campo de estado (p. ej. `approved`) el host debe no declararlo en el modal.
|
|
10
|
+
- `FieldDef.maxSize` (bytes) y `FieldDef.accept` (MIME/extensiones) en campos `file` e `image`: un archivo que no cumple NO se sube a `/upload`; se muestra un error en el campo (`role="alert"`) y, en `image`, también toast. Ambos campos aceptan arrastrar y soltar sobre su zona (el botón/selector sigue operable por teclado). `UploadField` ahora también valida el tipo contra `accept` (antes solo el tamaño). Nuevas claves i18n `common.upload.invalid_type`. Exporta `fileMatchesAccept` y `validateUploadFile`.
|
|
11
|
+
- `FieldDef.deriveFrom?: { field, transform: 'slug' }` (alias `derive_from`): mientras el usuario no edite el campo destino, se pre-rellena con el slug del origen (minúsculas, sin acentos, guiones); al editarlo a mano deja de derivarse (vaciarlo reactiva la derivación). Exporta `slugify`.
|
|
12
|
+
|
|
13
|
+
Nota: `maxSize` y `accept` son validación de comodidad en el cliente (se saltan fácilmente); el backend debe seguir validando tipo y tamaño. En `mode='edit'`, `deriveFrom` no pisa un destino ya guardado (solo deriva si estaba vacío).
|
|
14
|
+
|
|
15
|
+
NO cubierto: subir el archivo multipart directo al endpoint del modelo (como hace hoy el modal de categorías de TV de doctores.lat) — el contrato HTTP sigue siendo `POST /upload` + URL en el JSON; cambiarlo es una decisión de contrato del host.
|
|
16
|
+
|
|
17
|
+
- 95b55c2: DynamicRecordDialog / IconPickerField: `iconOnly` (también `icon_only`) por campo oculta la pestaña "Imagen" del selector de ícono y conserva un valor URL previo como valor actual con opción "Quitar"; y ModalMetadata acepta `createDescription`, `editDescription`, `viewDescription`, `createSubmitLabel`, `editSubmitLabel` (y snake_case) para sustituir la descripción y etiquetas de botón genéricas. Todo opcional: sin ellos el diálogo es idéntico.
|
|
18
|
+
- 479a351: `DynamicTable` y `DynamicKanban` aceptan `isRowActionVisible?: RowActionPredicate` (`(action, row) => boolean`, tipo exportado): un predicado del consumidor que oculta acciones por fila. Se evalúa con AND junto a `requiresState` y `condition` de la metadata (solo puede ocultar más), si lanza la acción se oculta (fail-closed, `console.error`) y sin predicado el comportamiento no cambia. `GetDynamicColumns` recibe un 8º parámetro opcional `rowActionPredicate`; los factories custom pueden ignorarlo. Memoiza el predicado para no reconstruir las columnas.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [b616c74]
|
|
23
|
+
- Updated dependencies [a8b3bce]
|
|
24
|
+
- @asteby/metacore-ui@2.25.0
|
|
25
|
+
|
|
26
|
+
## 49.13.0
|
|
27
|
+
|
|
28
|
+
### Minor Changes
|
|
29
|
+
|
|
30
|
+
- 2982fea: DynamicTable: el borrado masivo ahora muestra el motivo de cada rechazo del servidor. El toast de error conserva el conteo y añade como `description` hasta 3 motivos distintos agrupados con su cuenta ("• motivo (×2)", truncados a 200 caracteres, más "y N más"), como string con saltos de línea entregado en `description`; cómo se muestran esos saltos depende del toast del host. Los mensajes técnicos genéricos de axios ("Request failed with status code 500", "Network Error", "timeout of Nms exceeded") no cuentan como motivo. Si no hay motivo, el toast queda igual que antes. Nueva prop opcional `onBulkDeleteResult({ succeeded, failed })` llamada una vez al terminar (si lanza, se registra con `console.error` y la tabla se refresca igual), con `message` y `status` por fila fallida. Clave i18n nueva `dynamic.bulk_delete_error_more`.
|
|
31
|
+
|
|
3
32
|
## 49.12.0
|
|
4
33
|
|
|
5
34
|
### Minor Changes
|
|
@@ -89,7 +89,48 @@ export interface FieldDef {
|
|
|
89
89
|
* `groupFieldsBySection`.
|
|
90
90
|
*/
|
|
91
91
|
section?: string;
|
|
92
|
+
/** `icon` widget: only lucide names (no "Imagen" tab). */
|
|
93
|
+
iconOnly?: boolean;
|
|
94
|
+
/** snake_case alias for `iconOnly`. */
|
|
95
|
+
icon_only?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* `file` / `image` upload: maximum size in bytes. A larger file is rejected
|
|
98
|
+
* client-side (error toast + inline message) and never POSTed to `/upload`.
|
|
99
|
+
* Absent → no limit (retrocompat).
|
|
100
|
+
*/
|
|
101
|
+
maxSize?: number;
|
|
102
|
+
/**
|
|
103
|
+
* `file` / `image` upload: accept list (`"image/*"`, `"image/png,.webp"`).
|
|
104
|
+
* Forwarded to the file input and also enforced on pick and drag-and-drop.
|
|
105
|
+
* Absent → `image/*` for `image`, anything for `file` (retrocompat).
|
|
106
|
+
*/
|
|
107
|
+
accept?: string;
|
|
108
|
+
/**
|
|
109
|
+
* Pre-fills this field from a sibling while the user has not edited it by
|
|
110
|
+
* hand: `{ field: 'name', transform: 'slug' }` keeps `slug` in sync with
|
|
111
|
+
* `name`. Once the user types in this field it is no longer derived.
|
|
112
|
+
*/
|
|
113
|
+
deriveFrom?: {
|
|
114
|
+
field: string;
|
|
115
|
+
transform: 'slug';
|
|
116
|
+
};
|
|
117
|
+
/** snake_case alias for `deriveFrom`. */
|
|
118
|
+
derive_from?: {
|
|
119
|
+
field: string;
|
|
120
|
+
transform: 'slug';
|
|
121
|
+
};
|
|
92
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Lowercase, accent-free, hyphenated slug ("Asociaciones Médicas" →
|
|
125
|
+
* "asociaciones-medicas"). Pure — used by `FieldDef.deriveFrom`.
|
|
126
|
+
*/
|
|
127
|
+
export declare function slugify(input: unknown): string;
|
|
128
|
+
/**
|
|
129
|
+
* `editPayload: 'declared'` — keeps only the keys of the fields declared in the
|
|
130
|
+
* modal metadata. A declared field with no value is sent as '' (so a value can
|
|
131
|
+
* be cleared); one hidden by `visible_when` (already stripped) stays out.
|
|
132
|
+
*/
|
|
133
|
+
export declare function pickDeclaredFieldValues(values: Record<string, any>, fields: FieldDef[] | undefined): Record<string, any>;
|
|
93
134
|
export interface DynamicRecordDialogProps {
|
|
94
135
|
open: boolean;
|
|
95
136
|
onOpenChange: (open: boolean) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-record.d.ts","sourceRoot":"","sources":["../../src/dialogs/dynamic-record.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AA+C1C,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAGjF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAsB3C,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAEnE,OAAO,EAAqC,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAM1F,YAAY,EAAE,WAAW,EAAE,CAAA;AAE3B,MAAM,WAAW,WAAW;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,QAAQ;IACrB,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,SAAS,GAAG,OAAO,GACrG,UAAU,GAAG,OAAO,GAAG,KAAK,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,aAAa,GAAG,MAAM,GAAG,MAAM,CAAA;IACrG,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,OAAO,CAAC,EAAE,WAAW,EAAE,CAAA;IACvB,YAAY,CAAC,EAAE,GAAG,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAA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, localizeFieldIssue, localizeField
|
|
|
30
30
|
import { DynamicSelectField, OptionLead, OptionThumb } from '../dynamic-select-field';
|
|
31
31
|
import { RecordPicker } from '../record-picker';
|
|
32
32
|
import { DynamicMultiSelectField } from '../dynamic-multi-select-field';
|
|
33
|
-
import { UploadField } from '../upload-field';
|
|
33
|
+
import { UploadField, validateUploadFile } from '../upload-field';
|
|
34
34
|
import { DynamicRelations } from '../dynamic-relations';
|
|
35
35
|
import { AuditInfo, readAuditMeta } from '../audit-info';
|
|
36
36
|
import { useOptionsResolver } from '../use-options-resolver';
|
|
37
|
-
import { getFieldRef, getVisibleWhen, evaluateVisibleWhen, ATTRIBUTE_CLASSES_KEY } from '../dynamic-form-schema';
|
|
37
|
+
import { getFieldRef, getVisibleWhen, evaluateVisibleWhen, getUploadConfig, ATTRIBUTE_CLASSES_KEY } from '../dynamic-form-schema';
|
|
38
38
|
import { useAttributeClasses } from '../attribute-classes';
|
|
39
39
|
import { groupFieldsBySection } from '../form-layout';
|
|
40
40
|
import { FieldSection, WizardProgress } from '../form-layout-ui';
|
|
@@ -55,6 +55,36 @@ import { CollectionCell } from '../collection-cell';
|
|
|
55
55
|
import { ImageUrlContext, identityImageUrl } from '../image-url-context';
|
|
56
56
|
import { getFieldWidget, useFieldWidgetRegistryVersion } from '../field-widget-registry';
|
|
57
57
|
import { TimeZoneContext, CurrencyContext } from '../org-runtime-context';
|
|
58
|
+
/**
|
|
59
|
+
* Lowercase, accent-free, hyphenated slug ("Asociaciones Médicas" →
|
|
60
|
+
* "asociaciones-medicas"). Pure — used by `FieldDef.deriveFrom`.
|
|
61
|
+
*/
|
|
62
|
+
export function slugify(input) {
|
|
63
|
+
return String(input ?? '')
|
|
64
|
+
.normalize('NFD')
|
|
65
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
66
|
+
.toLowerCase()
|
|
67
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
68
|
+
.replace(/^-+|-+$/g, '');
|
|
69
|
+
}
|
|
70
|
+
const getDeriveFrom = (f) => f.deriveFrom ?? f.derive_from;
|
|
71
|
+
/**
|
|
72
|
+
* `editPayload: 'declared'` — keeps only the keys of the fields declared in the
|
|
73
|
+
* modal metadata. A declared field with no value is sent as '' (so a value can
|
|
74
|
+
* be cleared); one hidden by `visible_when` (already stripped) stays out.
|
|
75
|
+
*/
|
|
76
|
+
export function pickDeclaredFieldValues(values, fields) {
|
|
77
|
+
const out = {};
|
|
78
|
+
for (const f of fields ?? []) {
|
|
79
|
+
if (f.key in values) {
|
|
80
|
+
out[f.key] = values[f.key] ?? '';
|
|
81
|
+
}
|
|
82
|
+
else if (!getVisibleWhen(f) && !f.hidden && f.type !== 'hidden' && !f.readonly) {
|
|
83
|
+
out[f.key] = '';
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
58
88
|
// localizedModelName resolves the (possibly addon-i18n) model name: prefer the
|
|
59
89
|
// translated titleKey, fall back to the backend-provided raw title.
|
|
60
90
|
function localizedModelName(meta, t) {
|
|
@@ -233,6 +263,29 @@ function formatDisplayValue(rawValue, field) {
|
|
|
233
263
|
return JSON.stringify(value);
|
|
234
264
|
return String(value);
|
|
235
265
|
}
|
|
266
|
+
// modeTexts resolves the per-model description / submit label for a mode,
|
|
267
|
+
// falling back to the generic MODE_CONFIG strings when metadata omits them.
|
|
268
|
+
function modeTexts(meta, mode, base) {
|
|
269
|
+
const pick = (...v) => v.find((x) => typeof x === 'string' && x.trim() !== '');
|
|
270
|
+
if (!meta)
|
|
271
|
+
return base;
|
|
272
|
+
if (mode === 'create') {
|
|
273
|
+
return {
|
|
274
|
+
description: pick(meta.createDescription, meta.create_description) ?? base.description,
|
|
275
|
+
submitLabel: pick(meta.createSubmitLabel, meta.create_submit_label) ?? base.submitLabel,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
if (mode === 'edit') {
|
|
279
|
+
return {
|
|
280
|
+
description: pick(meta.editDescription, meta.edit_description) ?? base.description,
|
|
281
|
+
submitLabel: pick(meta.editSubmitLabel, meta.edit_submit_label) ?? base.submitLabel,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
return {
|
|
285
|
+
description: pick(meta.viewDescription, meta.view_description) ?? base.description,
|
|
286
|
+
submitLabel: base.submitLabel,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
236
289
|
const MODE_CONFIG = {
|
|
237
290
|
create: {
|
|
238
291
|
getTitle: (meta, t) => {
|
|
@@ -381,6 +434,8 @@ export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf
|
|
|
381
434
|
const [audit, setAudit] = useState(undefined);
|
|
382
435
|
const [record, setRecord] = useState(null);
|
|
383
436
|
const [formValues, setFormValues] = useState({});
|
|
437
|
+
// Derived fields (`deriveFrom`) the user has typed in by hand: no longer derived.
|
|
438
|
+
const manualDerived = useRef(new Set());
|
|
384
439
|
// Classes of the record's category (plus those its saved data carries), for
|
|
385
440
|
// `visible_when.class` fields.
|
|
386
441
|
const attributeClasses = useAttributeClasses(api, modalMeta, formValues, record);
|
|
@@ -415,6 +470,7 @@ export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf
|
|
|
415
470
|
// the wizard to its first step.
|
|
416
471
|
setFieldErrors({});
|
|
417
472
|
setStepIndex(0);
|
|
473
|
+
manualDerived.current.clear();
|
|
418
474
|
let cancelled = false;
|
|
419
475
|
// Seed instantly from the row the table already has so view/edit render
|
|
420
476
|
// without a spinner. The list row carries the pro siblings (resolved
|
|
@@ -429,6 +485,14 @@ export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf
|
|
|
429
485
|
? ''
|
|
430
486
|
: resolvePath(rec, field.key) ?? field.defaultValue ?? '';
|
|
431
487
|
}
|
|
488
|
+
// En edición, un destino derivado ya guardado no se pisa: cuenta como manual.
|
|
489
|
+
if (!isCreate) {
|
|
490
|
+
for (const field of meta.fields ?? []) {
|
|
491
|
+
if (getDeriveFrom(field) && initial[field.key] !== '' && initial[field.key] != null) {
|
|
492
|
+
manualDerived.current.add(field.key);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
432
496
|
setFormValues(initial);
|
|
433
497
|
};
|
|
434
498
|
// A field value is "missing" from the seed row when the list omitted that
|
|
@@ -657,7 +721,10 @@ export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf
|
|
|
657
721
|
// filter, so a DiscountRule with scope=category never submits the
|
|
658
722
|
// product_id / customer_id it isn't showing. Mirrors dynamic-form.tsx,
|
|
659
723
|
// which builds its Zod only over visibleFields.
|
|
660
|
-
|
|
724
|
+
let submittedValues = stripHiddenFieldValues(formValues, modalMeta.fields, mode, attributeClasses);
|
|
725
|
+
if (mode === 'edit' && (modalMeta.editPayload ?? modalMeta.edit_payload) === 'declared') {
|
|
726
|
+
submittedValues = pickDeclaredFieldValues(submittedValues, modalMeta.fields);
|
|
727
|
+
}
|
|
661
728
|
// Empty reference pickers → null (not "" / nil-UUID) so nullable FK
|
|
662
729
|
// columns accept them instead of raising a 23503 FK violation.
|
|
663
730
|
let payload = dropEmptyPasswords(normalizeRefFieldsForSubmit(submittedValues, modalMeta.fields), modalMeta.fields);
|
|
@@ -750,6 +817,7 @@ export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf
|
|
|
750
817
|
: mode === 'edit'
|
|
751
818
|
? 'Editar registro'
|
|
752
819
|
: 'Ver registro';
|
|
820
|
+
const texts = modeTexts(modalMeta, mode, config);
|
|
753
821
|
const visibleFields = filterVisibleFields(modalMeta?.fields, mode, formValues, attributeClasses);
|
|
754
822
|
// Declarative form layout: group the (already visibility-filtered) fields by
|
|
755
823
|
// their section. Empty sections drop out for free. Steps mode only drives a
|
|
@@ -766,7 +834,27 @@ export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf
|
|
|
766
834
|
field.widget === 'textarea' ||
|
|
767
835
|
field.widget === 'richtext';
|
|
768
836
|
return (_jsx(FieldCell, { fullWidth: isFullWidth, children: _jsx(FieldRow, { field: field, record: record, value: formValues[field.key] ?? '', mode: mode, locked: isCreate && !!lockedFields?.includes(field.key), error: fieldErrors[field.key], onChange: val => {
|
|
769
|
-
|
|
837
|
+
if (getDeriveFrom(field)) {
|
|
838
|
+
if (val === '' || val == null)
|
|
839
|
+
manualDerived.current.delete(field.key);
|
|
840
|
+
else
|
|
841
|
+
manualDerived.current.add(field.key);
|
|
842
|
+
}
|
|
843
|
+
setFormValues((prev) => {
|
|
844
|
+
const next = { ...prev, [field.key]: val };
|
|
845
|
+
for (const target of modalMeta?.fields ?? []) {
|
|
846
|
+
const d = getDeriveFrom(target);
|
|
847
|
+
if (!d || d.field !== field.key || d.transform !== 'slug')
|
|
848
|
+
continue;
|
|
849
|
+
if (manualDerived.current.has(target.key))
|
|
850
|
+
continue;
|
|
851
|
+
const current = prev[target.key] ?? '';
|
|
852
|
+
if (current === '' || current === slugify(prev[field.key])) {
|
|
853
|
+
next[target.key] = slugify(val);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
return next;
|
|
857
|
+
});
|
|
770
858
|
setFieldErrors(prev => {
|
|
771
859
|
if (!prev[field.key])
|
|
772
860
|
return prev;
|
|
@@ -794,10 +882,10 @@ export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf
|
|
|
794
882
|
setStepIndex(Math.min(clampedStep + 1, groups.length - 1));
|
|
795
883
|
};
|
|
796
884
|
const goBackStep = () => setStepIndex(Math.max(clampedStep - 1, 0));
|
|
797
|
-
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:
|
|
885
|
+
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: texts.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: [isEditable && (_jsx(RecordPrefillBar, { model: model, mode: isCreate ? 'create' : 'edit', recordId: recordId, values: formValues, allowedKeys: prefillAllowedKeys, onApply: applyPrefill })), _jsxs("form", { id: formId, "data-aby-record-form": "", "data-aby-model": model, "data-aby-mode": mode, onSubmit: handleSubmit, className: "grid gap-y-4", children: [isSteps && (_jsx(WizardProgress, { groups: groups, stepIndex: clampedStep, onStepClick: i => setStepIndex(i) })), (isSteps ? [groups[clampedStep]] : groups).map(group =>
|
|
798
886
|
// An assisted step IS the interview: no form inputs, the
|
|
799
887
|
// provider asks what it needs and fills the fields.
|
|
800
|
-
isSteps && isEditable && group.assist ? (_jsx(AssistInterview, { assist: group.assist, values: formValues, eyebrow: group.title, autoStart: group.assist.trigger !== 'button', onApply: fields => setFormValues(prev => ({ ...prev, ...fields })) }, group.key)) : (_jsxs(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) }), isEditable && group.assist && (_jsx(AssistInterview, { assist: group.assist, values: formValues, eyebrow: group.title, autoStart: group.assist.trigger === 'auto', onApply: fields => setFormValues(prev => ({ ...prev, ...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 }) })), !isCreate && record && audit && (_jsx(AuditInfo, { record: record, audit: audit, timeZone: timeZone, className: "mt-6 border-t pt-3" }))] }) }) }) })) : 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 :
|
|
888
|
+
isSteps && isEditable && group.assist ? (_jsx(AssistInterview, { assist: group.assist, values: formValues, eyebrow: group.title, autoStart: group.assist.trigger !== 'button', onApply: fields => setFormValues(prev => ({ ...prev, ...fields })) }, group.key)) : (_jsxs(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) }), isEditable && group.assist && (_jsx(AssistInterview, { assist: group.assist, values: formValues, eyebrow: group.title, autoStart: group.assist.trigger === 'auto', onApply: fields => setFormValues(prev => ({ ...prev, ...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 }) })), !isCreate && record && audit && (_jsx(AuditInfo, { record: record, audit: audit, timeZone: timeZone, className: "mt-6 border-t pt-3" }))] }) }) }) })) : 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 : texts.submitLabel] }))] })] })] }) }) }));
|
|
801
889
|
}
|
|
802
890
|
function LoadingSkeleton() {
|
|
803
891
|
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))) }));
|
|
@@ -1345,17 +1433,33 @@ function ScannableRecordInput({ field, value, onChange, inputType, invalid, clas
|
|
|
1345
1433
|
// (default) porque suma varios productos seguidos.
|
|
1346
1434
|
continuous: false, position: "fixed", title: `Escanear ${field.label ?? ''}`.trim() })] }));
|
|
1347
1435
|
}
|
|
1348
|
-
function ImageUploadField({ field
|
|
1436
|
+
function ImageUploadField({ field, value, onChange }) {
|
|
1349
1437
|
const { t } = useTranslation();
|
|
1350
1438
|
const api = useApi();
|
|
1351
1439
|
const model = useContext(ModelContext);
|
|
1352
1440
|
const getImageUrl = useContext(ImageUrlContext);
|
|
1353
1441
|
const [uploading, setUploading] = useState(false);
|
|
1442
|
+
const [error, setError] = useState(null);
|
|
1443
|
+
const [dragging, setDragging] = useState(false);
|
|
1354
1444
|
const inputRef = useRef(null);
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1445
|
+
const { accept: declaredAccept, maxSize } = getUploadConfig(field);
|
|
1446
|
+
const accept = declaredAccept || 'image/*';
|
|
1447
|
+
async function upload(file) {
|
|
1448
|
+
const rejected = validateUploadFile(file, { accept: declaredAccept, maxSize });
|
|
1449
|
+
if (rejected) {
|
|
1450
|
+
const msg = rejected === 'type'
|
|
1451
|
+
? t('common.upload.invalid_type', { defaultValue: 'File type not allowed.' })
|
|
1452
|
+
: t('common.upload.too_large', {
|
|
1453
|
+
mb: ((maxSize ?? 0) / (1024 * 1024)).toFixed(1),
|
|
1454
|
+
defaultValue: 'File too large (max {{mb}} MB).',
|
|
1455
|
+
});
|
|
1456
|
+
setError(msg);
|
|
1457
|
+
toast.error(msg);
|
|
1458
|
+
if (inputRef.current)
|
|
1459
|
+
inputRef.current.value = '';
|
|
1358
1460
|
return;
|
|
1461
|
+
}
|
|
1462
|
+
setError(null);
|
|
1359
1463
|
setUploading(true);
|
|
1360
1464
|
try {
|
|
1361
1465
|
const formData = new FormData();
|
|
@@ -1375,7 +1479,26 @@ function ImageUploadField({ field: _field, value, onChange }) {
|
|
|
1375
1479
|
inputRef.current.value = '';
|
|
1376
1480
|
}
|
|
1377
1481
|
}
|
|
1378
|
-
|
|
1482
|
+
function handleFile(e) {
|
|
1483
|
+
const file = e.target.files?.[0];
|
|
1484
|
+
if (!file)
|
|
1485
|
+
return;
|
|
1486
|
+
void upload(file);
|
|
1487
|
+
}
|
|
1488
|
+
return (_jsxs("div", { className: "grid gap-1.5", children: [_jsxs("div", { className: "flex items-center gap-3", onDragOver: (e) => {
|
|
1489
|
+
// Siempre preventDefault: si no, el navegador abre el archivo soltado.
|
|
1490
|
+
e.preventDefault();
|
|
1491
|
+
if (value || uploading)
|
|
1492
|
+
return;
|
|
1493
|
+
setDragging(true);
|
|
1494
|
+
}, onDragLeave: () => setDragging(false), onDrop: (e) => {
|
|
1495
|
+
e.preventDefault();
|
|
1496
|
+
setDragging(false);
|
|
1497
|
+
const dropped = e.dataTransfer?.files?.[0];
|
|
1498
|
+
if (!dropped || value || uploading)
|
|
1499
|
+
return;
|
|
1500
|
+
void upload(dropped);
|
|
1501
|
+
}, children: [value ? (_jsxs("div", { className: "relative", children: [_jsx("img", { src: getImageUrl(String(value)), alt: "", className: "h-16 w-16 rounded-lg object-cover border" }), _jsx("button", { type: "button", onClick: () => onChange(''), className: "absolute -top-1.5 -right-1.5 size-5 bg-destructive text-white rounded-full flex items-center justify-center hover:bg-destructive/90", children: _jsx(XIcon, { className: "size-3" }) })] })) : (_jsx("button", { type: "button", onClick: () => inputRef.current?.click(), disabled: uploading, className: cn('h-16 w-16 rounded-lg border-2 border-dashed border-muted-foreground/30 flex flex-col items-center justify-center gap-1 hover:border-primary/50 hover:bg-muted/50 transition-colors disabled:opacity-50', dragging && 'border-primary/50 bg-muted/50'), children: uploading ? (_jsx(Loader2, { className: "size-4 animate-spin text-muted-foreground" })) : (_jsx(Upload, { className: "size-4 text-muted-foreground" })) })), _jsx("input", { ref: inputRef, type: "file", accept: accept, onChange: handleFile, className: "hidden" }), !value && _jsx("span", { className: "text-xs text-muted-foreground", children: "PNG, JPG, WebP" })] }), error && (_jsx("span", { className: "text-sm text-destructive", role: "alert", children: error }))] }));
|
|
1379
1502
|
}
|
|
1380
1503
|
function extractArray(res) {
|
|
1381
1504
|
const d = res.data;
|
package/dist/dialogs/types.d.ts
CHANGED
|
@@ -28,6 +28,11 @@ export interface ModelSchema {
|
|
|
28
28
|
title?: string;
|
|
29
29
|
createTitle?: string;
|
|
30
30
|
editTitle?: string;
|
|
31
|
+
createDescription?: string;
|
|
32
|
+
editDescription?: string;
|
|
33
|
+
viewDescription?: string;
|
|
34
|
+
createSubmitLabel?: string;
|
|
35
|
+
editSubmitLabel?: string;
|
|
31
36
|
fields?: Array<{
|
|
32
37
|
key: string;
|
|
33
38
|
label: string;
|
|
@@ -1 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CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAClC;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,qDAAqD;IACrD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC5D,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,CAAA;IAChB,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,IAAI,CAAA;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CACjC"}
|
package/dist/dynamic-table.d.ts
CHANGED
|
@@ -127,6 +127,13 @@ export interface DynamicTableProps {
|
|
|
127
127
|
extraBulkActions?: ReactNode | ((ctx: DynamicTableBulkContext) => ReactNode);
|
|
128
128
|
/** Hide the built-in bulk "Eliminar" (e.g. a model whose rows must not be deleted in batch). */
|
|
129
129
|
hideBulkDelete?: boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Called once when a built-in bulk delete finishes, with the ids that were
|
|
132
|
+
* deleted and the ones refused (`message` / `status` come from the server
|
|
133
|
+
* response when available; a cancelled reason prompt has no message). Lets a
|
|
134
|
+
* host persist or log the outcome. The table's own toasts are unaffected.
|
|
135
|
+
*/
|
|
136
|
+
onBulkDeleteResult?: (result: BulkDeleteResult) => void;
|
|
130
137
|
/**
|
|
131
138
|
* First-use content shown instead of "No se encontraron resultados" when the
|
|
132
139
|
* list loaded fine, is empty, and no search/filter is active. Never shown
|
|
@@ -145,5 +152,14 @@ export interface DynamicTableBulkContext {
|
|
|
145
152
|
/** `true` when the user may run `actionKey` on this model; always `true` without a PermissionsProvider. */
|
|
146
153
|
can: (actionKey: string) => boolean;
|
|
147
154
|
}
|
|
148
|
-
|
|
155
|
+
/** Outcome of a built-in bulk delete (see `onBulkDeleteResult`). */
|
|
156
|
+
export interface BulkDeleteResult {
|
|
157
|
+
succeeded: Array<string | number>;
|
|
158
|
+
failed: Array<{
|
|
159
|
+
id: string | number;
|
|
160
|
+
message?: string;
|
|
161
|
+
status?: number;
|
|
162
|
+
}>;
|
|
163
|
+
}
|
|
164
|
+
export declare function DynamicTable({ model, endpoint, mutationEndpoint, enableUrlSync, defaultSort, hideImport, hideExport, hiddenColumns, allowedActionKeys, onAction, onRowClick, isRowActionVisible: rowActionPredicate, refreshTrigger, defaultFilters, extraColumns, getDynamicColumns, timeZone: timeZoneProp, currency: currencyProp, pagination: paginationMode, infiniteScroll: infiniteScrollProp, virtualizeRows, extraBulkActions, hideBulkDelete, onBulkDeleteResult, emptyState, }: DynamicTableProps): import("react").JSX.Element;
|
|
149
165
|
//# sourceMappingURL=dynamic-table.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-table.d.ts","sourceRoot":"","sources":["../src/dynamic-table.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAsE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAM1G,OAAO,EAKH,KAAK,SAAS,EAajB,MAAM,uBAAuB,CAAA;AAmC9B,OAAO,KAAK,EAAsB,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAavG,OAAO,KAAK,EAAgD,gBAAgB,EAAE,MAAM,SAAS,CAAA;AA6F7F,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,WAAW,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;IAC5C;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,6DAA6D;IAC7D,UAAU,CAAC,EAAE,OA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,CAAA;IACvD;;;;OAIG;IACH,UAAU,CAAC,EAAE,SAAS,CAAA;CACzB;AAED,oFAAoF;AACpF,MAAM,WAAW,uBAAuB;IACpC,YAAY,EAAE,GAAG,EAAE,CAAA;IACnB,WAAW,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAA;IACnC,cAAc,EAAE,MAAM,IAAI,CAAA;IAC1B,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,6GAA6G;IAC7G,OAAO,EAAE,gBAAgB,EAAE,CAAA;IAC3B,2GAA2G;IAC3G,GAAG,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAA;CACtC;AAQD,oEAAoE;AACpE,MAAM,WAAW,gBAAgB;IAC7B,SAAS,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAA;IACjC,MAAM,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC5E;AA2CD,wBAAgB,YAAY,CAAC,EACzB,KAAK,EACL,QAAQ,EACR,gBAAgB,EAChB,aAAoB,EACpB,WAAW,EACX,UAAU,EACV,UAAU,EACV,aAAkB,EAClB,iBAAiB,EACjB,QAAQ,EACR,UAAU,EACV,kBAAkB,EAAE,kBAAkB,EACtC,cAAc,EACd,cAAc,EACd,YAAiB,EACjB,iBAA4C,EAC5C,QAAQ,EAAE,YAAY,EACtB,QAAQ,EAAE,YAAY,EACtB,UAAU,EAAE,cAAc,EAC1B,cAAc,EAAE,kBAA0B,EAC1C,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,UAAU,GACb,EAAE,iBAAiB,+BA+pDnB"}
|
package/dist/dynamic-table.js
CHANGED
|
@@ -119,7 +119,48 @@ function isForbiddenError(error) {
|
|
|
119
119
|
const e = error;
|
|
120
120
|
return e?.response?.status === 403 || e?.status === 403;
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
const BULK_REASON_MAX_LEN = 200;
|
|
123
|
+
const BULK_REASON_MAX_GROUPS = 3;
|
|
124
|
+
/** Server text -> trimmed plain string, or undefined when there is nothing usable. */
|
|
125
|
+
function cleanReason(v) {
|
|
126
|
+
if (typeof v !== 'string')
|
|
127
|
+
return undefined;
|
|
128
|
+
const m = v.trim();
|
|
129
|
+
return m ? m : undefined;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Axios' own technical messages ("Request failed with status code 500",
|
|
133
|
+
* "Network Error", "timeout of 5000ms exceeded") say nothing the user can act
|
|
134
|
+
* on, so they never count as a refusal reason. Real server text
|
|
135
|
+
* (`response.data.message`) is unaffected and always wins.
|
|
136
|
+
*/
|
|
137
|
+
const GENERIC_TRANSPORT_MESSAGE = /^(request failed with status code \d+|network error|timeout of \d+ms exceeded)$/i;
|
|
138
|
+
function cleanTransportMessage(v) {
|
|
139
|
+
const m = cleanReason(v);
|
|
140
|
+
return m && !GENERIC_TRANSPORT_MESSAGE.test(m) ? m : undefined;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Groups refusal reasons ("• reason (×N)", at most 3 distinct, each truncated)
|
|
144
|
+
* plus an "and N more" line, as a string with line breaks. It is delivered as
|
|
145
|
+
* the toast `description`; how line breaks are shown depends on the host's toast.
|
|
146
|
+
*/
|
|
147
|
+
function groupBulkReasons(failed, more) {
|
|
148
|
+
const counts = new Map();
|
|
149
|
+
for (const f of failed) {
|
|
150
|
+
if (!f.message)
|
|
151
|
+
continue;
|
|
152
|
+
const m = f.message.length > BULK_REASON_MAX_LEN ? `${f.message.slice(0, BULK_REASON_MAX_LEN - 1)}…` : f.message;
|
|
153
|
+
counts.set(m, (counts.get(m) ?? 0) + 1);
|
|
154
|
+
}
|
|
155
|
+
if (counts.size === 0)
|
|
156
|
+
return undefined;
|
|
157
|
+
const entries = Array.from(counts.entries());
|
|
158
|
+
const lines = entries.slice(0, BULK_REASON_MAX_GROUPS).map(([m, n]) => (n > 1 ? `• ${m} (×${n})` : `• ${m}`));
|
|
159
|
+
if (entries.length > BULK_REASON_MAX_GROUPS)
|
|
160
|
+
lines.push(more(entries.length - BULK_REASON_MAX_GROUPS));
|
|
161
|
+
return lines.join('\n');
|
|
162
|
+
}
|
|
163
|
+
export function DynamicTable({ model, endpoint, mutationEndpoint, enableUrlSync = true, defaultSort, hideImport, hideExport, hiddenColumns = [], allowedActionKeys, onAction, onRowClick, isRowActionVisible: rowActionPredicate, refreshTrigger, defaultFilters, extraColumns = [], getDynamicColumns = defaultGetDynamicColumns, timeZone: timeZoneProp, currency: currencyProp, pagination: paginationMode, infiniteScroll: infiniteScrollProp = false, virtualizeRows, extraBulkActions, hideBulkDelete, onBulkDeleteResult, emptyState, }) {
|
|
123
164
|
// The org's timezone/currency: an explicit prop wins, else the app-wide
|
|
124
165
|
// OrgRuntimeProvider (without it, money fell back to USD).
|
|
125
166
|
const orgTimeZone = useTimeZone();
|
|
@@ -994,7 +1035,8 @@ export function DynamicTable({ model, endpoint, mutationEndpoint, enableUrlSync
|
|
|
994
1035
|
setIsBulkDeleting(true);
|
|
995
1036
|
setBulkDeleteTotal(selectedRows.length);
|
|
996
1037
|
setBulkDeleteProgress(0);
|
|
997
|
-
|
|
1038
|
+
const succeeded = [];
|
|
1039
|
+
const failed = [];
|
|
998
1040
|
// One reason for the whole batch: asked the first time a row is refused
|
|
999
1041
|
// for lacking it (model declares reason_required.delete), reused after.
|
|
1000
1042
|
let bulkReason;
|
|
@@ -1002,7 +1044,7 @@ export function DynamicTable({ model, endpoint, mutationEndpoint, enableUrlSync
|
|
|
1002
1044
|
for (let i = 0; i < selectedRows.length; i++) {
|
|
1003
1045
|
const row = selectedRows[i];
|
|
1004
1046
|
if (bulkCancelled) {
|
|
1005
|
-
|
|
1047
|
+
failed.push({ id: row.original.id });
|
|
1006
1048
|
setBulkDeleteProgress(i + 1);
|
|
1007
1049
|
continue;
|
|
1008
1050
|
}
|
|
@@ -1022,16 +1064,21 @@ export function DynamicTable({ model, endpoint, mutationEndpoint, enableUrlSync
|
|
|
1022
1064
|
});
|
|
1023
1065
|
if (!res) {
|
|
1024
1066
|
bulkCancelled = true;
|
|
1025
|
-
|
|
1067
|
+
failed.push({ id: row.original.id });
|
|
1026
1068
|
}
|
|
1027
1069
|
else if (res.data.success)
|
|
1028
|
-
|
|
1070
|
+
succeeded.push(row.original.id);
|
|
1029
1071
|
else
|
|
1030
|
-
|
|
1072
|
+
failed.push({ id: row.original.id, message: cleanReason(res.data.message) });
|
|
1031
1073
|
}
|
|
1032
1074
|
catch (e) {
|
|
1033
1075
|
console.error('Error al eliminar', e);
|
|
1034
|
-
|
|
1076
|
+
const err = e;
|
|
1077
|
+
failed.push({
|
|
1078
|
+
id: row.original.id,
|
|
1079
|
+
message: cleanReason(err?.response?.data?.message) ?? cleanTransportMessage(err?.message),
|
|
1080
|
+
status: err?.response?.status,
|
|
1081
|
+
});
|
|
1035
1082
|
}
|
|
1036
1083
|
setBulkDeleteProgress(i + 1);
|
|
1037
1084
|
}
|
|
@@ -1041,10 +1088,20 @@ export function DynamicTable({ model, endpoint, mutationEndpoint, enableUrlSync
|
|
|
1041
1088
|
setBulkDeleteProgress(0);
|
|
1042
1089
|
setBulkDeleteTotal(0);
|
|
1043
1090
|
setRowSelection({});
|
|
1091
|
+
const successCount = succeeded.length, errorCount = failed.length;
|
|
1044
1092
|
if (successCount > 0)
|
|
1045
1093
|
toast.success(t('dynamic.bulk_delete_success', { count: successCount, defaultValue: '{{count}} registro(s) eliminado(s) correctamente' }));
|
|
1046
|
-
if (errorCount > 0)
|
|
1047
|
-
|
|
1094
|
+
if (errorCount > 0) {
|
|
1095
|
+
const reasons = groupBulkReasons(failed, (count) => t('dynamic.bulk_delete_error_more', { count, defaultValue: 'y {{count}} más' }));
|
|
1096
|
+
toast.error(t('dynamic.bulk_delete_error', { count: errorCount, defaultValue: '{{count}} registro(s) no pudieron ser eliminados' }), reasons ? { description: reasons, style: { whiteSpace: 'pre-line' } } : undefined);
|
|
1097
|
+
}
|
|
1098
|
+
// A throwing host callback must not skip the refresh nor leave a rejected promise.
|
|
1099
|
+
try {
|
|
1100
|
+
onBulkDeleteResult?.({ succeeded, failed });
|
|
1101
|
+
}
|
|
1102
|
+
catch (e) {
|
|
1103
|
+
console.error('onBulkDeleteResult lanzó un error', e);
|
|
1104
|
+
}
|
|
1048
1105
|
handleRefresh();
|
|
1049
1106
|
};
|
|
1050
1107
|
const handleDynamicFilterChange = useCallback((filterKey, values) => {
|
|
@@ -3,8 +3,15 @@ export interface IconPickerFieldProps {
|
|
|
3
3
|
field: ActionFieldDef;
|
|
4
4
|
value: any;
|
|
5
5
|
onChange: (v: any) => void;
|
|
6
|
+
/**
|
|
7
|
+
* Icon-only mode: hide the "Imagen" tab so the field can only store a
|
|
8
|
+
* lucide icon name. Also read from `field.iconOnly` / `field.icon_only`
|
|
9
|
+
* (metadata). An existing url/path value is preserved untouched until the
|
|
10
|
+
* user picks an icon or clears it (shown as a non-editable current value).
|
|
11
|
+
*/
|
|
12
|
+
iconOnly?: boolean;
|
|
6
13
|
}
|
|
7
14
|
/** True when a stored value looks like an image url/path rather than an icon name. */
|
|
8
15
|
export declare function looksLikeImageValue(value: unknown): boolean;
|
|
9
|
-
export declare function IconPickerField({ field, value, onChange }: IconPickerFieldProps): import("react").JSX.Element;
|
|
16
|
+
export declare function IconPickerField({ field, value, onChange, iconOnly }: IconPickerFieldProps): import("react").JSX.Element;
|
|
10
17
|
//# sourceMappingURL=icon-picker-field.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icon-picker-field.d.ts","sourceRoot":"","sources":["../src/icon-picker-field.tsx"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,MAAM,WAAW,oBAAoB;IACjC,KAAK,EAAE,cAAc,CAAA;IACrB,KAAK,EAAE,GAAG,CAAA;IACV,QAAQ,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"icon-picker-field.d.ts","sourceRoot":"","sources":["../src/icon-picker-field.tsx"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,MAAM,WAAW,oBAAoB;IACjC,KAAK,EAAE,cAAc,CAAA;IACrB,KAAK,EAAE,GAAG,CAAA;IACV,QAAQ,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,CAAA;IAC1B;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACrB;AAQD,sFAAsF;AACtF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE3D;AAED,wBAAgB,eAAe,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,oBAAoB,+BAsKzF"}
|
|
@@ -26,12 +26,16 @@ const ALL_ICON_NAMES = lucideIconNames();
|
|
|
26
26
|
export function looksLikeImageValue(value) {
|
|
27
27
|
return typeof value === 'string' && value !== '' && /[/.]/.test(value);
|
|
28
28
|
}
|
|
29
|
-
export function IconPickerField({ field, value, onChange }) {
|
|
30
|
-
const
|
|
29
|
+
export function IconPickerField({ field, value, onChange, iconOnly }) {
|
|
30
|
+
const onlyIcon = iconOnly ?? field.iconOnly ?? field.icon_only ?? false;
|
|
31
|
+
const [mode, setMode] = useState(() => !onlyIcon && looksLikeImageValue(value) ? 'image' : 'icon');
|
|
32
|
+
// iconOnly + a stored url/path (written before the restriction): keep it,
|
|
33
|
+
// render it as a read-only current value the user can clear or replace.
|
|
34
|
+
const legacyImageValue = onlyIcon && looksLikeImageValue(value);
|
|
31
35
|
const [open, setOpen] = useState(false);
|
|
32
36
|
const [query, setQuery] = useState('');
|
|
33
37
|
const [limit, setLimit] = useState(PAGE);
|
|
34
|
-
const selected = mode === 'icon' ? resolveLucideIconName(value) : null;
|
|
38
|
+
const selected = mode === 'icon' && !legacyImageValue ? resolveLucideIconName(value) : null;
|
|
35
39
|
// Full match list (names only) — filtered by query, not yet capped.
|
|
36
40
|
const matches = useMemo(() => {
|
|
37
41
|
const q = query.trim().toLowerCase().replace(/[\s_-]/g, '');
|
|
@@ -45,7 +49,7 @@ export function IconPickerField({ field, value, onChange }) {
|
|
|
45
49
|
onChange(name);
|
|
46
50
|
setOpen(false);
|
|
47
51
|
};
|
|
48
|
-
return (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsxs("div", { className: "flex gap-1", role: "tablist", "aria-label": "Tipo de \u00EDcono", children: [_jsx(Button, { type: "button", role: "tab", "aria-selected": mode === 'icon', variant: mode === 'icon' ? 'secondary' : 'ghost', size: "sm", onClick: () => setMode('icon'), children: "\u00CDcono" }), _jsx(Button, { type: "button", role: "tab", "aria-selected": mode === 'image', variant: mode === 'image' ? 'secondary' : 'ghost', size: "sm", onClick: () => setMode('image'), children: "Imagen" })] }), mode === 'image' ? (_jsx(UploadField, { field: field, value: value, onChange: onChange })) : (_jsxs(Popover, { open: open, onOpenChange: (o) => {
|
|
52
|
+
return (_jsxs("div", { className: "flex flex-col gap-2", children: [!onlyIcon && (_jsxs("div", { className: "flex gap-1", role: "tablist", "aria-label": "Tipo de \u00EDcono", children: [_jsx(Button, { type: "button", role: "tab", "aria-selected": mode === 'icon', variant: mode === 'icon' ? 'secondary' : 'ghost', size: "sm", onClick: () => setMode('icon'), children: "\u00CDcono" }), _jsx(Button, { type: "button", role: "tab", "aria-selected": mode === 'image', variant: mode === 'image' ? 'secondary' : 'ghost', size: "sm", onClick: () => setMode('image'), children: "Imagen" })] })), legacyImageValue && (_jsxs("div", { className: "flex items-center justify-between gap-2 rounded-md border px-3 py-2 text-sm", "data-testid": "icon-legacy-value", children: [_jsxs("span", { className: "min-w-0 truncate text-muted-foreground", title: String(value), children: ["Valor actual: ", String(value)] }), _jsx(Button, { type: "button", variant: "ghost", size: "sm", onClick: () => onChange(''), children: "Quitar" })] })), mode === 'image' && !onlyIcon ? (_jsx(UploadField, { field: field, value: value, onChange: onChange })) : (_jsxs(Popover, { open: open, onOpenChange: (o) => {
|
|
49
53
|
setOpen(o);
|
|
50
54
|
if (o) {
|
|
51
55
|
// Fresh open: reset the search + paging.
|