@asteby/metacore-runtime-react 50.2.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 +13 -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/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/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/widgets/widget-card.tsx +26 -3
|
@@ -30,3 +30,21 @@ export const useCurrency = () => useContext(CurrencyContext);
|
|
|
30
30
|
export const TaxRateContext = createContext(undefined);
|
|
31
31
|
/** Reads the nearest org default tax rate (undefined outside a provider). */
|
|
32
32
|
export const useOrgTaxRate = () => useContext(TaxRateContext);
|
|
33
|
+
export const NumberLocalesContext = createContext(undefined);
|
|
34
|
+
/**
|
|
35
|
+
* Pure resolver: the Intl locale numbers should use for `language` given the
|
|
36
|
+
* org's overrides. Returns `language` unchanged when nothing matches.
|
|
37
|
+
*/
|
|
38
|
+
export function resolveNumberLocale(language, locales) {
|
|
39
|
+
if (!language || !locales)
|
|
40
|
+
return language;
|
|
41
|
+
const lower = language.toLowerCase();
|
|
42
|
+
const byKey = new Map(Object.entries(locales).map(([k, v]) => [k.toLowerCase(), v]));
|
|
43
|
+
return byKey.get(lower) ?? byKey.get(lower.split('-')[0]) ?? language;
|
|
44
|
+
}
|
|
45
|
+
export function useNumberLocale(language) {
|
|
46
|
+
return resolveNumberLocale(language, useContext(NumberLocalesContext));
|
|
47
|
+
}
|
|
48
|
+
export const SystemActorContext = createContext(undefined);
|
|
49
|
+
/** Reads the nearest system-actor presentation (undefined outside a provider). */
|
|
50
|
+
export const useSystemActor = () => useContext(SystemActorContext);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import { type GetImageUrl } from './image-url-context';
|
|
3
|
+
import { type NumberLocales, type SystemActor } from './org-runtime-context';
|
|
3
4
|
export interface OrgRuntimeProviderProps {
|
|
4
5
|
/** Org IANA timezone (e.g. `America/Mexico_City`). */
|
|
5
6
|
timeZone?: string;
|
|
@@ -7,9 +8,21 @@ export interface OrgRuntimeProviderProps {
|
|
|
7
8
|
currency?: string;
|
|
8
9
|
/** Org default tax rate as a fraction (e.g. `0.16`) for document lines. */
|
|
9
10
|
taxRate?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Number-locale overrides by UI language, e.g. `{ es: 'es-MX' }` so a
|
|
13
|
+
* Spanish UI formats numbers and money as Mexico does (11,461.50). Applies
|
|
14
|
+
* to table cells and footers, kanban cards and lane totals, and the record
|
|
15
|
+
* dialog. Omit to format with the UI language as-is.
|
|
16
|
+
*/
|
|
17
|
+
numberLocales?: NumberLocales;
|
|
18
|
+
/**
|
|
19
|
+
* Presentation of the system actor (name + avatar) wherever a record shows
|
|
20
|
+
* who created/changed it and nobody did — e.g. `{ name: 'Gobi' }`.
|
|
21
|
+
*/
|
|
22
|
+
systemActor?: SystemActor;
|
|
10
23
|
/** Resolver turning a stored path into a fetchable URL. Defaults to identity. */
|
|
11
24
|
getImageUrl?: GetImageUrl;
|
|
12
25
|
children: ReactNode;
|
|
13
26
|
}
|
|
14
|
-
export declare function OrgRuntimeProvider({ timeZone, currency, taxRate, getImageUrl, children, }: OrgRuntimeProviderProps): import("react").JSX.Element;
|
|
27
|
+
export declare function OrgRuntimeProvider({ timeZone, currency, taxRate, numberLocales, systemActor, getImageUrl, children, }: OrgRuntimeProviderProps): import("react").JSX.Element;
|
|
15
28
|
//# sourceMappingURL=org-runtime-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"org-runtime-provider.d.ts","sourceRoot":"","sources":["../src/org-runtime-provider.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,OAAO,EAGL,KAAK,WAAW,EACjB,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"org-runtime-provider.d.ts","sourceRoot":"","sources":["../src/org-runtime-provider.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,OAAO,EAGL,KAAK,WAAW,EACjB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAML,KAAK,aAAa,EAClB,KAAK,WAAW,EACjB,MAAM,uBAAuB,CAAA;AAE9B,MAAM,WAAW,uBAAuB;IACtC,sDAAsD;IACtD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,2EAA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B;;;OAGG;IACH,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,iFAAiF;IACjF,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,QAAQ,EAAE,SAAS,CAAA;CACpB;AAED,wBAAgB,kBAAkB,CAAC,EACjC,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,aAAa,EACb,WAAW,EACX,WAA8B,EAC9B,QAAQ,GACT,EAAE,uBAAuB,+BAgBzB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { ImageUrlContext, identityImageUrl, } from './image-url-context';
|
|
3
|
-
import { CurrencyContext, TaxRateContext, TimeZoneContext } from './org-runtime-context';
|
|
4
|
-
export function OrgRuntimeProvider({ timeZone, currency, taxRate, getImageUrl = identityImageUrl, children, }) {
|
|
5
|
-
return (_jsx(ImageUrlContext.Provider, { value: getImageUrl, children: _jsx(TimeZoneContext.Provider, { value: timeZone, children: _jsx(CurrencyContext.Provider, { value: currency, children: _jsx(TaxRateContext.Provider, { value: taxRate, children: children }) }) }) }));
|
|
3
|
+
import { CurrencyContext, NumberLocalesContext, SystemActorContext, TaxRateContext, TimeZoneContext, } from './org-runtime-context';
|
|
4
|
+
export function OrgRuntimeProvider({ timeZone, currency, taxRate, numberLocales, systemActor, getImageUrl = identityImageUrl, children, }) {
|
|
5
|
+
return (_jsx(ImageUrlContext.Provider, { value: getImageUrl, children: _jsx(TimeZoneContext.Provider, { value: timeZone, children: _jsx(CurrencyContext.Provider, { value: currency, children: _jsx(TaxRateContext.Provider, { value: taxRate, children: _jsx(NumberLocalesContext.Provider, { value: numberLocales, children: _jsx(SystemActorContext.Provider, { value: systemActor, children: children }) }) }) }) }) }));
|
|
6
6
|
}
|
|
@@ -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;AAgB9B,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,CAuLtD,CAAA"}
|
package/dist/record-history.js
CHANGED
|
@@ -11,6 +11,7 @@ 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';
|
|
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';
|
|
@@ -54,6 +55,7 @@ function actionDotColor(action) {
|
|
|
54
55
|
export const RecordHistory = ({ events, columns, timeZone, currency, locale = 'es', className, onOpenEvent, resolveAvatarUrl, moduleLabel, }) => {
|
|
55
56
|
const dateLocale = locale === 'en' ? enUS : es;
|
|
56
57
|
// Sort: most recent first
|
|
58
|
+
const systemName = useSystemActor()?.name || 'Sistema';
|
|
57
59
|
const sorted = React.useMemo(() => [...events].sort((a, b) => new Date(b.occurred_at).getTime() - new Date(a.occurred_at).getTime()), [events]);
|
|
58
60
|
// Expand the most-recent event by default
|
|
59
61
|
const [openIds, setOpenIds] = React.useState(() => sorted.length > 0 ? new Set([sorted[0].id]) : new Set());
|
|
@@ -73,7 +75,7 @@ export const RecordHistory = ({ events, columns, timeZone, currency, locale = 'e
|
|
|
73
75
|
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
76
|
const isOpen = openIds.has(event.id);
|
|
75
77
|
const dotColor = actionDotColor(event.action);
|
|
76
|
-
const actor = event.actor_label || event.actor_id ||
|
|
78
|
+
const actor = event.actor_label || event.actor_id || systemName;
|
|
77
79
|
const timeAgo = (() => {
|
|
78
80
|
try {
|
|
79
81
|
return formatDistanceToNow(new Date(event.occurred_at), { addSuffix: true, locale: dateLocale });
|
|
@@ -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": "51.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.27.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.27.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
|
+
})
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import * as React from 'react'
|
|
17
|
+
import { useSystemActor } from './org-runtime-context'
|
|
17
18
|
import { formatDistanceToNow } from 'date-fns'
|
|
18
19
|
import { es, enUS } from 'date-fns/locale'
|
|
19
20
|
import type { Locale } from 'date-fns'
|
|
@@ -201,7 +202,8 @@ const GroupCard: React.FC<GroupCardProps> = ({
|
|
|
201
202
|
}) => {
|
|
202
203
|
const { root, events, changedFieldCount } = group
|
|
203
204
|
const isMulti = events.length > 1
|
|
204
|
-
const
|
|
205
|
+
const systemName = useSystemActor()?.name || 'Sistema'
|
|
206
|
+
const actor = root.actor_label || root.actor_id || systemName
|
|
205
207
|
const dotColor = actionDotColor(root.action)
|
|
206
208
|
|
|
207
209
|
const timeAgo = (() => {
|
|
@@ -294,7 +296,7 @@ const GroupCard: React.FC<GroupCardProps> = ({
|
|
|
294
296
|
<div className="border-t border-border/40 divide-y divide-border/30">
|
|
295
297
|
{events.map((ev, idx) => {
|
|
296
298
|
const cols = resolveColumns(ev.model)
|
|
297
|
-
const evActor = ev.actor_label || ev.actor_id ||
|
|
299
|
+
const evActor = ev.actor_label || ev.actor_id || systemName
|
|
298
300
|
return (
|
|
299
301
|
<div key={ev.id} className="px-4 py-3 space-y-2">
|
|
300
302
|
{/* Show sub-actor + model when group has multiple events */}
|
package/src/audit-info.tsx
CHANGED
|
@@ -24,7 +24,7 @@ import { cn } from '@asteby/metacore-ui/lib'
|
|
|
24
24
|
import { formatDateCell } from './dynamic-columns'
|
|
25
25
|
import { objectLabel } from './dynamic-relation-helpers'
|
|
26
26
|
import { isNilUuid } from './nil-uuid'
|
|
27
|
-
import { useTimeZone } from './org-runtime-context'
|
|
27
|
+
import { useSystemActor, useTimeZone } from './org-runtime-context'
|
|
28
28
|
import type { AuditMeta } from './types'
|
|
29
29
|
|
|
30
30
|
/** The kernel's actor for unattended work (schedules, webhooks, connectors). */
|
|
@@ -145,6 +145,7 @@ export function AuditInfo({
|
|
|
145
145
|
}: AuditInfoProps) {
|
|
146
146
|
const { t, i18n } = useTranslation()
|
|
147
147
|
const ctxTz = useTimeZone()
|
|
148
|
+
const systemActor = useSystemActor()
|
|
148
149
|
const [open, setOpen] = React.useState(defaultOpen)
|
|
149
150
|
|
|
150
151
|
const meta = readAuditMeta(audit)
|
|
@@ -166,7 +167,7 @@ export function AuditInfo({
|
|
|
166
167
|
): Line | null => {
|
|
167
168
|
const f = atCol ? formatDateCell(record[atCol], undefined, dfLocale, tz) : null
|
|
168
169
|
if (!f) return null
|
|
169
|
-
const actor = resolveAuditActor(record, byCol, { resolveActor, systemLabel: tt('system') })
|
|
170
|
+
const actor = resolveAuditActor(record, byCol, { resolveActor, systemLabel: systemActor?.name || tt('system') })
|
|
170
171
|
const date = new Date(record[atCol as string] as string)
|
|
171
172
|
const relative = formatDistanceToNow(date, { addSuffix: true, locale: dfLocale })
|
|
172
173
|
return {
|
|
@@ -88,7 +88,7 @@ import { CollectionCell, type ItemField } from '../collection-cell'
|
|
|
88
88
|
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
|
-
import { TimeZoneContext, CurrencyContext } from '../org-runtime-context'
|
|
91
|
+
import { TimeZoneContext, CurrencyContext, useNumberLocale, useSystemActor } from '../org-runtime-context'
|
|
92
92
|
|
|
93
93
|
// Re-export the resolver type so `index.ts`'s
|
|
94
94
|
// `export type { … GetImageUrl } from './dialogs/dynamic-record'` keeps working.
|
|
@@ -1706,6 +1706,8 @@ export function ViewValue({
|
|
|
1706
1706
|
currency?: string
|
|
1707
1707
|
}) {
|
|
1708
1708
|
const { t, i18n } = useTranslation()
|
|
1709
|
+
const numberLocale = useNumberLocale(i18n.language)
|
|
1710
|
+
const systemActor = useSystemActor()
|
|
1709
1711
|
const ctxImageUrl = useContext(ImageUrlContext)
|
|
1710
1712
|
const ctxTimeZone = useContext(TimeZoneContext)
|
|
1711
1713
|
const ctxCurrency = useContext(CurrencyContext)
|
|
@@ -1748,7 +1750,7 @@ export function ViewValue({
|
|
|
1748
1750
|
(typeof field.key === 'string' && field.key.startsWith('created_by.')) ||
|
|
1749
1751
|
renderAs === 'creator'
|
|
1750
1752
|
if (isCreatedBy) {
|
|
1751
|
-
return <p className="text-sm py-1">Sistema</p>
|
|
1753
|
+
return <p className="text-sm py-1">{systemActor?.name || t('common.system', { defaultValue: 'Sistema' })}</p>
|
|
1752
1754
|
}
|
|
1753
1755
|
return <p className="text-sm py-1 text-muted-foreground">—</p>
|
|
1754
1756
|
}
|
|
@@ -1897,7 +1899,7 @@ export function ViewValue({
|
|
|
1897
1899
|
const num = typeof value === 'number' ? value : Number(value)
|
|
1898
1900
|
if (!isNaN(num)) {
|
|
1899
1901
|
const resolvedCurrency = field.styleConfig?.currency || currency || 'USD'
|
|
1900
|
-
const localeTag =
|
|
1902
|
+
const localeTag = numberLocale || 'es'
|
|
1901
1903
|
const formatted = new Intl.NumberFormat(localeTag, {
|
|
1902
1904
|
style: 'currency',
|
|
1903
1905
|
currency: resolvedCurrency,
|
|
@@ -1988,7 +1990,7 @@ export function ViewValue({
|
|
|
1988
1990
|
<StructuredViewValue
|
|
1989
1991
|
value={value}
|
|
1990
1992
|
field={field}
|
|
1991
|
-
locale={
|
|
1993
|
+
locale={numberLocale}
|
|
1992
1994
|
t={t}
|
|
1993
1995
|
/>
|
|
1994
1996
|
)
|
|
@@ -2221,6 +2223,7 @@ export function EditField({ field, value, onChange, record, invalid, error }: {
|
|
|
2221
2223
|
: undefined
|
|
2222
2224
|
|
|
2223
2225
|
const { t, i18n } = useTranslation()
|
|
2226
|
+
const numberLocale = useNumberLocale(i18n.language)
|
|
2224
2227
|
const editFieldImageUrl = useContext(ImageUrlContext)
|
|
2225
2228
|
const dialogModel = useContext(RecordDialogModelContext)
|
|
2226
2229
|
|
|
@@ -2252,7 +2255,7 @@ export function EditField({ field, value, onChange, record, invalid, error }: {
|
|
|
2252
2255
|
value={value}
|
|
2253
2256
|
itemFields={fieldItemFields(field)}
|
|
2254
2257
|
variant="inline"
|
|
2255
|
-
locale={
|
|
2258
|
+
locale={numberLocale}
|
|
2256
2259
|
t={t}
|
|
2257
2260
|
getImageUrl={editFieldImageUrl}
|
|
2258
2261
|
/>
|
package/src/dynamic-columns.tsx
CHANGED
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
relationChipStyles,
|
|
39
39
|
} from '@asteby/metacore-ui/lib'
|
|
40
40
|
import { Progress } from './dialogs/_primitives'
|
|
41
|
+
import { useSystemActor } from './org-runtime-context'
|
|
41
42
|
import { humanizeToken, translateMetadataLabel } from './dynamic-columns-helpers'
|
|
42
43
|
import { objectLabel } from './dynamic-relation-helpers'
|
|
43
44
|
import {
|
|
@@ -604,19 +605,33 @@ export function resolveMissingActorLabel(
|
|
|
604
605
|
namePath: string | undefined,
|
|
605
606
|
t?: (key: string, options?: { defaultValue?: string }) => string,
|
|
606
607
|
): string {
|
|
608
|
+
if (isSystemActorColumn(renderAs, colKey, namePath)) {
|
|
609
|
+
return t ? t('common.system', { defaultValue: 'Sistema' }) : 'Sistema'
|
|
610
|
+
}
|
|
611
|
+
return 'N/A'
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* True when an EMPTY actor in this cell means "the system did it": `creator`
|
|
616
|
+
* cells and `created_by.*` columns. Exported so hosts and renderers share the
|
|
617
|
+
* rule with resolveMissingActorLabel.
|
|
618
|
+
*/
|
|
619
|
+
export function isSystemActorColumn(
|
|
620
|
+
renderAs: string | undefined,
|
|
621
|
+
colKey: string | undefined,
|
|
622
|
+
namePath: string | undefined,
|
|
623
|
+
): boolean {
|
|
607
624
|
const path = namePath || ''
|
|
608
625
|
const key = colKey || ''
|
|
609
|
-
|
|
626
|
+
return (
|
|
627
|
+
renderAs === 'creator' ||
|
|
610
628
|
key === 'created_by' ||
|
|
611
629
|
key === 'created_by_id' ||
|
|
612
630
|
key.startsWith('created_by.') ||
|
|
613
631
|
path === 'created_by' ||
|
|
614
632
|
path === 'created_by.name' ||
|
|
615
633
|
path.startsWith('created_by.')
|
|
616
|
-
|
|
617
|
-
return t ? t('common.system', { defaultValue: 'Sistema' }) : 'Sistema'
|
|
618
|
-
}
|
|
619
|
-
return 'N/A'
|
|
634
|
+
)
|
|
620
635
|
}
|
|
621
636
|
|
|
622
637
|
/**
|
|
@@ -866,6 +881,27 @@ const AvatarCell: React.FC<{
|
|
|
866
881
|
</div>
|
|
867
882
|
)
|
|
868
883
|
|
|
884
|
+
/**
|
|
885
|
+
* Avatar cell for the system actor: the OrgRuntimeProvider `systemActor`
|
|
886
|
+
* name/avatar when set, else the localized fallback label with initials.
|
|
887
|
+
*/
|
|
888
|
+
const identityUrl = (p: string) => p
|
|
889
|
+
const SystemActorCell: React.FC<{
|
|
890
|
+
fallbackName: string
|
|
891
|
+
desc?: string
|
|
892
|
+
getImageUrl: (path: string) => string
|
|
893
|
+
}> = ({ fallbackName, desc, getImageUrl }) => {
|
|
894
|
+
const actor = useSystemActor()
|
|
895
|
+
return (
|
|
896
|
+
<AvatarCell
|
|
897
|
+
name={actor?.name || fallbackName}
|
|
898
|
+
desc={desc}
|
|
899
|
+
avatarSrc={actor?.avatarUrl}
|
|
900
|
+
getImageUrl={actor?.avatarUrl ? identityUrl : getImageUrl}
|
|
901
|
+
/>
|
|
902
|
+
)
|
|
903
|
+
}
|
|
904
|
+
|
|
869
905
|
/**
|
|
870
906
|
* Builds the canonical column factory used by `<DynamicTable>` when the host
|
|
871
907
|
* does not supply its own. Pass `{ getImageUrl, apiBaseUrl }` to wire avatar
|
|
@@ -934,7 +970,9 @@ export function makeDefaultGetDynamicColumns(
|
|
|
934
970
|
currency?: string,
|
|
935
971
|
rowActionPredicate?: RowActionPredicate,
|
|
936
972
|
): ColumnDef<any>[] {
|
|
937
|
-
|
|
973
|
+
// currentLanguage may be a regional number locale (es-MX, en-US) when
|
|
974
|
+
// the host sets OrgRuntimeProvider numberLocales; dates key off its base.
|
|
975
|
+
const dateLocale = currentLanguage?.toLowerCase().startsWith('en') ? enUS : es
|
|
938
976
|
const columns: ColumnDef<any>[] = [
|
|
939
977
|
{
|
|
940
978
|
id: 'select',
|
|
@@ -1186,6 +1224,16 @@ export function makeDefaultGetDynamicColumns(
|
|
|
1186
1224
|
resolveMissingActorLabel(renderAs, col.key, namePath, t)
|
|
1187
1225
|
const desc = getNestedValue(row.original, col.description || '')
|
|
1188
1226
|
|
|
1227
|
+
if (!resolvedName && isSystemActorColumn(renderAs, col.key, namePath)) {
|
|
1228
|
+
return (
|
|
1229
|
+
<SystemActorCell
|
|
1230
|
+
fallbackName={String(name)}
|
|
1231
|
+
desc={desc ? String(desc) : undefined}
|
|
1232
|
+
getImageUrl={getImageUrl}
|
|
1233
|
+
/>
|
|
1234
|
+
)
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1189
1237
|
const avatarSrc = resolveAvatarSrc(col, row.original, value, apiBaseUrl)
|
|
1190
1238
|
|
|
1191
1239
|
return (
|
package/src/dynamic-kanban.tsx
CHANGED
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
useSyncExternalStore,
|
|
38
38
|
} from 'react'
|
|
39
39
|
import { useTranslation } from 'react-i18next'
|
|
40
|
-
import { useTimeZone, useCurrency } from './org-runtime-context'
|
|
40
|
+
import { useTimeZone, useCurrency, useNumberLocale } from './org-runtime-context'
|
|
41
41
|
import {
|
|
42
42
|
QueryClient,
|
|
43
43
|
QueryClientContext,
|
|
@@ -950,6 +950,7 @@ function DynamicKanbanBoard({
|
|
|
950
950
|
groupBy: groupByProp,
|
|
951
951
|
}: DynamicKanbanProps) {
|
|
952
952
|
const { t, i18n } = useTranslation()
|
|
953
|
+
const numberLocale = useNumberLocale(i18n.language)
|
|
953
954
|
// The org's timezone/currency: an explicit prop wins, else the app-wide
|
|
954
955
|
// OrgRuntimeProvider (without it, money fell back to USD).
|
|
955
956
|
const orgTimeZone = useTimeZone()
|
|
@@ -2096,7 +2097,7 @@ function DynamicKanbanBoard({
|
|
|
2096
2097
|
col,
|
|
2097
2098
|
(laneSums[col.key] ?? 0) + (delta?.sums[col.key] ?? 0),
|
|
2098
2099
|
currency,
|
|
2099
|
-
|
|
2100
|
+
numberLocale,
|
|
2100
2101
|
),
|
|
2101
2102
|
}))
|
|
2102
2103
|
: []
|
|
@@ -2160,7 +2161,7 @@ function DynamicKanbanBoard({
|
|
|
2160
2161
|
actions={rowActions}
|
|
2161
2162
|
stageField={lifecycleStageField(metadata)}
|
|
2162
2163
|
rowActionPredicate={rowActionPredicate}
|
|
2163
|
-
locale={
|
|
2164
|
+
locale={numberLocale}
|
|
2164
2165
|
timeZone={timeZone}
|
|
2165
2166
|
currency={currency}
|
|
2166
2167
|
onClick={onCardClick}
|
|
@@ -2194,7 +2195,7 @@ function DynamicKanbanBoard({
|
|
|
2194
2195
|
actions={rowActions}
|
|
2195
2196
|
stageField={lifecycleStageField(metadata)}
|
|
2196
2197
|
rowActionPredicate={rowActionPredicate}
|
|
2197
|
-
locale={
|
|
2198
|
+
locale={numberLocale}
|
|
2198
2199
|
timeZone={timeZone}
|
|
2199
2200
|
currency={currency}
|
|
2200
2201
|
onClick={onCardClick}
|
|
@@ -2404,7 +2405,7 @@ function DynamicKanbanBoard({
|
|
|
2404
2405
|
titleCol={titleCol}
|
|
2405
2406
|
fieldCols={fieldCols}
|
|
2406
2407
|
showAllFields={explicitCard}
|
|
2407
|
-
locale={
|
|
2408
|
+
locale={numberLocale}
|
|
2408
2409
|
timeZone={timeZone}
|
|
2409
2410
|
currency={currency}
|
|
2410
2411
|
blocked={overBlocked}
|
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)
|