@asteby/metacore-runtime-react 51.0.0 → 52.1.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.
Files changed (62) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/activity-diff.d.ts +5 -0
  3. package/dist/activity-diff.d.ts.map +1 -1
  4. package/dist/activity-timeline.d.ts.map +1 -1
  5. package/dist/activity-timeline.js +7 -2
  6. package/dist/audit-info.d.ts.map +1 -1
  7. package/dist/audit-info.js +14 -1
  8. package/dist/barcode-scanner.js +4 -4
  9. package/dist/dialogs/dynamic-record.d.ts +3 -1
  10. package/dist/dialogs/dynamic-record.d.ts.map +1 -1
  11. package/dist/dialogs/dynamic-record.js +11 -1
  12. package/dist/dynamic-columns.d.ts.map +1 -1
  13. package/dist/dynamic-columns.js +11 -0
  14. package/dist/dynamic-date-field.js +1 -1
  15. package/dist/dynamic-form.js +2 -2
  16. package/dist/index.d.ts +3 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +5 -1
  19. package/dist/org-runtime-context.d.ts +27 -0
  20. package/dist/org-runtime-context.d.ts.map +1 -1
  21. package/dist/org-runtime-context.js +6 -0
  22. package/dist/org-runtime-provider.d.ts +13 -2
  23. package/dist/org-runtime-provider.d.ts.map +1 -1
  24. package/dist/org-runtime-provider.js +3 -3
  25. package/dist/provenance.d.ts +216 -0
  26. package/dist/provenance.d.ts.map +1 -0
  27. package/dist/provenance.js +386 -0
  28. package/dist/record-history.d.ts.map +1 -1
  29. package/dist/record-history.js +3 -1
  30. package/dist/sidebar-layout-manager.js +2 -2
  31. package/dist/widgets/charts.d.ts +9 -0
  32. package/dist/widgets/charts.d.ts.map +1 -0
  33. package/dist/widgets/charts.js +55 -0
  34. package/dist/widgets/lazy-charts.d.ts +10 -0
  35. package/dist/widgets/lazy-charts.d.ts.map +1 -0
  36. package/dist/widgets/lazy-charts.js +30 -0
  37. package/dist/widgets/renderers.d.ts +5 -5
  38. package/dist/widgets/renderers.d.ts.map +1 -1
  39. package/dist/widgets/renderers.js +3 -53
  40. package/dist/widgets/widget-renderer.d.ts.map +1 -1
  41. package/dist/widgets/widget-renderer.js +2 -1
  42. package/package.json +8 -4
  43. package/src/__tests__/index-static-graph.test.ts +65 -0
  44. package/src/__tests__/provenance.test.tsx +209 -0
  45. package/src/activity-diff.tsx +5 -0
  46. package/src/activity-timeline.tsx +13 -1
  47. package/src/audit-info.tsx +17 -1
  48. package/src/barcode-scanner.tsx +4 -4
  49. package/src/dialogs/dynamic-record.tsx +18 -0
  50. package/src/dynamic-columns.tsx +14 -0
  51. package/src/dynamic-date-field.tsx +1 -1
  52. package/src/dynamic-form.tsx +2 -2
  53. package/src/index.ts +10 -4
  54. package/src/org-runtime-context.ts +36 -0
  55. package/src/org-runtime-provider.tsx +22 -1
  56. package/src/provenance.tsx +585 -0
  57. package/src/record-history.tsx +14 -3
  58. package/src/sidebar-layout-manager.tsx +2 -2
  59. package/src/widgets/charts.tsx +225 -0
  60. package/src/widgets/lazy-charts.tsx +51 -0
  61. package/src/widgets/renderers.tsx +5 -210
  62. package/src/widgets/widget-renderer.tsx +6 -4
@@ -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 actor = root.actor_label || root.actor_id || systemName
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 */}
@@ -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>
@@ -175,7 +175,7 @@ export function BarcodeScanner({
175
175
  continuous = true,
176
176
  beepOnScan = true,
177
177
  title = 'Escanear código',
178
- hint = 'Apuntá al código de barras',
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. Usá un lector físico (escribe en el campo) o escribí el código a mano.',
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. Usá un lector físico o escribí el código a mano.',
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} · tocá la linterna si está oscuro`
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 (
@@ -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 || 'Elegí una fecha')}
74
+ {selected ? label(selected) : (field.placeholder || 'Elige una fecha')}
75
75
  </span>
76
76
  </Button>
77
77
  </PopoverTrigger>
@@ -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 querés corregir o
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 ("usá un lector físico / escribí a mano") cuando no
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).
@@ -700,15 +701,20 @@ export type {
700
701
  } from './dashboard-types'
701
702
  export {
702
703
  StatWidget,
704
+ ListWidget,
705
+ ProgressWidget,
706
+ type WidgetRenderProps,
707
+ } from './widgets/renderers'
708
+ // recharts-backed widgets: lazy facades, recharts stays out of the index graph.
709
+ // The eager components are at '@asteby/metacore-runtime-react/charts'.
710
+ export {
703
711
  BarWidget,
704
712
  LineWidget,
705
713
  AreaWidget,
706
714
  PieWidget,
707
715
  DonutWidget,
708
- ListWidget,
709
- ProgressWidget,
710
- type WidgetRenderProps,
711
- } from './widgets/renderers'
716
+ preloadWidgetCharts,
717
+ } from './widgets/lazy-charts'
712
718
  export {
713
719
  WidgetRenderer,
714
720
  WidgetSkeleton,
@@ -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
- {children}
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>