@asteby/metacore-runtime-react 53.28.0 → 53.29.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 +18 -0
- package/dist/business/customer-picker.d.ts.map +1 -1
- package/dist/business/customer-picker.js +4 -0
- package/dist/dialogs/create-record-dialog.d.ts +1 -1
- package/dist/dialogs/create-record-dialog.d.ts.map +1 -1
- package/dist/dialogs/create-record-dialog.js +2 -2
- package/dist/dialogs/dynamic-record.d.ts +16 -1
- package/dist/dialogs/dynamic-record.d.ts.map +1 -1
- package/dist/dialogs/dynamic-record.js +49 -3
- package/dist/dialogs/types.d.ts +4 -0
- package/dist/dialogs/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/loom/index.d.ts +9 -0
- package/dist/loom/index.d.ts.map +1 -0
- package/dist/loom/index.js +9 -0
- package/dist/loom/overlay.d.ts +74 -0
- package/dist/loom/overlay.d.ts.map +1 -0
- package/dist/loom/overlay.js +142 -0
- package/dist/loom/proposals.d.ts +26 -0
- package/dist/loom/proposals.d.ts.map +1 -0
- package/dist/loom/proposals.js +74 -0
- package/dist/loom/provider.d.ts +28 -0
- package/dist/loom/provider.d.ts.map +1 -0
- package/dist/loom/provider.js +31 -0
- package/dist/loom/resolve.d.ts +23 -0
- package/dist/loom/resolve.d.ts.map +1 -0
- package/dist/loom/resolve.js +138 -0
- package/dist/loom/seam.d.ts +28 -0
- package/dist/loom/seam.d.ts.map +1 -0
- package/dist/loom/seam.js +127 -0
- package/dist/loom/seams.d.ts +31 -0
- package/dist/loom/seams.d.ts.map +1 -0
- package/dist/loom/seams.js +21 -0
- package/dist/loom/store.d.ts +16 -0
- package/dist/loom/store.d.ts.map +1 -0
- package/dist/loom/store.js +72 -0
- package/dist/loom/types.d.ts +153 -0
- package/dist/loom/types.d.ts.map +1 -0
- package/dist/loom/types.js +1 -0
- package/dist/record-picker-dialog.d.ts +7 -1
- package/dist/record-picker-dialog.d.ts.map +1 -1
- package/dist/record-picker-dialog.js +18 -3
- package/package.json +6 -6
- package/src/__tests__/dynamic-record-seam.test.tsx +194 -0
- package/src/__tests__/loom-overlay.test.ts +94 -0
- package/src/__tests__/loom-resolve.test.ts +108 -0
- package/src/business/customer-picker.tsx +4 -0
- package/src/dialogs/create-record-dialog.tsx +4 -0
- package/src/dialogs/dynamic-record.tsx +83 -0
- package/src/dialogs/types.ts +4 -0
- package/src/index.ts +1 -0
- package/src/loom/index.ts +36 -0
- package/src/loom/overlay.ts +196 -0
- package/src/loom/proposals.tsx +156 -0
- package/src/loom/provider.tsx +69 -0
- package/src/loom/resolve.ts +136 -0
- package/src/loom/seam.tsx +235 -0
- package/src/loom/seams.ts +42 -0
- package/src/loom/store.ts +81 -0
- package/src/loom/types.ts +167 -0
- package/src/record-picker-dialog.tsx +37 -1
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
/** Clase de datos de una lente. Decide la redacción en errores/telemetría. */
|
|
3
|
+
export type DataClass = 'public' | 'internal' | 'money' | 'pii' | 'pii.fiscal' | 'secret';
|
|
4
|
+
/** Contrato que el anfitrión publica para un seam. */
|
|
5
|
+
export interface SeamContract {
|
|
6
|
+
id: string;
|
|
7
|
+
/** Semver del contrato (`1.0.0`). Un injerto declara `requires: '^1'`. */
|
|
8
|
+
version: string;
|
|
9
|
+
/** Lentes que el seam ofrece y su clase de datos. */
|
|
10
|
+
lenses: Readonly<Record<string, DataClass>>;
|
|
11
|
+
/**
|
|
12
|
+
* Campos que un injerto puede proponer cambiar en este seam. `undefined` = el seam no
|
|
13
|
+
* acepta propuestas. El anfitrión lo calcula (p. ej. los campos editables del formulario).
|
|
14
|
+
*/
|
|
15
|
+
writable?: ReadonlySet<string>;
|
|
16
|
+
/** Intenciones que el anfitrión atiende (`record.select`, `record.edit`). */
|
|
17
|
+
intents?: readonly string[];
|
|
18
|
+
}
|
|
19
|
+
export type GraftKind = 'view' | 'action' | 'transform' | 'source';
|
|
20
|
+
/** Condiciones de montaje. Todas las presentes deben cumplirse. */
|
|
21
|
+
export interface GraftWhen {
|
|
22
|
+
/** Todos estos permisos RBAC. */
|
|
23
|
+
permission?: string | string[];
|
|
24
|
+
/** Al menos uno de estos permisos. */
|
|
25
|
+
anyPermission?: string[];
|
|
26
|
+
/** Feature flag activo. */
|
|
27
|
+
flag?: string;
|
|
28
|
+
/** Ajuste de la organización/addon: presente y verdadero, o igual a `equals`. */
|
|
29
|
+
setting?: {
|
|
30
|
+
key: string;
|
|
31
|
+
equals?: unknown;
|
|
32
|
+
};
|
|
33
|
+
/** Modelos del anfitrión (acepta `Customer` o `customers.Customer`). */
|
|
34
|
+
model?: string[];
|
|
35
|
+
/** Modos del anfitrión (`create`, `edit`, `view`). */
|
|
36
|
+
mode?: string[];
|
|
37
|
+
}
|
|
38
|
+
export interface GraftCapabilities {
|
|
39
|
+
/** Proponer un parche. Sólo pasan los campos de `writes` ∩ `contract.writable`. */
|
|
40
|
+
propose: (p: ProposalInput) => void;
|
|
41
|
+
/** Pedir al anfitrión una intención declarada en el contrato. false = nadie la atendió. */
|
|
42
|
+
emit: (intent: string, payload?: unknown) => boolean;
|
|
43
|
+
/** RBAC del usuario actual (mismo `useCan` del host). */
|
|
44
|
+
can: (permission: string) => boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface GraftProps<P = Record<string, unknown>> {
|
|
47
|
+
/** Sólo las lentes declaradas en `reads`, congeladas. */
|
|
48
|
+
lenses: Readonly<Record<string, unknown>>;
|
|
49
|
+
/** Props estáticas del manifiesto/registro. */
|
|
50
|
+
props: P;
|
|
51
|
+
caps: GraftCapabilities;
|
|
52
|
+
graft: {
|
|
53
|
+
id: string;
|
|
54
|
+
addon: string;
|
|
55
|
+
seam: string;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export type GraftComponent<P = Record<string, unknown>> = ComponentType<GraftProps<P>>;
|
|
59
|
+
export type GraftModule = GraftComponent<any> | {
|
|
60
|
+
default: GraftComponent<any>;
|
|
61
|
+
};
|
|
62
|
+
/** Componente expuesto por un addon (lo que el manifiesto llama `extension_points.parts[]`). */
|
|
63
|
+
export interface PartDef {
|
|
64
|
+
/** `<addon>.<nombre>`. */
|
|
65
|
+
id: string;
|
|
66
|
+
addon?: string;
|
|
67
|
+
version?: string;
|
|
68
|
+
component?: GraftComponent<any>;
|
|
69
|
+
/** Carga perezosa (chunk local o remoto federado). */
|
|
70
|
+
load?: () => Promise<GraftModule>;
|
|
71
|
+
}
|
|
72
|
+
export interface GraftDef {
|
|
73
|
+
/** Id estable `<addon>.<nombre>`; registrar el mismo id reemplaza. */
|
|
74
|
+
id: string;
|
|
75
|
+
addon?: string;
|
|
76
|
+
seam: string;
|
|
77
|
+
/** Rango semver del contrato del seam (`^1`). Sin él, cualquiera. */
|
|
78
|
+
requires?: string;
|
|
79
|
+
kind?: GraftKind;
|
|
80
|
+
/** Ascendente; empates por orden de registro. */
|
|
81
|
+
order?: number;
|
|
82
|
+
when?: GraftWhen;
|
|
83
|
+
/** Lentes que lee. Una lente no declarada no llega. */
|
|
84
|
+
reads?: string[];
|
|
85
|
+
/** Campos que puede proponer cambiar. Admite `prefijo.*`. */
|
|
86
|
+
writes?: string[];
|
|
87
|
+
/** Red que necesita (declarativo; lo hace cumplir el sandbox/CSP, ver RFC §Seguridad). */
|
|
88
|
+
network?: 'none' | 'org' | string[];
|
|
89
|
+
offline?: boolean;
|
|
90
|
+
props?: Record<string, unknown>;
|
|
91
|
+
/** Part que monta (registrado con `registerPart`) o el componente en línea. */
|
|
92
|
+
part?: string;
|
|
93
|
+
component?: GraftComponent<any>;
|
|
94
|
+
load?: () => Promise<GraftModule>;
|
|
95
|
+
}
|
|
96
|
+
export interface ProposalInput {
|
|
97
|
+
patch: Record<string, unknown>;
|
|
98
|
+
/** Por qué (se muestra al usuario): «Datos de la constancia fiscal». */
|
|
99
|
+
reason?: string;
|
|
100
|
+
/** 0..1. */
|
|
101
|
+
confidence?: number;
|
|
102
|
+
/** Etiquetas legibles por campo, si el injerto las conoce. */
|
|
103
|
+
labels?: Record<string, string>;
|
|
104
|
+
/** `review` (por omisión) o `auto` si el preset lo permite. */
|
|
105
|
+
apply?: 'review' | 'auto';
|
|
106
|
+
}
|
|
107
|
+
export interface Proposal extends ProposalInput {
|
|
108
|
+
id: string;
|
|
109
|
+
graft: string;
|
|
110
|
+
addon: string;
|
|
111
|
+
/** Valores antes del parche (para el diff y el deshacer). */
|
|
112
|
+
previous: Record<string, unknown>;
|
|
113
|
+
/** Claves descartadas por no estar en `writes`/`writable`. */
|
|
114
|
+
dropped: string[];
|
|
115
|
+
}
|
|
116
|
+
export type SkipReason = 'not_granted' | 'permission' | 'flag' | 'setting' | 'model' | 'mode' | 'version' | 'no_component';
|
|
117
|
+
export interface SkippedGraft {
|
|
118
|
+
graft: GraftDef;
|
|
119
|
+
reason: SkipReason;
|
|
120
|
+
detail?: string;
|
|
121
|
+
}
|
|
122
|
+
export interface ResolvedSeam {
|
|
123
|
+
mounted: GraftDef[];
|
|
124
|
+
skipped: SkippedGraft[];
|
|
125
|
+
}
|
|
126
|
+
/** Lo que el anfitrión sabe del usuario/organización para evaluar `when`. */
|
|
127
|
+
export interface LoomEnv {
|
|
128
|
+
can: (permission: string) => boolean;
|
|
129
|
+
flags?: ReadonlySet<string>;
|
|
130
|
+
settings?: Readonly<Record<string, unknown>>;
|
|
131
|
+
model?: string;
|
|
132
|
+
mode?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Ids de injertos que el servidor autorizó para este usuario. Presente = el cliente no monta
|
|
135
|
+
* nada fuera de la lista (el servidor manda). Ausente = sólo código local de confianza.
|
|
136
|
+
*/
|
|
137
|
+
granted?: ReadonlySet<string>;
|
|
138
|
+
}
|
|
139
|
+
export type LoomEvent = {
|
|
140
|
+
type: 'graft_failed';
|
|
141
|
+
seam: string;
|
|
142
|
+
graft: string;
|
|
143
|
+
addon: string;
|
|
144
|
+
reason: 'load' | 'render';
|
|
145
|
+
message: string;
|
|
146
|
+
} | {
|
|
147
|
+
type: 'proposal_dropped_keys';
|
|
148
|
+
seam: string;
|
|
149
|
+
graft: string;
|
|
150
|
+
addon: string;
|
|
151
|
+
keys: string[];
|
|
152
|
+
};
|
|
153
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/loom/types.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAE1C,8EAA8E;AAC9E,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,GAAG,KAAK,GAAG,YAAY,GAAG,QAAQ,CAAA;AAEzF,sDAAsD;AACtD,MAAM,WAAW,YAAY;IACzB,EAAE,EAAE,MAAM,CAAA;IACV,0EAA0E;IAC1E,OAAO,EAAE,MAAM,CAAA;IACf,qDAAqD;IACrD,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAA;IAC3C;;;OAGG;IACH,QAAQ,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IAC9B,6EAA6E;IAC7E,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAC9B;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAAA;AAElE,mEAAmE;AACnE,MAAM,WAAW,SAAS;IACtB,iCAAiC;IACjC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAC9B,sCAAsC;IACtC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;IACxB,2BAA2B;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,iFAAiF;IACjF,OAAO,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC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H;IAAE,IAAI,EAAE,uBAAuB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -13,6 +13,12 @@ export interface UseRecordPickerDialogOptions {
|
|
|
13
13
|
lockedCreateFields?: string[];
|
|
14
14
|
/** Fields merged into the modal schema (e.g. a `widget` field that fills siblings via `setValues`). */
|
|
15
15
|
ensureFields?: FieldDef[];
|
|
16
|
+
/**
|
|
17
|
+
* Un injerto del modal (Loom `record.dialog.header`) detectó que el registro ya existe y pide
|
|
18
|
+
* usarlo (`record.select`): se cierra el modal y se entrega el registro. Sin él, la intención
|
|
19
|
+
* no se atiende y el injerto sigue su camino (p. ej. rellena el formulario).
|
|
20
|
+
*/
|
|
21
|
+
onSelectExisting?: (record: Record<string, unknown>) => void;
|
|
16
22
|
/** The saved record (`{ id, ...fields }`). */
|
|
17
23
|
onSaved: (record: Record<string, unknown>, kind: 'create' | 'edit') => void;
|
|
18
24
|
}
|
|
@@ -22,5 +28,5 @@ export interface UseRecordPickerDialogResult {
|
|
|
22
28
|
/** Render it next to the picker. */
|
|
23
29
|
dialog: ReactNode;
|
|
24
30
|
}
|
|
25
|
-
export declare function useRecordPickerDialog({ model, endpoint, prefillField, createDefaults, lockedCreateFields, ensureFields, onSaved, }: UseRecordPickerDialogOptions): UseRecordPickerDialogResult;
|
|
31
|
+
export declare function useRecordPickerDialog({ model, endpoint, prefillField, createDefaults, lockedCreateFields, ensureFields, onSelectExisting, onSaved, }: UseRecordPickerDialogOptions): UseRecordPickerDialogResult;
|
|
26
32
|
//# sourceMappingURL=record-picker-dialog.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record-picker-dialog.d.ts","sourceRoot":"","sources":["../src/record-picker-dialog.tsx"],"names":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W,4BAA4B;IACzC,wBAAwB;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,sEAAsE;IACtE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,mFAAmF;IACnF,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,qDAAqD;IACrD,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACxC,4DAA4D;IAC5D,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC7B,uGAAuG;IACvG,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAA;IACzB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;IAC5D,8CAA8C;IAC9C,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,GAAG,MAAM,KAAK,IAAI,CAAA;CAC9E;AAED,MAAM,WAAW,2BAA2B;IACxC,UAAU,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IACpC,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;IAC9B,oCAAoC;IACpC,MAAM,EAAE,SAAS,CAAA;CACpB;AAID,wBAAgB,qBAAqB,CAAC,EAClC,KAAK,EACL,QAAQ,EACR,YAAqB,EACrB,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAChB,OAAO,GACV,EAAE,4BAA4B,GAAG,2BAA2B,CAgE5D"}
|
|
@@ -14,14 +14,29 @@ import { CreateRecordDialog } from './dialogs/create-record-dialog.js';
|
|
|
14
14
|
import { useApi } from './api-context.js';
|
|
15
15
|
import { withSearchPrefill } from './record-picker-actions.js';
|
|
16
16
|
const unwrapRecord = (res) => unwrapResponse(res) ?? {};
|
|
17
|
-
export function useRecordPickerDialog({ model, endpoint, prefillField = 'name', createDefaults, lockedCreateFields, ensureFields, onSaved, }) {
|
|
17
|
+
export function useRecordPickerDialog({ model, endpoint, prefillField = 'name', createDefaults, lockedCreateFields, ensureFields, onSelectExisting, onSaved, }) {
|
|
18
18
|
const api = useApi();
|
|
19
19
|
const base = endpoint ?? `/data/${model}/me`;
|
|
20
20
|
const [state, setState] = useState(null);
|
|
21
|
+
// Intenciones Loom: `record.select` entrega el existente; `record.edit` reabre en edición con
|
|
22
|
+
// el parche como propuesta revisable (nada se guarda sin confirmar).
|
|
23
|
+
const onIntent = (intent, payload) => {
|
|
24
|
+
const p = (payload ?? {});
|
|
25
|
+
if (intent === 'record.select' && onSelectExisting && p.record) {
|
|
26
|
+
setState(null);
|
|
27
|
+
onSelectExisting(p.record);
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
if (intent === 'record.edit' && p.id != null) {
|
|
31
|
+
setState({ recordId: String(p.id), proposal: p.patch ? { patch: p.patch, reason: p.reason, apply: p.apply } : undefined });
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
};
|
|
21
36
|
const dialog = state ? (_jsx(CreateRecordDialog, { modelKey: model, open: true, onOpenChange: (o) => {
|
|
22
37
|
if (!o)
|
|
23
38
|
setState(null);
|
|
24
|
-
}, recordId: state.recordId, endpoint: base, defaults: state.recordId ? undefined : state.defaults, lockedFields: state.recordId ? undefined : lockedCreateFields, ensureFields: ensureFields, onCreate: async (data) => {
|
|
39
|
+
}, recordId: state.recordId, endpoint: base, defaults: state.recordId ? undefined : state.defaults, lockedFields: state.recordId ? undefined : lockedCreateFields, ensureFields: ensureFields, onIntent: onIntent, initialProposal: state.proposal, onCreate: async (data) => {
|
|
25
40
|
const rec = unwrapRecord(await api.post(base, data));
|
|
26
41
|
onSaved(rec, 'create');
|
|
27
42
|
return rec.id != null ? { id: String(rec.id) } : undefined;
|
|
@@ -29,7 +44,7 @@ export function useRecordPickerDialog({ model, endpoint, prefillField = 'name',
|
|
|
29
44
|
const rec = unwrapRecord(await api.put(`${base}/${id}`, data));
|
|
30
45
|
onSaved({ ...rec, id: rec.id ?? id }, 'edit');
|
|
31
46
|
return { id: String(id) };
|
|
32
|
-
} })) : null;
|
|
47
|
+
} }, state.recordId ?? 'new')) : null;
|
|
33
48
|
return {
|
|
34
49
|
openCreate: (query = '') => setState({ defaults: withSearchPrefill(query, prefillField, createDefaults) }),
|
|
35
50
|
openEdit: (id) => setState({ recordId: id }),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asteby/metacore-runtime-react",
|
|
3
|
-
"version": "53.
|
|
3
|
+
"version": "53.29.0",
|
|
4
4
|
"description": "React runtime for metacore hosts — renders addon contributions dynamically",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@asteby/metacore-charts": "^0.
|
|
40
|
+
"@asteby/metacore-charts": "^0.2.0",
|
|
41
41
|
"@asteby/metacore-lib": "^0.12.1",
|
|
42
42
|
"@dnd-kit/core": "^6.3.0",
|
|
43
43
|
"@dnd-kit/sortable": "^10.0.0",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"@asteby/metacore-sdk": "^3.23.0",
|
|
51
|
-
"@asteby/metacore-ui": "^2.
|
|
51
|
+
"@asteby/metacore-ui": "^2.40.0",
|
|
52
52
|
"@tanstack/react-query": ">=5",
|
|
53
53
|
"@tanstack/react-router": ">=1.100",
|
|
54
54
|
"@tanstack/react-table": ">=8",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"zustand": ">=5",
|
|
64
64
|
"@module-federation/runtime": ">=2.5",
|
|
65
65
|
"@testing-library/react": ">=14",
|
|
66
|
-
"@asteby/metacore-genui": "^2.
|
|
66
|
+
"@asteby/metacore-genui": "^2.10.0"
|
|
67
67
|
},
|
|
68
68
|
"peerDependenciesMeta": {
|
|
69
69
|
"@tanstack/react-router": {
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@asteby/metacore-sdk": "3.23.0",
|
|
87
|
-
"@asteby/metacore-ui": "2.
|
|
87
|
+
"@asteby/metacore-ui": "2.40.0",
|
|
88
88
|
"@tanstack/react-query": "^5.95.0",
|
|
89
89
|
"@tanstack/react-router": "^1.168.0",
|
|
90
90
|
"@tanstack/react-table": "^8.20.0",
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"vitest": "^4.0.0",
|
|
106
106
|
"zustand": "^5.0.0",
|
|
107
107
|
"@module-federation/runtime": "^2.5.0",
|
|
108
|
-
"@asteby/metacore-genui": "2.
|
|
108
|
+
"@asteby/metacore-genui": "2.10.0"
|
|
109
109
|
},
|
|
110
110
|
"scripts": {
|
|
111
111
|
"build": "tsc -p tsconfig.json && node ../../scripts/fix-dist-esm-imports.mjs",
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
//
|
|
3
|
+
// Seam `record.dialog.header` de DynamicRecordDialog (Loom, RFC 0005): un injerto
|
|
4
|
+
// registrado para el modelo propone un parche; el diálogo muestra el diff, aplica,
|
|
5
|
+
// deshace; las claves fuera de `writes` se descartan; un injerto que lanza no
|
|
6
|
+
// rompe el formulario; las intenciones llegan a quien abrió el diálogo.
|
|
7
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
8
|
+
import { act, cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
|
|
9
|
+
import { I18nextProvider } from 'react-i18next'
|
|
10
|
+
import i18next from 'i18next'
|
|
11
|
+
|
|
12
|
+
import { DynamicRecordDialog } from '../dialogs/dynamic-record'
|
|
13
|
+
import { ApiProvider } from '../api-context'
|
|
14
|
+
import { clearLoom, LoomProvider, registerGraft, type GraftProps, type LoomEvent } from '../loom'
|
|
15
|
+
|
|
16
|
+
vi.mock('sonner', () => ({ toast: { error: vi.fn(), success: vi.fn() } }))
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
cleanup()
|
|
19
|
+
clearLoom()
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
const i18n = (() => {
|
|
23
|
+
const inst = i18next.createInstance()
|
|
24
|
+
void inst.init({ lng: 'es', fallbackLng: 'es', react: { useSuspense: false }, resources: { es: { translation: {} } } })
|
|
25
|
+
return inst
|
|
26
|
+
})()
|
|
27
|
+
|
|
28
|
+
const api = { get: vi.fn(async () => ({ data: { data: {} } })), post: vi.fn(), put: vi.fn(), delete: vi.fn() } as never
|
|
29
|
+
|
|
30
|
+
const schema = {
|
|
31
|
+
title: 'Cliente',
|
|
32
|
+
fields: [
|
|
33
|
+
{ key: 'name', label: 'Nombre', type: 'text' },
|
|
34
|
+
{ key: 'tax_id', label: 'RFC', type: 'text' },
|
|
35
|
+
{ key: 'postal_code', label: 'Código postal', type: 'text' },
|
|
36
|
+
],
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function Reader({ lenses, caps }: GraftProps) {
|
|
40
|
+
const values = lenses.values as Record<string, unknown>
|
|
41
|
+
return (
|
|
42
|
+
<div>
|
|
43
|
+
<span data-testid="lens-keys">{Object.keys(lenses).join(',')}</span>
|
|
44
|
+
<span data-testid="lens-name">{String(values.name ?? '')}</span>
|
|
45
|
+
<button type="button" onClick={() => caps.propose({ patch: { tax_id: 'XAXX010101000', postal_code: '64000', organization_id: 'hack' }, reason: 'Datos de la constancia fiscal' })}>
|
|
46
|
+
Leer constancia
|
|
47
|
+
</button>
|
|
48
|
+
<button type="button" onClick={() => caps.emit('record.select', { record: { id: '9' } })}>
|
|
49
|
+
Usar existente
|
|
50
|
+
</button>
|
|
51
|
+
</div>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function renderDialog(extra: Record<string, unknown> = {}, onEvent?: (e: LoomEvent) => void, model = 'Customer') {
|
|
56
|
+
return render(
|
|
57
|
+
<I18nextProvider i18n={i18n}>
|
|
58
|
+
<ApiProvider client={api}>
|
|
59
|
+
<LoomProvider onEvent={onEvent}>
|
|
60
|
+
<DynamicRecordDialog open onOpenChange={() => {}} mode="create" model={model} schema={schema as never} defaults={{ name: 'Ana' }} {...extra} />
|
|
61
|
+
</LoomProvider>
|
|
62
|
+
</ApiProvider>
|
|
63
|
+
</I18nextProvider>,
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const csf = () =>
|
|
68
|
+
registerGraft({
|
|
69
|
+
id: 'fiscal_mexico.csf',
|
|
70
|
+
addon: 'fiscal_mexico',
|
|
71
|
+
seam: 'record.dialog.header',
|
|
72
|
+
requires: '^1',
|
|
73
|
+
when: { model: ['Customer'] },
|
|
74
|
+
reads: ['values', 'mode'],
|
|
75
|
+
writes: ['tax_id', 'postal_code'],
|
|
76
|
+
network: 'none',
|
|
77
|
+
component: Reader,
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
describe('DynamicRecordDialog · seam record.dialog.header', () => {
|
|
81
|
+
it('propuesta con diff → aplicar → deshacer; sólo pasan los writes', async () => {
|
|
82
|
+
csf()
|
|
83
|
+
const events: LoomEvent[] = []
|
|
84
|
+
renderDialog({}, (e) => events.push(e))
|
|
85
|
+
await waitFor(() => expect(screen.getByText('Leer constancia')).toBeTruthy())
|
|
86
|
+
expect(screen.getByTestId('lens-keys').textContent).toBe('values,mode')
|
|
87
|
+
expect(screen.getByTestId('lens-name').textContent).toBe('Ana')
|
|
88
|
+
|
|
89
|
+
fireEvent.click(screen.getByText('Leer constancia'))
|
|
90
|
+
const review = await screen.findByRole('region', { name: 'Datos de la constancia fiscal' })
|
|
91
|
+
expect(within(review).getByText('RFC')).toBeTruthy()
|
|
92
|
+
expect(within(review).getByText('XAXX010101000')).toBeTruthy()
|
|
93
|
+
expect(within(review).queryByText('hack')).toBeNull()
|
|
94
|
+
expect(events).toContainEqual(expect.objectContaining({ type: 'proposal_dropped_keys', keys: ['organization_id'] }))
|
|
95
|
+
// Nada se aplica hasta confirmar.
|
|
96
|
+
const taxInput = () => document.querySelector<HTMLInputElement>('input[name="tax_id"], #tax_id') ?? screen.getAllByRole('textbox')[1]
|
|
97
|
+
expect(taxInput().value).toBe('')
|
|
98
|
+
|
|
99
|
+
fireEvent.click(within(review).getByRole('button', { name: 'Aplicar' }))
|
|
100
|
+
await waitFor(() => expect(taxInput().value).toBe('XAXX010101000'))
|
|
101
|
+
fireEvent.click(screen.getByRole('button', { name: 'Deshacer' }))
|
|
102
|
+
await waitFor(() => expect(taxInput().value).toBe(''))
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
it('no aparece en otro modelo', async () => {
|
|
106
|
+
csf()
|
|
107
|
+
renderDialog({}, undefined, 'Supplier')
|
|
108
|
+
await waitFor(() => expect(screen.getByRole('button', { name: 'Crear' })).toBeTruthy())
|
|
109
|
+
expect(screen.queryByText('Leer constancia')).toBeNull()
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('un injerto que lanza no rompe el formulario y su error sale redactado', async () => {
|
|
113
|
+
registerGraft({
|
|
114
|
+
id: 'bad.x',
|
|
115
|
+
addon: 'bad',
|
|
116
|
+
seam: 'record.dialog.header',
|
|
117
|
+
reads: ['values'],
|
|
118
|
+
component: () => {
|
|
119
|
+
throw new Error('RFC XAXX010101000 inválido')
|
|
120
|
+
},
|
|
121
|
+
})
|
|
122
|
+
const events: LoomEvent[] = []
|
|
123
|
+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
124
|
+
renderDialog({}, (e) => events.push(e))
|
|
125
|
+
await waitFor(() => expect(screen.getByRole('button', { name: 'Crear' })).toBeTruthy())
|
|
126
|
+
spy.mockRestore()
|
|
127
|
+
const failed = events.find((e) => e.type === 'graft_failed')
|
|
128
|
+
expect(failed).toMatchObject({ graft: 'bad.x', reason: 'render' })
|
|
129
|
+
expect(JSON.stringify(failed)).not.toContain('XAXX')
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
it('las intenciones llegan al anfitrión', async () => {
|
|
133
|
+
csf()
|
|
134
|
+
const onIntent = vi.fn(() => true)
|
|
135
|
+
renderDialog({ onIntent })
|
|
136
|
+
fireEvent.click(await screen.findByText('Usar existente'))
|
|
137
|
+
expect(onIntent).toHaveBeenCalledWith('record.select', { record: { id: '9' } })
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it('initialProposal se muestra como diff al abrir', async () => {
|
|
141
|
+
renderDialog({ initialProposal: { patch: { tax_id: 'XEXX010101000', organization_id: 'x' }, reason: 'Constancia' } })
|
|
142
|
+
const review = await screen.findByRole('region', { name: 'Constancia' })
|
|
143
|
+
expect(within(review).getByText('XEXX010101000')).toBeTruthy()
|
|
144
|
+
act(() => fireEvent.click(within(review).getByRole('button', { name: 'Descartar' })))
|
|
145
|
+
expect(screen.queryByRole('region', { name: 'Constancia' })).toBeNull()
|
|
146
|
+
})
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
describe('useRecordPickerDialog · intenciones', () => {
|
|
150
|
+
it('record.select entrega el existente y cierra; record.edit reabre en edición con la propuesta', async () => {
|
|
151
|
+
const { useRecordPickerDialog } = await import('../record-picker-dialog')
|
|
152
|
+
csf()
|
|
153
|
+
const onSelectExisting = vi.fn()
|
|
154
|
+
function Host() {
|
|
155
|
+
const d = useRecordPickerDialog({ model: 'Customer', onSaved: () => {}, onSelectExisting })
|
|
156
|
+
return (
|
|
157
|
+
<>
|
|
158
|
+
<button type="button" onClick={() => d.openCreate('Ana')}>abrir</button>
|
|
159
|
+
{d.dialog}
|
|
160
|
+
</>
|
|
161
|
+
)
|
|
162
|
+
}
|
|
163
|
+
const getApi = { get: vi.fn(async () => ({ data: { data: { id: '9', name: 'Ana', tax_id: '' } } })), post: vi.fn(), put: vi.fn(), delete: vi.fn() } as never
|
|
164
|
+
render(
|
|
165
|
+
<I18nextProvider i18n={i18n}>
|
|
166
|
+
<ApiProvider client={getApi}>
|
|
167
|
+
<LoomProvider>
|
|
168
|
+
<Host />
|
|
169
|
+
</LoomProvider>
|
|
170
|
+
</ApiProvider>
|
|
171
|
+
</I18nextProvider>,
|
|
172
|
+
)
|
|
173
|
+
fireEvent.click(screen.getByText('abrir'))
|
|
174
|
+
fireEvent.click(await screen.findByText('Usar existente'))
|
|
175
|
+
expect(onSelectExisting).toHaveBeenCalledWith({ id: '9' })
|
|
176
|
+
await waitFor(() => expect(screen.queryByText('Usar existente')).toBeNull())
|
|
177
|
+
})
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
describe('DynamicRecordDialog · seam record.form.section', () => {
|
|
181
|
+
it('monta contenido dentro del modal, después de los campos', async () => {
|
|
182
|
+
registerGraft({
|
|
183
|
+
id: 'fiscal_mexico.csf-section',
|
|
184
|
+
seam: 'record.form.section',
|
|
185
|
+
when: { model: ['Customer'] },
|
|
186
|
+
component: () => <section aria-label="Constancia fiscal">contenido</section>,
|
|
187
|
+
})
|
|
188
|
+
renderDialog()
|
|
189
|
+
const section = await screen.findByRole('region', { name: 'Constancia fiscal' }, { timeout: 5000 })
|
|
190
|
+
const form = document.querySelector('form[data-aby-record-form]')!
|
|
191
|
+
expect(form.compareDocumentPosition(section) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy()
|
|
192
|
+
expect(section.closest('[data-loom-seam="record.form.section"]')).toBeTruthy()
|
|
193
|
+
})
|
|
194
|
+
})
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Overlays sobre el grafo de bloques del tablero: base de OPS + capas del preset
|
|
2
|
+
// (7 Leguas), organización y rol.
|
|
3
|
+
import { describe, expect, it } from 'vitest'
|
|
4
|
+
import { applyOverlays, mergeConfig, type BlockGraph, type OverlayLayer } from '../loom'
|
|
5
|
+
|
|
6
|
+
const base: BlockGraph = {
|
|
7
|
+
id: 'ops.dashboard',
|
|
8
|
+
version: '1.3.0',
|
|
9
|
+
blocks: [
|
|
10
|
+
{ id: 'kpi.sales', type: 'kpi', config: { metric: 'sales', range: '7d', style: { tone: 'primary' } } },
|
|
11
|
+
{ id: 'chart.sales', type: 'chart', config: { kind: 'line' } },
|
|
12
|
+
{ id: 'list.recent', type: 'table', config: { model: 'SalesOrder' } },
|
|
13
|
+
],
|
|
14
|
+
}
|
|
15
|
+
const ids = (g: BlockGraph) => g.blocks.map((b) => b.id)
|
|
16
|
+
|
|
17
|
+
describe('applyOverlays', () => {
|
|
18
|
+
it('aplica capas por alcance (preset < org < role) sin importar el orden de entrada', () => {
|
|
19
|
+
const layers: OverlayLayer[] = [
|
|
20
|
+
{ id: 'role.cajero', scope: 'role', ops: [{ op: 'remove', id: 'leguas.vehicles' }] },
|
|
21
|
+
{
|
|
22
|
+
id: 'preset.7leguas',
|
|
23
|
+
scope: 'preset',
|
|
24
|
+
targets: '^1.2',
|
|
25
|
+
ops: [
|
|
26
|
+
{ op: 'add', block: { id: 'leguas.vehicles', type: 'kpi', config: { metric: 'vehicles' } }, after: 'kpi.sales' },
|
|
27
|
+
{ op: 'configure', id: 'kpi.sales', set: { range: '30d', style: { tone: null } } },
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
{ id: 'org.matriz', scope: 'org', ops: [{ op: 'move', id: 'list.recent', before: 'kpi.sales' }] },
|
|
31
|
+
]
|
|
32
|
+
const r = applyOverlays(base, layers)
|
|
33
|
+
expect(r.applied).toEqual(['preset.7leguas', 'org.matriz', 'role.cajero'])
|
|
34
|
+
expect(ids(r.graph)).toEqual(['list.recent', 'kpi.sales', 'chart.sales'])
|
|
35
|
+
expect(r.graph.blocks[1].config).toEqual({ metric: 'sales', range: '30d', style: {} })
|
|
36
|
+
expect(r.removed).toEqual({ 'leguas.vehicles': 'role.cajero' })
|
|
37
|
+
expect(r.provenance['kpi.sales']).toEqual({ origin: 'base', touchedBy: ['preset.7leguas'] })
|
|
38
|
+
expect(r.conflicts).toEqual([])
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('una capa es atómica: si una operación no aplica, no aplica ninguna', () => {
|
|
42
|
+
const r = applyOverlays(base, [
|
|
43
|
+
{
|
|
44
|
+
id: 'org.x',
|
|
45
|
+
scope: 'org',
|
|
46
|
+
ops: [
|
|
47
|
+
{ op: 'remove', id: 'chart.sales' },
|
|
48
|
+
{ op: 'configure', id: 'kpi.inexistente', set: { a: 1 } },
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
])
|
|
52
|
+
expect(ids(r.graph)).toEqual(ids(base))
|
|
53
|
+
expect(r.conflicts).toEqual([{ layer: 'org.x', index: 1, reason: 'missing_target', detail: 'kpi.inexistente' }])
|
|
54
|
+
expect(r.applied).toEqual([])
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('si la base cambió de mayor, la capa cae al comportamiento base y avisa', () => {
|
|
58
|
+
const r = applyOverlays({ ...base, version: '2.0.0' }, [
|
|
59
|
+
{ id: 'preset.7leguas', scope: 'preset', targets: '^1.2', ops: [{ op: 'remove', id: 'chart.sales' }] },
|
|
60
|
+
])
|
|
61
|
+
expect(ids(r.graph)).toEqual(ids(base))
|
|
62
|
+
expect(r.conflicts[0]).toMatchObject({ reason: 'base_incompatible', index: -1 })
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('replace guarda el original como fallback y conserva el id', () => {
|
|
66
|
+
const r = applyOverlays(base, [
|
|
67
|
+
{ id: 'preset.p', scope: 'preset', ops: [{ op: 'replace', id: 'chart.sales', with: { id: 'x', type: 'leguas.sales-chart' } }] },
|
|
68
|
+
])
|
|
69
|
+
const b = r.graph.blocks[1]
|
|
70
|
+
expect(b).toMatchObject({ id: 'chart.sales', type: 'leguas.sales-chart' })
|
|
71
|
+
expect(b.fallback).toMatchObject({ type: 'chart' })
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('add con id repetido o ancla inexistente es conflicto', () => {
|
|
75
|
+
const r = applyOverlays(base, [
|
|
76
|
+
{ id: 'a', scope: 'org', ops: [{ op: 'add', block: { id: 'kpi.sales', type: 'kpi' } }] },
|
|
77
|
+
{ id: 'b', scope: 'org', ops: [{ op: 'add', block: { id: 'n', type: 'kpi' }, before: 'nope' }] },
|
|
78
|
+
])
|
|
79
|
+
expect(r.conflicts.map((c) => c.reason)).toEqual(['duplicate_id', 'missing_anchor'])
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('no muta la base y es determinista', () => {
|
|
83
|
+
const snap = JSON.stringify(base)
|
|
84
|
+
const layers: OverlayLayer[] = [{ id: 'o', scope: 'org', ops: [{ op: 'configure', id: 'kpi.sales', set: { range: '1d' } }] }]
|
|
85
|
+
const a = applyOverlays(base, layers)
|
|
86
|
+
const b = applyOverlays(base, layers)
|
|
87
|
+
expect(JSON.stringify(base)).toBe(snap)
|
|
88
|
+
expect(a).toEqual(b)
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('mergeConfig: arrays se sustituyen, null borra', () => {
|
|
92
|
+
expect(mergeConfig({ a: [1, 2], b: { c: 1, d: 2 } }, { a: [3], b: { d: null } })).toEqual({ a: [3], b: { c: 1 } })
|
|
93
|
+
})
|
|
94
|
+
})
|