@asteby/metacore-runtime-react 53.13.0 → 53.14.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 +22 -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/bulk-image-dialog.d.ts +0 -13
- package/dist/bulk-image-dialog.d.ts.map +1 -1
- package/dist/bulk-image-dialog.js +9 -280
- package/dist/bulk-image-import.d.ts +2 -24
- package/dist/bulk-image-import.d.ts.map +1 -1
- package/dist/bulk-image-import.js +11 -30
- package/dist/bulk-image-target.d.ts +25 -0
- package/dist/bulk-image-target.d.ts.map +1 -0
- package/dist/bulk-image-target.js +30 -0
- package/dist/bulk-image-wizard.d.ts +15 -0
- package/dist/bulk-image-wizard.d.ts.map +1 -0
- package/dist/bulk-image-wizard.js +282 -0
- 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 +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- 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/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 +3 -3
- package/src/__tests__/bulk-image-dialog.test.tsx +3 -3
- package/src/__tests__/nullable-boolean.test.tsx +458 -0
- package/src/action-modal-dispatcher.tsx +32 -6
- package/src/bulk-image-dialog.tsx +21 -496
- package/src/bulk-image-import.ts +2 -51
- package/src/bulk-image-target.ts +55 -0
- package/src/bulk-image-wizard.tsx +494 -0
- 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 +2 -8
- package/src/nullable-boolean.ts +96 -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
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
// Carga masiva de imágenes a nivel catálogo — lógica pura (sin React).
|
|
2
|
+
//
|
|
3
|
+
// Genérica para cualquier modelo con una galería (relación 1:N cuya columna de
|
|
4
|
+
// imagen declara `display_config.gallery: true`): el archivo `SKU.ext`,
|
|
5
|
+
// `SKU_2.ext`… se asigna al registro padre cuyo campo SKU coincide, y cada
|
|
6
|
+
// archivo crea UNA fila hija. Nada aquí conoce productos, Protek ni el kernel:
|
|
7
|
+
// la unión con el SKU se resuelve contra la API de datos existente.
|
|
2
8
|
export const BULK_IMAGE_EXTENSIONS = ['jpg', 'jpeg', 'png', 'webp', 'gif', 'avif'];
|
|
3
9
|
/** Lado largo por debajo del cual la foto se avisa como «baja resolución». */
|
|
4
10
|
export const DEFAULT_MIN_LONG_SIDE = 600;
|
|
@@ -66,35 +72,10 @@ export function chunk(arr, size) {
|
|
|
66
72
|
out.push(arr.slice(i, i + size));
|
|
67
73
|
return out;
|
|
68
74
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
export function deriveBulkImageTarget(relation, childMetadata) {
|
|
74
|
-
if (relation.kind !== 'one_to_many')
|
|
75
|
-
return null;
|
|
76
|
-
const img = relationGalleryColumn(childMetadata);
|
|
77
|
-
if (!img)
|
|
78
|
-
return null;
|
|
79
|
-
// Sin la FK declarada el listado ignoraría `f_<fk>=in:` en silencio y devolvería todo.
|
|
80
|
-
if (!(childMetadata?.columns ?? []).some((c) => c.key === relation.foreign_key))
|
|
81
|
-
return null;
|
|
82
|
-
const sc = (img.styleConfig ?? {});
|
|
83
|
-
const keyOf = (derive) => (childMetadata?.columns ?? []).find((c) => relationColumnUi(c).derive === derive)?.key;
|
|
84
|
-
const storagePath = (sc.storage_path ?? sc.storagePath);
|
|
85
|
-
return {
|
|
86
|
-
childModel: relation.through,
|
|
87
|
-
foreignKey: relation.foreign_key,
|
|
88
|
-
imageKey: img.key,
|
|
89
|
-
widthKey: keyOf('image_width'),
|
|
90
|
-
heightKey: keyOf('image_height'),
|
|
91
|
-
positionKey: keyOf('next_position') ?? (childMetadata?.columns ?? []).find((c) => c.key === 'position')?.key,
|
|
92
|
-
storagePath: typeof storagePath === 'string' && storagePath ? storagePath : undefined,
|
|
93
|
-
accept: img.accept || 'image/*',
|
|
94
|
-
maxSize: img.maxSize ?? img.max_size,
|
|
95
|
-
scope: relation.scope,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
// Configuración (descubierta de la metadata, sin tocar el kernel)
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
export * from './bulk-image-target';
|
|
98
79
|
/** ¿La fila se importa por defecto? (`low_res` sí, con aviso; el usuario puede excluirla). */
|
|
99
80
|
export const isImportable = (r) => r.status === 'ok' || r.status === 'low_res';
|
|
100
81
|
/**
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RelationMeta, TableMetadata } from './types';
|
|
2
|
+
export interface BulkImageTarget {
|
|
3
|
+
/** Modelo hijo (galería), p. ej. `product_images`. */
|
|
4
|
+
childModel: string;
|
|
5
|
+
/** FK del hijo hacia el padre. */
|
|
6
|
+
foreignKey: string;
|
|
7
|
+
/** Columna de imagen (la de `gallery: true`). */
|
|
8
|
+
imageKey: string;
|
|
9
|
+
/** Columnas derivadas (si el modelo las tiene). */
|
|
10
|
+
widthKey?: string;
|
|
11
|
+
heightKey?: string;
|
|
12
|
+
positionKey?: string;
|
|
13
|
+
/** Carpeta de almacenamiento (`storage_path` de la columna). */
|
|
14
|
+
storagePath?: string;
|
|
15
|
+
accept: string;
|
|
16
|
+
maxSize?: number;
|
|
17
|
+
/** Filtros de alcance de la relación (polimórficos): se copian a cada fila. */
|
|
18
|
+
scope?: Record<string, string>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Busca la relación 1:N con galería. Necesita la metadata del hijo (para saber
|
|
22
|
+
* cuál es su columna de imagen); `childMetadata` la resuelve el llamador.
|
|
23
|
+
*/
|
|
24
|
+
export declare function deriveBulkImageTarget(relation: Pick<RelationMeta, 'through' | 'foreign_key' | 'scope' | 'kind'>, childMetadata: Pick<TableMetadata, 'columns'> | null | undefined): BulkImageTarget | null;
|
|
25
|
+
//# sourceMappingURL=bulk-image-target.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bulk-image-target.d.ts","sourceRoot":"","sources":["../src/bulk-image-target.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoB,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAG5E,MAAM,WAAW,eAAe;IAC5B,sDAAsD;IACtD,UAAU,EAAE,MAAM,CAAA;IAClB,kCAAkC;IAClC,UAAU,EAAE,MAAM,CAAA;IAClB,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAA;IAChB,mDAAmD;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,gEAAgE;IAChE,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,+EAA+E;IAC/E,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACjC;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACjC,QAAQ,EAAE,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,aAAa,GAAG,OAAO,GAAG,MAAM,CAAC,EAC1E,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,GAAG,IAAI,GAAG,SAAS,GACjE,eAAe,GAAG,IAAI,CAsBxB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { relationColumnUi, relationGalleryColumn } from './dynamic-relation-helpers';
|
|
2
|
+
/**
|
|
3
|
+
* Busca la relación 1:N con galería. Necesita la metadata del hijo (para saber
|
|
4
|
+
* cuál es su columna de imagen); `childMetadata` la resuelve el llamador.
|
|
5
|
+
*/
|
|
6
|
+
export function deriveBulkImageTarget(relation, childMetadata) {
|
|
7
|
+
if (relation.kind !== 'one_to_many')
|
|
8
|
+
return null;
|
|
9
|
+
const img = relationGalleryColumn(childMetadata);
|
|
10
|
+
if (!img)
|
|
11
|
+
return null;
|
|
12
|
+
// Sin la FK declarada el listado ignoraría `f_<fk>=in:` en silencio y devolvería todo.
|
|
13
|
+
if (!(childMetadata?.columns ?? []).some((c) => c.key === relation.foreign_key))
|
|
14
|
+
return null;
|
|
15
|
+
const sc = (img.styleConfig ?? {});
|
|
16
|
+
const keyOf = (derive) => (childMetadata?.columns ?? []).find((c) => relationColumnUi(c).derive === derive)?.key;
|
|
17
|
+
const storagePath = (sc.storage_path ?? sc.storagePath);
|
|
18
|
+
return {
|
|
19
|
+
childModel: relation.through,
|
|
20
|
+
foreignKey: relation.foreign_key,
|
|
21
|
+
imageKey: img.key,
|
|
22
|
+
widthKey: keyOf('image_width'),
|
|
23
|
+
heightKey: keyOf('image_height'),
|
|
24
|
+
positionKey: keyOf('next_position') ?? (childMetadata?.columns ?? []).find((c) => c.key === 'position')?.key,
|
|
25
|
+
storagePath: typeof storagePath === 'string' && storagePath ? storagePath : undefined,
|
|
26
|
+
accept: img.accept || 'image/*',
|
|
27
|
+
maxSize: img.maxSize ?? img.max_size,
|
|
28
|
+
scope: relation.scope,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type BulkImageTarget } from './bulk-image-import';
|
|
2
|
+
export type BulkImageDialogProps = DialogProps;
|
|
3
|
+
interface DialogProps {
|
|
4
|
+
open: boolean;
|
|
5
|
+
onOpenChange: (o: boolean) => void;
|
|
6
|
+
model: string;
|
|
7
|
+
target: BulkImageTarget;
|
|
8
|
+
skuKey: string;
|
|
9
|
+
dataBase: string;
|
|
10
|
+
minLongSide?: number;
|
|
11
|
+
onChange?: () => void;
|
|
12
|
+
}
|
|
13
|
+
export declare function BulkImageDialog({ open, onOpenChange, model, target, skuKey, dataBase, minLongSide, onChange }: DialogProps): import("react").JSX.Element;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=bulk-image-wizard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bulk-image-wizard.d.ts","sourceRoot":"","sources":["../src/bulk-image-wizard.tsx"],"names":[],"mappings":"AA2BA,OAAO,EAkBH,KAAK,eAAe,EAGvB,MAAM,qBAAqB,CAAA;AAwC5B,MAAM,MAAM,oBAAoB,GAAG,WAAW,CAAA;AAE9C,UAAU,WAAW;IACjB,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;IAClC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;CACxB;AAED,wBAAgB,eAAe,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE,WAAW,+BAwY1H"}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// Asistente de carga masiva (se carga bajo demanda desde bulk-image-dialog.tsx para no
|
|
3
|
+
// engordar el JS inicial del shell). Ver el encabezado de ese archivo.
|
|
4
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import { Button, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@asteby/metacore-ui/primitives';
|
|
7
|
+
import { AlertCircle, Check, FolderUp, ImagePlus, Loader2, Undo2, Download } from 'lucide-react';
|
|
8
|
+
import { useApi } from './api-context';
|
|
9
|
+
import { cacheScope } from './cache-scope';
|
|
10
|
+
import { Progress } from './dialogs/_primitives';
|
|
11
|
+
import { extractUploadedValue, readImageSize } from './upload-field';
|
|
12
|
+
import { buildChildPayload, buildPreview, chunk, collectBulkFiles, collectCandidateSkus, isImportable, loadBatchLogs, MAX_BULK_FILES, newBatchId, normalizeSku, pendingUndo, saveBatchLog, selectForImport, summarizePreview, } from './bulk-image-import';
|
|
13
|
+
const LOOKUP_CHUNK = 40;
|
|
14
|
+
const CONCURRENCY = 3;
|
|
15
|
+
const PAGE_SIZE = 200;
|
|
16
|
+
/**
|
|
17
|
+
* Alcance del registro de lotes: organización + usuario (sin el idioma de
|
|
18
|
+
* cacheScope, para que cambiar de idioma no esconda lotes). null = desconocido:
|
|
19
|
+
* no se ofrecen lotes anteriores.
|
|
20
|
+
*/
|
|
21
|
+
function batchScope() {
|
|
22
|
+
const s = cacheScope();
|
|
23
|
+
return s ? s.split(':').slice(0, 2).join(':') : null;
|
|
24
|
+
}
|
|
25
|
+
/** map con concurrencia acotada (decodificar cientos de bitmaps a la vez tumba la pestaña). */
|
|
26
|
+
async function mapPool(items, limit, fn) {
|
|
27
|
+
const out = new Array(items.length);
|
|
28
|
+
let i = 0;
|
|
29
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
30
|
+
while (i < items.length) {
|
|
31
|
+
const idx = i++;
|
|
32
|
+
out[idx] = await fn(items[idx]);
|
|
33
|
+
}
|
|
34
|
+
}));
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
function asRows(res) {
|
|
38
|
+
const d = res?.data?.data ?? res?.data;
|
|
39
|
+
return Array.isArray(d) ? d : Array.isArray(d?.data) ? d.data : [];
|
|
40
|
+
}
|
|
41
|
+
export function BulkImageDialog({ open, onOpenChange, model, target, skuKey, dataBase, minLongSide, onChange }) {
|
|
42
|
+
const { t } = useTranslation();
|
|
43
|
+
const api = useApi();
|
|
44
|
+
const [step, setStep] = useState('pick');
|
|
45
|
+
const [error, setError] = useState(null);
|
|
46
|
+
const [note, setNote] = useState(null);
|
|
47
|
+
const [rows, setRows] = useState([]);
|
|
48
|
+
const [excluded, setExcluded] = useState(new Set());
|
|
49
|
+
const [items, setItems] = useState({});
|
|
50
|
+
const [log, setLog] = useState(null);
|
|
51
|
+
const [undoing, setUndoing] = useState(null);
|
|
52
|
+
const [previousLogs, setPreviousLogs] = useState(() => { const sc = batchScope(); return sc === null ? [] : loadBatchLogs(undefined, sc).filter((l) => l.childModel === target.childModel && pendingUndo(l).length > 0); });
|
|
53
|
+
const filesRef = useRef(new Map());
|
|
54
|
+
const urlsRef = useRef(new Map());
|
|
55
|
+
const cancelRef = useRef(false);
|
|
56
|
+
const zipInput = useRef(null);
|
|
57
|
+
const dirInput = useRef(null);
|
|
58
|
+
const releaseUrls = () => {
|
|
59
|
+
urlsRef.current.forEach((u) => URL.revokeObjectURL?.(u));
|
|
60
|
+
urlsRef.current.clear();
|
|
61
|
+
};
|
|
62
|
+
useEffect(() => () => releaseUrls(), []);
|
|
63
|
+
const childEndpoint = `${dataBase}/${target.childModel}`;
|
|
64
|
+
const parentEndpoint = `${dataBase}/${model}`;
|
|
65
|
+
const analyze = useCallback(async (picked) => {
|
|
66
|
+
if (picked.length === 0)
|
|
67
|
+
return;
|
|
68
|
+
setError(null);
|
|
69
|
+
setNote(null);
|
|
70
|
+
setStep('analyzing');
|
|
71
|
+
try {
|
|
72
|
+
const { files, skipped } = await collectBulkFiles(picked);
|
|
73
|
+
if (files.length === 0)
|
|
74
|
+
throw new Error(t('bulk_images.no_images', { defaultValue: 'No se encontraron imágenes (jpg, png, webp, gif, avif).' }));
|
|
75
|
+
if (files.length > MAX_BULK_FILES) {
|
|
76
|
+
throw new Error(t('bulk_images.too_many', { defaultValue: 'Máximo {{n}} imágenes por lote; divide la carga.', n: MAX_BULK_FILES }));
|
|
77
|
+
}
|
|
78
|
+
if (skipped > 0)
|
|
79
|
+
setNote(t('bulk_images.skipped', { defaultValue: '{{n}} archivos ignorados (no son imágenes o son demasiado grandes).', n: skipped }));
|
|
80
|
+
// Medir en el navegador (el servidor no mide nada).
|
|
81
|
+
releaseUrls();
|
|
82
|
+
filesRef.current = new Map();
|
|
83
|
+
const inputs = await mapPool(files, 4, async (f) => {
|
|
84
|
+
const size = await readImageSize(f.file);
|
|
85
|
+
filesRef.current.set(f.path, f.file);
|
|
86
|
+
urlsRef.current.set(f.path, URL.createObjectURL(f.file));
|
|
87
|
+
const ok = !!(size.width && size.height);
|
|
88
|
+
return { path: f.path, size: f.file.size, width: size.width, height: size.height, decodable: ok };
|
|
89
|
+
});
|
|
90
|
+
// Resolver SKU contra la API de datos existente (por lotes).
|
|
91
|
+
const skus = collectCandidateSkus(inputs.map((i) => i.path)).filter((s) => !s.includes(','));
|
|
92
|
+
const parents = new Map();
|
|
93
|
+
for (const part of chunk(skus, LOOKUP_CHUNK)) {
|
|
94
|
+
const res = await api.get(parentEndpoint, {
|
|
95
|
+
params: { [`f_${skuKey}`]: `in:${part.join(',')}`, per_page: Math.min(200, part.length + 20) },
|
|
96
|
+
});
|
|
97
|
+
for (const r of asRows(res)) {
|
|
98
|
+
const sku = String(r[skuKey] ?? '');
|
|
99
|
+
if (!sku || r.id === undefined || r.id === null)
|
|
100
|
+
continue;
|
|
101
|
+
parents.set(normalizeSku(sku), {
|
|
102
|
+
id: String(r.id),
|
|
103
|
+
sku,
|
|
104
|
+
label: String(r.name ?? r.title ?? r.label ?? sku),
|
|
105
|
+
existingMaxPosition: -1,
|
|
106
|
+
existingCount: 0,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// Fotos que ya tiene cada producto: las nuevas van a continuación.
|
|
111
|
+
if (target.positionKey) {
|
|
112
|
+
const byId = new Map([...parents.values()].map((p) => [p.id, p]));
|
|
113
|
+
// El kernel limita per_page a 200: se pagina hasta agotar.
|
|
114
|
+
for (const part of chunk([...byId.keys()], LOOKUP_CHUNK)) {
|
|
115
|
+
for (let page = 1; page <= 50; page++) {
|
|
116
|
+
const res = await api.get(childEndpoint, {
|
|
117
|
+
params: { [`f_${target.foreignKey}`]: `in:${part.join(',')}`, per_page: PAGE_SIZE, page },
|
|
118
|
+
});
|
|
119
|
+
const got = asRows(res);
|
|
120
|
+
for (const r of got) {
|
|
121
|
+
const p = byId.get(String(r[target.foreignKey]));
|
|
122
|
+
if (!p)
|
|
123
|
+
continue;
|
|
124
|
+
p.existingCount += 1;
|
|
125
|
+
const n = Number(r[target.positionKey]);
|
|
126
|
+
if (Number.isFinite(n) && n > p.existingMaxPosition)
|
|
127
|
+
p.existingMaxPosition = n;
|
|
128
|
+
}
|
|
129
|
+
if (got.length < PAGE_SIZE)
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// Fotos existentes sin posición: las nuevas van detrás, nunca delante.
|
|
134
|
+
for (const p of byId.values()) {
|
|
135
|
+
if (p.existingCount > 0 && p.existingMaxPosition < p.existingCount - 1)
|
|
136
|
+
p.existingMaxPosition = p.existingCount - 1;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
setRows(buildPreview(inputs, parents, { minLongSide, maxSize: target.maxSize }));
|
|
140
|
+
setExcluded(new Set());
|
|
141
|
+
setStep('preview');
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
setError(e?.message || t('bulk_images.analyze_failed', { defaultValue: 'No se pudo analizar la selección.' }));
|
|
145
|
+
setStep('pick');
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
149
|
+
[api, childEndpoint, minLongSide, parentEndpoint, skuKey, target]);
|
|
150
|
+
const summary = useMemo(() => summarizePreview(rows, excluded), [rows, excluded]);
|
|
151
|
+
const runImport = useCallback(async () => {
|
|
152
|
+
const queue = selectForImport(rows, excluded);
|
|
153
|
+
if (queue.length === 0)
|
|
154
|
+
return;
|
|
155
|
+
cancelRef.current = false;
|
|
156
|
+
setStep('importing');
|
|
157
|
+
setError(null);
|
|
158
|
+
const batch = { batchId: newBatchId(), createdAt: new Date().toISOString(), childModel: target.childModel, scope: batchScope() ?? undefined, items: [] };
|
|
159
|
+
setLog(batch);
|
|
160
|
+
setItems(Object.fromEntries(queue.map((r) => [r.key, { status: 'pending', progress: 0 }])));
|
|
161
|
+
const patch = (key, s) => setItems((m) => ({ ...m, [key]: { ...m[key], ...s } }));
|
|
162
|
+
let next = 0;
|
|
163
|
+
const worker = async () => {
|
|
164
|
+
while (!cancelRef.current) {
|
|
165
|
+
const row = queue[next++];
|
|
166
|
+
if (!row)
|
|
167
|
+
return;
|
|
168
|
+
patch(row.key, { status: 'uploading', progress: 0 });
|
|
169
|
+
let url = '';
|
|
170
|
+
try {
|
|
171
|
+
const file = filesRef.current.get(row.path);
|
|
172
|
+
if (!file)
|
|
173
|
+
throw new Error('archivo no disponible');
|
|
174
|
+
const form = new FormData();
|
|
175
|
+
form.append('file', file);
|
|
176
|
+
if (target.storagePath) {
|
|
177
|
+
form.append('folder', target.storagePath);
|
|
178
|
+
form.append('storage_path', target.storagePath);
|
|
179
|
+
}
|
|
180
|
+
const up = await api.post('/upload', form, {
|
|
181
|
+
headers: { 'Content-Type': 'multipart/form-data' },
|
|
182
|
+
onUploadProgress: (e) => {
|
|
183
|
+
if (e.total)
|
|
184
|
+
patch(row.key, { progress: (e.loaded / e.total) * 0.9 });
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
const body = up?.data;
|
|
188
|
+
if (body && body.success === false)
|
|
189
|
+
throw new Error(body.message || 'upload failed');
|
|
190
|
+
url = extractUploadedValue(body);
|
|
191
|
+
if (!url)
|
|
192
|
+
throw new Error('upload failed');
|
|
193
|
+
const res = (await api.post(childEndpoint, buildChildPayload(target, row, url)));
|
|
194
|
+
if (!res?.data?.success)
|
|
195
|
+
throw new Error(res?.data?.message || 'create failed');
|
|
196
|
+
const created = res.data.data ?? res.data;
|
|
197
|
+
const rowId = created?.id;
|
|
198
|
+
// Sin id no hay deshacer fiable: se avisa en vez de callar.
|
|
199
|
+
if (rowId === undefined || rowId === null)
|
|
200
|
+
throw new Error('el servidor no devolvió el id de la fila creada');
|
|
201
|
+
batch.items.push({ rowId: String(rowId), path: row.path, sku: row.sku ?? '', parentId: row.parent.id, url });
|
|
202
|
+
saveBatchLog(batch);
|
|
203
|
+
patch(row.key, { status: 'done', progress: 1 });
|
|
204
|
+
}
|
|
205
|
+
catch (e) {
|
|
206
|
+
patch(row.key, { status: 'error', progress: 0, error: e?.response?.data?.message || e?.message || 'error' });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
await Promise.all(Array.from({ length: Math.min(CONCURRENCY, queue.length) }, worker));
|
|
211
|
+
setLog({ ...batch, items: [...batch.items] });
|
|
212
|
+
setStep('done');
|
|
213
|
+
if (batch.items.length)
|
|
214
|
+
onChange?.();
|
|
215
|
+
}, [api, childEndpoint, excluded, onChange, rows, target]);
|
|
216
|
+
const undo = useCallback(async (l) => {
|
|
217
|
+
const todo = pendingUndo(l);
|
|
218
|
+
setUndoing({ done: 0, total: todo.length });
|
|
219
|
+
setError(null);
|
|
220
|
+
const failures = [];
|
|
221
|
+
for (const it of todo) {
|
|
222
|
+
try {
|
|
223
|
+
const res = (await api.delete(`${childEndpoint}/${it.rowId}`));
|
|
224
|
+
if (res?.data?.success === false)
|
|
225
|
+
throw new Error(res.data.message || 'delete failed');
|
|
226
|
+
it.undone = true;
|
|
227
|
+
}
|
|
228
|
+
catch (e) {
|
|
229
|
+
// 404 = ya no existe: el objetivo (que no esté) está cumplido.
|
|
230
|
+
if (e?.response?.status === 404)
|
|
231
|
+
it.undone = true;
|
|
232
|
+
else
|
|
233
|
+
failures.push(`${it.sku || it.path}`);
|
|
234
|
+
}
|
|
235
|
+
setUndoing((u) => (u ? { ...u, done: u.done + 1 } : u));
|
|
236
|
+
}
|
|
237
|
+
saveBatchLog(l);
|
|
238
|
+
setUndoing(null);
|
|
239
|
+
setLog((cur) => (cur && cur.batchId === l.batchId ? { ...l, items: [...l.items] } : cur));
|
|
240
|
+
setPreviousLogs((ls) => ls.map((x) => (x.batchId === l.batchId ? { ...l, items: [...l.items] } : x)).filter((x) => pendingUndo(x).length > 0));
|
|
241
|
+
if (failures.length) {
|
|
242
|
+
setError(t('bulk_images.undo_partial', { defaultValue: 'No se pudieron deshacer: {{list}}. Reintenta.', list: failures.slice(0, 10).join(', ') }));
|
|
243
|
+
}
|
|
244
|
+
onChange?.();
|
|
245
|
+
}, [api, childEndpoint, onChange, t]);
|
|
246
|
+
const downloadLog = (l) => {
|
|
247
|
+
const blob = new Blob([JSON.stringify(l, null, 2)], { type: 'application/json' });
|
|
248
|
+
const a = document.createElement('a');
|
|
249
|
+
a.href = URL.createObjectURL(blob);
|
|
250
|
+
a.download = `${l.batchId}.json`;
|
|
251
|
+
a.click();
|
|
252
|
+
setTimeout(() => URL.revokeObjectURL(a.href), 1000);
|
|
253
|
+
};
|
|
254
|
+
const statusLabel = (r) => {
|
|
255
|
+
switch (r.status) {
|
|
256
|
+
case 'ok': return t('bulk_images.s_ok', { defaultValue: 'Listo' });
|
|
257
|
+
case 'low_res': return t('bulk_images.s_low', { defaultValue: 'Baja resolución' });
|
|
258
|
+
case 'sku_not_found': return t('bulk_images.s_nosku', { defaultValue: 'SKU no encontrado' });
|
|
259
|
+
case 'duplicate': return t('bulk_images.s_dup', { defaultValue: 'Duplicado' });
|
|
260
|
+
case 'invalid_image': return t('bulk_images.s_invalid', { defaultValue: 'No es imagen' });
|
|
261
|
+
case 'too_large': return t('bulk_images.s_large', { defaultValue: 'Muy pesada' });
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
const doneCount = Object.values(items).filter((i) => i.status === 'done').length;
|
|
265
|
+
const errCount = Object.values(items).filter((i) => i.status === 'error').length;
|
|
266
|
+
const total = Object.keys(items).length;
|
|
267
|
+
const busy = step === 'importing' || step === 'analyzing' || !!undoing;
|
|
268
|
+
return (_jsx(Dialog, { open: open, onOpenChange: (o) => { if (!o && busy)
|
|
269
|
+
return; if (!o)
|
|
270
|
+
releaseUrls(); onOpenChange(o); }, children: _jsxs(DialogContent, { className: "max-w-4xl max-h-[90vh] overflow-y-auto", "data-testid": "bulk-image-dialog", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: t('bulk_images.title', { defaultValue: 'Carga masiva de imágenes' }) }), _jsx(DialogDescription, { children: t('bulk_images.help', {
|
|
271
|
+
defaultValue: 'Sube un ZIP o una carpeta con archivos nombrados SKU.jpg, SKU_2.jpg… Cada archivo se agrega a la galería del producto con ese SKU.',
|
|
272
|
+
}) })] }), error && _jsxs("div", { role: "alert", className: "text-sm text-destructive flex gap-2 items-start", children: [_jsx(AlertCircle, { className: "size-4 mt-0.5" }), error] }), note && _jsx("div", { className: "text-xs text-muted-foreground", children: note }), step === 'pick' && (_jsxs("div", { className: "space-y-4", children: [_jsxs("div", { className: "border-2 border-dashed rounded-lg p-8 text-center text-sm text-muted-foreground", onDragOver: (e) => e.preventDefault(), onDrop: (e) => { e.preventDefault(); void analyze(Array.from(e.dataTransfer?.files ?? [])); }, children: [_jsx("p", { className: "mb-3", children: t('bulk_images.drop', { defaultValue: 'Arrastra aquí el ZIP o las imágenes' }) }), _jsxs("div", { className: "flex gap-2 justify-center", children: [_jsxs(Button, { variant: "outline", onClick: () => zipInput.current?.click(), children: [_jsx(ImagePlus, { className: "size-4 mr-1" }), t('bulk_images.pick_zip', { defaultValue: 'Elegir ZIP o imágenes' })] }), _jsxs(Button, { variant: "outline", onClick: () => dirInput.current?.click(), children: [_jsx(FolderUp, { className: "size-4 mr-1" }), t('bulk_images.pick_folder', { defaultValue: 'Elegir carpeta' })] })] }), _jsx("input", { ref: zipInput, type: "file", multiple: true, className: "hidden", "data-testid": "bulk-image-input", accept: ".zip,application/zip,image/*", onChange: (e) => { void analyze(Array.from(e.target.files ?? [])); e.target.value = ''; } }), _jsx("input", { ref: dirInput, type: "file", multiple: true, className: "hidden", "data-testid": "bulk-image-dir", ...{ webkitdirectory: '' }, onChange: (e) => { void analyze(Array.from(e.target.files ?? [])); e.target.value = ''; } })] }), previousLogs.length > 0 && (_jsxs("div", { className: "text-sm space-y-2", children: [_jsx("div", { className: "font-medium", children: t('bulk_images.previous', { defaultValue: 'Lotes anteriores' }) }), previousLogs.map((l) => (_jsxs("div", { className: "flex items-center justify-between gap-2 border rounded-md px-3 py-2", children: [_jsxs("span", { children: [new Date(l.createdAt).toLocaleString(), " \u00B7 ", pendingUndo(l).length, " ", t('bulk_images.images', { defaultValue: 'imágenes' })] }), _jsxs("span", { className: "flex gap-2", children: [_jsx(Button, { size: "sm", variant: "ghost", onClick: () => downloadLog(l), children: _jsx(Download, { className: "size-4" }) }), _jsxs(Button, { size: "sm", variant: "outline", disabled: !!undoing, onClick: () => void undo(l), children: [_jsx(Undo2, { className: "size-4 mr-1" }), t('bulk_images.undo', { defaultValue: 'Deshacer lote' })] })] })] }, l.batchId))), undoing && _jsx(Progress, { value: (undoing.done / Math.max(1, undoing.total)) * 100 })] }))] })), step === 'analyzing' && (_jsxs("div", { className: "flex items-center gap-2 text-sm py-8 justify-center", children: [_jsx(Loader2, { className: "size-4 animate-spin" }), t('bulk_images.analyzing', { defaultValue: 'Analizando imágenes y buscando SKU…' })] })), (step === 'preview' || step === 'importing' || step === 'done') && (_jsxs("div", { className: "space-y-3", children: [_jsxs("div", { className: "flex flex-wrap gap-3 text-sm", "data-testid": "bulk-image-summary", children: [_jsx("span", { children: t('bulk_images.sum_import', { defaultValue: '{{n}} fotos para {{p}} productos', n: summary.importable, p: summary.products }) }), summary.sku_not_found > 0 && _jsxs("span", { className: "text-destructive", children: [summary.sku_not_found, " ", t('bulk_images.s_nosku', { defaultValue: 'SKU no encontrado' })] }), summary.duplicate > 0 && _jsxs("span", { className: "text-destructive", children: [summary.duplicate, " ", t('bulk_images.s_dup', { defaultValue: 'Duplicado' })] }), summary.low_res > 0 && _jsxs("span", { className: "text-amber-600", children: [summary.low_res, " ", t('bulk_images.s_low', { defaultValue: 'Baja resolución' })] }), (summary.invalid_image + summary.too_large) > 0 && _jsxs("span", { className: "text-destructive", children: [summary.invalid_image + summary.too_large, " ", t('bulk_images.s_invalid', { defaultValue: 'No es imagen' })] })] }), step !== 'preview' && (_jsxs("div", { className: "space-y-1", children: [_jsx(Progress, { value: (doneCount + errCount) / Math.max(1, total) * 100 }), _jsx("div", { className: "text-xs text-muted-foreground", "data-testid": "bulk-image-progress", children: t('bulk_images.progress', { defaultValue: '{{done}} de {{total}} subidas · {{err}} con error', done: doneCount, total, err: errCount }) })] })), _jsx("div", { className: "border rounded-md max-h-[45vh] overflow-auto", children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [step === 'preview' && _jsx(TableHead, { className: "w-8" }), _jsx(TableHead, { className: "w-14" }), _jsx(TableHead, { children: t('bulk_images.col_file', { defaultValue: 'Archivo' }) }), _jsx(TableHead, { children: t('bulk_images.col_product', { defaultValue: 'Producto' }) }), _jsx(TableHead, { children: t('bulk_images.col_pos', { defaultValue: 'Pos.' }) }), _jsx(TableHead, { children: t('bulk_images.col_status', { defaultValue: 'Estado' }) })] }) }), _jsx(TableBody, { children: rows.map((r) => {
|
|
273
|
+
const it = items[r.key];
|
|
274
|
+
const skip = excluded.has(r.key);
|
|
275
|
+
return (_jsxs(TableRow, { "data-status": r.status, className: skip ? 'opacity-50' : undefined, children: [step === 'preview' && (_jsx(TableCell, { children: isImportable(r) && (_jsx("input", { type: "checkbox", checked: !skip, "aria-label": r.path, onChange: () => setExcluded((s) => { const n = new Set(s); if (n.has(r.key))
|
|
276
|
+
n.delete(r.key);
|
|
277
|
+
else
|
|
278
|
+
n.add(r.key); return n; }) })) })), _jsx(TableCell, { children: urlsRef.current.get(r.path) && _jsx("img", { src: urlsRef.current.get(r.path), alt: "", className: "size-10 object-contain rounded bg-muted", loading: "lazy" }) }), _jsxs(TableCell, { className: "text-xs break-all", children: [r.path, _jsx("div", { className: "text-muted-foreground", children: r.width && r.height ? `${r.width}×${r.height}` : '' })] }), _jsx(TableCell, { className: "text-xs", children: r.parent ? _jsxs(_Fragment, { children: [r.parent.label, _jsxs("div", { className: "text-muted-foreground", children: [r.sku, r.parent.existingCount ? ` · ${r.parent.existingCount} ${t('bulk_images.already', { defaultValue: 'ya tiene' })}` : ''] })] }) : '—' }), _jsx(TableCell, { className: "text-xs", children: isImportable(r) && !skip && typeof r.position === 'number' ? (r.position === 0 ? `1 · ${t('bulk_images.main', { defaultValue: 'Principal' })}` : r.position + 1) : '—' }), _jsx(TableCell, { className: "text-xs", children: it ? (it.status === 'done' ? _jsxs("span", { className: "text-emerald-600 inline-flex items-center gap-1", children: [_jsx(Check, { className: "size-3" }), t('bulk_images.uploaded', { defaultValue: 'Subida' })] })
|
|
279
|
+
: it.status === 'error' ? _jsx("span", { className: "text-destructive", title: it.error, children: it.error })
|
|
280
|
+
: _jsx("div", { className: "w-24", children: _jsx(Progress, { value: it.progress * 100 }) })) : (_jsx("span", { className: r.status === 'ok' ? '' : r.status === 'low_res' ? 'text-amber-600' : 'text-destructive', title: r.note, children: statusLabel(r) })) })] }, r.key));
|
|
281
|
+
}) })] }) })] })), _jsxs(DialogFooter, { className: "gap-2", children: [step === 'preview' && (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "outline", onClick: () => { releaseUrls(); setRows([]); setStep('pick'); }, children: t('bulk_images.back', { defaultValue: 'Elegir otros' }) }), _jsx(Button, { disabled: summary.importable === 0, onClick: () => void runImport(), "data-testid": "bulk-image-import", children: t('bulk_images.import', { defaultValue: 'Importar {{n}} fotos', n: summary.importable }) })] })), step === 'importing' && (_jsx(Button, { variant: "outline", onClick: () => { cancelRef.current = true; }, children: t('bulk_images.cancel', { defaultValue: 'Detener' }) })), step === 'done' && log && (_jsxs(_Fragment, { children: [_jsxs(Button, { variant: "ghost", onClick: () => downloadLog(log), children: [_jsx(Download, { className: "size-4 mr-1" }), t('bulk_images.download_log', { defaultValue: 'Descargar registro' })] }), pendingUndo(log).length > 0 && (_jsxs(Button, { variant: "outline", disabled: !!undoing, onClick: () => void undo(log), "data-testid": "bulk-image-undo", children: [_jsx(Undo2, { className: "size-4 mr-1" }), undoing ? `${undoing.done}/${undoing.total}` : t('bulk_images.undo', { defaultValue: 'Deshacer lote' })] })), _jsx(Button, { onClick: () => { releaseUrls(); onOpenChange(false); }, children: t('bulk_images.close', { defaultValue: 'Cerrar' }) })] }))] })] }) }));
|
|
282
|
+
}
|
|
@@ -22,6 +22,11 @@ export interface FieldDef {
|
|
|
22
22
|
label: string;
|
|
23
23
|
type: 'text' | 'textarea' | 'select' | 'search' | 'number' | 'date' | 'email' | 'url' | 'boolean' | 'image' | 'password' | 'phone' | 'tel' | 'checkbox' | 'time' | 'hidden' | 'multiselect' | 'file' | string;
|
|
24
24
|
required?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Contrato de nulabilidad del kernel (`nullable = !required`). En un
|
|
27
|
+
* booleano decide el control de tres estados (Sí / No / Sin definir).
|
|
28
|
+
*/
|
|
29
|
+
nullable?: boolean;
|
|
25
30
|
options?: FieldOption[];
|
|
26
31
|
defaultValue?: any;
|
|
27
32
|
placeholder?: string;
|
|
@@ -264,8 +269,10 @@ export declare function ViewValue({ field, value: rawValue, record, getImageUrl:
|
|
|
264
269
|
/** Optional override; when omitted falls back to the nearest provider. */
|
|
265
270
|
currency?: string;
|
|
266
271
|
}): import("react").JSX.Element;
|
|
267
|
-
export declare function EditField({ field, value, onChange, record, invalid, error }: {
|
|
272
|
+
export declare function EditField({ field, value, onChange, record, invalid, error, labelId }: {
|
|
268
273
|
field: FieldDef;
|
|
274
|
+
/** id de la etiqueta visible (FieldRow); el control de tres estados la referencia. */
|
|
275
|
+
labelId?: string;
|
|
269
276
|
value: any;
|
|
270
277
|
onChange: (val: any) => void;
|
|
271
278
|
/** The full record being edited — supplies FK relation siblings + line-items. */
|
|
@@ -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,MA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ACxE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,mFAAmF;IACnF,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAA;CACpB,+BAiVA;AAwLD,wBAAgB,SAAS,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;IACnF,KAAK,EAAE,QAAQ,CAAA;IACf,sFAAsF;IACtF,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,GAAG,CAAA;IACV,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAA;IAC5B,iFAAiF;IACjF,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ,8EAA8E;IAC9E,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAA;CACjB,+BAuSA"}
|
|
@@ -41,6 +41,8 @@ import { FieldSection, WizardProgress } from '../form-layout-ui';
|
|
|
41
41
|
import { AssistInterview } from '../assist-interview';
|
|
42
42
|
import { RecordPrefillBar } from '../record-prefill-bar';
|
|
43
43
|
import { FieldCell } from '../field-grid';
|
|
44
|
+
import { isNullableBooleanField, omitUntouchedNullBooleans, usesTriState } from '../nullable-boolean';
|
|
45
|
+
import { NullBooleanMark, TriStateBooleanField } from '../tri-state-boolean';
|
|
44
46
|
import { isNilUuid, normalizeNilUuid } from '../nil-uuid';
|
|
45
47
|
import { normalizeRefFieldsForSubmit } from './normalize-submit';
|
|
46
48
|
import { validateValues, bagHasErrors, exemptUnchangedRuleIssues } from '../validator';
|
|
@@ -78,7 +80,9 @@ export function pickDeclaredFieldValues(values, fields) {
|
|
|
78
80
|
const out = {};
|
|
79
81
|
for (const f of fields ?? []) {
|
|
80
82
|
if (f.key in values) {
|
|
81
|
-
|
|
83
|
+
// Un booleano opcional en null viaja null («Sin definir»): '' lo
|
|
84
|
+
// descartaría el kernel y no podría volver a NULL.
|
|
85
|
+
out[f.key] = values[f.key] === null && isNullableBooleanField(f) ? null : values[f.key] ?? '';
|
|
82
86
|
}
|
|
83
87
|
else if (!getVisibleWhen(f) && !f.hidden && f.type !== 'hidden' && !f.readonly) {
|
|
84
88
|
out[f.key] = '';
|
|
@@ -482,9 +486,16 @@ export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf
|
|
|
482
486
|
const seedForm = (meta, rec) => {
|
|
483
487
|
const initial = {};
|
|
484
488
|
for (const field of meta.fields ?? []) {
|
|
489
|
+
const v = resolvePath(rec, field.key);
|
|
490
|
+
// Booleano opcional en NULL: se queda null («Sin definir»). Si
|
|
491
|
+
// cayera al default o a '' el PUT lo convertiría en otro valor.
|
|
492
|
+
if (v === null && isNullableBooleanField(field)) {
|
|
493
|
+
initial[field.key] = null;
|
|
494
|
+
continue;
|
|
495
|
+
}
|
|
485
496
|
initial[field.key] = isPasswordField(field)
|
|
486
497
|
? ''
|
|
487
|
-
:
|
|
498
|
+
: v ?? field.defaultValue ?? '';
|
|
488
499
|
}
|
|
489
500
|
// En edición, un destino derivado ya guardado no se pisa: cuenta como manual.
|
|
490
501
|
if (!isCreate) {
|
|
@@ -729,6 +740,10 @@ export function DynamicRecordDialog({ open, onOpenChange, nestedInlineCreateSelf
|
|
|
729
740
|
// Empty reference pickers → null (not "" / nil-UUID) so nullable FK
|
|
730
741
|
// columns accept them instead of raising a 23503 FK violation.
|
|
731
742
|
let payload = dropEmptyPasswords(normalizeRefFieldsForSubmit(submittedValues, modalMeta.fields), modalMeta.fields);
|
|
743
|
+
// Edición: un booleano NULL que nadie tocó no viaja (conserva el NULL).
|
|
744
|
+
if (mode === 'edit' && record) {
|
|
745
|
+
payload = omitUntouchedNullBooleans(payload, modalMeta.fields, (k) => resolvePath(record, k));
|
|
746
|
+
}
|
|
732
747
|
if (isCreate &&
|
|
733
748
|
branchGate &&
|
|
734
749
|
(payload.branch_id == null || payload.branch_id === '')) {
|
|
@@ -901,7 +916,9 @@ function FieldRow({ field, record, value, mode, onChange, error, locked }) {
|
|
|
901
916
|
// CREATE for a caller-specified field (see `lockedFields`).
|
|
902
917
|
const isEditReadonly = (mode === 'edit' && !!field.readonly) || !!locked;
|
|
903
918
|
const { t } = useTranslation();
|
|
904
|
-
|
|
919
|
+
// Único por instancia (dos diálogos abiertos con el mismo campo no chocan).
|
|
920
|
+
const labelId = `${useId()}-label`;
|
|
921
|
+
return (_jsxs("div", { className: "flex flex-col gap-1.5", "data-aby-field": field.key, children: [_jsxs(Label, { id: labelId, className: "text-sm font-medium text-foreground/80", children: [localizeFieldLabel(field.label, t), field.required && mode !== 'view' && !isEditReadonly && (_jsx("span", { className: "text-destructive ml-0.5", children: "*" }))] }), mode === 'view' ? (_jsx(ViewValue, { field: field, value: value, record: record })) : isEditReadonly ? (_jsx(ReadonlyEditField, { field: field, value: value })) : (_jsx(EditField, { field: field, value: value, onChange: onChange, record: record, invalid: !!error, error: error, labelId: labelId })), error && mode !== 'view' && (_jsx("p", { className: "text-destructive text-xs mt-1", children: error }))] }));
|
|
905
922
|
}
|
|
906
923
|
// ReadonlyEditField — the edit-mode rendering of a `readonly` (system-generated)
|
|
907
924
|
// field: a disabled, muted input that shows the current value without allowing
|
|
@@ -916,6 +933,9 @@ export function ReadonlyEditField({ field, value }) {
|
|
|
916
933
|
return _jsx(HostWidget, { field: field, value: value, onChange: noopChange, disabled: true });
|
|
917
934
|
}
|
|
918
935
|
if (field.type === 'boolean' || field.type === 'checkbox' || typeof value === 'boolean') {
|
|
936
|
+
if (value === null || value === undefined || value === '') {
|
|
937
|
+
return (_jsx("div", { className: "flex items-center gap-2 py-1", children: _jsx(NullBooleanMark, { className: "text-sm text-muted-foreground" }) }));
|
|
938
|
+
}
|
|
919
939
|
return (_jsxs("div", { className: "flex items-center gap-2 py-1", children: [_jsx(Switch, { checked: !!value, disabled: true }), _jsx("span", { className: "text-sm text-muted-foreground", children: value ? 'Sí' : 'No' })] }));
|
|
920
940
|
}
|
|
921
941
|
const fieldRef = getFieldRef(field);
|
|
@@ -1063,6 +1083,10 @@ export function ViewValue({ field, value: rawValue, record, getImageUrl: getImag
|
|
|
1063
1083
|
return _jsx("p", { className: "text-sm py-1", children: inlineLabel });
|
|
1064
1084
|
}
|
|
1065
1085
|
if (field.type === 'boolean' || field.type === 'checkbox' || typeof value === 'boolean') {
|
|
1086
|
+
// NULL no es «No»: se pinta «—» (misma convención que formatDisplayValue).
|
|
1087
|
+
if (value === null || value === undefined || value === '') {
|
|
1088
|
+
return _jsx("p", { className: "text-sm py-1", children: _jsx(NullBooleanMark, {}) });
|
|
1089
|
+
}
|
|
1066
1090
|
return (_jsxs("div", { className: "flex items-center gap-2 py-1", children: [_jsx(Switch, { checked: !!value, disabled: true }), _jsx("span", { className: "text-sm text-muted-foreground", children: value ? 'Sí' : 'No' })] }));
|
|
1067
1091
|
}
|
|
1068
1092
|
if (field.type === 'color') {
|
|
@@ -1290,7 +1314,7 @@ function JsonObjectViewValue({ value }) {
|
|
|
1290
1314
|
return (_jsxs("div", { className: "min-w-0", children: [_jsx("dt", { className: "text-[11px] font-medium uppercase tracking-wide text-muted-foreground", children: label }), _jsx("dd", { className: "mt-0.5 break-words text-foreground", children: isNest ? (_jsx("pre", { className: "max-h-48 overflow-auto rounded-md bg-muted/40 p-2 text-[11px] leading-relaxed whitespace-pre-wrap", children: JSON.stringify(raw, null, 2) })) : raw === null || raw === '' ? (_jsx("span", { className: "text-muted-foreground", children: "\u2014" })) : (String(raw)) })] }, key));
|
|
1291
1315
|
}) }));
|
|
1292
1316
|
}
|
|
1293
|
-
export function EditField({ field, value, onChange, record, invalid, error }) {
|
|
1317
|
+
export function EditField({ field, value, onChange, record, invalid, error, labelId }) {
|
|
1294
1318
|
const invalidCls = invalid
|
|
1295
1319
|
? 'border-destructive ring-1 ring-destructive/30 focus-visible:ring-destructive aria-invalid:border-destructive'
|
|
1296
1320
|
: undefined;
|
|
@@ -1312,6 +1336,12 @@ export function EditField({ field, value, onChange, record, invalid, error }) {
|
|
|
1312
1336
|
if (isLineItemsField(field, value)) {
|
|
1313
1337
|
return (_jsxs("div", { className: "space-y-1", children: [_jsx("div", { className: "rounded-md border bg-muted/30 p-2", children: _jsx(CollectionCell, { value: value, itemFields: fieldItemFields(field), variant: "inline", locale: numberLocale, t: t, getImageUrl: editFieldImageUrl }) }), _jsx("p", { className: "text-[11px] text-muted-foreground", children: t('datatable.readOnly', { defaultValue: 'Solo lectura' }) })] }));
|
|
1314
1338
|
}
|
|
1339
|
+
// Booleano opcional (nullable): Sí / No / Sin definir. Nunca convierte un
|
|
1340
|
+
// NULL en `false` sin que el usuario lo elija.
|
|
1341
|
+
if ((field.type === 'boolean' || field.type === 'checkbox') &&
|
|
1342
|
+
usesTriState(field, record ? resolvePath(record, field.key) : undefined)) {
|
|
1343
|
+
return (_jsx("div", { className: "py-1", children: _jsx(TriStateBooleanField, { id: field.key, value: value, onChange: onChange, label: localizeFieldLabel(field.label, t), labelledBy: labelId, invalid: invalid }) }));
|
|
1344
|
+
}
|
|
1315
1345
|
if (field.type === 'boolean') {
|
|
1316
1346
|
return (_jsxs("div", { className: "flex items-center gap-2 py-1", children: [_jsx(Switch, { checked: !!value, onCheckedChange: onChange }), _jsx("span", { className: "text-sm text-muted-foreground", children: value ? 'Sí' : 'No' })] }));
|
|
1317
1347
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-columns.d.ts","sourceRoot":"","sources":["../src/dynamic-columns.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAU,KAAK,MAAM,EAAE,MAAM,UAAU,CAAA;AA4C9C,OAAO,KAAK,EAAiB,gBAAgB,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"dynamic-columns.d.ts","sourceRoot":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AAE,MAAM,GAAG,SAAS,GAC7B,OAAO,CAYT;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAOxE;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,GACzB,KAAK,gBAAgB,EACrB,KAAK,GAAG,EACR,OAAO,GAAG,EACV,mBAAe,KAChB,MAAM,GAAG,SAoBX,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GACxB,KAAK,gBAAgB,EACrB,KAAK,MAAM,EACX,mBAAe,EACf,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,gBAAgB,KAAK,MAAM,KACpE,MAMF,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,GAAI,KAAK,gBAAgB,EAAE,KAAK,GAAG,KAAG,MAOzE,CAAA;AAgMD;;;;GAIG;AACH;;;;;GAKG;AACH,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC;IAC7B,KAAK,EAAE,OAAO,CAAA;IACd,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;IACrC,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,OAAO,CAAA;CAClB,CAqBA,CAAA;AAsBD,wBAAgB,4BAA4B,CACxC,OAAO,GAAE,qBAA0B,GACpC,iBAAiB,CAixBnB;AAED;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,EAAE,iBACL,CAAA"}
|
package/dist/dynamic-columns.js
CHANGED
|
@@ -35,6 +35,7 @@ import { isNilUuid, normalizeNilUuid } from './nil-uuid';
|
|
|
35
35
|
import { useOptionsResolver } from './use-options-resolver';
|
|
36
36
|
import { RowActionsMenu } from './row-actions-menu';
|
|
37
37
|
import { isColumnVisibleInTable } from './column-visibility';
|
|
38
|
+
import { NullBooleanMark } from './tri-state-boolean';
|
|
38
39
|
const defaultGetImageUrl = (path) => path;
|
|
39
40
|
const getNestedValue = (obj, path) => path.split('.').reduce((acc, part) => acc && acc[part], obj);
|
|
40
41
|
/**
|
|
@@ -1053,6 +1054,9 @@ export function makeDefaultGetDynamicColumns(helpers = {}) {
|
|
|
1053
1054
|
return _jsx("span", { className: "font-medium text-sm", children: String(value) });
|
|
1054
1055
|
}
|
|
1055
1056
|
case 'boolean': {
|
|
1057
|
+
// NULL (booleano opcional sin definir) no es «No».
|
|
1058
|
+
if (value === null || value === undefined)
|
|
1059
|
+
return _jsx(NullBooleanMark, {});
|
|
1056
1060
|
const showText = styleCfg(col, 'show_text', 'showText') !== false;
|
|
1057
1061
|
return (_jsxs("span", { className: "inline-flex items-center gap-1.5", children: [value ? (_jsx(Check, { className: "h-4 w-4 text-green-500" })) : (_jsx(Minus, { className: "h-4 w-4 text-muted-foreground" })), showText && (_jsx("span", { className: "text-sm text-muted-foreground", children: value ? 'Sí' : 'No' }))] }));
|
|
1058
1062
|
}
|