@asteby/metacore-runtime-react 50.1.0 → 51.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 +19 -0
- package/README.md +26 -0
- package/dist/activity-timeline.d.ts.map +1 -1
- package/dist/activity-timeline.js +4 -2
- package/dist/audit-info.d.ts.map +1 -1
- package/dist/audit-info.js +3 -2
- package/dist/dialogs/dynamic-record.d.ts.map +1 -1
- package/dist/dialogs/dynamic-record.js +8 -5
- package/dist/dynamic-columns.d.ts +6 -0
- package/dist/dynamic-columns.d.ts.map +1 -1
- package/dist/dynamic-columns.js +30 -7
- 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 +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/org-runtime-context.d.ts +38 -0
- package/dist/org-runtime-context.d.ts.map +1 -1
- package/dist/org-runtime-context.js +18 -0
- package/dist/org-runtime-provider.d.ts +14 -1
- package/dist/org-runtime-provider.d.ts.map +1 -1
- package/dist/org-runtime-provider.js +3 -3
- package/dist/record-history.d.ts.map +1 -1
- package/dist/record-history.js +3 -1
- package/dist/row-actions-menu.d.ts +7 -1
- package/dist/row-actions-menu.d.ts.map +1 -1
- package/dist/row-actions-menu.js +3 -3
- 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__/secondary-actions.test.tsx +19 -0
- package/src/activity-timeline.tsx +4 -2
- package/src/audit-info.tsx +3 -2
- package/src/dialogs/dynamic-record.tsx +8 -5
- package/src/dynamic-columns.tsx +54 -6
- package/src/dynamic-kanban.tsx +6 -5
- package/src/dynamic-table.tsx +6 -4
- package/src/index.ts +1 -0
- package/src/org-runtime-context.ts +56 -0
- package/src/org-runtime-provider.tsx +29 -3
- package/src/record-history.tsx +3 -1
- package/src/row-actions-menu.tsx +14 -3
- package/src/widgets/widget-card.tsx +26 -3
package/src/dynamic-table.tsx
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// column cells are tightly coupled to their design system).
|
|
13
13
|
import { useEffect, useState, useMemo, useCallback, useRef, type MouseEvent, type ReactNode } from 'react'
|
|
14
14
|
import { useTranslation } from 'react-i18next'
|
|
15
|
-
import { useTimeZone, useCurrency } from './org-runtime-context'
|
|
15
|
+
import { useTimeZone, useCurrency, useNumberLocale } from './org-runtime-context'
|
|
16
16
|
import { format } from 'date-fns'
|
|
17
17
|
import type { DateRange } from 'react-day-picker'
|
|
18
18
|
import { useVirtualizer } from '@tanstack/react-virtual'
|
|
@@ -417,6 +417,8 @@ export function DynamicTable({
|
|
|
417
417
|
// still selects the mode when `pagination` is absent (back-compat).
|
|
418
418
|
const infiniteScroll = paginationMode ? paginationMode === 'infinite' : infiniteScrollProp
|
|
419
419
|
const { t, i18n } = useTranslation()
|
|
420
|
+
// Number/currency locale (org override, e.g. es → es-MX); dates keep i18n.
|
|
421
|
+
const numberLocale = useNumberLocale(i18n.language)
|
|
420
422
|
const api = useApi()
|
|
421
423
|
const currentBranch = useCurrentBranch()
|
|
422
424
|
|
|
@@ -1502,12 +1504,12 @@ export function DynamicTable({
|
|
|
1502
1504
|
}
|
|
1503
1505
|
return actions === viewMetadata.actions ? viewMetadata : { ...viewMetadata, actions }
|
|
1504
1506
|
})()
|
|
1505
|
-
const baseColumns = getDynamicColumns(rowMetadata, handleInternalAction, t,
|
|
1507
|
+
const baseColumns = getDynamicColumns(rowMetadata, handleInternalAction, t, numberLocale, columnFilterConfigs, timeZone, currency, rowActionPredicate)
|
|
1506
1508
|
const filteredBase = baseColumns.filter((col: ColumnDef<any>) => !effectiveHiddenColumns.includes(col.id as string))
|
|
1507
1509
|
const actionsCol = filteredBase.find((c: ColumnDef<any>) => c.id === 'actions')
|
|
1508
1510
|
const otherCols = filteredBase.filter((c: ColumnDef<any>) => c.id !== 'actions')
|
|
1509
1511
|
return [...otherCols, ...extraColumns, ...(actionsCol ? [actionsCol] : [])]
|
|
1510
|
-
}, [viewMetadata, handleInternalAction, effectiveHiddenColumns, allowedActionKeys, extraColumns, t,
|
|
1512
|
+
}, [viewMetadata, handleInternalAction, effectiveHiddenColumns, allowedActionKeys, extraColumns, t, numberLocale, columnFilterConfigs, getDynamicColumns, timeZone, currency, rowActionPredicate])
|
|
1511
1513
|
|
|
1512
1514
|
const filters = useMemo(() => [], [])
|
|
1513
1515
|
|
|
@@ -1837,7 +1839,7 @@ export function DynamicTable({
|
|
|
1837
1839
|
col as any,
|
|
1838
1840
|
footerTotals[leaf.id],
|
|
1839
1841
|
currency,
|
|
1840
|
-
|
|
1842
|
+
numberLocale,
|
|
1841
1843
|
)}
|
|
1842
1844
|
</TableCell>
|
|
1843
1845
|
)
|
package/src/index.ts
CHANGED
|
@@ -36,3 +36,59 @@ export const TaxRateContext = createContext<number | undefined>(undefined)
|
|
|
36
36
|
|
|
37
37
|
/** Reads the nearest org default tax rate (undefined outside a provider). */
|
|
38
38
|
export const useOrgTaxRate = () => useContext(TaxRateContext)
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Number-locale overrides keyed by UI language: `{ es: 'es-MX' }` makes a
|
|
42
|
+
* Spanish UI format numbers and money the Mexican way (11,461.50) instead of
|
|
43
|
+
* Intl's bare `'es'` (Spain: 11.461,50). Keys match the full language
|
|
44
|
+
* (`'es-mx'`) first, then its base (`'es'`), case-insensitive. `undefined`
|
|
45
|
+
* outside a provider → numbers use the UI language as-is (legacy behaviour).
|
|
46
|
+
*/
|
|
47
|
+
export type NumberLocales = Readonly<Record<string, string>>
|
|
48
|
+
|
|
49
|
+
export const NumberLocalesContext = createContext<NumberLocales | undefined>(undefined)
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Pure resolver: the Intl locale numbers should use for `language` given the
|
|
53
|
+
* org's overrides. Returns `language` unchanged when nothing matches.
|
|
54
|
+
*/
|
|
55
|
+
export function resolveNumberLocale(
|
|
56
|
+
language: string | undefined,
|
|
57
|
+
locales: NumberLocales | undefined,
|
|
58
|
+
): string | undefined {
|
|
59
|
+
if (!language || !locales) return language
|
|
60
|
+
const lower = language.toLowerCase()
|
|
61
|
+
const byKey = new Map(Object.entries(locales).map(([k, v]) => [k.toLowerCase(), v]))
|
|
62
|
+
return byKey.get(lower) ?? byKey.get(lower.split('-')[0]) ?? language
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The Intl locale for number/currency formatting of the current UI language
|
|
67
|
+
* (`language`, usually `i18n.language`), honouring the nearest
|
|
68
|
+
* `OrgRuntimeProvider numberLocales`.
|
|
69
|
+
*/
|
|
70
|
+
export function useNumberLocale(language: string): string
|
|
71
|
+
export function useNumberLocale(language: string | undefined): string | undefined
|
|
72
|
+
export function useNumberLocale(language: string | undefined): string | undefined {
|
|
73
|
+
return resolveNumberLocale(language, useContext(NumberLocalesContext))
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* How the SYSTEM actor (records created or changed by a seed, an event, an
|
|
78
|
+
* agent or an automation — `created_by` empty or `SYSTEM_ACTOR_ID`) is
|
|
79
|
+
* presented: e.g. `{ name: 'Gobi', avatarUrl: '/brand/gobi.png' }`. Read by
|
|
80
|
+
* creator/created_by table cells, AuditInfo, ActivityTimeline, RecordHistory
|
|
81
|
+
* and the record dialog. `undefined` outside a provider → the localized
|
|
82
|
+
* "Sistema"/"System" label and initials (legacy behaviour).
|
|
83
|
+
*/
|
|
84
|
+
export interface SystemActor {
|
|
85
|
+
/** Display name (already localized). */
|
|
86
|
+
name?: string
|
|
87
|
+
/** Absolute URL or app path of the avatar image; used as-is. */
|
|
88
|
+
avatarUrl?: string
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export const SystemActorContext = createContext<SystemActor | undefined>(undefined)
|
|
92
|
+
|
|
93
|
+
/** Reads the nearest system-actor presentation (undefined outside a provider). */
|
|
94
|
+
export const useSystemActor = () => useContext(SystemActorContext)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// OrgRuntimeProvider — one place to feed the org's display config (timezone,
|
|
2
|
-
// currency, image-url resolver) to EVERY nested SDK renderer: dynamic tables,
|
|
2
|
+
// currency, number locale, image-url resolver) to EVERY nested SDK renderer: dynamic tables,
|
|
3
3
|
// relation tables, record dialogs and field cells all read these via context.
|
|
4
4
|
// The record dialog provides them locally, but standalone surfaces (the
|
|
5
5
|
// full-page detail view, any table mounted outside a dialog) had no provider,
|
|
@@ -12,7 +12,15 @@ import {
|
|
|
12
12
|
identityImageUrl,
|
|
13
13
|
type GetImageUrl,
|
|
14
14
|
} from './image-url-context'
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
CurrencyContext,
|
|
17
|
+
NumberLocalesContext,
|
|
18
|
+
SystemActorContext,
|
|
19
|
+
TaxRateContext,
|
|
20
|
+
TimeZoneContext,
|
|
21
|
+
type NumberLocales,
|
|
22
|
+
type SystemActor,
|
|
23
|
+
} from './org-runtime-context'
|
|
16
24
|
|
|
17
25
|
export interface OrgRuntimeProviderProps {
|
|
18
26
|
/** Org IANA timezone (e.g. `America/Mexico_City`). */
|
|
@@ -21,6 +29,18 @@ export interface OrgRuntimeProviderProps {
|
|
|
21
29
|
currency?: string
|
|
22
30
|
/** Org default tax rate as a fraction (e.g. `0.16`) for document lines. */
|
|
23
31
|
taxRate?: number
|
|
32
|
+
/**
|
|
33
|
+
* Number-locale overrides by UI language, e.g. `{ es: 'es-MX' }` so a
|
|
34
|
+
* Spanish UI formats numbers and money as Mexico does (11,461.50). Applies
|
|
35
|
+
* to table cells and footers, kanban cards and lane totals, and the record
|
|
36
|
+
* dialog. Omit to format with the UI language as-is.
|
|
37
|
+
*/
|
|
38
|
+
numberLocales?: NumberLocales
|
|
39
|
+
/**
|
|
40
|
+
* Presentation of the system actor (name + avatar) wherever a record shows
|
|
41
|
+
* who created/changed it and nobody did — e.g. `{ name: 'Gobi' }`.
|
|
42
|
+
*/
|
|
43
|
+
systemActor?: SystemActor
|
|
24
44
|
/** Resolver turning a stored path into a fetchable URL. Defaults to identity. */
|
|
25
45
|
getImageUrl?: GetImageUrl
|
|
26
46
|
children: ReactNode
|
|
@@ -30,6 +50,8 @@ export function OrgRuntimeProvider({
|
|
|
30
50
|
timeZone,
|
|
31
51
|
currency,
|
|
32
52
|
taxRate,
|
|
53
|
+
numberLocales,
|
|
54
|
+
systemActor,
|
|
33
55
|
getImageUrl = identityImageUrl,
|
|
34
56
|
children,
|
|
35
57
|
}: OrgRuntimeProviderProps) {
|
|
@@ -38,7 +60,11 @@ export function OrgRuntimeProvider({
|
|
|
38
60
|
<TimeZoneContext.Provider value={timeZone}>
|
|
39
61
|
<CurrencyContext.Provider value={currency}>
|
|
40
62
|
<TaxRateContext.Provider value={taxRate}>
|
|
41
|
-
{
|
|
63
|
+
<NumberLocalesContext.Provider value={numberLocales}>
|
|
64
|
+
<SystemActorContext.Provider value={systemActor}>
|
|
65
|
+
{children}
|
|
66
|
+
</SystemActorContext.Provider>
|
|
67
|
+
</NumberLocalesContext.Provider>
|
|
42
68
|
</TaxRateContext.Provider>
|
|
43
69
|
</CurrencyContext.Provider>
|
|
44
70
|
</TimeZoneContext.Provider>
|
package/src/record-history.tsx
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import * as React from 'react'
|
|
14
|
+
import { useSystemActor } from './org-runtime-context'
|
|
14
15
|
import { formatDistanceToNow } from 'date-fns'
|
|
15
16
|
import { es, enUS } from 'date-fns/locale'
|
|
16
17
|
import { ChevronDown, ChevronRight, Clock, ExternalLink } from 'lucide-react'
|
|
@@ -124,6 +125,7 @@ export const RecordHistory: React.FC<RecordHistoryProps> = ({
|
|
|
124
125
|
const dateLocale = locale === 'en' ? enUS : es
|
|
125
126
|
|
|
126
127
|
// Sort: most recent first
|
|
128
|
+
const systemName = useSystemActor()?.name || 'Sistema'
|
|
127
129
|
const sorted = React.useMemo(
|
|
128
130
|
() => [...events].sort((a, b) => new Date(b.occurred_at).getTime() - new Date(a.occurred_at).getTime()),
|
|
129
131
|
[events],
|
|
@@ -164,7 +166,7 @@ export const RecordHistory: React.FC<RecordHistoryProps> = ({
|
|
|
164
166
|
{sorted.map((event) => {
|
|
165
167
|
const isOpen = openIds.has(event.id)
|
|
166
168
|
const dotColor = actionDotColor(event.action)
|
|
167
|
-
const actor = event.actor_label || event.actor_id ||
|
|
169
|
+
const actor = event.actor_label || event.actor_id || systemName
|
|
168
170
|
const timeAgo = (() => {
|
|
169
171
|
try {
|
|
170
172
|
return formatDistanceToNow(new Date(event.occurred_at), { addSuffix: true, locale: dateLocale })
|
package/src/row-actions-menu.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// RowActionsMenu — el «…» de una fila: la acción primaria (si hay) arriba y
|
|
2
2
|
// destacada, las principales debajo y las secundarias (compartir, imprimir,
|
|
3
3
|
// correo, chat, PDF/XML y lo que aporten addons vía registerRecordAction)
|
|
4
|
-
// agrupadas en un «Más…» discreto. Una acción por capacidad sin proveedor
|
|
4
|
+
// agrupadas en un «Más…» discreto (o en el primer nivel con groupSecondary={false}). Una acción por capacidad sin proveedor
|
|
5
5
|
// activo, o una contribución cuyo addon no está instalado, no aparece.
|
|
6
6
|
//
|
|
7
7
|
// DynamicTable lo usa por defecto (getDynamicColumns) y los hosts que arman su
|
|
@@ -71,6 +71,12 @@ export interface RowActionsMenuProps {
|
|
|
71
71
|
/** Sustituye el ícono del disparador (p. ej. un spinner mientras imprime). */
|
|
72
72
|
triggerIcon?: React.ReactNode
|
|
73
73
|
disabled?: boolean
|
|
74
|
+
/**
|
|
75
|
+
* Agrupa las acciones secundarias en un submenú «Más…» (por defecto). Con
|
|
76
|
+
* `false` todas se listan en el primer nivel: las secundarias van después
|
|
77
|
+
* de un separador, sin submenú.
|
|
78
|
+
*/
|
|
79
|
+
groupSecondary?: boolean
|
|
74
80
|
}
|
|
75
81
|
|
|
76
82
|
/**
|
|
@@ -84,7 +90,7 @@ type MenuEntry =
|
|
|
84
90
|
| { kind: 'action'; action: any }
|
|
85
91
|
| { kind: 'contribution'; item: ResolvedRecordAction }
|
|
86
92
|
|
|
87
|
-
export function RowActionsMenu({ actions, row, model, onAction, triggerIcon, disabled }: RowActionsMenuProps) {
|
|
93
|
+
export function RowActionsMenu({ actions, row, model, onAction, triggerIcon, disabled, groupSecondary = true }: RowActionsMenuProps) {
|
|
88
94
|
const { t } = useTranslation()
|
|
89
95
|
const installed = useInstalledAddons()
|
|
90
96
|
const ctxModel = React.useContext(RowActionsModelContext)
|
|
@@ -138,7 +144,12 @@ export function RowActionsMenu({ actions, row, model, onAction, triggerIcon, dis
|
|
|
138
144
|
/>
|
|
139
145
|
) : null}
|
|
140
146
|
{mainEntries.map(renderEntry)}
|
|
141
|
-
{secondaryEntries.length > 0 && hasMain ? (
|
|
147
|
+
{secondaryEntries.length > 0 && hasMain && !groupSecondary ? (
|
|
148
|
+
<>
|
|
149
|
+
<DropdownMenuSeparator />
|
|
150
|
+
{secondaryEntries.map(renderEntry)}
|
|
151
|
+
</>
|
|
152
|
+
) : secondaryEntries.length > 0 && hasMain ? (
|
|
142
153
|
<>
|
|
143
154
|
<DropdownMenuSeparator />
|
|
144
155
|
<DropdownMenuSub>
|
|
@@ -114,12 +114,35 @@ export function WidgetEmpty({ message }: { message: string }) {
|
|
|
114
114
|
)
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
/**
|
|
118
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Per-widget error state — isolated so a broken widget never tumbles the grid.
|
|
119
|
+
* Pass `onRetry` to offer a retry (e.g. the widget query's `refetch`).
|
|
120
|
+
*/
|
|
121
|
+
export function WidgetError({
|
|
122
|
+
message,
|
|
123
|
+
onRetry,
|
|
124
|
+
retryLabel = 'Reintentar',
|
|
125
|
+
}: {
|
|
126
|
+
message: string
|
|
127
|
+
onRetry?: () => void
|
|
128
|
+
retryLabel?: string
|
|
129
|
+
}) {
|
|
119
130
|
return (
|
|
120
|
-
<div
|
|
131
|
+
<div
|
|
132
|
+
role="alert"
|
|
133
|
+
className="flex flex-1 flex-wrap items-center justify-center gap-2 py-6 text-center text-xs text-destructive"
|
|
134
|
+
>
|
|
121
135
|
<DynamicIcon name="TriangleAlert" className="size-4" />
|
|
122
136
|
<span>{message}</span>
|
|
137
|
+
{onRetry && (
|
|
138
|
+
<button
|
|
139
|
+
type="button"
|
|
140
|
+
onClick={onRetry}
|
|
141
|
+
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"
|
|
142
|
+
>
|
|
143
|
+
{retryLabel}
|
|
144
|
+
</button>
|
|
145
|
+
)}
|
|
123
146
|
</div>
|
|
124
147
|
)
|
|
125
148
|
}
|