@asteby/metacore-runtime-react 53.22.0 → 53.23.2
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 +33 -0
- package/dist/assist-interview.d.ts.map +1 -1
- package/dist/assist-interview.js +7 -10
- package/dist/custom-stages.d.ts.map +1 -1
- package/dist/custom-stages.js +2 -10
- package/dist/dialogs/dynamic-record.d.ts.map +1 -1
- package/dist/dialogs/dynamic-record.js +5 -3
- package/dist/dialogs/use-inline-relations.d.ts.map +1 -1
- package/dist/dialogs/use-inline-relations.js +4 -4
- package/dist/genui/settings-block.d.ts.map +1 -1
- package/dist/genui/settings-block.js +7 -12
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/record-picker-dialog.d.ts.map +1 -1
- package/dist/record-picker-dialog.js +4 -3
- package/dist/setup/addon-config-surface.d.ts.map +1 -1
- package/dist/setup/addon-config-surface.js +14 -12
- package/dist/stage-automations.d.ts.map +1 -1
- package/dist/stage-automations.js +3 -12
- package/dist/stage-layout.d.ts.map +1 -1
- package/dist/stage-layout.js +2 -7
- package/dist/use-addon-installed-probe.d.ts +8 -0
- package/dist/use-addon-installed-probe.d.ts.map +1 -0
- package/dist/use-addon-installed-probe.js +36 -0
- package/dist/use-addon-settings.d.ts +24 -0
- package/dist/use-addon-settings.d.ts.map +1 -1
- package/dist/use-addon-settings.js +39 -13
- package/dist/use-org-document-templates.d.ts.map +1 -1
- package/dist/use-org-document-templates.js +5 -9
- package/dist/view-system/card-spec.d.ts +3 -2
- package/dist/view-system/card-spec.d.ts.map +1 -1
- package/dist/view-system/card-spec.js +7 -6
- package/dist/views/data-source.d.ts.map +1 -1
- package/dist/views/data-source.js +9 -14
- package/dist/views/panels.d.ts.map +1 -1
- package/dist/views/panels.js +2 -1
- package/package.json +7 -6
- package/src/__tests__/genui-settings-block.test.tsx +6 -3
- package/src/__tests__/use-addon-settings-hooks.test.tsx +73 -0
- package/src/__tests__/use-addon-settings.test.ts +19 -3
- package/src/assist-interview.tsx +7 -11
- package/src/custom-stages.tsx +2 -7
- package/src/dialogs/dynamic-record.tsx +7 -2
- package/src/dialogs/use-inline-relations.ts +4 -5
- package/src/genui/settings-block.tsx +7 -13
- package/src/index.ts +1 -0
- package/src/record-picker-dialog.tsx +4 -3
- package/src/setup/addon-config-surface.tsx +16 -15
- package/src/stage-automations.tsx +3 -9
- package/src/stage-layout.ts +2 -7
- package/src/use-addon-installed-probe.ts +39 -0
- package/src/use-addon-settings.ts +66 -12
- package/src/use-org-document-templates.ts +5 -10
- package/src/view-system/card-spec.tsx +7 -6
- package/src/views/data-source.ts +6 -16
- package/src/views/panels.tsx +2 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BADGE_TONE_CLASS, type Severity } from '@asteby/metacore-ui/layout'
|
|
2
2
|
import { cn } from '@asteby/metacore-ui/lib'
|
|
3
|
+
import { formatAmount } from '@asteby/metacore-lib'
|
|
3
4
|
import type { CardFieldSpec, CardSpec } from './types'
|
|
4
5
|
|
|
5
6
|
export interface ResolvedCard {
|
|
@@ -10,12 +11,12 @@ export interface ResolvedCard {
|
|
|
10
11
|
meta: { label?: string; value: string }[]
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
function fmt(v: unknown, f: CardFieldSpec['format'] = 'text', locale?: string): string {
|
|
14
|
+
function fmt(v: unknown, f: CardFieldSpec['format'] = 'text', locale?: string, currency?: string): string {
|
|
14
15
|
if (v == null || v === '') return ''
|
|
15
16
|
try {
|
|
16
17
|
if (f === 'number') return new Intl.NumberFormat(locale).format(Number(v))
|
|
17
18
|
if (f === 'percent') return `${new Intl.NumberFormat(locale, { maximumFractionDigits: 1 }).format(Number(v))}%`
|
|
18
|
-
if (f === 'currency') return
|
|
19
|
+
if (f === 'currency') return formatAmount(v as number | string, { currency, locale })
|
|
19
20
|
if (f === 'date') return new Date(String(v)).toLocaleDateString(locale)
|
|
20
21
|
if (f === 'datetime') return new Date(String(v)).toLocaleString(locale)
|
|
21
22
|
} catch {
|
|
@@ -25,7 +26,7 @@ function fmt(v: unknown, f: CardFieldSpec['format'] = 'text', locale?: string):
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
/** Pure: row + manifest CardSpec -> display model. Missing fields are skipped, never throw. */
|
|
28
|
-
export function resolveCard(spec: CardSpec, row: Record<string, unknown>, locale?: string): ResolvedCard {
|
|
29
|
+
export function resolveCard(spec: CardSpec, row: Record<string, unknown>, locale?: string, currency?: string): ResolvedCard {
|
|
29
30
|
const bv = spec.badge ? row[spec.badge.field] : undefined
|
|
30
31
|
const key = bv == null ? '' : String(bv)
|
|
31
32
|
return {
|
|
@@ -33,12 +34,12 @@ export function resolveCard(spec: CardSpec, row: Record<string, unknown>, locale
|
|
|
33
34
|
subtitle: spec.subtitle ? fmt(row[spec.subtitle]) || undefined : undefined,
|
|
34
35
|
badge: spec.badge && key ? { text: spec.badge.labels?.[key] ?? key, tone: spec.badge.tones?.[key] ?? 'info' } : undefined,
|
|
35
36
|
chips: (spec.chips ?? []).map((f) => fmt(row[f])).filter(Boolean),
|
|
36
|
-
meta: (spec.meta ?? []).map((m) => ({ label: m.label, value: fmt(row[m.field], m.format, locale) })).filter((m) => m.value),
|
|
37
|
+
meta: (spec.meta ?? []).map((m) => ({ label: m.label, value: fmt(row[m.field], m.format, locale, currency) })).filter((m) => m.value),
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
export function ConfigurableCard({ spec, row, onClick, locale }: { spec: CardSpec; row: Record<string, unknown>; onClick?: () => void; locale?: string }) {
|
|
41
|
-
const c = resolveCard(spec, row, locale)
|
|
41
|
+
export function ConfigurableCard({ spec, row, onClick, locale, currency }: { spec: CardSpec; row: Record<string, unknown>; onClick?: () => void; locale?: string; currency?: string }) {
|
|
42
|
+
const c = resolveCard(spec, row, locale, currency)
|
|
42
43
|
const Tag = onClick ? 'button' : 'div'
|
|
43
44
|
return (
|
|
44
45
|
<Tag
|
package/src/views/data-source.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Default ViewDataSource over the runtime-react ApiClient, plus the pure
|
|
2
2
|
// helpers renderers share (capability input mapping, item extraction, date
|
|
3
3
|
// grouping). Light on purpose: this module is in the static graph.
|
|
4
|
+
import { unwrapEnvelope, unwrapList } from '@asteby/metacore-lib/envelope'
|
|
4
5
|
import type { ApiClient } from '../api-context'
|
|
5
6
|
import type { WidgetData } from '../dashboard-types'
|
|
6
7
|
import type { ChartRequest, ViewDataSource, ViewListParams, ViewRows } from './types'
|
|
@@ -16,17 +17,6 @@ export interface ApiViewDataSourceOptions {
|
|
|
16
17
|
capabilityPath?: string
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
type Envelope<T> = { success?: boolean; data?: T; meta?: { total?: number }; message?: string }
|
|
20
|
-
|
|
21
|
-
function unwrap<T>(body: unknown): { data: T | undefined; total?: number } {
|
|
22
|
-
const env = body as Envelope<T>
|
|
23
|
-
if (env && typeof env === 'object' && 'success' in env) {
|
|
24
|
-
if (env.success === false) throw new Error(env.message || 'request failed')
|
|
25
|
-
return { data: env.data, total: env.meta?.total }
|
|
26
|
-
}
|
|
27
|
-
return { data: body as T }
|
|
28
|
-
}
|
|
29
|
-
|
|
30
20
|
export function createApiViewDataSource(
|
|
31
21
|
api: ApiClient,
|
|
32
22
|
opts: ApiViewDataSourceOptions = {},
|
|
@@ -36,12 +26,12 @@ export function createApiViewDataSource(
|
|
|
36
26
|
return {
|
|
37
27
|
async list(model: string, params?: ViewListParams): Promise<ViewRows> {
|
|
38
28
|
const res = await api.get(`/data/${encodeURIComponent(model)}`, params ? { params } : undefined)
|
|
39
|
-
const {
|
|
40
|
-
return { rows:
|
|
29
|
+
const { items, meta } = unwrapList<Record<string, unknown>>(res.data)
|
|
30
|
+
return { rows: items, total: meta.total }
|
|
41
31
|
},
|
|
42
32
|
async record(model: string, id: string) {
|
|
43
33
|
const res = await api.get(`/data/${encodeURIComponent(model)}/${encodeURIComponent(id)}`)
|
|
44
|
-
return
|
|
34
|
+
return unwrapEnvelope<Record<string, unknown> | undefined>(res.data) ?? null
|
|
45
35
|
},
|
|
46
36
|
async chart(req: ChartRequest): Promise<WidgetData> {
|
|
47
37
|
const res = await api.post(chartPath, {
|
|
@@ -51,11 +41,11 @@ export function createApiViewDataSource(
|
|
|
51
41
|
record_id: req.recordId,
|
|
52
42
|
panel_key: req.panelKey,
|
|
53
43
|
})
|
|
54
|
-
return
|
|
44
|
+
return unwrapEnvelope<WidgetData | undefined>(res.data) ?? {}
|
|
55
45
|
},
|
|
56
46
|
async capability(key: string, input: Record<string, unknown>) {
|
|
57
47
|
const res = await api.post(capabilityPath, { capability: key, input })
|
|
58
|
-
return
|
|
48
|
+
return unwrapEnvelope<unknown>(res.data)
|
|
59
49
|
},
|
|
60
50
|
}
|
|
61
51
|
}
|
package/src/views/panels.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next'
|
|
|
6
6
|
import { buildRelationFilterParams } from '../dynamic-relation-helpers'
|
|
7
7
|
import type { PanelRendererProps } from './types'
|
|
8
8
|
import { displayValue, toDate } from './data-source'
|
|
9
|
+
import { formatAmount } from '@asteby/metacore-lib'
|
|
9
10
|
import { ViewSkeleton } from './skeleton'
|
|
10
11
|
|
|
11
12
|
export type StatFormat =
|
|
@@ -30,7 +31,7 @@ export function formatStat(
|
|
|
30
31
|
switch (format as StatFormat | undefined) {
|
|
31
32
|
case 'currency':
|
|
32
33
|
if (Number.isNaN(num)) break
|
|
33
|
-
return
|
|
34
|
+
return formatAmount(num, { currency, locale })
|
|
34
35
|
case 'percent':
|
|
35
36
|
if (Number.isNaN(num)) break
|
|
36
37
|
return new Intl.NumberFormat(locale, { style: 'percent', maximumFractionDigits: 1 }).format(num)
|