@asteby/metacore-runtime-react 50.2.0 → 52.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 +25 -0
- package/README.md +26 -0
- package/dist/activity-diff.d.ts +5 -0
- package/dist/activity-diff.d.ts.map +1 -1
- package/dist/activity-timeline.d.ts.map +1 -1
- package/dist/activity-timeline.js +10 -3
- package/dist/audit-info.d.ts.map +1 -1
- package/dist/audit-info.js +17 -3
- package/dist/barcode-scanner.js +4 -4
- package/dist/dialogs/dynamic-record.d.ts +3 -1
- package/dist/dialogs/dynamic-record.d.ts.map +1 -1
- package/dist/dialogs/dynamic-record.js +19 -6
- package/dist/dynamic-columns.d.ts +6 -0
- package/dist/dynamic-columns.d.ts.map +1 -1
- package/dist/dynamic-columns.js +41 -7
- package/dist/dynamic-date-field.js +1 -1
- package/dist/dynamic-form.js +2 -2
- package/dist/dynamic-kanban.js +6 -5
- package/dist/dynamic-table.d.ts.map +1 -1
- package/dist/dynamic-table.js +6 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/org-runtime-context.d.ts +65 -0
- package/dist/org-runtime-context.d.ts.map +1 -1
- package/dist/org-runtime-context.js +24 -0
- package/dist/org-runtime-provider.d.ts +25 -1
- package/dist/org-runtime-provider.d.ts.map +1 -1
- package/dist/org-runtime-provider.js +3 -3
- package/dist/provenance.d.ts +216 -0
- package/dist/provenance.d.ts.map +1 -0
- package/dist/provenance.js +386 -0
- package/dist/record-history.d.ts.map +1 -1
- package/dist/record-history.js +6 -2
- package/dist/sidebar-layout-manager.js +2 -2
- package/dist/widgets/widget-card.d.ts +7 -2
- package/dist/widgets/widget-card.d.ts.map +1 -1
- package/dist/widgets/widget-card.js +6 -3
- package/package.json +3 -3
- package/src/__tests__/org-runtime-number-locale-system-actor.test.tsx +80 -0
- package/src/__tests__/provenance.test.tsx +209 -0
- package/src/activity-diff.tsx +5 -0
- package/src/activity-timeline.tsx +16 -2
- package/src/audit-info.tsx +20 -3
- package/src/barcode-scanner.tsx +4 -4
- package/src/dialogs/dynamic-record.tsx +26 -5
- package/src/dynamic-columns.tsx +68 -6
- package/src/dynamic-date-field.tsx +1 -1
- package/src/dynamic-form.tsx +2 -2
- package/src/dynamic-kanban.tsx +6 -5
- package/src/dynamic-table.tsx +6 -4
- package/src/index.ts +2 -0
- package/src/org-runtime-context.ts +92 -0
- package/src/org-runtime-provider.tsx +50 -3
- package/src/provenance.tsx +585 -0
- package/src/record-history.tsx +17 -4
- package/src/sidebar-layout-manager.tsx +2 -2
- package/src/widgets/widget-card.tsx +26 -3
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* provenance.tsx — who made a record, and how.
|
|
4
|
+
*
|
|
5
|
+
* The kernel's `provenance` package stores, per record and per change, the
|
|
6
|
+
* actor kind (human | agent | system | integration), the person the agent
|
|
7
|
+
* acted for, who authorized an agent proposal and when, the channel (`via`),
|
|
8
|
+
* the origin and the mode (manual | assisted | automated). Hosts attach the
|
|
9
|
+
* creation provenance to list rows at `created_by.provenance` (or
|
|
10
|
+
* `row.provenance`); this module turns it into one of four presentations:
|
|
11
|
+
*
|
|
12
|
+
* human — a person on their own: their avatar and name.
|
|
13
|
+
* agent — the app's agent (OrgRuntimeProvider `agentActor`, e.g. Gobi)
|
|
14
|
+
* with the origin; "pending proposal" when it waits for a person.
|
|
15
|
+
* system — platform work or an integration: system icon + origin.
|
|
16
|
+
* assisted — "Ana with Gobi": the person's avatar with the agent's
|
|
17
|
+
* superimposed, and an accessible tooltip with who authorized,
|
|
18
|
+
* what the agent proposed and when.
|
|
19
|
+
*
|
|
20
|
+
* Rows without stored provenance keep the legacy rules: a null/system
|
|
21
|
+
* `created_by_id` is the system (origin from OrgRuntimeProvider
|
|
22
|
+
* `provenanceOrigin`), anything else is the person in `created_by`.
|
|
23
|
+
*/
|
|
24
|
+
import * as React from 'react';
|
|
25
|
+
import { useTranslation } from 'react-i18next';
|
|
26
|
+
import { Bot, Plug, Server } from 'lucide-react';
|
|
27
|
+
import { Avatar, AvatarFallback, AvatarImage, Tooltip, TooltipContent, TooltipTrigger } from '@asteby/metacore-ui';
|
|
28
|
+
import { cn, getInitials } from '@asteby/metacore-ui/lib';
|
|
29
|
+
import { useImageUrl } from './image-url-context';
|
|
30
|
+
import { isNilUuid } from './nil-uuid';
|
|
31
|
+
import { useAgentActor, useProvenanceOrigin, useSystemActor, useTimeZone } from './org-runtime-context';
|
|
32
|
+
/** The kernel's fixed actor for unattended work. */
|
|
33
|
+
const KERNEL_SYSTEM_ACTOR_ID = '00000000-0000-0000-0000-000000000001';
|
|
34
|
+
const KINDS = new Set(['human', 'agent', 'system', 'integration']);
|
|
35
|
+
function str(v) {
|
|
36
|
+
return typeof v === 'string' && v.trim() !== '' ? v : undefined;
|
|
37
|
+
}
|
|
38
|
+
/** Defensive reader: an object or JSON string with a known `actor_kind`. */
|
|
39
|
+
export function parseProvenance(raw) {
|
|
40
|
+
let v = raw;
|
|
41
|
+
if (typeof v === 'string') {
|
|
42
|
+
try {
|
|
43
|
+
v = JSON.parse(v);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (!v || typeof v !== 'object' || Array.isArray(v))
|
|
50
|
+
return undefined;
|
|
51
|
+
const o = v;
|
|
52
|
+
if (typeof o.actor_kind !== 'string' || !KINDS.has(o.actor_kind))
|
|
53
|
+
return undefined;
|
|
54
|
+
return o;
|
|
55
|
+
}
|
|
56
|
+
/** Reads a row's creation provenance (`created_by.provenance` or `provenance`). */
|
|
57
|
+
export function readProvenance(row) {
|
|
58
|
+
if (!row)
|
|
59
|
+
return undefined;
|
|
60
|
+
const cb = row.created_by;
|
|
61
|
+
if (cb && typeof cb === 'object') {
|
|
62
|
+
const p = parseProvenance(cb.provenance);
|
|
63
|
+
if (p)
|
|
64
|
+
return p;
|
|
65
|
+
}
|
|
66
|
+
return parseProvenance(row.provenance);
|
|
67
|
+
}
|
|
68
|
+
/** Which of the four presentations a provenance gets. */
|
|
69
|
+
export function classifyProvenance(p) {
|
|
70
|
+
if (p.actor_kind === 'human')
|
|
71
|
+
return 'human';
|
|
72
|
+
if (p.mode === 'assisted' || (p.authorized_by && !p.proposed))
|
|
73
|
+
return 'assisted';
|
|
74
|
+
if (p.actor_kind === 'agent')
|
|
75
|
+
return 'agent';
|
|
76
|
+
return 'system';
|
|
77
|
+
}
|
|
78
|
+
/** True when the row's creator is the system (null / nil / kernel actor). */
|
|
79
|
+
export function isSystemCreated(row) {
|
|
80
|
+
if (!row)
|
|
81
|
+
return false;
|
|
82
|
+
const cb = row.created_by;
|
|
83
|
+
if (cb && typeof cb === 'object') {
|
|
84
|
+
const o = cb;
|
|
85
|
+
if (o.system === true)
|
|
86
|
+
return true;
|
|
87
|
+
if (str(o.name) || str(o.email))
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
if ('created_by_id' in row) {
|
|
91
|
+
const id = row.created_by_id;
|
|
92
|
+
if (id === null || id === undefined || id === '')
|
|
93
|
+
return true;
|
|
94
|
+
const s = String(id).trim().toLowerCase();
|
|
95
|
+
return s === '<nil>' || isNilUuid(s) || s === KERNEL_SYSTEM_ACTOR_ID;
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
// ---- copy -------------------------------------------------------------------
|
|
100
|
+
const COPY = {
|
|
101
|
+
es: {
|
|
102
|
+
system: 'Sistema',
|
|
103
|
+
agent: 'Asistente',
|
|
104
|
+
user: 'Usuario',
|
|
105
|
+
with: '{{person}} con {{agent}}',
|
|
106
|
+
proposedBy: 'Propuesto por {{agent}}',
|
|
107
|
+
pending: 'Propuesta pendiente',
|
|
108
|
+
authorizedBy: 'Autorizó: {{person}}',
|
|
109
|
+
onBehalfOf: 'En nombre de {{person}}',
|
|
110
|
+
proposal: '{{agent}} propuso: {{summary}}',
|
|
111
|
+
createdBy: 'Creado por {{who}}',
|
|
112
|
+
'via.chat': 'Chat',
|
|
113
|
+
'via.automation': 'Automatización',
|
|
114
|
+
'via.import': 'Importación',
|
|
115
|
+
'via.webhook': 'Webhook',
|
|
116
|
+
'via.seed': 'Datos iniciales',
|
|
117
|
+
'via.migration': 'Migración',
|
|
118
|
+
'via.job': 'Proceso programado',
|
|
119
|
+
'via.event': 'Evento',
|
|
120
|
+
'via.ui': 'Manual',
|
|
121
|
+
'via.api': 'API',
|
|
122
|
+
'mode.manual': 'Manual',
|
|
123
|
+
'mode.assisted': 'Con asistencia',
|
|
124
|
+
'mode.automated': 'Automático',
|
|
125
|
+
},
|
|
126
|
+
en: {
|
|
127
|
+
system: 'System',
|
|
128
|
+
agent: 'Assistant',
|
|
129
|
+
user: 'User',
|
|
130
|
+
with: '{{person}} with {{agent}}',
|
|
131
|
+
proposedBy: 'Proposed by {{agent}}',
|
|
132
|
+
pending: 'Pending proposal',
|
|
133
|
+
authorizedBy: 'Authorized by: {{person}}',
|
|
134
|
+
onBehalfOf: 'On behalf of {{person}}',
|
|
135
|
+
proposal: '{{agent}} proposed: {{summary}}',
|
|
136
|
+
createdBy: 'Created by {{who}}',
|
|
137
|
+
'via.chat': 'Chat',
|
|
138
|
+
'via.automation': 'Automation',
|
|
139
|
+
'via.import': 'Import',
|
|
140
|
+
'via.webhook': 'Webhook',
|
|
141
|
+
'via.seed': 'Initial data',
|
|
142
|
+
'via.migration': 'Migration',
|
|
143
|
+
'via.job': 'Scheduled job',
|
|
144
|
+
'via.event': 'Event',
|
|
145
|
+
'via.ui': 'Manual',
|
|
146
|
+
'via.api': 'API',
|
|
147
|
+
'mode.manual': 'Manual',
|
|
148
|
+
'mode.assisted': 'Assisted',
|
|
149
|
+
'mode.automated': 'Automated',
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
/** Copy lookup: `provenance.<key>` from the host i18n, else the built-in es/en. */
|
|
153
|
+
export function useProvenanceCopy() {
|
|
154
|
+
const { t, i18n } = useTranslation();
|
|
155
|
+
const lang = (i18n?.language || 'es').toLowerCase().startsWith('en') ? 'en' : 'es';
|
|
156
|
+
const copy = COPY[lang];
|
|
157
|
+
const tt = React.useCallback((key, vars) => {
|
|
158
|
+
const fallback = copy[key].replace(/\{\{(\w+)\}\}/g, (_, k) => vars?.[k] ?? '');
|
|
159
|
+
const out = t(`provenance.${key}`, { defaultValue: fallback, ...vars });
|
|
160
|
+
// i18n mocks/backends that ignore defaultValue echo the key back.
|
|
161
|
+
return !out || out === `provenance.${key}` ? fallback : out;
|
|
162
|
+
}, [t, copy]);
|
|
163
|
+
return { tt, lang };
|
|
164
|
+
}
|
|
165
|
+
function formatWhen(iso, lang, timeZone) {
|
|
166
|
+
if (!iso)
|
|
167
|
+
return undefined;
|
|
168
|
+
const d = new Date(iso);
|
|
169
|
+
if (Number.isNaN(d.getTime()))
|
|
170
|
+
return undefined;
|
|
171
|
+
try {
|
|
172
|
+
return d.toLocaleString(lang === 'en' ? 'en-US' : 'es-MX', {
|
|
173
|
+
dateStyle: 'medium',
|
|
174
|
+
timeStyle: 'short',
|
|
175
|
+
...(timeZone ? { timeZone } : {}),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
return d.toISOString();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/** Pure-ish resolver (hooks for copy and presentation contexts). */
|
|
183
|
+
export function useResolvedAuthorship(input) {
|
|
184
|
+
const { tt, lang } = useProvenanceCopy();
|
|
185
|
+
const agent = useAgentActor();
|
|
186
|
+
const sys = useSystemActor();
|
|
187
|
+
const tz = useTimeZone();
|
|
188
|
+
const { provenance: p, person, fallbackOrigin, system } = input;
|
|
189
|
+
const viaLabel = (via) => {
|
|
190
|
+
if (!via)
|
|
191
|
+
return undefined;
|
|
192
|
+
const key = `via.${via}`;
|
|
193
|
+
return key in COPY.es ? tt(key) : via;
|
|
194
|
+
};
|
|
195
|
+
if (!p) {
|
|
196
|
+
if (!system)
|
|
197
|
+
return null;
|
|
198
|
+
const name = sys?.name || tt('system');
|
|
199
|
+
return {
|
|
200
|
+
kind: 'system', label: name, subtitle: fallbackOrigin,
|
|
201
|
+
description: [tt('createdBy', { who: name }), fallbackOrigin].filter(Boolean).join(' · '),
|
|
202
|
+
agentName: agent?.name || tt('agent'), systemAvatar: sys?.avatarUrl, integration: false, proposed: false,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
const kind = classifyProvenance(p);
|
|
206
|
+
const agentName = agent?.name || str(p.actor_name) || tt('agent');
|
|
207
|
+
const when = formatWhen(p.authorized_at || p.at, lang, tz);
|
|
208
|
+
const origin = str(p.origin);
|
|
209
|
+
if (kind === 'human') {
|
|
210
|
+
const name = str(person?.name) || str(p.actor_person_name) || tt('user');
|
|
211
|
+
return {
|
|
212
|
+
kind, label: name, subtitle: origin,
|
|
213
|
+
description: [tt('createdBy', { who: name }), viaLabel(p.via), when].filter(Boolean).join(' · '),
|
|
214
|
+
person: { name, avatar: person?.avatar || p.actor_person_avatar },
|
|
215
|
+
agentName, integration: false, proposed: false,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
if (kind === 'assisted') {
|
|
219
|
+
const name = str(p.authorized_by_name) || str(person?.name) || str(p.on_behalf_of_name) || tt('user');
|
|
220
|
+
const avatar = p.authorized_by_avatar || person?.avatar || p.on_behalf_of_avatar;
|
|
221
|
+
const parts = [tt('authorizedBy', { person: name })];
|
|
222
|
+
parts.push(p.summary ? tt('proposal', { agent: agentName, summary: p.summary }) : tt('proposedBy', { agent: agentName }));
|
|
223
|
+
if (origin)
|
|
224
|
+
parts.push(origin);
|
|
225
|
+
if (when)
|
|
226
|
+
parts.push(when);
|
|
227
|
+
return {
|
|
228
|
+
kind, label: tt('with', { person: name, agent: agentName }),
|
|
229
|
+
subtitle: origin || tt('proposedBy', { agent: agentName }),
|
|
230
|
+
description: parts.join(' · '),
|
|
231
|
+
person: { name, avatar }, agentName, agentAvatar: agent?.avatarUrl, integration: false, proposed: false,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
if (kind === 'agent') {
|
|
235
|
+
const proposed = !!p.proposed;
|
|
236
|
+
const sub = proposed ? tt('pending') : origin || viaLabel(p.via);
|
|
237
|
+
const parts = [tt('createdBy', { who: agentName })];
|
|
238
|
+
if (proposed)
|
|
239
|
+
parts.push(tt('pending'));
|
|
240
|
+
if (origin)
|
|
241
|
+
parts.push(origin);
|
|
242
|
+
else if (p.via)
|
|
243
|
+
parts.push(viaLabel(p.via));
|
|
244
|
+
if (p.on_behalf_of_name)
|
|
245
|
+
parts.push(tt('onBehalfOf', { person: p.on_behalf_of_name }));
|
|
246
|
+
if (p.summary)
|
|
247
|
+
parts.push(p.summary);
|
|
248
|
+
if (when)
|
|
249
|
+
parts.push(when);
|
|
250
|
+
return {
|
|
251
|
+
kind, label: agentName, subtitle: sub, description: parts.join(' · '),
|
|
252
|
+
agentName, agentAvatar: agent?.avatarUrl, integration: false, proposed,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
const integration = p.actor_kind === 'integration';
|
|
256
|
+
const name = integration ? str(p.actor_name) || tt('system') : sys?.name || tt('system');
|
|
257
|
+
const sub = origin || viaLabel(p.via);
|
|
258
|
+
return {
|
|
259
|
+
kind: 'system', label: name, subtitle: sub,
|
|
260
|
+
description: [tt('createdBy', { who: name }), sub, when].filter(Boolean).join(' · '),
|
|
261
|
+
agentName, systemAvatar: integration ? undefined : sys?.avatarUrl, integration, proposed: false,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
const PX = { sm: 20, md: 32 };
|
|
265
|
+
function PersonAvatar({ name, avatar, size }) {
|
|
266
|
+
const getImageUrl = useImageUrl();
|
|
267
|
+
const px = PX[size];
|
|
268
|
+
return (_jsxs(Avatar, { className: "rounded-lg ring-1 ring-border/50", style: { width: px, height: px }, children: [_jsx(AvatarImage, { src: avatar ? getImageUrl(avatar) : '', alt: "", className: "object-cover" }), _jsx(AvatarFallback, { className: "rounded-lg bg-primary/5 text-[10px] font-bold text-primary", children: getInitials(name) })] }));
|
|
269
|
+
}
|
|
270
|
+
function AgentAvatar({ name, url, px, round }) {
|
|
271
|
+
const radius = round ? 'rounded-full' : 'rounded-lg';
|
|
272
|
+
if (url) {
|
|
273
|
+
return (_jsx("img", { src: url, alt: "", "aria-hidden": "true", draggable: false, className: cn('shrink-0 select-none bg-primary/5 object-contain', radius), style: { width: px, height: px } }));
|
|
274
|
+
}
|
|
275
|
+
return (_jsx("span", { "aria-hidden": "true", "data-agent-initials": getInitials(name), className: cn('flex shrink-0 items-center justify-center bg-primary/10 text-primary', radius), style: { width: px, height: px }, children: _jsx(Bot, { style: { width: px * 0.6, height: px * 0.6 } }) }));
|
|
276
|
+
}
|
|
277
|
+
function SystemAvatar({ url, integration, px }) {
|
|
278
|
+
if (url) {
|
|
279
|
+
return _jsx("img", { src: url, alt: "", "aria-hidden": "true", className: "shrink-0 rounded-lg object-contain", style: { width: px, height: px } });
|
|
280
|
+
}
|
|
281
|
+
const Icon = integration ? Plug : Server;
|
|
282
|
+
return (_jsx("span", { "aria-hidden": "true", className: "flex shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground ring-1 ring-border/50", style: { width: px, height: px }, children: _jsx(Icon, { style: { width: px * 0.55, height: px * 0.55 } }) }));
|
|
283
|
+
}
|
|
284
|
+
/** Avatar for a resolved authorship (person with the agent superimposed when assisted). */
|
|
285
|
+
export function ProvenanceAvatar({ authorship: a, size = 'md' }) {
|
|
286
|
+
const px = PX[size];
|
|
287
|
+
if (a.kind === 'agent')
|
|
288
|
+
return _jsx(AgentAvatar, { name: a.agentName, url: a.agentAvatar, px: px });
|
|
289
|
+
if (a.kind === 'system')
|
|
290
|
+
return _jsx(SystemAvatar, { url: a.systemAvatar, integration: a.integration, px: px });
|
|
291
|
+
const person = _jsx(PersonAvatar, { name: a.person?.name || a.label, avatar: a.person?.avatar, size: size });
|
|
292
|
+
if (a.kind === 'human')
|
|
293
|
+
return person;
|
|
294
|
+
const mini = Math.max(12, Math.round(px * 0.5));
|
|
295
|
+
return (_jsxs("span", { className: "relative inline-flex shrink-0", style: { width: px, height: px }, "data-provenance-overlay": "", children: [person, _jsx("span", { className: "absolute -bottom-1 -right-1 rounded-full bg-background p-px ring-1 ring-border", style: { lineHeight: 0 }, children: _jsx(AgentAvatar, { name: a.agentName, url: a.agentAvatar, px: mini, round: true }) })] }));
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Who made a record and how — the four presentations (see module doc) with a
|
|
299
|
+
* keyboard-focusable trigger whose tooltip and screen-reader description say
|
|
300
|
+
* who authorized, what the agent proposed and when.
|
|
301
|
+
*/
|
|
302
|
+
export function ProvenanceBadge({ provenance, person, system, fallbackOrigin, variant = 'cell', className }) {
|
|
303
|
+
const a = useResolvedAuthorship({ provenance, person, system, fallbackOrigin });
|
|
304
|
+
const descId = React.useId();
|
|
305
|
+
if (!a)
|
|
306
|
+
return null;
|
|
307
|
+
const inline = variant === 'inline';
|
|
308
|
+
const body = inline ? (_jsxs("span", { className: "inline-flex min-w-0 max-w-full items-center gap-2 overflow-hidden", children: [_jsx(ProvenanceAvatar, { authorship: a, size: "sm" }), _jsx("span", { className: "shrink-0 truncate font-medium", children: a.label }), a.subtitle ? _jsxs("span", { className: "min-w-0 truncate text-muted-foreground", children: ["\u00B7 ", a.subtitle] }) : null] })) : (_jsxs("span", { className: "flex min-w-0 items-center gap-3", children: [_jsx(ProvenanceAvatar, { authorship: a, size: "md" }), _jsxs("span", { className: "flex min-w-0 flex-col overflow-hidden", children: [_jsx("span", { className: "mb-0.5 truncate text-sm font-medium leading-none text-foreground/90", children: a.label }), a.subtitle ? (_jsx("span", { className: cn('truncate text-[11px] leading-none', a.proposed ? 'text-amber-700 dark:text-amber-400' : 'text-muted-foreground'), children: a.subtitle })) : null] })] }));
|
|
309
|
+
return (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsxs("span", { tabIndex: 0, role: "group", "aria-label": a.label, "aria-describedby": descId, "data-provenance": a.kind, className: cn('min-w-0 rounded-md outline-none focus-visible:ring-2 focus-visible:ring-ring', inline ? 'inline-flex max-w-full text-sm' : 'flex max-w-full', className), children: [body, _jsx("span", { id: descId, className: "sr-only", children: a.description })] }) }), _jsx(TooltipContent, { className: "max-w-xs", children: a.description })] }));
|
|
310
|
+
}
|
|
311
|
+
function personFromRow(row) {
|
|
312
|
+
const cb = row?.created_by;
|
|
313
|
+
if (cb && typeof cb === 'object') {
|
|
314
|
+
const o = cb;
|
|
315
|
+
const name = str(o.name) || str(o.label) || str(o.email);
|
|
316
|
+
const avatar = str(o.avatar) || str(o.image) || str(o.photo);
|
|
317
|
+
if (name || avatar)
|
|
318
|
+
return { name, avatar };
|
|
319
|
+
}
|
|
320
|
+
if (typeof cb === 'string' && cb.trim())
|
|
321
|
+
return { name: cb };
|
|
322
|
+
return undefined;
|
|
323
|
+
}
|
|
324
|
+
/** True when the row has something AuthorshipCell renders differently from a plain person. */
|
|
325
|
+
export function hasSpecialAuthorship(row) {
|
|
326
|
+
const p = readProvenance(row);
|
|
327
|
+
if (p)
|
|
328
|
+
return classifyProvenance(p) !== 'human';
|
|
329
|
+
return isSystemCreated(row);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* "Created by" for any record: the stored provenance when the host attached
|
|
333
|
+
* it, else the legacy rule (system when `created_by_id` is empty or the kernel
|
|
334
|
+
* actor, the `created_by` person otherwise). Renders nothing for a row with no
|
|
335
|
+
* creator information at all.
|
|
336
|
+
*/
|
|
337
|
+
export function AuthorshipCell({ row, model, variant = 'cell', className }) {
|
|
338
|
+
const originFor = useProvenanceOrigin();
|
|
339
|
+
const provenance = readProvenance(row);
|
|
340
|
+
const person = personFromRow(row);
|
|
341
|
+
const system = !provenance && isSystemCreated(row);
|
|
342
|
+
if (!provenance && !system && !person)
|
|
343
|
+
return null;
|
|
344
|
+
if (!provenance && !system) {
|
|
345
|
+
return (_jsx(ProvenanceBadge, { provenance: { actor_kind: 'human', mode: 'manual' }, person: person, variant: variant, className: className }));
|
|
346
|
+
}
|
|
347
|
+
return (_jsx(ProvenanceBadge, { provenance: provenance, person: person, system: system, fallbackOrigin: system ? originFor?.(model, row) : undefined, variant: variant, className: className }));
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Avatar + name for an activity/history event that carries provenance (no
|
|
351
|
+
* tooltip trigger: it lives inside the event's toggle button). The full
|
|
352
|
+
* sentence goes to `title` and to screen readers.
|
|
353
|
+
*/
|
|
354
|
+
export function ProvenanceActorChip({ provenance, person, className, }) {
|
|
355
|
+
const a = useResolvedAuthorship({ provenance, person });
|
|
356
|
+
if (!a)
|
|
357
|
+
return null;
|
|
358
|
+
return (_jsxs("span", { className: cn('inline-flex min-w-0 items-center gap-2', className), title: a.description, "data-provenance": a.kind, children: [_jsx(ProvenanceAvatar, { authorship: a, size: "sm" }), _jsx("span", { className: "truncate text-sm font-semibold text-foreground", children: a.label }), _jsxs("span", { className: "sr-only", children: ["(", a.description, ")"] })] }));
|
|
359
|
+
}
|
|
360
|
+
/** Provenance carried by a notification (metadata.provenance), if any. */
|
|
361
|
+
export function notificationProvenance(item) {
|
|
362
|
+
let meta = item?.metadata;
|
|
363
|
+
if (typeof meta === 'string') {
|
|
364
|
+
try {
|
|
365
|
+
meta = JSON.parse(meta);
|
|
366
|
+
}
|
|
367
|
+
catch {
|
|
368
|
+
return undefined;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
if (!meta || typeof meta !== 'object')
|
|
372
|
+
return undefined;
|
|
373
|
+
return parseProvenance(meta.provenance);
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Avatar for a notification list (`renderAvatar` of the notifications
|
|
377
|
+
* dropdown): the provenance avatar when the notification carries one, else
|
|
378
|
+
* `fallback`.
|
|
379
|
+
*/
|
|
380
|
+
export function NotificationProvenanceAvatar({ item, fallback = null, }) {
|
|
381
|
+
const p = notificationProvenance(item);
|
|
382
|
+
const a = useResolvedAuthorship({ provenance: p });
|
|
383
|
+
if (!a)
|
|
384
|
+
return _jsx(_Fragment, { children: fallback });
|
|
385
|
+
return (_jsx("span", { title: a.description, "aria-label": a.description, role: "img", className: "inline-flex", children: _jsx(ProvenanceAvatar, { authorship: a, size: "md" }) }));
|
|
386
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record-history.d.ts","sourceRoot":"","sources":["../src/record-history.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"record-history.d.ts","sourceRoot":"","sources":["../src/record-history.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAiB9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAOpD,MAAM,WAAW,kBAAkB;IAC/B;;;OAGG;IACH,MAAM,EAAE,aAAa,EAAE,CAAA;IACvB;;;OAGG;IACH,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAA;IAC5B,wCAAwC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAA;IAC5C;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;IAC3C;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACvB;AAoCD;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAiMtD,CAAA"}
|
package/dist/record-history.js
CHANGED
|
@@ -11,6 +11,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
11
11
|
* Transport-agnostic: events and column metadata arrive via props. No fetching.
|
|
12
12
|
*/
|
|
13
13
|
import * as React from 'react';
|
|
14
|
+
import { useSystemActor } from './org-runtime-context';
|
|
15
|
+
import { parseProvenance, ProvenanceActorChip } from './provenance';
|
|
14
16
|
import { formatDistanceToNow } from 'date-fns';
|
|
15
17
|
import { es, enUS } from 'date-fns/locale';
|
|
16
18
|
import { ChevronDown, ChevronRight, Clock, ExternalLink } from 'lucide-react';
|
|
@@ -54,6 +56,7 @@ function actionDotColor(action) {
|
|
|
54
56
|
export const RecordHistory = ({ events, columns, timeZone, currency, locale = 'es', className, onOpenEvent, resolveAvatarUrl, moduleLabel, }) => {
|
|
55
57
|
const dateLocale = locale === 'en' ? enUS : es;
|
|
56
58
|
// Sort: most recent first
|
|
59
|
+
const systemName = useSystemActor()?.name || 'Sistema';
|
|
57
60
|
const sorted = React.useMemo(() => [...events].sort((a, b) => new Date(b.occurred_at).getTime() - new Date(a.occurred_at).getTime()), [events]);
|
|
58
61
|
// Expand the most-recent event by default
|
|
59
62
|
const [openIds, setOpenIds] = React.useState(() => sorted.length > 0 ? new Set([sorted[0].id]) : new Set());
|
|
@@ -73,7 +76,8 @@ export const RecordHistory = ({ events, columns, timeZone, currency, locale = 'e
|
|
|
73
76
|
return (_jsxs("div", { className: cn('relative pl-5', className), children: [_jsx("span", { className: "absolute left-2 top-2 bottom-2 w-px bg-border", "aria-hidden": "true" }), _jsx("div", { className: "space-y-3", children: sorted.map((event) => {
|
|
74
77
|
const isOpen = openIds.has(event.id);
|
|
75
78
|
const dotColor = actionDotColor(event.action);
|
|
76
|
-
const actor = event.actor_label || event.actor_id ||
|
|
79
|
+
const actor = event.actor_label || event.actor_id || systemName;
|
|
80
|
+
const prov = parseProvenance(event.provenance);
|
|
77
81
|
const timeAgo = (() => {
|
|
78
82
|
try {
|
|
79
83
|
return formatDistanceToNow(new Date(event.occurred_at), { addSuffix: true, locale: dateLocale });
|
|
@@ -94,7 +98,7 @@ export const RecordHistory = ({ events, columns, timeZone, currency, locale = 'e
|
|
|
94
98
|
return event.occurred_at;
|
|
95
99
|
}
|
|
96
100
|
})();
|
|
97
|
-
return (_jsx(Collapsible, { open: isOpen, onOpenChange: () => toggle(event.id), children: _jsxs("div", { className: "relative", children: [_jsx("span", { className: "absolute -left-5 top-3.5 h-2.5 w-2.5 rounded-full border-2 border-background -translate-x-[4px]", style: { background: dotColor }, "aria-hidden": "true" }), _jsxs("div", { className: "rounded-lg border border-border/60 bg-card overflow-hidden", children: [_jsx(CollapsibleTrigger, { asChild: true, children: _jsxs("button", { type: "button", className: "w-full flex items-center gap-3 px-4 py-3 text-left hover:bg-muted/30 transition-colors", children: [_jsxs(Avatar, { className: "h-7 w-7 rounded-full shrink-0", children: [event.actor_avatar ? (_jsx(AvatarImage, { src: resolveAvatarUrl ? resolveAvatarUrl(event.actor_avatar) : event.actor_avatar, alt: actor })) : null, _jsx(AvatarFallback, { className: "text-[9px] font-bold bg-primary/10 text-primary", children: getInitials(actor) })] }), _jsxs("div", { className: "flex-1 min-w-0", children: [_jsxs("div", { className: "flex items-center gap-2 flex-wrap", children: [_jsx("span", { className: "text-sm font-semibold text-foreground truncate", children: actor }), _jsx("span", { className: "text-sm text-muted-foreground", children: actionLabel(event.action) })] }), _jsxs("div", { className: "flex items-center gap-1.5 mt-0.5", children: [_jsx(Clock, { className: "h-3 w-3 text-muted-foreground/60 shrink-0" }), _jsx("span", { className: "text-xs text-muted-foreground", title: fullDate, children: timeAgo }), (moduleLabel || event.addon_key) && (_jsx(Badge, { variant: "outline", className: "text-[10px] px-1.5 py-0 h-4 ml-1", children: moduleLabel || event.addon_key }))] })] }), onOpenEvent && (_jsx("span", { role: "button", tabIndex: 0, "aria-label": "Ver en registro de actividad", title: "Ver en registro de actividad", className: "shrink-0 rounded-md p-1.5 text-muted-foreground hover:text-foreground hover:bg-muted/60 transition-colors cursor-pointer", onClick: (e) => {
|
|
101
|
+
return (_jsx(Collapsible, { open: isOpen, onOpenChange: () => toggle(event.id), children: _jsxs("div", { className: "relative", children: [_jsx("span", { className: "absolute -left-5 top-3.5 h-2.5 w-2.5 rounded-full border-2 border-background -translate-x-[4px]", style: { background: dotColor }, "aria-hidden": "true" }), _jsxs("div", { className: "rounded-lg border border-border/60 bg-card overflow-hidden", children: [_jsx(CollapsibleTrigger, { asChild: true, children: _jsxs("button", { type: "button", className: "w-full flex items-center gap-3 px-4 py-3 text-left hover:bg-muted/30 transition-colors", children: [prov ? null : (_jsxs(Avatar, { className: "h-7 w-7 rounded-full shrink-0", children: [event.actor_avatar ? (_jsx(AvatarImage, { src: resolveAvatarUrl ? resolveAvatarUrl(event.actor_avatar) : event.actor_avatar, alt: actor })) : null, _jsx(AvatarFallback, { className: "text-[9px] font-bold bg-primary/10 text-primary", children: getInitials(actor) })] })), _jsxs("div", { className: "flex-1 min-w-0", children: [_jsxs("div", { className: "flex items-center gap-2 flex-wrap", children: [prov ? (_jsx(ProvenanceActorChip, { provenance: prov, person: { name: event.actor_label ?? undefined, avatar: event.actor_avatar ?? undefined } })) : (_jsx("span", { className: "text-sm font-semibold text-foreground truncate", children: actor })), _jsx("span", { className: "text-sm text-muted-foreground", children: actionLabel(event.action) })] }), _jsxs("div", { className: "flex items-center gap-1.5 mt-0.5", children: [_jsx(Clock, { className: "h-3 w-3 text-muted-foreground/60 shrink-0" }), _jsx("span", { className: "text-xs text-muted-foreground", title: fullDate, children: timeAgo }), (moduleLabel || event.addon_key) && (_jsx(Badge, { variant: "outline", className: "text-[10px] px-1.5 py-0 h-4 ml-1", children: moduleLabel || event.addon_key }))] })] }), onOpenEvent && (_jsx("span", { role: "button", tabIndex: 0, "aria-label": "Ver en registro de actividad", title: "Ver en registro de actividad", className: "shrink-0 rounded-md p-1.5 text-muted-foreground hover:text-foreground hover:bg-muted/60 transition-colors cursor-pointer", onClick: (e) => {
|
|
98
102
|
e.stopPropagation();
|
|
99
103
|
onOpenEvent(event);
|
|
100
104
|
}, onKeyDown: (e) => {
|
|
@@ -141,7 +141,7 @@ function SortableRow({ id, depth, kind, label, hidden, collapsed, onToggleCollap
|
|
|
141
141
|
}, children: [_jsx("option", { value: "", children: "+ \u00EDtem" }), unusedLeaves.map((l) => (_jsx("option", { value: l.ref, children: l.title }, l.ref)))] })) : null] })) : null, _jsx(Button, { type: "button", size: "icon", variant: "ghost", className: "size-6", title: "Renombrar", onClick: () => setEditing(true), children: _jsx(Pencil, { className: "size-3" }) }), _jsx(Button, { type: "button", size: "icon", variant: "ghost", className: "size-6", title: hidden ? 'Mostrar' : 'Ocultar', onClick: onToggleHidden, children: hidden ? _jsx(EyeOff, { className: "size-3" }) : _jsx(Eye, { className: "size-3" }) }), _jsx(Button, { type: "button", size: "icon", variant: "ghost", className: "text-destructive size-6", title: "Quitar", onClick: onDelete, children: _jsx(Trash2, { className: "size-3" }) })] })] }), !collapsed ? children : null] }));
|
|
142
142
|
}
|
|
143
143
|
// ── Manager ───────────────────────────────────────────────────────────────
|
|
144
|
-
export function SidebarLayoutManager({ loadLayout, saveLayout, resetLayout, catalog, currentGroups, resolveLabel = (s) => s, title = 'Menú lateral', description = '
|
|
144
|
+
export function SidebarLayoutManager({ loadLayout, saveLayout, resetLayout, catalog, currentGroups, resolveLabel = (s) => s, title = 'Menú lateral', description = 'Arrastra, renombra y agrupa como en Discord. Así lo verá toda la organización.', }) {
|
|
145
145
|
const [tree, setTree] = React.useState([]);
|
|
146
146
|
const [baseline, setBaseline] = React.useState('[]');
|
|
147
147
|
const [loading, setLoading] = React.useState(true);
|
|
@@ -357,7 +357,7 @@ export function SidebarLayoutManager({ loadLayout, saveLayout, resetLayout, cata
|
|
|
357
357
|
toast.message('Árbol recargado desde el menú actual');
|
|
358
358
|
}, children: "Recargar men\u00FA actual" }), _jsxs(Button, { type: "button", variant: "outline", size: "sm", disabled: saving, onClick: () => void handleReset(), children: [_jsx(RotateCcw, { className: "mr-1 size-3.5" }), "Restaurar default"] }), _jsxs(Button, { type: "button", size: "sm", disabled: !dirty || saving, onClick: () => void handleSave(), children: [_jsx(Save, { className: "mr-1 size-3.5" }), saving ? 'Guardando…' : dirty ? 'Guardar cambios' : 'Guardado'] })] })] }), loading ? (_jsx("p", { className: "text-muted-foreground text-sm", children: "Cargando men\u00FA\u2026" })) : (_jsxs("div", { className: "grid gap-4 lg:grid-cols-[minmax(0,1fr)_240px]", children: [_jsxs("div", { className: "bg-muted/20 border-border overflow-hidden rounded-xl border", children: [_jsxs("div", { className: "border-border/60 flex items-center justify-between border-b px-3 py-2", children: [_jsx("span", { className: "text-muted-foreground text-[11px] font-semibold uppercase tracking-wider", children: "Vista del men\u00FA" }), baseline === '[]' && dirty ? (_jsx("span", { className: "text-amber-600 text-[11px]", children: "Sin guardar \u00B7 borrador del men\u00FA actual" })) : dirty ? (_jsx("span", { className: "text-amber-600 text-[11px]", children: "Cambios sin guardar" })) : (_jsx("span", { className: "text-muted-foreground text-[11px]", children: folderKeys.length
|
|
359
359
|
? `${folderKeys.length} carpeta(s) con permiso`
|
|
360
|
-
: 'Layout activo' }))] }), _jsx(ScrollArea, { className: "h-[min(70vh,640px)]", children: _jsxs("div", { className: "p-2 pb-4", children: [_jsxs(DndContext, { sensors: sensors, collisionDetection: closestCenter, onDragStart: handleDragStart, onDragEnd: handleDragEnd, children: [tree.length === 0 ? (_jsx("p", { className: "text-muted-foreground px-3 py-8 text-center text-sm", children: "Men\u00FA vac\u00EDo.
|
|
360
|
+
: 'Layout activo' }))] }), _jsx(ScrollArea, { className: "h-[min(70vh,640px)]", children: _jsxs("div", { className: "p-2 pb-4", children: [_jsxs(DndContext, { sensors: sensors, collisionDetection: closestCenter, onDragStart: handleDragStart, onDragEnd: handleDragEnd, children: [tree.length === 0 ? (_jsx("p", { className: "text-muted-foreground px-3 py-8 text-center text-sm", children: "Men\u00FA vac\u00EDo. Crea una secci\u00F3n o recarga el men\u00FA actual." })) : (renderList(tree, [])), _jsx(PortalDragOverlay, { children: activeLabel ? (_jsx("div", { className: "bg-background border-border rounded-md border px-3 py-1.5 text-sm shadow-lg", children: activeLabel })) : null })] }), _jsxs("div", { className: "mt-3 flex gap-2 px-2", children: [_jsx(Input, { value: newCategory, onChange: (e) => setNewCategory(e.target.value), placeholder: "Nombre de secci\u00F3n\u2026", className: "h-8 text-sm", onKeyDown: (e) => {
|
|
361
361
|
if (e.key === 'Enter')
|
|
362
362
|
addRootCategory();
|
|
363
363
|
} }), _jsxs(Button, { type: "button", size: "sm", className: "h-8 shrink-0", onClick: addRootCategory, children: [_jsx(Plus, { className: "mr-1 size-3.5" }), "Secci\u00F3n"] })] })] }) })] }), _jsxs("div", { className: "bg-muted/10 border-border flex flex-col overflow-hidden rounded-xl border", children: [_jsxs("div", { className: "border-border/60 border-b px-3 py-2", children: [_jsx("p", { className: "text-muted-foreground text-[11px] font-semibold uppercase tracking-wider", children: "Sin colocar" }), _jsx("p", { className: "text-muted-foreground mt-0.5 text-[11px]", children: "Agregalos desde el men\u00FA + de cada secci\u00F3n" })] }), _jsx(ScrollArea, { className: "flex-1", children: _jsx("ul", { className: "space-y-1 p-2", children: unused.length === 0 ? (_jsx("li", { className: "text-muted-foreground px-1 py-4 text-center text-xs", children: "Todo est\u00E1 en el men\u00FA" })) : (unused.map((l) => (_jsx("li", { children: _jsxs("button", { type: "button", className: "hover:bg-muted/60 flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs", title: l.ref, onClick: () => {
|
|
@@ -27,8 +27,13 @@ export declare function DeltaChip({ delta, text }: {
|
|
|
27
27
|
export declare function WidgetEmpty({ message }: {
|
|
28
28
|
message: string;
|
|
29
29
|
}): React.JSX.Element;
|
|
30
|
-
/**
|
|
31
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Per-widget error state — isolated so a broken widget never tumbles the grid.
|
|
32
|
+
* Pass `onRetry` to offer a retry (e.g. the widget query's `refetch`).
|
|
33
|
+
*/
|
|
34
|
+
export declare function WidgetError({ message, onRetry, retryLabel, }: {
|
|
32
35
|
message: string;
|
|
36
|
+
onRetry?: () => void;
|
|
37
|
+
retryLabel?: string;
|
|
33
38
|
}): React.JSX.Element;
|
|
34
39
|
//# sourceMappingURL=widget-card.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget-card.d.ts","sourceRoot":"","sources":["../../src/widgets/widget-card.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAK9B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEtD,MAAM,WAAW,eAAe;IAC5B,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,YAAY,CAAA;IACrB,qDAAqD;IACrD,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC7B,oBAAoB;IACpB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,wCAAwC;IACxC,aAAa,CAAC,EAAE,MAAM,CAAA;CACzB;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,EACvB,KAAK,EACL,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,WAAW,EACX,QAAQ,EACR,SAAS,EACT,GAAG,IAAI,EACV,EAAE,eAAe,qBA6CjB;AAED,gFAAgF;AAChF,wBAAgB,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,qBAiBzE;AAED,qEAAqE;AACrE,wBAAgB,WAAW,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,qBAM3D;AAED
|
|
1
|
+
{"version":3,"file":"widget-card.d.ts","sourceRoot":"","sources":["../../src/widgets/widget-card.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAK9B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEtD,MAAM,WAAW,eAAe;IAC5B,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,YAAY,CAAA;IACrB,qDAAqD;IACrD,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC7B,oBAAoB;IACpB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,wCAAwC;IACxC,aAAa,CAAC,EAAE,MAAM,CAAA;CACzB;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,EACvB,KAAK,EACL,QAAQ,EACR,IAAI,EACJ,MAAM,EACN,WAAW,EACX,QAAQ,EACR,SAAS,EACT,GAAG,IAAI,EACV,EAAE,eAAe,qBA6CjB;AAED,gFAAgF;AAChF,wBAAgB,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,qBAiBzE;AAED,qEAAqE;AACrE,wBAAgB,WAAW,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,qBAM3D;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,EACxB,OAAO,EACP,OAAO,EACP,UAAyB,GAC5B,EAAE;IACC,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;CACtB,qBAmBA"}
|
|
@@ -24,7 +24,10 @@ export function DeltaChip({ delta, text }) {
|
|
|
24
24
|
export function WidgetEmpty({ message }) {
|
|
25
25
|
return (_jsx("div", { className: "flex flex-1 items-center justify-center py-6 text-center text-xs text-muted-foreground", children: message }));
|
|
26
26
|
}
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Per-widget error state — isolated so a broken widget never tumbles the grid.
|
|
29
|
+
* Pass `onRetry` to offer a retry (e.g. the widget query's `refetch`).
|
|
30
|
+
*/
|
|
31
|
+
export function WidgetError({ message, onRetry, retryLabel = 'Reintentar', }) {
|
|
32
|
+
return (_jsxs("div", { role: "alert", className: "flex flex-1 flex-wrap items-center justify-center gap-2 py-6 text-center text-xs text-destructive", children: [_jsx(DynamicIcon, { name: "TriangleAlert", className: "size-4" }), _jsx("span", { children: message }), onRetry && (_jsx("button", { type: "button", onClick: onRetry, className: "rounded-md border px-2 py-0.5 font-medium text-foreground hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", children: retryLabel }))] }));
|
|
30
33
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asteby/metacore-runtime-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "52.0.0",
|
|
4
4
|
"description": "React runtime for metacore hosts — renders addon contributions dynamically",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@asteby/metacore-sdk": "^3.14.0",
|
|
29
|
-
"@asteby/metacore-ui": "^2.
|
|
29
|
+
"@asteby/metacore-ui": "^2.28.0",
|
|
30
30
|
"@tanstack/react-query": ">=5",
|
|
31
31
|
"@tanstack/react-router": ">=1.100",
|
|
32
32
|
"@tanstack/react-table": ">=8",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@asteby/metacore-sdk": "3.14.0",
|
|
57
|
-
"@asteby/metacore-ui": "2.
|
|
57
|
+
"@asteby/metacore-ui": "2.28.0",
|
|
58
58
|
"@tanstack/react-query": "^5.95.0",
|
|
59
59
|
"@tanstack/react-router": "^1.168.0",
|
|
60
60
|
"@tanstack/react-table": "^8.20.0",
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
// OrgRuntimeProvider `numberLocales` (es → es-MX) and `systemActor`
|
|
3
|
+
// (presentable name/avatar for records the system created or changed).
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
5
|
+
import { cleanup, fireEvent, render, renderHook, screen } from '@testing-library/react'
|
|
6
|
+
import type { ReactNode } from 'react'
|
|
7
|
+
|
|
8
|
+
vi.mock('react-i18next', () => {
|
|
9
|
+
const t = (k: string, o?: { defaultValue?: string; who?: string }) =>
|
|
10
|
+
(o?.defaultValue ?? k).replace('{{who}}', o?.who ?? '')
|
|
11
|
+
return { useTranslation: () => ({ t, i18n: { language: 'es' } }) }
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
import { OrgRuntimeProvider } from '../org-runtime-provider'
|
|
15
|
+
import { resolveNumberLocale, useNumberLocale, useSystemActor } from '../org-runtime-context'
|
|
16
|
+
import { isSystemActorColumn } from '../dynamic-columns'
|
|
17
|
+
import { AuditInfo, SYSTEM_ACTOR_ID } from '../audit-info'
|
|
18
|
+
|
|
19
|
+
afterEach(cleanup)
|
|
20
|
+
|
|
21
|
+
describe('resolveNumberLocale', () => {
|
|
22
|
+
it('maps by full language, then base, case-insensitive', () => {
|
|
23
|
+
expect(resolveNumberLocale('es', { es: 'es-MX' })).toBe('es-MX')
|
|
24
|
+
expect(resolveNumberLocale('ES', { es: 'es-MX' })).toBe('es-MX')
|
|
25
|
+
expect(resolveNumberLocale('es-AR', { es: 'es-MX' })).toBe('es-MX')
|
|
26
|
+
expect(resolveNumberLocale('es-AR', { es: 'es-MX', 'es-ar': 'es-AR' })).toBe('es-AR')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('leaves unmatched languages and missing config untouched', () => {
|
|
30
|
+
expect(resolveNumberLocale('en', { es: 'es-MX' })).toBe('en')
|
|
31
|
+
expect(resolveNumberLocale('es', undefined)).toBe('es')
|
|
32
|
+
expect(resolveNumberLocale(undefined, { es: 'es-MX' })).toBeUndefined()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('es-MX formats thousands the Mexican way (vs bare es)', () => {
|
|
36
|
+
const mx = new Intl.NumberFormat(resolveNumberLocale('es', { es: 'es-MX' })).format(11461.5)
|
|
37
|
+
expect(mx).toBe('11,461.5')
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
describe('OrgRuntimeProvider contexts', () => {
|
|
42
|
+
const wrap =
|
|
43
|
+
(props: Record<string, unknown>) =>
|
|
44
|
+
({ children }: { children: ReactNode }) => <OrgRuntimeProvider {...props}>{children}</OrgRuntimeProvider>
|
|
45
|
+
|
|
46
|
+
it('useNumberLocale reads numberLocales; defaults to the language', () => {
|
|
47
|
+
expect(renderHook(() => useNumberLocale('es'), { wrapper: wrap({ numberLocales: { es: 'es-MX' } }) }).result.current).toBe('es-MX')
|
|
48
|
+
expect(renderHook(() => useNumberLocale('es')).result.current).toBe('es')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('useSystemActor reads systemActor; undefined outside a provider', () => {
|
|
52
|
+
const actor = { name: 'Gobi', avatarUrl: '/brand/gobi.png' }
|
|
53
|
+
expect(renderHook(() => useSystemActor(), { wrapper: wrap({ systemActor: actor }) }).result.current).toEqual(actor)
|
|
54
|
+
expect(renderHook(() => useSystemActor()).result.current).toBeUndefined()
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
describe('isSystemActorColumn', () => {
|
|
59
|
+
it('creator and created_by.* are system columns; plain people are not', () => {
|
|
60
|
+
expect(isSystemActorColumn('creator', 'owner', 'owner.name')).toBe(true)
|
|
61
|
+
expect(isSystemActorColumn('avatar', 'created_by.avatar', 'created_by.name')).toBe(true)
|
|
62
|
+
expect(isSystemActorColumn('user', 'assignee', 'assignee.name')).toBe(false)
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
describe('<AuditInfo> with systemActor', () => {
|
|
67
|
+
it('names the configured system actor instead of "Sistema"', () => {
|
|
68
|
+
render(
|
|
69
|
+
<OrgRuntimeProvider systemActor={{ name: 'Gobi' }}>
|
|
70
|
+
<AuditInfo
|
|
71
|
+
record={{ created_at: '2026-01-01T10:00:00Z', created_by_id: SYSTEM_ACTOR_ID }}
|
|
72
|
+
audit={{ created_at: 'created_at', created_by: 'created_by_id' }}
|
|
73
|
+
timeZone="UTC"
|
|
74
|
+
/>
|
|
75
|
+
</OrgRuntimeProvider>,
|
|
76
|
+
)
|
|
77
|
+
fireEvent.click(screen.getByRole('button'))
|
|
78
|
+
expect(screen.getByText('Creado por Gobi')).toBeTruthy()
|
|
79
|
+
})
|
|
80
|
+
})
|