@burdenoff/microfe-bigconsole 2026.1119.1 → 2026.1119.3
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/dist/bigconsole/asof/AsOfBanner.js +28 -14
- package/dist/bigconsole/asof/AsOfControl.js +84 -16
- package/dist/bigconsole/asof/AsOfProvider.d.ts +7 -0
- package/dist/bigconsole/asof/AsOfProvider.js +74 -52
- package/dist/bigconsole/asof/index.d.ts +1 -1
- package/dist/bigconsole/asof/index.js +4 -4
- package/dist/bigconsole/compare/compareEngine.d.ts +104 -0
- package/dist/bigconsole/compare/compareEngine.js +172 -0
- package/dist/bigconsole/compare/compareParam.d.ts +9 -0
- package/dist/bigconsole/compare/compareParam.js +13 -0
- package/dist/bigconsole/compare/compareSide.d.ts +5 -0
- package/dist/bigconsole/compare/compareSide.js +39 -0
- package/dist/bigconsole/compare/index.d.ts +3 -0
- package/dist/bigconsole/components/widgets/FilterNotAppliedNotice.d.ts +15 -0
- package/dist/bigconsole/components/widgets/FilterNotAppliedNotice.js +62 -0
- package/dist/bigconsole/components/widgets/WidgetCompareView.d.ts +12 -0
- package/dist/bigconsole/components/widgets/WidgetCompareView.js +215 -0
- package/dist/bigconsole/components/widgets/WidgetWrapper.js +380 -329
- package/dist/bigconsole/components/widgets/chart/ChartWidget.js +131 -126
- package/dist/bigconsole/components/widgets/chart/chartRows.d.ts +16 -0
- package/dist/bigconsole/components/widgets/chart/chartRows.js +33 -1
- package/dist/bigconsole/components/widgets/metric-card/MetricCardWidget.d.ts +2 -20
- package/dist/bigconsole/components/widgets/metric-card/MetricCardWidget.js +48 -148
- package/dist/bigconsole/components/widgets/metric-card/metricCardData.d.ts +48 -0
- package/dist/bigconsole/components/widgets/metric-card/metricCardData.js +96 -0
- package/dist/bigconsole/components/widgets/metric-card/metricData.d.ts +30 -0
- package/dist/bigconsole/components/widgets/metric-card/metricData.js +46 -0
- package/dist/bigconsole/components/widgets/table/TableCell.d.ts +2 -1
- package/dist/bigconsole/components/widgets/table/TableCell.js +1 -1
- package/dist/bigconsole/components/widgets/table/TableWidget.js +142 -168
- package/dist/bigconsole/components/widgets/table/tableRows.d.ts +17 -0
- package/dist/bigconsole/components/widgets/table/tableRows.js +35 -0
- package/dist/bigconsole/hooks/index.d.ts +1 -0
- package/dist/bigconsole/hooks/index.js +25 -24
- package/dist/bigconsole/hooks/useWidgetCompareData.d.ts +8 -0
- package/dist/bigconsole/hooks/useWidgetCompareData.js +24 -0
- package/dist/bigconsole/utils/applyGlobalFilters.d.ts +3 -1
- package/dist/bigconsole/utils/applyGlobalFilters.js +53 -4
- package/dist/bigconsole/utils/globalFilterMatching.d.ts +21 -3
- package/dist/bigconsole/utils/globalFilterMatching.js +14 -9
- package/dist/bigconsole/utils/widgetDisplayData.d.ts +10 -0
- package/dist/bigconsole/utils/widgetDisplayData.js +8 -1
- package/package.json +1 -1
|
@@ -1,204 +1,104 @@
|
|
|
1
1
|
import { TrendIndicator as e } from "./TrendIndicator.js";
|
|
2
2
|
import { ComparisonBadge as t } from "./ComparisonBadge.js";
|
|
3
3
|
import { SparklineChart as n } from "./SparklineChart.js";
|
|
4
|
-
import {
|
|
4
|
+
import { resolveMetricCardData as r } from "./metricCardData.js";
|
|
5
|
+
import { formatValue as i, resolveFormat as a } from "./metricData.js";
|
|
5
6
|
import { conditionalStyleToClassName as o, resolveConditionalStyle as s } from "../utils/conditionalFormat.js";
|
|
6
7
|
import { clampProgressWidth as c, getTargetProgress as l } from "../utils/targetProgress.js";
|
|
7
8
|
import { memo as u, useCallback as d, useMemo as f } from "react";
|
|
8
9
|
import { jsx as p, jsxs as m } from "react/jsx-runtime";
|
|
9
10
|
// src/bigconsole/components/widgets/metric-card/MetricCardWidget.tsx
|
|
10
11
|
function h(e) {
|
|
11
|
-
return e !== void 0 && /^[a-z]{3}$/i.test(e) ? e.toUpperCase() : void 0;
|
|
12
|
-
}
|
|
13
|
-
function g(e, t) {
|
|
14
|
-
let n = e?.format, r = n !== void 0 && n !== "auto" ? n === "currency" || n === "percentage" || n === "compact" ? n : "number" : t?.isCurrency === !0 ? "currency" : "number";
|
|
15
|
-
return {
|
|
16
|
-
style: r,
|
|
17
|
-
currency: h(t?.unit) ?? "USD",
|
|
18
|
-
unitSuffix: r === "currency" || e?.suffix ? void 0 : t?.unit
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function _(e, t, n) {
|
|
22
|
-
if (typeof e == "string") return e;
|
|
23
|
-
let { prefix: r, suffix: i, decimalPlaces: a } = t || {}, o = n.style, s = typeof a == "number" && Number.isFinite(a) ? Math.min(Math.max(Math.trunc(a), 0), 20) : void 0, c;
|
|
24
|
-
switch (o) {
|
|
25
|
-
case "currency":
|
|
26
|
-
c = new Intl.NumberFormat("en-US", {
|
|
27
|
-
style: "currency",
|
|
28
|
-
currency: n.currency,
|
|
29
|
-
minimumFractionDigits: s ?? 0,
|
|
30
|
-
maximumFractionDigits: s ?? 2
|
|
31
|
-
}).format(e);
|
|
32
|
-
break;
|
|
33
|
-
case "percentage":
|
|
34
|
-
c = `${(e * 100).toFixed(s ?? 1)}%`;
|
|
35
|
-
break;
|
|
36
|
-
case "compact":
|
|
37
|
-
c = new Intl.NumberFormat("en-US", {
|
|
38
|
-
notation: "compact",
|
|
39
|
-
minimumFractionDigits: s,
|
|
40
|
-
maximumFractionDigits: s ?? 1
|
|
41
|
-
}).format(e);
|
|
42
|
-
break;
|
|
43
|
-
default: c = new Intl.NumberFormat("en-US", {
|
|
44
|
-
minimumFractionDigits: s,
|
|
45
|
-
maximumFractionDigits: s ?? 2
|
|
46
|
-
}).format(e);
|
|
47
|
-
}
|
|
48
|
-
return r && (c = `${r}${c}`), i && (c = `${c}${i}`), n.unitSuffix && !c.endsWith(n.unitSuffix) && (c = `${c} ${n.unitSuffix}`), c;
|
|
49
|
-
}
|
|
50
|
-
function v(e) {
|
|
51
12
|
return e === void 0 || e === 0 ? "flat" : e > 0 ? "up" : "down";
|
|
52
13
|
}
|
|
53
|
-
function
|
|
14
|
+
function g(e, t) {
|
|
54
15
|
return e === "flat" ? "muted" : (t ? e === "up" : e === "down") ? "success" : "error";
|
|
55
16
|
}
|
|
56
|
-
var
|
|
57
|
-
let
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
let n = h, r = e(n, t);
|
|
64
|
-
if (r !== void 0) {
|
|
65
|
-
let t = S?.previousValueField, i = t ? e(n, t) : void 0, a = i !== void 0 && i !== 0 && Number.isFinite(i) && typeof r == "number" ? (r - i) / i * 100 : void 0, o = h.changePercent, s = i === void 0 ? {} : {
|
|
66
|
-
previousValue: i,
|
|
67
|
-
changePercent: a ?? (Number.isFinite(o) ? o : void 0)
|
|
68
|
-
};
|
|
69
|
-
return {
|
|
70
|
-
...h,
|
|
71
|
-
value: r,
|
|
72
|
-
...s
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (typeof h == "object" && "value" in h && h.value !== void 0) return h;
|
|
77
|
-
let n = [
|
|
78
|
-
"value",
|
|
79
|
-
"total",
|
|
80
|
-
"amount",
|
|
81
|
-
"count",
|
|
82
|
-
"sum",
|
|
83
|
-
"totalSales",
|
|
84
|
-
"totalRevenue",
|
|
85
|
-
"totalOrders"
|
|
86
|
-
];
|
|
87
|
-
for (let e of n) if (typeof h == "object" && e in h) {
|
|
88
|
-
let t = h[e];
|
|
89
|
-
if (typeof t == "number" || typeof t == "string") return { value: t };
|
|
90
|
-
}
|
|
91
|
-
if (typeof h == "object" && "summary" in h) {
|
|
92
|
-
let e = h.summary;
|
|
93
|
-
if (e && typeof e == "object") {
|
|
94
|
-
for (let t of n) if (t in e) {
|
|
95
|
-
let n = e[t];
|
|
96
|
-
if (typeof n == "number" || typeof n == "string") return { value: n };
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (typeof h == "number" || typeof h == "string") return { value: h };
|
|
101
|
-
let o = r(h);
|
|
102
|
-
if (o) {
|
|
103
|
-
let t = S?.valueField;
|
|
104
|
-
if (t) {
|
|
105
|
-
let n = a(h) ?? [o];
|
|
106
|
-
for (let r of n) if (r && typeof r == "object") {
|
|
107
|
-
let n = e(r, t);
|
|
108
|
-
if (typeof n == "number" || typeof n == "string") return { value: n };
|
|
109
|
-
}
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
let n = i(o);
|
|
113
|
-
if (n) {
|
|
114
|
-
let e = o[n];
|
|
115
|
-
if (typeof e == "number" || typeof e == "string") return { value: e };
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}, [h, S]), w = f(() => C?.trend || v(C?.changePercent), [C?.trend, C?.changePercent]), T = C?.trend !== void 0 || C?.changePercent !== void 0, E = S?.positiveIsGood ?? !0, D = f(() => g(S, C), [S, C]), O = f(() => C?.value === void 0 || C?.value === null ? "—" : _(C.value, S, D), [
|
|
119
|
-
C?.value,
|
|
120
|
-
S,
|
|
121
|
-
D
|
|
122
|
-
]), k = f(() => l(C?.value, C?.target), [C?.value, C?.target]), A = f(() => y(w, E), [w, E]), j = f(() => {
|
|
123
|
-
let e = s(C?.value, S?.conditionalRules);
|
|
17
|
+
var _ = u(function({ widget: u, data: _, onClick: v, onDrilldown: y }) {
|
|
18
|
+
let b = u.config, x = f(() => r(_, b).data, [_, b]), S = f(() => x?.trend || h(x?.changePercent), [x?.trend, x?.changePercent]), C = x?.trend !== void 0 || x?.changePercent !== void 0, w = b?.positiveIsGood ?? !0, T = f(() => a(b, x), [b, x]), E = f(() => x?.value === void 0 || x?.value === null ? "—" : i(x.value, b, T), [
|
|
19
|
+
x?.value,
|
|
20
|
+
b,
|
|
21
|
+
T
|
|
22
|
+
]), D = f(() => l(x?.value, x?.target), [x?.value, x?.target]), O = f(() => g(S, w), [S, w]), k = f(() => {
|
|
23
|
+
let e = s(x?.value, b?.conditionalRules);
|
|
124
24
|
return o(e);
|
|
125
|
-
}, [
|
|
126
|
-
|
|
127
|
-
value:
|
|
128
|
-
changePercent:
|
|
129
|
-
trend:
|
|
130
|
-
target:
|
|
131
|
-
}) :
|
|
25
|
+
}, [x?.value, b?.conditionalRules]), A = d(() => {
|
|
26
|
+
y ? y({
|
|
27
|
+
value: x?.value,
|
|
28
|
+
changePercent: x?.changePercent,
|
|
29
|
+
trend: S,
|
|
30
|
+
target: x?.target
|
|
31
|
+
}) : v && u.drilldowns?.length && v();
|
|
132
32
|
}, [
|
|
133
|
-
|
|
134
|
-
|
|
33
|
+
v,
|
|
34
|
+
y,
|
|
135
35
|
u.drilldowns,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
]),
|
|
36
|
+
x,
|
|
37
|
+
S
|
|
38
|
+
]), j = !!(y || v && u.drilldowns?.length);
|
|
139
39
|
return /* @__PURE__ */ m("div", {
|
|
140
40
|
className: `
|
|
141
41
|
flex min-w-0 flex-col h-full p-4
|
|
142
|
-
${
|
|
42
|
+
${j ? "cursor-pointer hover:bg-bg-sunken/50 transition-colors" : ""}
|
|
143
43
|
`,
|
|
144
44
|
style: { containerType: "inline-size" },
|
|
145
|
-
onClick:
|
|
146
|
-
role:
|
|
147
|
-
tabIndex:
|
|
45
|
+
onClick: A,
|
|
46
|
+
role: j ? "button" : void 0,
|
|
47
|
+
tabIndex: j ? 0 : void 0,
|
|
148
48
|
onKeyDown: (e) => {
|
|
149
|
-
|
|
49
|
+
j && (e.key === "Enter" || e.key === " ") && (e.preventDefault(), A());
|
|
150
50
|
},
|
|
151
51
|
children: [
|
|
152
|
-
|
|
52
|
+
b?.subtitle && /* @__PURE__ */ p("p", {
|
|
153
53
|
className: "text-xs text-text-secondary mb-1 truncate",
|
|
154
|
-
children:
|
|
54
|
+
children: b.subtitle
|
|
155
55
|
}),
|
|
156
56
|
/* @__PURE__ */ m("div", {
|
|
157
57
|
className: "flex min-w-0 flex-wrap items-baseline gap-2 mb-2",
|
|
158
58
|
children: [/* @__PURE__ */ p("span", {
|
|
159
|
-
className: `min-w-0 max-w-full [overflow-wrap:anywhere] font-semibold tracking-tight ${
|
|
59
|
+
className: `min-w-0 max-w-full [overflow-wrap:anywhere] font-semibold tracking-tight ${k || "text-text-primary"}`,
|
|
160
60
|
style: { fontSize: "clamp(1rem, 12cqi, 1.875rem)" },
|
|
161
|
-
title:
|
|
162
|
-
children:
|
|
163
|
-
}),
|
|
164
|
-
direction:
|
|
61
|
+
title: E,
|
|
62
|
+
children: E
|
|
63
|
+
}), b?.showTrend !== !1 && C && /* @__PURE__ */ p(e, {
|
|
64
|
+
direction: S,
|
|
165
65
|
size: "md",
|
|
166
|
-
positiveIsGood:
|
|
66
|
+
positiveIsGood: w
|
|
167
67
|
})]
|
|
168
68
|
}),
|
|
169
|
-
|
|
69
|
+
b?.showComparison !== !1 && x?.changePercent !== void 0 && /* @__PURE__ */ p("div", {
|
|
170
70
|
className: "mb-3",
|
|
171
71
|
children: /* @__PURE__ */ p(t, {
|
|
172
|
-
value:
|
|
173
|
-
label:
|
|
174
|
-
positiveIsGood:
|
|
72
|
+
value: x.changePercent,
|
|
73
|
+
label: b?.comparisonLabel,
|
|
74
|
+
positiveIsGood: w,
|
|
175
75
|
size: "sm"
|
|
176
76
|
})
|
|
177
77
|
}),
|
|
178
|
-
|
|
78
|
+
D !== null && x?.target !== void 0 && /* @__PURE__ */ m("div", {
|
|
179
79
|
className: "mb-3",
|
|
180
80
|
children: [/* @__PURE__ */ m("div", {
|
|
181
81
|
className: "flex justify-between text-xs text-text-secondary mb-1",
|
|
182
|
-
children: [/* @__PURE__ */ m("span", { children: ["Target: ",
|
|
82
|
+
children: [/* @__PURE__ */ m("span", { children: ["Target: ", i(x.target, b, T)] }), /* @__PURE__ */ m("span", { children: [D.toFixed(0), "%"] })]
|
|
183
83
|
}), /* @__PURE__ */ p("div", {
|
|
184
84
|
className: "h-1.5 bg-bg-sunken rounded-full overflow-hidden",
|
|
185
85
|
children: /* @__PURE__ */ p("div", {
|
|
186
|
-
className: `h-full rounded-full transition-all ${
|
|
187
|
-
style: { width: `${c(
|
|
86
|
+
className: `h-full rounded-full transition-all ${D >= 100 ? "bg-status-success-bg" : "bg-action-primary-bg"}`,
|
|
87
|
+
style: { width: `${c(D)}%` }
|
|
188
88
|
})
|
|
189
89
|
})]
|
|
190
90
|
}),
|
|
191
|
-
|
|
91
|
+
b?.showSparkline !== !1 && x?.sparklineData?.length ? /* @__PURE__ */ p("div", {
|
|
192
92
|
className: "mt-auto pt-2",
|
|
193
93
|
children: /* @__PURE__ */ p(n, {
|
|
194
|
-
data:
|
|
94
|
+
data: x.sparklineData,
|
|
195
95
|
width: 120,
|
|
196
96
|
height: 32,
|
|
197
|
-
color:
|
|
97
|
+
color: O,
|
|
198
98
|
showFill: !0
|
|
199
99
|
})
|
|
200
100
|
}) : null,
|
|
201
|
-
|
|
101
|
+
j && /* @__PURE__ */ p("div", {
|
|
202
102
|
className: "mt-auto pt-2 flex items-center justify-end",
|
|
203
103
|
children: /* @__PURE__ */ m("span", {
|
|
204
104
|
className: "text-xs text-text-secondary flex items-center gap-1",
|
|
@@ -219,4 +119,4 @@ var b = u(function({ widget: u, data: h, onClick: b, onDrilldown: x }) {
|
|
|
219
119
|
]
|
|
220
120
|
});
|
|
221
121
|
});
|
|
222
|
-
export {
|
|
122
|
+
export { _ as MetricCardWidget, _ as default };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { MetricCardConfig } from '../../../types';
|
|
2
|
+
import { TrendDirection } from './TrendIndicator';
|
|
3
|
+
import { SparklineDataPoint } from './SparklineChart';
|
|
4
|
+
export interface MetricCardData {
|
|
5
|
+
/** Primary value to display */
|
|
6
|
+
value: number | string;
|
|
7
|
+
/** Previous value for comparison */
|
|
8
|
+
previousValue?: number;
|
|
9
|
+
/** Percentage change from previous */
|
|
10
|
+
changePercent?: number;
|
|
11
|
+
/** Trend direction override */
|
|
12
|
+
trend?: TrendDirection;
|
|
13
|
+
/** Sparkline data points */
|
|
14
|
+
sparklineData?: SparklineDataPoint[];
|
|
15
|
+
/** Target value for comparison */
|
|
16
|
+
target?: number;
|
|
17
|
+
/** Unit label (e.g., "users", "$") */
|
|
18
|
+
unit?: string;
|
|
19
|
+
/** Whether the metric is a currency */
|
|
20
|
+
isCurrency?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Where the headline value came from.
|
|
24
|
+
* - `scalar`: a single value in the payload (a bare number, `value`, a
|
|
25
|
+
* configured top-level `valueField`, a common total field, `summary.*`).
|
|
26
|
+
* - `rows`: aggregated from the payload's row array, so it follows filters.
|
|
27
|
+
* - `none`: nothing could be resolved; the card shows an em dash.
|
|
28
|
+
*/
|
|
29
|
+
export type MetricValueSource = 'scalar' | 'rows' | 'none';
|
|
30
|
+
export interface ResolvedMetricCardData {
|
|
31
|
+
data: MetricCardData | undefined;
|
|
32
|
+
source: MetricValueSource;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Aggregate `field` across rows: the sum of the numeric values, or their mean
|
|
36
|
+
* when the card is formatted as a percentage (rates and shares do not add up).
|
|
37
|
+
* Rows without a numeric value are skipped. With no numeric value at all, the
|
|
38
|
+
* first text value is shown as-is, as before. Undefined when no row has it.
|
|
39
|
+
*
|
|
40
|
+
* The card used to show the first row's value, which is one arbitrary row of
|
|
41
|
+
* the result: it did not follow a dashboard filter in any meaningful way.
|
|
42
|
+
*/
|
|
43
|
+
export declare function aggregateRowValues(rows: readonly Record<string, unknown>[], field: string, format?: MetricCardConfig['format']): number | string | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Resolve a Metric Card's display data and where its value came from. Pass the
|
|
46
|
+
* same config the card renders with.
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolveMetricCardData(rawData: unknown, config: Partial<MetricCardConfig> | undefined): ResolvedMetricCardData;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { inferValueField as e } from "../utils/inferFields.js";
|
|
2
|
+
import { findRows as t } from "../../../utils/globalFilterMatching.js";
|
|
3
|
+
// src/bigconsole/components/widgets/metric-card/metricCardData.ts
|
|
4
|
+
var n = [
|
|
5
|
+
"value",
|
|
6
|
+
"total",
|
|
7
|
+
"amount",
|
|
8
|
+
"count",
|
|
9
|
+
"sum",
|
|
10
|
+
"totalSales",
|
|
11
|
+
"totalRevenue",
|
|
12
|
+
"totalOrders"
|
|
13
|
+
], r = {
|
|
14
|
+
data: void 0,
|
|
15
|
+
source: "none"
|
|
16
|
+
};
|
|
17
|
+
function i(e, t) {
|
|
18
|
+
return t.split(".").reduce((e, t) => e && typeof e == "object" ? e[t] : void 0, e);
|
|
19
|
+
}
|
|
20
|
+
function a(e) {
|
|
21
|
+
if (typeof e == "number") return Number.isFinite(e) ? e : void 0;
|
|
22
|
+
if (typeof e == "string" && e.trim() !== "") {
|
|
23
|
+
let t = Number(e);
|
|
24
|
+
return Number.isFinite(t) ? t : void 0;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function o(e) {
|
|
28
|
+
return typeof e == "number" || typeof e == "string";
|
|
29
|
+
}
|
|
30
|
+
function s(e, t) {
|
|
31
|
+
for (let n of t) if (n in e && o(e[n])) return e[n];
|
|
32
|
+
}
|
|
33
|
+
function c(e, t, n) {
|
|
34
|
+
let r = 0, o = 0, s;
|
|
35
|
+
for (let n of e) {
|
|
36
|
+
let e = i(n, t), c = a(e);
|
|
37
|
+
c === void 0 ? typeof e == "string" && s === void 0 && (s = e) : (r += c, o += 1);
|
|
38
|
+
}
|
|
39
|
+
return o === 0 ? s : n === "percentage" ? r / o : r;
|
|
40
|
+
}
|
|
41
|
+
function l(e, t, n) {
|
|
42
|
+
let r = n ? i(e, n) : void 0, a = r !== void 0 && r !== 0 && Number.isFinite(r) && typeof t == "number" ? (t - r) / r * 100 : void 0, o = e.changePercent, s = r === void 0 ? {} : {
|
|
43
|
+
previousValue: r,
|
|
44
|
+
changePercent: a ?? (Number.isFinite(o) ? o : void 0)
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
...e,
|
|
48
|
+
value: t,
|
|
49
|
+
...s
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function u(a, u) {
|
|
53
|
+
if (a == null) return r;
|
|
54
|
+
if (o(a)) return {
|
|
55
|
+
data: { value: a },
|
|
56
|
+
source: "scalar"
|
|
57
|
+
};
|
|
58
|
+
if (typeof a != "object") return r;
|
|
59
|
+
let d = a, f = u?.valueField;
|
|
60
|
+
if (f) {
|
|
61
|
+
let e = i(d, f);
|
|
62
|
+
if (e !== void 0) return {
|
|
63
|
+
data: l(d, e, u?.previousValueField),
|
|
64
|
+
source: "scalar"
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (!Array.isArray(a)) {
|
|
68
|
+
if ("value" in d && d.value !== void 0) return {
|
|
69
|
+
data: d,
|
|
70
|
+
source: "scalar"
|
|
71
|
+
};
|
|
72
|
+
let e = s(d, n);
|
|
73
|
+
if (e !== void 0) return {
|
|
74
|
+
data: { value: e },
|
|
75
|
+
source: "scalar"
|
|
76
|
+
};
|
|
77
|
+
let t = d.summary;
|
|
78
|
+
if (t && typeof t == "object" && !Array.isArray(t)) {
|
|
79
|
+
let e = s(t, n);
|
|
80
|
+
if (e !== void 0) return {
|
|
81
|
+
data: { value: e },
|
|
82
|
+
source: "scalar"
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
let p = t(a, "metric_card"), m = p[0];
|
|
87
|
+
if (!m) return r;
|
|
88
|
+
let h = f || e(m);
|
|
89
|
+
if (!h) return r;
|
|
90
|
+
let g = c(p, h, u?.format);
|
|
91
|
+
return g === void 0 ? r : {
|
|
92
|
+
data: { value: g },
|
|
93
|
+
source: "rows"
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
export { c as aggregateRowValues, u as resolveMetricCardData };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { MetricCardConfig } from '../../../types';
|
|
2
|
+
import { MetricCardData } from './metricCardData';
|
|
3
|
+
export interface ResolvedFormat {
|
|
4
|
+
style: 'currency' | 'percentage' | 'compact' | 'number';
|
|
5
|
+
currency: string;
|
|
6
|
+
/** Payload unit rendered as a trailing label; undefined when the style or config already covers it. */
|
|
7
|
+
unitSuffix?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Decide the numeric style, honouring the payload without ever overriding the user.
|
|
11
|
+
*
|
|
12
|
+
* `MetricCardData` documents `unit` and `isCurrency`, but nothing read them — a
|
|
13
|
+
* parser emitting `{value: 482350.75, unit: "USD", isCurrency: true}` rendered a
|
|
14
|
+
* bare "482,350.75". They cannot simply take precedence though: WidgetRegistry
|
|
15
|
+
* seeds `format` onto every card, so a persisted `'number'` is indistinguishable
|
|
16
|
+
* from a deliberate choice. `'auto'` is the sentinel that defers to the payload.
|
|
17
|
+
*/
|
|
18
|
+
export declare function resolveFormat(config?: MetricCardConfig, data?: MetricCardData): ResolvedFormat;
|
|
19
|
+
/**
|
|
20
|
+
* Format a number based on configuration
|
|
21
|
+
*/
|
|
22
|
+
export declare function formatValue(value: number | string, config: MetricCardConfig | undefined, resolved: ResolvedFormat): string;
|
|
23
|
+
/**
|
|
24
|
+
* Reads the value a Metric Card shows out of the data a widget was given.
|
|
25
|
+
*
|
|
26
|
+
* Kept apart from the component so the "As of" compare (BOFF-14758) reads a metric
|
|
27
|
+
* exactly the way the card does: it delegates to the card's own resolver, so the
|
|
28
|
+
* same field mapping, fallbacks and row aggregation apply (BOFF-10063).
|
|
29
|
+
*/
|
|
30
|
+
export declare function normalizeMetricData(rawData: unknown, config: MetricCardConfig | undefined): MetricCardData | undefined;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { resolveMetricCardData as e } from "./metricCardData.js";
|
|
2
|
+
// src/bigconsole/components/widgets/metric-card/metricData.ts
|
|
3
|
+
function t(e) {
|
|
4
|
+
return e !== void 0 && /^[a-z]{3}$/i.test(e) ? e.toUpperCase() : void 0;
|
|
5
|
+
}
|
|
6
|
+
function n(e, n) {
|
|
7
|
+
let r = e?.format, i = r !== void 0 && r !== "auto" ? r === "currency" || r === "percentage" || r === "compact" ? r : "number" : n?.isCurrency === !0 ? "currency" : "number";
|
|
8
|
+
return {
|
|
9
|
+
style: i,
|
|
10
|
+
currency: t(n?.unit) ?? "USD",
|
|
11
|
+
unitSuffix: i === "currency" || e?.suffix ? void 0 : n?.unit
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function r(e, t, n) {
|
|
15
|
+
if (typeof e == "string") return e;
|
|
16
|
+
let { prefix: r, suffix: i, decimalPlaces: a } = t || {}, o = n.style, s = typeof a == "number" && Number.isFinite(a) ? Math.min(Math.max(Math.trunc(a), 0), 20) : void 0, c;
|
|
17
|
+
switch (o) {
|
|
18
|
+
case "currency":
|
|
19
|
+
c = new Intl.NumberFormat("en-US", {
|
|
20
|
+
style: "currency",
|
|
21
|
+
currency: n.currency,
|
|
22
|
+
minimumFractionDigits: s ?? 0,
|
|
23
|
+
maximumFractionDigits: s ?? 2
|
|
24
|
+
}).format(e);
|
|
25
|
+
break;
|
|
26
|
+
case "percentage":
|
|
27
|
+
c = `${(e * 100).toFixed(s ?? 1)}%`;
|
|
28
|
+
break;
|
|
29
|
+
case "compact":
|
|
30
|
+
c = new Intl.NumberFormat("en-US", {
|
|
31
|
+
notation: "compact",
|
|
32
|
+
minimumFractionDigits: s,
|
|
33
|
+
maximumFractionDigits: s ?? 1
|
|
34
|
+
}).format(e);
|
|
35
|
+
break;
|
|
36
|
+
default: c = new Intl.NumberFormat("en-US", {
|
|
37
|
+
minimumFractionDigits: s,
|
|
38
|
+
maximumFractionDigits: s ?? 2
|
|
39
|
+
}).format(e);
|
|
40
|
+
}
|
|
41
|
+
return r && (c = `${r}${c}`), i && (c = `${c}${i}`), n.unitSuffix && !c.endsWith(n.unitSuffix) && (c = `${c} ${n.unitSuffix}`), c;
|
|
42
|
+
}
|
|
43
|
+
function i(t, n) {
|
|
44
|
+
return e(t, n).data;
|
|
45
|
+
}
|
|
46
|
+
export { r as formatValue, i as normalizeMetricData, n as resolveFormat };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
1
|
+
import { FC, ReactNode } from 'react';
|
|
2
2
|
import { ColumnDefinition } from './TableHeader';
|
|
3
3
|
import { ConditionalRule } from '../utils/conditionalFormat';
|
|
4
4
|
/** In-cell mini-chart kinds. */
|
|
@@ -36,5 +36,6 @@ export interface TableCellProps {
|
|
|
36
36
|
/** Click handler */
|
|
37
37
|
onClick?: () => void;
|
|
38
38
|
}
|
|
39
|
+
export declare function formatValue(value: unknown, format?: CellFormatConfig): ReactNode;
|
|
39
40
|
export declare const TableCell: FC<TableCellProps>;
|
|
40
41
|
export default TableCell;
|