@asteby/metacore-runtime-react 51.0.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 +12 -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 +7 -2
- package/dist/audit-info.d.ts.map +1 -1
- package/dist/audit-info.js +14 -1
- 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 +11 -1
- package/dist/dynamic-columns.d.ts.map +1 -1
- package/dist/dynamic-columns.js +11 -0
- package/dist/dynamic-date-field.js +1 -1
- package/dist/dynamic-form.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/org-runtime-context.d.ts +27 -0
- package/dist/org-runtime-context.d.ts.map +1 -1
- package/dist/org-runtime-context.js +6 -0
- package/dist/org-runtime-provider.d.ts +13 -2
- 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 +3 -1
- package/dist/sidebar-layout-manager.js +2 -2
- package/package.json +3 -3
- package/src/__tests__/provenance.test.tsx +209 -0
- package/src/activity-diff.tsx +5 -0
- package/src/activity-timeline.tsx +13 -1
- package/src/audit-info.tsx +17 -1
- package/src/barcode-scanner.tsx +4 -4
- package/src/dialogs/dynamic-record.tsx +18 -0
- package/src/dynamic-columns.tsx +14 -0
- package/src/dynamic-date-field.tsx +1 -1
- package/src/dynamic-form.tsx +2 -2
- package/src/index.ts +1 -0
- package/src/org-runtime-context.ts +36 -0
- package/src/org-runtime-provider.tsx +22 -1
- package/src/provenance.tsx +585 -0
- package/src/record-history.tsx +14 -3
- package/src/sidebar-layout-manager.tsx +2 -2
|
@@ -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: () => {
|
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,209 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
// Provenance badges: human, agent (Gobi), system/integration with origin and
|
|
3
|
+
// "person with agent" with the authorizer, the proposal and the date.
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
5
|
+
import { cleanup, render, screen } from '@testing-library/react'
|
|
6
|
+
import type { ReactNode } from 'react'
|
|
7
|
+
|
|
8
|
+
let language = 'es'
|
|
9
|
+
vi.mock('react-i18next', () => {
|
|
10
|
+
const t = (k: string, o?: Record<string, string>) =>
|
|
11
|
+
(o?.defaultValue ?? k).replace(/\{\{(\w+)\}\}/g, (_: string, v: string) => o?.[v] ?? '')
|
|
12
|
+
return { useTranslation: () => ({ t, i18n: { language } }) }
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
import { OrgRuntimeProvider } from '../org-runtime-provider'
|
|
16
|
+
import {
|
|
17
|
+
AuthorshipCell,
|
|
18
|
+
classifyProvenance,
|
|
19
|
+
hasSpecialAuthorship,
|
|
20
|
+
isSystemCreated,
|
|
21
|
+
notificationProvenance,
|
|
22
|
+
parseProvenance,
|
|
23
|
+
ProvenanceActorChip,
|
|
24
|
+
ProvenanceBadge,
|
|
25
|
+
readProvenance,
|
|
26
|
+
type ProvenanceData,
|
|
27
|
+
} from '../provenance'
|
|
28
|
+
import { AuditInfo } from '../audit-info'
|
|
29
|
+
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
cleanup()
|
|
32
|
+
language = 'es'
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const gobi = { name: 'Gobi', avatarUrl: '/images/gobi.svg' }
|
|
36
|
+
const wrap = (ui: ReactNode, extra: Record<string, unknown> = {}) =>
|
|
37
|
+
render(
|
|
38
|
+
<OrgRuntimeProvider agentActor={gobi} timeZone="America/Mexico_City" {...extra}>
|
|
39
|
+
{ui}
|
|
40
|
+
</OrgRuntimeProvider>,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
const assisted: ProvenanceData = {
|
|
44
|
+
actor_kind: 'agent',
|
|
45
|
+
actor_name: 'Gobi',
|
|
46
|
+
mode: 'assisted',
|
|
47
|
+
authorized_by: 'u-1',
|
|
48
|
+
authorized_by_name: 'Ana Pérez',
|
|
49
|
+
authorized_at: '2026-10-12T16:30:00Z',
|
|
50
|
+
via: 'chat',
|
|
51
|
+
origin: 'Borrador aprobado en el chat',
|
|
52
|
+
summary: 'Propuso crear la acción «Recorrido en Tecomán»',
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
describe('provenance model', () => {
|
|
56
|
+
it('classifies the four presentations', () => {
|
|
57
|
+
expect(classifyProvenance({ actor_kind: 'human', mode: 'manual' })).toBe('human')
|
|
58
|
+
expect(classifyProvenance(assisted)).toBe('assisted')
|
|
59
|
+
expect(classifyProvenance({ actor_kind: 'agent', mode: 'automated', on_behalf_of: 'u-1' })).toBe('agent')
|
|
60
|
+
expect(classifyProvenance({ actor_kind: 'agent', mode: 'automated', proposed: true })).toBe('agent')
|
|
61
|
+
expect(classifyProvenance({ actor_kind: 'system', mode: 'automated' })).toBe('system')
|
|
62
|
+
expect(classifyProvenance({ actor_kind: 'integration', mode: 'automated' })).toBe('system')
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('reads provenance from created_by, the row or JSON strings', () => {
|
|
66
|
+
expect(readProvenance({ created_by: { name: 'Ana', provenance: assisted } })?.mode).toBe('assisted')
|
|
67
|
+
expect(readProvenance({ provenance: JSON.stringify(assisted) })?.actor_kind).toBe('agent')
|
|
68
|
+
expect(readProvenance({ provenance: { actor_kind: 'robot' } })).toBeUndefined()
|
|
69
|
+
expect(parseProvenance('{bad')).toBeUndefined()
|
|
70
|
+
expect(notificationProvenance({ metadata: JSON.stringify({ provenance: { actor_kind: 'agent' } }) })?.actor_kind).toBe('agent')
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it('legacy system rows: null, nil and the kernel actor', () => {
|
|
74
|
+
expect(isSystemCreated({ created_by_id: null })).toBe(true)
|
|
75
|
+
expect(isSystemCreated({ created_by_id: '00000000-0000-0000-0000-000000000001' })).toBe(true)
|
|
76
|
+
expect(isSystemCreated({ created_by_id: 'abc', created_by: { name: 'Ana' } })).toBe(false)
|
|
77
|
+
expect(hasSpecialAuthorship({ created_by_id: 'abc', created_by: { name: 'Ana' } })).toBe(false)
|
|
78
|
+
expect(hasSpecialAuthorship({ created_by: { name: 'Ana', provenance: assisted } })).toBe(true)
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
describe('<ProvenanceBadge>', () => {
|
|
83
|
+
it('person with agent: label, overlay avatar and accessible description', () => {
|
|
84
|
+
const { container } = wrap(<ProvenanceBadge provenance={assisted} />)
|
|
85
|
+
expect(screen.getByText('Ana Pérez con Gobi')).toBeTruthy()
|
|
86
|
+
expect(screen.getByText('Borrador aprobado en el chat')).toBeTruthy()
|
|
87
|
+
const trigger = container.querySelector('[data-provenance="assisted"]') as HTMLElement
|
|
88
|
+
expect(trigger.tabIndex).toBe(0)
|
|
89
|
+
const desc = document.getElementById(trigger.getAttribute('aria-describedby') as string)
|
|
90
|
+
expect(desc?.textContent).toContain('Autorizó: Ana Pérez')
|
|
91
|
+
expect(desc?.textContent).toContain('Gobi propuso: Propuso crear la acción')
|
|
92
|
+
expect(desc?.textContent).toMatch(/12 oct 2026/)
|
|
93
|
+
expect(container.querySelector('[data-provenance-overlay] img[src="/images/gobi.svg"]')).toBeTruthy()
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it('agent alone uses the app agent and its origin; pending proposals say so', () => {
|
|
97
|
+
const { rerender } = wrap(<ProvenanceBadge provenance={{ actor_kind: 'agent', mode: 'automated', origin: 'Briefing automático' }} />)
|
|
98
|
+
expect(screen.getByText('Gobi')).toBeTruthy()
|
|
99
|
+
expect(screen.getByText('Briefing automático')).toBeTruthy()
|
|
100
|
+
rerender(
|
|
101
|
+
<OrgRuntimeProvider agentActor={gobi}>
|
|
102
|
+
<ProvenanceBadge provenance={{ actor_kind: 'agent', mode: 'automated', proposed: true, via: 'chat' }} />
|
|
103
|
+
</OrgRuntimeProvider>,
|
|
104
|
+
)
|
|
105
|
+
expect(screen.getByText('Propuesta pendiente')).toBeTruthy()
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('system and integration show their origin, never the agent', () => {
|
|
109
|
+
const { container } = wrap(
|
|
110
|
+
<>
|
|
111
|
+
<ProvenanceBadge provenance={{ actor_kind: 'system', mode: 'automated', via: 'seed' }} />
|
|
112
|
+
<ProvenanceBadge provenance={{ actor_kind: 'integration', actor_name: 'gobiernos-intel', mode: 'automated', origin: 'Plano de datos' }} />
|
|
113
|
+
</>,
|
|
114
|
+
)
|
|
115
|
+
expect(screen.getByText('Sistema')).toBeTruthy()
|
|
116
|
+
expect(screen.getByText('Datos iniciales')).toBeTruthy()
|
|
117
|
+
expect(screen.getByText('gobiernos-intel')).toBeTruthy()
|
|
118
|
+
expect(screen.getByText('Plano de datos')).toBeTruthy()
|
|
119
|
+
expect(container.querySelectorAll('[data-provenance="system"]').length).toBe(2)
|
|
120
|
+
expect(screen.queryByText('Gobi')).toBeNull()
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('human alone', () => {
|
|
124
|
+
wrap(<ProvenanceBadge provenance={{ actor_kind: 'human', mode: 'manual', actor_person_name: 'Luis Gómez' }} />)
|
|
125
|
+
expect(screen.getByText('Luis Gómez')).toBeTruthy()
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it('English copy', () => {
|
|
129
|
+
language = 'en'
|
|
130
|
+
wrap(<ProvenanceBadge provenance={assisted} />)
|
|
131
|
+
expect(screen.getByText('Ana Pérez with Gobi')).toBeTruthy()
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
it('without agentActor falls back to the stored agent name', () => {
|
|
135
|
+
render(<ProvenanceBadge provenance={{ ...assisted, actor_name: 'Llantonio' }} />)
|
|
136
|
+
expect(screen.getByText('Ana Pérez con Llantonio')).toBeTruthy()
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
describe('<AuthorshipCell>', () => {
|
|
141
|
+
it('legacy system row gets the host origin', () => {
|
|
142
|
+
const origin = vi.fn(() => 'Importación de investigación pública')
|
|
143
|
+
wrap(<AuthorshipCell row={{ id: 'r', created_by_id: null }} model="findings" />, { provenanceOrigin: origin, systemActor: { name: 'Sistema' } })
|
|
144
|
+
expect(origin).toHaveBeenCalledWith('findings', { id: 'r', created_by_id: null })
|
|
145
|
+
expect(screen.getByText('Importación de investigación pública')).toBeTruthy()
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
it('stored provenance wins over the legacy rule', () => {
|
|
149
|
+
wrap(<AuthorshipCell row={{ created_by_id: 'u-1', created_by: { name: 'Ana Pérez', provenance: assisted } }} />)
|
|
150
|
+
expect(screen.getByText('Ana Pérez con Gobi')).toBeTruthy()
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it('a plain person renders the person', () => {
|
|
154
|
+
wrap(<AuthorshipCell row={{ created_by_id: 'u-2', created_by: { name: 'Luis' } }} variant="inline" />)
|
|
155
|
+
expect(screen.getByText('Luis')).toBeTruthy()
|
|
156
|
+
})
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
describe('history and audit', () => {
|
|
160
|
+
it('ProvenanceActorChip names the actor with the full sentence for screen readers', () => {
|
|
161
|
+
wrap(<ProvenanceActorChip provenance={assisted} />)
|
|
162
|
+
expect(screen.getByText('Ana Pérez con Gobi')).toBeTruthy()
|
|
163
|
+
expect(screen.getByText(/Autorizó: Ana Pérez/)).toBeTruthy()
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
it('AuditInfo "Creado por" uses the provenance label', () => {
|
|
167
|
+
wrap(
|
|
168
|
+
<AuditInfo
|
|
169
|
+
defaultOpen
|
|
170
|
+
record={{ created_at: '2026-10-12T16:30:00Z', created_by_id: 'u-1', created_by: { name: 'Ana Pérez', provenance: assisted } }}
|
|
171
|
+
audit={{ created_at: 'created_at', created_by: 'created_by_id' }}
|
|
172
|
+
/>,
|
|
173
|
+
)
|
|
174
|
+
expect(screen.getByText('Creado por Ana Pérez con Gobi')).toBeTruthy()
|
|
175
|
+
})
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
describe('dynamic table created_by column', () => {
|
|
179
|
+
it('renders the provenance badge by default', async () => {
|
|
180
|
+
const { defaultGetDynamicColumns } = await import('../dynamic-columns')
|
|
181
|
+
const cols = defaultGetDynamicColumns(
|
|
182
|
+
{
|
|
183
|
+
title: 'Acciones',
|
|
184
|
+
endpoint: '/data/actions',
|
|
185
|
+
columns: [{ key: 'created_by.avatar', label: 'Creado por', type: 'avatar', tooltip: 'created_by.name' }],
|
|
186
|
+
actions: [],
|
|
187
|
+
perPageOptions: [10],
|
|
188
|
+
defaultPerPage: 10,
|
|
189
|
+
searchPlaceholder: '',
|
|
190
|
+
enableCRUDActions: false,
|
|
191
|
+
hasActions: false,
|
|
192
|
+
} as never,
|
|
193
|
+
() => {},
|
|
194
|
+
(k: string, o?: { defaultValue?: string }) => o?.defaultValue ?? k,
|
|
195
|
+
'es',
|
|
196
|
+
new Map(),
|
|
197
|
+
)
|
|
198
|
+
const col = cols.find((c) => (c as { accessorKey?: string }).accessorKey === 'created_by.avatar' || c.id === 'created_by.avatar')
|
|
199
|
+
expect(col).toBeTruthy()
|
|
200
|
+
const original = { id: 'r1', created_by_id: 'u-1', created_by: { name: 'Ana Pérez', provenance: assisted } }
|
|
201
|
+
const cell = (col!.cell as (ctx: unknown) => ReactNode)({
|
|
202
|
+
row: { original, getValue: () => undefined },
|
|
203
|
+
getValue: () => undefined,
|
|
204
|
+
column: { id: 'created_by.avatar' },
|
|
205
|
+
})
|
|
206
|
+
wrap(<>{cell}</>)
|
|
207
|
+
expect(screen.getByText('Ana Pérez con Gobi')).toBeTruthy()
|
|
208
|
+
})
|
|
209
|
+
})
|
package/src/activity-diff.tsx
CHANGED
|
@@ -35,6 +35,11 @@ export interface ActivityEvent {
|
|
|
35
35
|
correlation_id?: string | null
|
|
36
36
|
actor_id?: string | null
|
|
37
37
|
actor_label?: string | null
|
|
38
|
+
/**
|
|
39
|
+
* Provenance of the change (kernel `provenance`, JSON string or object):
|
|
40
|
+
* person, agent, system or integration, and the mode. Optional.
|
|
41
|
+
*/
|
|
42
|
+
provenance?: unknown
|
|
38
43
|
/** Storage path of the actor's avatar image, when the backend resolves one. */
|
|
39
44
|
actor_avatar?: string | null
|
|
40
45
|
addon_key: string
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
import * as React from 'react'
|
|
17
17
|
import { useSystemActor } from './org-runtime-context'
|
|
18
|
+
import { parseProvenance, ProvenanceAvatar, useResolvedAuthorship } from './provenance'
|
|
18
19
|
import { formatDistanceToNow } from 'date-fns'
|
|
19
20
|
import { es, enUS } from 'date-fns/locale'
|
|
20
21
|
import type { Locale } from 'date-fns'
|
|
@@ -203,7 +204,11 @@ const GroupCard: React.FC<GroupCardProps> = ({
|
|
|
203
204
|
const { root, events, changedFieldCount } = group
|
|
204
205
|
const isMulti = events.length > 1
|
|
205
206
|
const systemName = useSystemActor()?.name || 'Sistema'
|
|
206
|
-
const
|
|
207
|
+
const authorship = useResolvedAuthorship({
|
|
208
|
+
provenance: parseProvenance(root.provenance),
|
|
209
|
+
person: root.actor_label ? { name: root.actor_label } : undefined,
|
|
210
|
+
})
|
|
211
|
+
const actor = authorship?.label || root.actor_label || root.actor_id || systemName
|
|
207
212
|
const dotColor = actionDotColor(root.action)
|
|
208
213
|
|
|
209
214
|
const timeAgo = (() => {
|
|
@@ -247,11 +252,18 @@ const GroupCard: React.FC<GroupCardProps> = ({
|
|
|
247
252
|
type="button"
|
|
248
253
|
className="w-full flex items-start gap-3 px-4 py-3 text-left hover:bg-muted/30 transition-colors"
|
|
249
254
|
>
|
|
255
|
+
{authorship ? (
|
|
256
|
+
<span className="mt-0.5 shrink-0" title={authorship.description}>
|
|
257
|
+
<ProvenanceAvatar authorship={authorship} size="sm" />
|
|
258
|
+
<span className="sr-only">{authorship.description}</span>
|
|
259
|
+
</span>
|
|
260
|
+
) : (
|
|
250
261
|
<Avatar className="h-7 w-7 rounded-full shrink-0 mt-0.5">
|
|
251
262
|
<AvatarFallback className="text-[9px] font-bold bg-primary/10 text-primary">
|
|
252
263
|
{getInitials(actor)}
|
|
253
264
|
</AvatarFallback>
|
|
254
265
|
</Avatar>
|
|
266
|
+
)}
|
|
255
267
|
|
|
256
268
|
<div className="flex-1 min-w-0">
|
|
257
269
|
{/* Summary line */}
|
package/src/audit-info.tsx
CHANGED
|
@@ -25,6 +25,7 @@ import { formatDateCell } from './dynamic-columns'
|
|
|
25
25
|
import { objectLabel } from './dynamic-relation-helpers'
|
|
26
26
|
import { isNilUuid } from './nil-uuid'
|
|
27
27
|
import { useSystemActor, useTimeZone } from './org-runtime-context'
|
|
28
|
+
import { readProvenance, useResolvedAuthorship } from './provenance'
|
|
28
29
|
import type { AuditMeta } from './types'
|
|
29
30
|
|
|
30
31
|
/** The kernel's actor for unattended work (schedules, webhooks, connectors). */
|
|
@@ -129,6 +130,8 @@ export interface AuditInfoProps {
|
|
|
129
130
|
interface Line {
|
|
130
131
|
key: string
|
|
131
132
|
text: string
|
|
133
|
+
/** Full provenance sentence (who authorized, what the agent proposed). */
|
|
134
|
+
detail?: string
|
|
132
135
|
absolute: string
|
|
133
136
|
title?: string
|
|
134
137
|
relative: string
|
|
@@ -147,6 +150,8 @@ export function AuditInfo({
|
|
|
147
150
|
const ctxTz = useTimeZone()
|
|
148
151
|
const systemActor = useSystemActor()
|
|
149
152
|
const [open, setOpen] = React.useState(defaultOpen)
|
|
153
|
+
// Stored creation provenance (person with agent, agent, system, integration).
|
|
154
|
+
const authorship = useResolvedAuthorship({ provenance: readProvenance(record ?? undefined) })
|
|
150
155
|
|
|
151
156
|
const meta = readAuditMeta(audit)
|
|
152
157
|
if (!meta || !record) return null
|
|
@@ -170,6 +175,16 @@ export function AuditInfo({
|
|
|
170
175
|
const actor = resolveAuditActor(record, byCol, { resolveActor, systemLabel: systemActor?.name || tt('system') })
|
|
171
176
|
const date = new Date(record[atCol as string] as string)
|
|
172
177
|
const relative = formatDistanceToNow(date, { addSuffix: true, locale: dfLocale })
|
|
178
|
+
if (key === 'created' && authorship) {
|
|
179
|
+
return {
|
|
180
|
+
key,
|
|
181
|
+
text: tt(whoKey, { who: authorship.label }),
|
|
182
|
+
detail: authorship.description,
|
|
183
|
+
absolute: f.display,
|
|
184
|
+
title: f.title,
|
|
185
|
+
relative,
|
|
186
|
+
}
|
|
187
|
+
}
|
|
173
188
|
return {
|
|
174
189
|
key,
|
|
175
190
|
text: actor ? tt(whoKey, { who: actor.name }) : tt(whenKey),
|
|
@@ -207,7 +222,8 @@ export function AuditInfo({
|
|
|
207
222
|
<ul className="mt-2 space-y-1 pl-6">
|
|
208
223
|
{lines.map(l => (
|
|
209
224
|
<li key={l.key} data-audit-line={l.key}>
|
|
210
|
-
<span>{l.text}</span>
|
|
225
|
+
<span title={l.detail}>{l.text}</span>
|
|
226
|
+
{l.detail ? <span className="sr-only"> ({l.detail})</span> : null}
|
|
211
227
|
{' · '}
|
|
212
228
|
<time title={l.title}>{l.absolute}</time>
|
|
213
229
|
<span className="opacity-70"> ({l.relative})</span>
|
package/src/barcode-scanner.tsx
CHANGED
|
@@ -175,7 +175,7 @@ export function BarcodeScanner({
|
|
|
175
175
|
continuous = true,
|
|
176
176
|
beepOnScan = true,
|
|
177
177
|
title = 'Escanear código',
|
|
178
|
-
hint = '
|
|
178
|
+
hint = 'Apunta al código de barras',
|
|
179
179
|
position = 'absolute',
|
|
180
180
|
feedback = null,
|
|
181
181
|
}: BarcodeScannerProps) {
|
|
@@ -220,7 +220,7 @@ export function BarcodeScanner({
|
|
|
220
220
|
const Ctor = getDetectorCtor()
|
|
221
221
|
if (!navigator.mediaDevices?.getUserMedia || !Ctor) {
|
|
222
222
|
setError(
|
|
223
|
-
'Tu navegador no soporta escaneo por cámara.
|
|
223
|
+
'Tu navegador no soporta escaneo por cámara. Usa un lector físico (escribe en el campo) o escribe el código a mano.',
|
|
224
224
|
)
|
|
225
225
|
return
|
|
226
226
|
}
|
|
@@ -281,7 +281,7 @@ export function BarcodeScanner({
|
|
|
281
281
|
setError(
|
|
282
282
|
name === 'NotAllowedError'
|
|
283
283
|
? 'Permiso de cámara denegado. Habilitalo en el navegador para escanear.'
|
|
284
|
-
: 'No se pudo abrir la cámara.
|
|
284
|
+
: 'No se pudo abrir la cámara. Usa un lector físico o escribe el código a mano.',
|
|
285
285
|
)
|
|
286
286
|
}
|
|
287
287
|
})()
|
|
@@ -384,7 +384,7 @@ export function BarcodeScanner({
|
|
|
384
384
|
{!ready
|
|
385
385
|
? 'Abriendo cámara…'
|
|
386
386
|
: torchAvailable
|
|
387
|
-
? `${hint} ·
|
|
387
|
+
? `${hint} · toca la linterna si está oscuro`
|
|
388
388
|
: hint}
|
|
389
389
|
</p>
|
|
390
390
|
</>
|
|
@@ -89,6 +89,7 @@ import type { ActionFieldDef, RelationMeta } from '../types'
|
|
|
89
89
|
import { ImageUrlContext, identityImageUrl, type GetImageUrl } from '../image-url-context'
|
|
90
90
|
import { getFieldWidget, useFieldWidgetRegistryVersion } from '../field-widget-registry'
|
|
91
91
|
import { TimeZoneContext, CurrencyContext, useNumberLocale, useSystemActor } from '../org-runtime-context'
|
|
92
|
+
import { AuthorshipCell, hasSpecialAuthorship, readProvenance } from '../provenance'
|
|
92
93
|
|
|
93
94
|
// Re-export the resolver type so `index.ts`'s
|
|
94
95
|
// `export type { … GetImageUrl } from './dialogs/dynamic-record'` keeps working.
|
|
@@ -1694,10 +1695,13 @@ export function ViewValue({
|
|
|
1694
1695
|
getImageUrl: getImageUrlProp,
|
|
1695
1696
|
timeZone: timeZoneProp,
|
|
1696
1697
|
currency: currencyProp,
|
|
1698
|
+
model,
|
|
1697
1699
|
}: {
|
|
1698
1700
|
field: FieldDef
|
|
1699
1701
|
value: any
|
|
1700
1702
|
record: any
|
|
1703
|
+
/** Model key; lets the host origin resolver name legacy system rows. */
|
|
1704
|
+
model?: string
|
|
1701
1705
|
/** Optional override; when omitted falls back to the nearest provider/identity. */
|
|
1702
1706
|
getImageUrl?: GetImageUrl
|
|
1703
1707
|
/** Optional override; when omitted falls back to the nearest provider. */
|
|
@@ -1731,6 +1735,20 @@ export function ViewValue({
|
|
|
1731
1735
|
field.key === 'created_by' ||
|
|
1732
1736
|
field.key === 'created_by_id'
|
|
1733
1737
|
) {
|
|
1738
|
+
const isCreatedByField =
|
|
1739
|
+
field.key === 'created_by' ||
|
|
1740
|
+
field.key === 'created_by_id' ||
|
|
1741
|
+
(typeof field.key === 'string' && field.key.startsWith('created_by.')) ||
|
|
1742
|
+
renderAs === 'creator'
|
|
1743
|
+
// Provenance: person with the agent, the agent alone, the system or an
|
|
1744
|
+
// integration with its origin (kernel `provenance`).
|
|
1745
|
+
if (isCreatedByField && (hasSpecialAuthorship(record) || readProvenance(record))) {
|
|
1746
|
+
return (
|
|
1747
|
+
<div className="py-1">
|
|
1748
|
+
<AuthorshipCell row={record} model={model} variant="inline" />
|
|
1749
|
+
</div>
|
|
1750
|
+
)
|
|
1751
|
+
}
|
|
1734
1752
|
const user = createdBySibling(rawValue, record)
|
|
1735
1753
|
if (user) {
|
|
1736
1754
|
return (
|
package/src/dynamic-columns.tsx
CHANGED
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
} from '@asteby/metacore-ui/lib'
|
|
40
40
|
import { Progress } from './dialogs/_primitives'
|
|
41
41
|
import { useSystemActor } from './org-runtime-context'
|
|
42
|
+
import { AuthorshipCell, hasSpecialAuthorship } from './provenance'
|
|
42
43
|
import { humanizeToken, translateMetadataLabel } from './dynamic-columns-helpers'
|
|
43
44
|
import { objectLabel } from './dynamic-relation-helpers'
|
|
44
45
|
import {
|
|
@@ -970,6 +971,9 @@ export function makeDefaultGetDynamicColumns(
|
|
|
970
971
|
currency?: string,
|
|
971
972
|
rowActionPredicate?: RowActionPredicate,
|
|
972
973
|
): ColumnDef<any>[] {
|
|
974
|
+
// Model key for the provenance origin resolver: last endpoint segment
|
|
975
|
+
// ("/data/findings" → "findings").
|
|
976
|
+
const model = (metadata.endpoint || '').split('?')[0].split('/').filter(Boolean).pop()
|
|
973
977
|
// currentLanguage may be a regional number locale (es-MX, en-US) when
|
|
974
978
|
// the host sets OrgRuntimeProvider numberLocales; dates key off its base.
|
|
975
979
|
const dateLocale = currentLanguage?.toLowerCase().startsWith('en') ? enUS : es
|
|
@@ -1224,6 +1228,16 @@ export function makeDefaultGetDynamicColumns(
|
|
|
1224
1228
|
resolveMissingActorLabel(renderAs, col.key, namePath, t)
|
|
1225
1229
|
const desc = getNestedValue(row.original, col.description || '')
|
|
1226
1230
|
|
|
1231
|
+
// Provenance (kernel `provenance`): a person with
|
|
1232
|
+
// the agent, the agent alone, or the system /
|
|
1233
|
+
// an integration with its origin.
|
|
1234
|
+
if (
|
|
1235
|
+
isSystemActorColumn(renderAs, col.key, namePath) &&
|
|
1236
|
+
hasSpecialAuthorship(row.original as Record<string, unknown>)
|
|
1237
|
+
) {
|
|
1238
|
+
return <AuthorshipCell row={row.original as Record<string, unknown>} model={model} />
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1227
1241
|
if (!resolvedName && isSystemActorColumn(renderAs, col.key, namePath)) {
|
|
1228
1242
|
return (
|
|
1229
1243
|
<SystemActorCell
|
|
@@ -71,7 +71,7 @@ export function DynamicDateField({ field, value, onChange, invalid }: DynamicDat
|
|
|
71
71
|
>
|
|
72
72
|
<CalendarIcon className="mr-2 size-4 shrink-0 opacity-50" />
|
|
73
73
|
<span className="truncate">
|
|
74
|
-
{selected ? label(selected) : (field.placeholder || '
|
|
74
|
+
{selected ? label(selected) : (field.placeholder || 'Elige una fecha')}
|
|
75
75
|
</span>
|
|
76
76
|
</Button>
|
|
77
77
|
</PopoverTrigger>
|
package/src/dynamic-form.tsx
CHANGED
|
@@ -528,7 +528,7 @@ function FieldRenderer({
|
|
|
528
528
|
* Input de texto/número con opción de ESCANEO por cámara para "llenar rápido".
|
|
529
529
|
* Cuando el campo declara `scan` (alias `scannable`) y el navegador soporta
|
|
530
530
|
* `BarcodeDetector`, agrega un botón de cámara: el código escaneado se escribe
|
|
531
|
-
* en el input y el escáner SE QUEDA ABIERTO (continuo) por si
|
|
531
|
+
* en el input y el escáner SE QUEDA ABIERTO (continuo) por si quieres corregir o
|
|
532
532
|
* escanear otro — lo cerrás con la X. Sin el flag o sin soporte, es un Input
|
|
533
533
|
* normal (retrocompat total).
|
|
534
534
|
*/
|
|
@@ -544,7 +544,7 @@ function ScannableInput({
|
|
|
544
544
|
// `isCameraScanSupported()`: en un navegador sin `BarcodeDetector` el botón
|
|
545
545
|
// seguía sin verse en escritorio aunque el campo lo pidiera, y el usuario no
|
|
546
546
|
// entendía por qué el POS sí lo mostraba y el form no. El BarcodeScanner ya
|
|
547
|
-
// degrada con un mensaje ("
|
|
547
|
+
// degrada con un mensaje ("usa un lector físico / escribe a mano") cuando no
|
|
548
548
|
// hay soporte, así que mostrar el botón es seguro y consistente.
|
|
549
549
|
const scanEnabled = !!(field.scan ?? field.scannable)
|
|
550
550
|
const input = (
|
package/src/index.ts
CHANGED
|
@@ -370,6 +370,7 @@ export {
|
|
|
370
370
|
type SidebarLayoutManagerProps,
|
|
371
371
|
} from './sidebar-layout-manager'
|
|
372
372
|
export * from './org-runtime-context'
|
|
373
|
+
export * from './provenance'
|
|
373
374
|
export * from './business'
|
|
374
375
|
// Primitivos de negocio (PaymentAllocator, AgingTable, ApprovalInbox,
|
|
375
376
|
// contribuciones/modales federados, tipos de documento y contratos de paneles).
|
|
@@ -92,3 +92,39 @@ export const SystemActorContext = createContext<SystemActor | undefined>(undefin
|
|
|
92
92
|
|
|
93
93
|
/** Reads the nearest system-actor presentation (undefined outside a provider). */
|
|
94
94
|
export const useSystemActor = () => useContext(SystemActorContext)
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* How the app's AGENT (its assistant: Gobi in GobiernOS) is presented when a
|
|
98
|
+
* record's provenance says an agent made it or proposed it. Separate from
|
|
99
|
+
* `SystemActor`: unattended platform work (seeds, imports) is not the agent.
|
|
100
|
+
* `undefined` outside a provider → the provenance `actor_name`, else a
|
|
101
|
+
* localized "Asistente"/"Assistant".
|
|
102
|
+
*/
|
|
103
|
+
export interface AgentActor {
|
|
104
|
+
/** Display name (already localized). */
|
|
105
|
+
name?: string
|
|
106
|
+
/** Absolute URL or app path of the avatar image; used as-is. */
|
|
107
|
+
avatarUrl?: string
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const AgentActorContext = createContext<AgentActor | undefined>(undefined)
|
|
111
|
+
|
|
112
|
+
/** Reads the nearest agent presentation (undefined outside a provider). */
|
|
113
|
+
export const useAgentActor = () => useContext(AgentActorContext)
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Host hook naming the ORIGIN of a record that has no stored provenance but
|
|
117
|
+
* was clearly made by the system (null `created_by_id`): e.g. GobiernOS maps
|
|
118
|
+
* `findings` → "Importación de investigación pública". Return `undefined` when
|
|
119
|
+
* unknown — the badge then shows the system actor alone, never an invented
|
|
120
|
+
* origin.
|
|
121
|
+
*/
|
|
122
|
+
export type ProvenanceOriginResolver = (
|
|
123
|
+
model: string | undefined,
|
|
124
|
+
row: Record<string, unknown> | null | undefined,
|
|
125
|
+
) => string | undefined
|
|
126
|
+
|
|
127
|
+
export const ProvenanceOriginContext = createContext<ProvenanceOriginResolver | undefined>(undefined)
|
|
128
|
+
|
|
129
|
+
/** Reads the nearest origin resolver (undefined outside a provider). */
|
|
130
|
+
export const useProvenanceOrigin = () => useContext(ProvenanceOriginContext)
|
|
@@ -13,12 +13,16 @@ import {
|
|
|
13
13
|
type GetImageUrl,
|
|
14
14
|
} from './image-url-context'
|
|
15
15
|
import {
|
|
16
|
+
AgentActorContext,
|
|
16
17
|
CurrencyContext,
|
|
18
|
+
ProvenanceOriginContext,
|
|
17
19
|
NumberLocalesContext,
|
|
18
20
|
SystemActorContext,
|
|
19
21
|
TaxRateContext,
|
|
20
22
|
TimeZoneContext,
|
|
23
|
+
type AgentActor,
|
|
21
24
|
type NumberLocales,
|
|
25
|
+
type ProvenanceOriginResolver,
|
|
22
26
|
type SystemActor,
|
|
23
27
|
} from './org-runtime-context'
|
|
24
28
|
|
|
@@ -41,6 +45,17 @@ export interface OrgRuntimeProviderProps {
|
|
|
41
45
|
* who created/changed it and nobody did — e.g. `{ name: 'Gobi' }`.
|
|
42
46
|
*/
|
|
43
47
|
systemActor?: SystemActor
|
|
48
|
+
/**
|
|
49
|
+
* Presentation of the app's agent (name + avatar) in provenance badges:
|
|
50
|
+
* records an agent made, proposed, or a person made with it — e.g.
|
|
51
|
+
* `{ name: 'Gobi', avatarUrl: '/images/gobi.svg' }`.
|
|
52
|
+
*/
|
|
53
|
+
agentActor?: AgentActor
|
|
54
|
+
/**
|
|
55
|
+
* Names the origin of system-made records without stored provenance
|
|
56
|
+
* (legacy rows). Optional; see ProvenanceOriginResolver.
|
|
57
|
+
*/
|
|
58
|
+
provenanceOrigin?: ProvenanceOriginResolver
|
|
44
59
|
/** Resolver turning a stored path into a fetchable URL. Defaults to identity. */
|
|
45
60
|
getImageUrl?: GetImageUrl
|
|
46
61
|
children: ReactNode
|
|
@@ -52,6 +67,8 @@ export function OrgRuntimeProvider({
|
|
|
52
67
|
taxRate,
|
|
53
68
|
numberLocales,
|
|
54
69
|
systemActor,
|
|
70
|
+
agentActor,
|
|
71
|
+
provenanceOrigin,
|
|
55
72
|
getImageUrl = identityImageUrl,
|
|
56
73
|
children,
|
|
57
74
|
}: OrgRuntimeProviderProps) {
|
|
@@ -62,7 +79,11 @@ export function OrgRuntimeProvider({
|
|
|
62
79
|
<TaxRateContext.Provider value={taxRate}>
|
|
63
80
|
<NumberLocalesContext.Provider value={numberLocales}>
|
|
64
81
|
<SystemActorContext.Provider value={systemActor}>
|
|
65
|
-
{
|
|
82
|
+
<AgentActorContext.Provider value={agentActor}>
|
|
83
|
+
<ProvenanceOriginContext.Provider value={provenanceOrigin}>
|
|
84
|
+
{children}
|
|
85
|
+
</ProvenanceOriginContext.Provider>
|
|
86
|
+
</AgentActorContext.Provider>
|
|
66
87
|
</SystemActorContext.Provider>
|
|
67
88
|
</NumberLocalesContext.Provider>
|
|
68
89
|
</TaxRateContext.Provider>
|