@asteby/metacore-runtime-react 53.6.0 → 53.8.1

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 (84) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/action-modal-dispatcher.d.ts.map +1 -1
  3. package/dist/action-modal-dispatcher.js +3 -1
  4. package/dist/api-context.d.ts.map +1 -1
  5. package/dist/api-context.js +15 -0
  6. package/dist/cache-scope.d.ts +52 -0
  7. package/dist/cache-scope.d.ts.map +1 -0
  8. package/dist/cache-scope.js +200 -0
  9. package/dist/capability-providers/index.d.ts +4 -0
  10. package/dist/capability-providers/index.d.ts.map +1 -0
  11. package/dist/capability-providers/index.js +3 -0
  12. package/dist/capability-providers/model.d.ts +201 -0
  13. package/dist/capability-providers/model.d.ts.map +1 -0
  14. package/dist/capability-providers/model.js +293 -0
  15. package/dist/capability-providers/provider-sortable-list.d.ts +86 -0
  16. package/dist/capability-providers/provider-sortable-list.d.ts.map +1 -0
  17. package/dist/capability-providers/provider-sortable-list.js +263 -0
  18. package/dist/capability-providers/reorder.d.ts +10 -0
  19. package/dist/capability-providers/reorder.d.ts.map +1 -0
  20. package/dist/capability-providers/reorder.js +31 -0
  21. package/dist/dashboard-types.d.ts +2 -4
  22. package/dist/dashboard-types.d.ts.map +1 -1
  23. package/dist/dynamic-kanban.d.ts.map +1 -1
  24. package/dist/dynamic-kanban.js +9 -4
  25. package/dist/dynamic-relation.d.ts.map +1 -1
  26. package/dist/dynamic-relation.js +5 -2
  27. package/dist/dynamic-table.d.ts +2 -0
  28. package/dist/dynamic-table.d.ts.map +1 -1
  29. package/dist/dynamic-table.js +40 -6
  30. package/dist/dynamic-view.d.ts.map +1 -1
  31. package/dist/dynamic-view.js +3 -1
  32. package/dist/index.d.ts +4 -1
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +5 -1
  35. package/dist/metadata-cache.d.ts +22 -2
  36. package/dist/metadata-cache.d.ts.map +1 -1
  37. package/dist/metadata-cache.js +73 -13
  38. package/dist/query-batch.d.ts +12 -0
  39. package/dist/query-batch.d.ts.map +1 -1
  40. package/dist/query-batch.js +70 -29
  41. package/dist/setup/addon-config-surface.d.ts +7 -1
  42. package/dist/setup/addon-config-surface.d.ts.map +1 -1
  43. package/dist/setup/addon-config-surface.js +128 -10
  44. package/dist/setup/messages.d.ts.map +1 -1
  45. package/dist/setup/messages.js +10 -0
  46. package/dist/use-option-ids.d.ts.map +1 -1
  47. package/dist/use-option-ids.js +3 -1
  48. package/dist/use-options-resolver.d.ts +4 -1
  49. package/dist/use-options-resolver.d.ts.map +1 -1
  50. package/dist/use-options-resolver.js +27 -16
  51. package/dist/widgets/charts.d.ts.map +1 -1
  52. package/dist/widgets/charts.js +11 -43
  53. package/dist/widgets/widget-format.d.ts +1 -41
  54. package/dist/widgets/widget-format.d.ts.map +1 -1
  55. package/dist/widgets/widget-format.js +3 -138
  56. package/package.json +4 -4
  57. package/src/__tests__/addon-config-surface.test.tsx +55 -0
  58. package/src/__tests__/charts-reexport.test.ts +30 -0
  59. package/src/action-modal-dispatcher.tsx +3 -1
  60. package/src/api-context.tsx +14 -0
  61. package/src/cache-scope-inflight.test.ts +369 -0
  62. package/src/cache-scope.test.ts +234 -0
  63. package/src/cache-scope.ts +202 -0
  64. package/src/capability-providers/index.ts +46 -0
  65. package/src/capability-providers/model.test.ts +186 -0
  66. package/src/capability-providers/model.ts +464 -0
  67. package/src/capability-providers/provider-sortable-list.test.tsx +284 -0
  68. package/src/capability-providers/provider-sortable-list.tsx +452 -0
  69. package/src/capability-providers/reorder.ts +29 -0
  70. package/src/dashboard-types.ts +2 -11
  71. package/src/dynamic-kanban.tsx +9 -4
  72. package/src/dynamic-relation.tsx +5 -2
  73. package/src/dynamic-table.tsx +41 -10
  74. package/src/dynamic-view.tsx +3 -1
  75. package/src/index.ts +13 -0
  76. package/src/metadata-cache.ts +85 -15
  77. package/src/query-batch.ts +71 -30
  78. package/src/setup/addon-config-surface.tsx +202 -18
  79. package/src/setup/messages.ts +10 -0
  80. package/src/use-option-ids.ts +3 -1
  81. package/src/use-options-resolver.ts +28 -15
  82. package/src/widgets/charts.tsx +26 -189
  83. package/src/widgets/widget-format.ts +14 -181
  84. package/vitest.setup.ts +16 -0
@@ -1,138 +1,3 @@
1
- // Shared widget formatting + accent theming. Reuses the same Intl-based
2
- // approach as the table cells (dynamic-columns) so dashboard numbers read
3
- // identically to the grids: org currency + locale, compact notation, percent.
4
- /**
5
- * Formats a scalar/series value with the widget's declared format. `currency`
6
- * uses the org currency + locale (same fallback chain as table cells); `percent`
7
- * treats the value as a fraction (0.142 → "14.2%"); `compact` uses Intl compact
8
- * notation (1_200 → "1.2K").
9
- */
10
- export function formatWidgetValue(value, { format = 'number', locale, currency }) {
11
- if (value === null || value === undefined || Number.isNaN(value))
12
- return '—';
13
- const loc = locale || undefined;
14
- switch (format) {
15
- case 'currency':
16
- return new Intl.NumberFormat(loc, {
17
- style: 'currency',
18
- currency: currency || 'USD',
19
- maximumFractionDigits: 2,
20
- }).format(value);
21
- case 'percent':
22
- return new Intl.NumberFormat(loc, {
23
- style: 'percent',
24
- minimumFractionDigits: 0,
25
- maximumFractionDigits: 1,
26
- }).format(value);
27
- case 'compact':
28
- return new Intl.NumberFormat(loc, {
29
- notation: 'compact',
30
- maximumFractionDigits: 1,
31
- }).format(value);
32
- case 'number':
33
- default:
34
- return new Intl.NumberFormat(loc, {
35
- maximumFractionDigits: 2,
36
- }).format(value);
37
- }
38
- }
39
- /** Axis-tick formatter — always compact so charts stay legible. */
40
- export function formatAxisTick(value, { format, locale, currency }) {
41
- const loc = locale || undefined;
42
- if (format === 'currency') {
43
- return new Intl.NumberFormat(loc, {
44
- style: 'currency',
45
- currency: currency || 'USD',
46
- notation: 'compact',
47
- maximumFractionDigits: 1,
48
- }).format(value);
49
- }
50
- if (format === 'percent') {
51
- return new Intl.NumberFormat(loc, {
52
- style: 'percent',
53
- maximumFractionDigits: 0,
54
- }).format(value);
55
- }
56
- return new Intl.NumberFormat(loc, {
57
- notation: 'compact',
58
- maximumFractionDigits: 1,
59
- }).format(value);
60
- }
61
- /** Formats the compare delta fraction (0.142 → "+14.2%"). */
62
- export function formatDelta(delta, locale) {
63
- const sign = delta > 0 ? '+' : '';
64
- return (sign +
65
- new Intl.NumberFormat(locale || undefined, {
66
- style: 'percent',
67
- minimumFractionDigits: 0,
68
- maximumFractionDigits: 1,
69
- }).format(delta));
70
- }
71
- const ACCENTS = {
72
- emerald: {
73
- chip: 'bg-emerald-500/10 text-emerald-600 dark:text-emerald-400',
74
- text: 'text-emerald-600 dark:text-emerald-400',
75
- bar: 'bg-emerald-500',
76
- track: 'bg-emerald-500/15',
77
- chartVar: 'var(--color-widget-emerald, #10b981)',
78
- },
79
- sky: {
80
- chip: 'bg-sky-500/10 text-sky-600 dark:text-sky-400',
81
- text: 'text-sky-600 dark:text-sky-400',
82
- bar: 'bg-sky-500',
83
- track: 'bg-sky-500/15',
84
- chartVar: 'var(--color-widget-sky, #0ea5e9)',
85
- },
86
- violet: {
87
- chip: 'bg-violet-500/10 text-violet-600 dark:text-violet-400',
88
- text: 'text-violet-600 dark:text-violet-400',
89
- bar: 'bg-violet-500',
90
- track: 'bg-violet-500/15',
91
- chartVar: 'var(--color-widget-violet, #8b5cf6)',
92
- },
93
- amber: {
94
- chip: 'bg-amber-500/10 text-amber-600 dark:text-amber-400',
95
- text: 'text-amber-600 dark:text-amber-400',
96
- bar: 'bg-amber-500',
97
- track: 'bg-amber-500/15',
98
- chartVar: 'var(--color-widget-amber, #f59e0b)',
99
- },
100
- rose: {
101
- chip: 'bg-rose-500/10 text-rose-600 dark:text-rose-400',
102
- text: 'text-rose-600 dark:text-rose-400',
103
- bar: 'bg-rose-500',
104
- track: 'bg-rose-500/15',
105
- chartVar: 'var(--color-widget-rose, #f43f5e)',
106
- },
107
- slate: {
108
- chip: 'bg-slate-500/10 text-slate-600 dark:text-slate-300',
109
- text: 'text-slate-600 dark:text-slate-300',
110
- bar: 'bg-slate-500',
111
- track: 'bg-slate-500/15',
112
- chartVar: 'var(--color-widget-slate, #64748b)',
113
- },
114
- };
115
- const DEFAULT_ACCENT = 'sky';
116
- /** Resolves the accent class bundle, defaulting to `sky`. */
117
- export function accentClasses(accent) {
118
- return ACCENTS[accent ?? DEFAULT_ACCENT] ?? ACCENTS[DEFAULT_ACCENT];
119
- }
120
- /**
121
- * A categorical palette for multi-series charts (pie/donut/bar by bucket).
122
- * Cycles the accent chart vars so slices stay theme-aware + dark-mode safe.
123
- */
124
- export const CHART_PALETTE = [
125
- ACCENTS.sky.chartVar,
126
- ACCENTS.emerald.chartVar,
127
- ACCENTS.violet.chartVar,
128
- ACCENTS.amber.chartVar,
129
- ACCENTS.rose.chartVar,
130
- ACCENTS.slate.chartVar,
131
- ];
132
- /** Picks a palette color by index, wrapping around. */
133
- export function paletteColor(index) {
134
- return CHART_PALETTE[index % CHART_PALETTE.length];
135
- }
136
- /** Grid/axis muted color from the theme (works in light + dark). */
137
- export const CHART_MUTED = 'var(--muted-foreground, #94a3b8)';
138
- export const CHART_GRID = 'var(--border, #e2e8f0)';
1
+ // Moved to @asteby/metacore-charts (shared palette + formatting). Re-exported
2
+ // here so existing imports keep compiling.
3
+ export { formatWidgetValue, formatAxisTick, formatDelta, accentClasses, paletteColor, CHART_PALETTE, CHART_GRID, CHART_MUTED, } from '@asteby/metacore-charts';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asteby/metacore-runtime-react",
3
- "version": "53.6.0",
3
+ "version": "53.8.1",
4
4
  "description": "React runtime for metacore hosts — renders addon contributions dynamically",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,15 +33,15 @@
33
33
  }
34
34
  },
35
35
  "dependencies": {
36
+ "@asteby/metacore-charts": "^0.1.0",
36
37
  "@dnd-kit/core": "^6.3.0",
37
38
  "@dnd-kit/sortable": "^10.0.0",
38
39
  "@dnd-kit/utilities": "^3.2.2",
39
40
  "@tanstack/react-virtual": "^3.14.13",
40
- "recharts": "^3.8.1",
41
41
  "zod": "^4.3.0"
42
42
  },
43
43
  "peerDependencies": {
44
- "@asteby/metacore-sdk": "^3.18.0",
44
+ "@asteby/metacore-sdk": "^3.18.1",
45
45
  "@asteby/metacore-ui": "^2.31.0",
46
46
  "@tanstack/react-query": ">=5",
47
47
  "@tanstack/react-router": ">=1.100",
@@ -73,7 +73,7 @@
73
73
  }
74
74
  },
75
75
  "devDependencies": {
76
- "@asteby/metacore-sdk": "3.18.0",
76
+ "@asteby/metacore-sdk": "3.18.1",
77
77
  "@asteby/metacore-ui": "2.31.0",
78
78
  "@tanstack/react-query": "^5.95.0",
79
79
  "@tanstack/react-router": "^1.168.0",
@@ -112,6 +112,61 @@ describe('AddonConfigSurface', () => {
112
112
  expect(onSaved).toHaveBeenCalled()
113
113
  })
114
114
 
115
+ it('stored fields open locked: pencil unlocks, eye reveals a secret only for owners', async () => {
116
+ const values = { 'GET /integrations/mp/values': { data: { values: { public_key: 'APP_USR-x' }, secrets_set: ['access_token'] } } }
117
+ const reveal = { 'GET /integrations/mp/values/access_token/reveal?environment=sandbox': { data: { value: 'APP_USR-secret' } } }
118
+ const { calls } = setup({ connector, canRevealSecrets: true }, { ...values, ...reveal })
119
+ const pub = (await screen.findByLabelText(/Llave pública/)) as HTMLInputElement
120
+ const secret = screen.getByLabelText(/Token/) as HTMLInputElement
121
+ await waitFor(() => expect(pub.readOnly).toBe(true))
122
+ expect(secret.readOnly).toBe(true)
123
+ // eye on the locked secret fetches the value on demand
124
+ fireEvent.click(screen.getAllByLabelText('Ver')[0])
125
+ await waitFor(() => expect(secret.value).toBe('APP_USR-secret'))
126
+ expect(calls.some((c) => c.url === '/integrations/mp/values/access_token/reveal?environment=sandbox')).toBe(true)
127
+ // pencil unlocks the public key for editing
128
+ fireEvent.click(screen.getAllByLabelText('Editar')[0])
129
+ await waitFor(() => expect(pub.readOnly).toBe(false))
130
+ })
131
+
132
+ it('flipping the environment swaps the scoped fields for that environment\'s stored ones', async () => {
133
+ const conn: ConnectorEntry = {
134
+ ...connector,
135
+ credentials: [connector.credentials![2], connector.credentials![0], connector.credentials![1]].map((f) =>
136
+ f.key === 'env' ? { ...f, default: 'sandbox' } : f,
137
+ ),
138
+ }
139
+ const { calls } = setup(
140
+ { connector: conn },
141
+ {
142
+ 'GET /integrations/mp/values': { data: { values: { public_key: 'TEST-pub', env: 'sandbox' }, secrets_set: ['access_token'], env_scoped: ['public_key', 'access_token'] } },
143
+ 'GET /integrations/mp/values?environment=prod': { data: { values: {}, secrets_set: [], env_scoped: ['public_key', 'access_token'] } },
144
+ },
145
+ )
146
+ const pub = (await screen.findByLabelText(/Llave pública/)) as HTMLInputElement
147
+ await waitFor(() => expect(pub.value).toBe('TEST-pub'))
148
+ expect(pub.readOnly).toBe(true)
149
+ // flip to production: the sandbox keys go away, the fields open empty (nothing stored there yet)
150
+ const trigger = screen.getByRole('combobox')
151
+ fireEvent.pointerDown(trigger)
152
+ fireEvent.click(trigger)
153
+ fireEvent.click(await screen.findByText('prod'))
154
+ await waitFor(() => expect(calls.some((c) => c.url === '/integrations/mp/values?environment=prod')).toBe(true))
155
+ await waitFor(() => expect(pub.value).toBe(''))
156
+ expect(screen.queryByLabelText('Editar')).toBeNull()
157
+ })
158
+
159
+ it('without owner rights a locked secret has no eye and nothing is fetched', async () => {
160
+ const { calls } = setup(
161
+ { connector },
162
+ { 'GET /integrations/mp/values': { data: { values: { public_key: 'APP_USR-x' }, secrets_set: ['access_token'] } } },
163
+ )
164
+ const secret = (await screen.findByLabelText(/Token/)) as HTMLInputElement
165
+ await waitFor(() => expect(secret.readOnly).toBe(true))
166
+ expect(screen.queryByLabelText('Ver')).toBeNull()
167
+ expect(calls.some((c) => c.url.endsWith('/reveal'))).toBe(false)
168
+ })
169
+
115
170
  it('does not fetch stored values for non-admins and explains why', async () => {
116
171
  const { calls } = setup({ connector, canManageIssuer: false })
117
172
  expect(await screen.findByText(/Solo un administrador de la organización/)).toBeTruthy()
@@ -0,0 +1,30 @@
1
+ // The chart code moved to @asteby/metacore-charts; everything runtime-react
2
+ // used to expose must still be exported from its index, and the formatters
3
+ // must be the very same functions.
4
+ import { describe, expect, it } from 'vitest'
5
+ import * as runtime from '../index'
6
+ import * as charts from '@asteby/metacore-charts'
7
+
8
+ describe('runtime-react keeps exporting the chart surface', () => {
9
+ it.each([
10
+ 'BarWidget', 'LineWidget', 'AreaWidget', 'PieWidget', 'DonutWidget', 'preloadWidgetCharts',
11
+ 'formatWidgetValue', 'formatAxisTick', 'formatDelta', 'accentClasses', 'paletteColor', 'CHART_PALETTE',
12
+ 'WidgetCard', 'WidgetRenderer', 'StatWidget',
13
+ ])('exports %s', (name) => {
14
+ expect((runtime as Record<string, unknown>)[name]).toBeDefined()
15
+ })
16
+
17
+ it('shares the implementation with @asteby/metacore-charts', () => {
18
+ expect(runtime.formatWidgetValue).toBe(charts.formatWidgetValue)
19
+ expect(runtime.paletteColor).toBe(charts.paletteColor)
20
+ expect(runtime.CHART_PALETTE).toBe(charts.CHART_PALETTE)
21
+ expect(runtime.Sparkline).toBe(charts.Sparkline)
22
+ })
23
+
24
+ it('keeps the eager ./charts module exporting the five widgets', async () => {
25
+ const m = await import('../widgets/charts')
26
+ for (const k of ['BarWidget', 'LineWidget', 'AreaWidget', 'PieWidget', 'DonutWidget']) {
27
+ expect(typeof (m as Record<string, unknown>)[k]).toBe('function')
28
+ }
29
+ })
30
+ })
@@ -72,6 +72,7 @@ import { UploadField } from './upload-field'
72
72
  import { isLineItemsField, resolveWidget, resolveDependsValue, getDependsOn, getFieldRef, applyOptionWhen } from './dynamic-form-schema'
73
73
  import { FieldGrid, FieldCell, FieldLabel } from './field-grid'
74
74
  import { useMetadataCache } from './metadata-cache'
75
+ import { cacheScope } from './cache-scope'
75
76
  import {
76
77
  ViewValue,
77
78
  objectLabel,
@@ -800,6 +801,7 @@ function RecordPreview({ model, record }: { model: string; record: any }) {
800
801
  useEffect(() => {
801
802
  if (cached || !model) return
802
803
  let cancelled = false
804
+ const askedScope = cacheScope()
803
805
  api
804
806
  .get(`/metadata/table/${model}`)
805
807
  .then((res) => {
@@ -807,7 +809,7 @@ function RecordPreview({ model, record }: { model: string; record: any }) {
807
809
  const meta = (res.data?.data ?? res.data) as TableMetadata
808
810
  if (meta && Array.isArray(meta.columns)) {
809
811
  setFetched(meta)
810
- setMetadata(model, meta)
812
+ setMetadata(model, meta, { scope: askedScope })
811
813
  }
812
814
  })
813
815
  .catch(() => {
@@ -4,6 +4,7 @@
4
4
  // their app in <ApiProvider value={axiosInstance}> once at the root.
5
5
  import React, { createContext, useContext, useEffect, useMemo } from 'react'
6
6
  import { batchGet, invalidateQueryBatchData } from './query-batch'
7
+ import { syncCacheScope } from './cache-scope'
7
8
  import { invalidateOptionsCache } from './use-options-resolver'
8
9
  import {
9
10
  epochFromAxiosHeaders,
@@ -38,6 +39,19 @@ export interface ApiProviderProps {
38
39
  }
39
40
 
40
41
  export function ApiProvider({ client, batch = true, children }: ApiProviderProps) {
42
+ // Login, logout or an org/user/language switch (also from another tab)
43
+ // empties the scoped caches (metadata store, query batch).
44
+ useEffect(() => {
45
+ syncCacheScope()
46
+ if (typeof window === 'undefined') return
47
+ const onChange = () => syncCacheScope()
48
+ window.addEventListener('storage', onChange)
49
+ window.addEventListener('focus', onChange)
50
+ return () => {
51
+ window.removeEventListener('storage', onChange)
52
+ window.removeEventListener('focus', onChange)
53
+ }
54
+ }, [])
41
55
  // Hosts also write through their own client (native dialogs, settings
42
56
  // screens) without going through useApi(). When the client is axios,
43
57
  // every non-GET response drops what the runtime remembered as well.