@burdenoff/microfe-bigconsole 2026.1119.2 → 2026.1119.4

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 (36) hide show
  1. package/dist/bigconsole/components/parser/ParserSelector.js +150 -145
  2. package/dist/bigconsole/components/widgets/FilterNotAppliedNotice.d.ts +15 -0
  3. package/dist/bigconsole/components/widgets/FilterNotAppliedNotice.js +62 -0
  4. package/dist/bigconsole/components/widgets/WidgetWrapper.js +353 -351
  5. package/dist/bigconsole/components/widgets/chart/ChartWidget.js +131 -126
  6. package/dist/bigconsole/components/widgets/chart/chartRows.d.ts +16 -0
  7. package/dist/bigconsole/components/widgets/chart/chartRows.js +33 -1
  8. package/dist/bigconsole/components/widgets/metric-card/MetricCardWidget.d.ts +2 -20
  9. package/dist/bigconsole/components/widgets/metric-card/MetricCardWidget.js +4 -3
  10. package/dist/bigconsole/components/widgets/metric-card/metricCardData.d.ts +48 -0
  11. package/dist/bigconsole/components/widgets/metric-card/metricCardData.js +96 -0
  12. package/dist/bigconsole/components/widgets/metric-card/metricData.d.ts +9 -2
  13. package/dist/bigconsole/components/widgets/metric-card/metricData.js +10 -69
  14. package/dist/bigconsole/customWidget/CustomWidgetBuilderSheet.js +50 -49
  15. package/dist/bigconsole/customWidget/CustomWidgetProposalPanel.js +223 -201
  16. package/dist/bigconsole/customWidget/index.d.ts +2 -1
  17. package/dist/bigconsole/customWidget/index.js +1 -0
  18. package/dist/bigconsole/customWidget/proposalContract.d.ts +55 -1
  19. package/dist/bigconsole/customWidget/proposalContract.js +37 -14
  20. package/dist/bigconsole/customWidget/proposalPreviewData.d.ts +18 -0
  21. package/dist/bigconsole/customWidget/proposalPreviewData.js +70 -0
  22. package/dist/bigconsole/customWidget/proposalSource.d.ts +10 -0
  23. package/dist/bigconsole/customWidget/proposalSource.js +197 -51
  24. package/dist/bigconsole/hooks/useParserOperations.js +80 -74
  25. package/dist/bigconsole/pages/ParserBuilderPage.js +540 -518
  26. package/dist/bigconsole/store/parserScope.d.ts +24 -0
  27. package/dist/bigconsole/store/parserScope.js +17 -0
  28. package/dist/bigconsole/store/parserStore.d.ts +3 -0
  29. package/dist/bigconsole/store/parserStore.js +70 -68
  30. package/dist/bigconsole/utils/applyGlobalFilters.d.ts +3 -1
  31. package/dist/bigconsole/utils/applyGlobalFilters.js +53 -4
  32. package/dist/bigconsole/utils/globalFilterMatching.d.ts +21 -3
  33. package/dist/bigconsole/utils/globalFilterMatching.js +14 -9
  34. package/dist/generated/wspace-operations.d.ts +10 -0
  35. package/dist/generated/wspace-operations.js +180 -110
  36. package/package.json +1 -1
@@ -12,12 +12,12 @@ import { ScatterChart as f } from "./charts/ScatterChart.js";
12
12
  import { ChartLegend as p } from "./ChartLegend.js";
13
13
  import "../../../contexts/index.js";
14
14
  import { WidgetEmptyState as m } from "../states/EmptyState.js";
15
- import { classifyChartData as h } from "./chartRows.js";
16
- import { memo as g, useCallback as _, useMemo as v, useState as y } from "react";
17
- import { useI18n as b } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
18
- import { jsx as x, jsxs as S } from "react/jsx-runtime";
15
+ import { aggregatePieRows as h, classifyChartData as g } from "./chartRows.js";
16
+ import { memo as _, useCallback as v, useMemo as y, useState as b } from "react";
17
+ import { useI18n as x } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
18
+ import { jsx as S, jsxs as C } from "react/jsx-runtime";
19
19
  // src/bigconsole/components/widgets/chart/ChartWidget.tsx
20
- var C = [], w = {
20
+ var w = [], T = {
21
21
  number: {
22
22
  key: "bigconsole.widget.chart.unsupported.number",
23
23
  fallback: "This data is a single value."
@@ -34,162 +34,167 @@ var C = [], w = {
34
34
  key: "bigconsole.widget.chart.unsupported.values",
35
35
  fallback: "This data is a list of values without field names."
36
36
  }
37
- }, T = [
37
+ }, E = [
38
38
  "var(--color-chart-1)",
39
39
  "var(--color-chart-2)",
40
40
  "var(--color-chart-3)",
41
41
  "var(--color-chart-4)",
42
42
  "var(--color-chart-5)"
43
- ], E = g(function({ widget: g, data: E = [], onClick: D, onDrilldown: O }) {
44
- let { t: k } = b(), A = g.config, [j, M] = y([]), N = v(() => h(E), [E]), P = N.kind === "rows" ? N.rows : C, { handleDataClick: F, enabled: I } = t(g.id, A?.crossFilterMappings || [{
45
- sourceField: A?.labelField || "name",
43
+ ], D = _(function({ widget: _, data: D = [], onClick: O, onDrilldown: k }) {
44
+ let { t: A } = x(), j = _.config, [M, N] = b([]), P = y(() => g(D), [D]), F = P.kind === "rows" ? P.rows : w, I = j?.valueField || "value", L = j?.labelField || "name", R = j?.chartType?.toLowerCase() === "pie", z = y(() => R ? h(F, L, I) : F, [
45
+ R,
46
+ F,
47
+ L,
48
+ I
49
+ ]), { handleDataClick: B, enabled: V } = t(_.id, j?.crossFilterMappings || [{
50
+ sourceField: j?.labelField || "name",
46
51
  targetFilterId: "category"
47
- }]), { clearAllCrossFilters: L, hasCrossFilters: R } = e(), z = v(() => ({
48
- type: g.type === "funnel_chart" ? "funnel" : A?.chartType?.toLowerCase() || "line",
49
- xAxisKey: A?.xAxisField || A?.labelField || "name",
50
- xAxisLabel: A?.xAxisLabel,
51
- yAxisLabel: A?.yAxisLabel,
52
- showGrid: A?.showGrid,
53
- showLegend: A?.showLegend,
54
- legendPosition: A?.legendPosition,
55
- showDots: A?.showDataPoints,
56
- curveType: A?.curveType,
57
- colors: A?.colors,
58
- seriesNames: A?.seriesLabels,
59
- stacked: A?.stacked,
60
- isDonut: A?.showAsDonut,
61
- innerRadius: A?.innerRadius,
62
- outerRadius: A?.outerRadius,
63
- referenceLines: A?.referenceLines,
64
- series: A?.series,
65
- selectedFields: A?.selectedFields,
66
- dualAxis: A?.dualAxis,
67
- yAxisRightLabel: A?.yAxisRightLabel,
68
- logScale: A?.logScale,
69
- startAtZero: A?.startAtZero,
70
- yMin: A?.yMin,
71
- yMax: A?.yMax,
72
- valueField: A?.valueField,
73
- labelField: A?.labelField,
74
- showTotal: A?.showTotal,
75
- totalLabel: A?.totalLabel,
76
- xField: A?.xField,
77
- yField: A?.yField,
78
- sizeField: A?.sizeField,
79
- colorField: A?.colorField
80
- }), [A, g.type]), B = z.type !== "funnel" && (z.type === "combo" || z.dualAxis === !0 || z.series?.some((e) => e.axis === "right" || e.type === "bar") && z.series?.some((e) => e.type === "line") || !1), V = v(() => !P.length || z.type === "pie" || z.type === "funnel" || z.type === "scatter" || z.type === "waterfall" ? [] : (B && z.selectedFields !== void 0 ? n(P, z).map((e) => e.field) : r(P, z.xAxisKey, z.selectedFields)).map((e, t) => ({
52
+ }]), { clearAllCrossFilters: H, hasCrossFilters: U } = e(), W = y(() => ({
53
+ type: _.type === "funnel_chart" ? "funnel" : j?.chartType?.toLowerCase() || "line",
54
+ xAxisKey: j?.xAxisField || j?.labelField || "name",
55
+ xAxisLabel: j?.xAxisLabel,
56
+ yAxisLabel: j?.yAxisLabel,
57
+ showGrid: j?.showGrid,
58
+ showLegend: j?.showLegend,
59
+ legendPosition: j?.legendPosition,
60
+ showDots: j?.showDataPoints,
61
+ curveType: j?.curveType,
62
+ colors: j?.colors,
63
+ seriesNames: j?.seriesLabels,
64
+ stacked: j?.stacked,
65
+ isDonut: j?.showAsDonut,
66
+ innerRadius: j?.innerRadius,
67
+ outerRadius: j?.outerRadius,
68
+ referenceLines: j?.referenceLines,
69
+ series: j?.series,
70
+ selectedFields: j?.selectedFields,
71
+ dualAxis: j?.dualAxis,
72
+ yAxisRightLabel: j?.yAxisRightLabel,
73
+ logScale: j?.logScale,
74
+ startAtZero: j?.startAtZero,
75
+ yMin: j?.yMin,
76
+ yMax: j?.yMax,
77
+ valueField: j?.valueField,
78
+ labelField: j?.labelField,
79
+ showTotal: j?.showTotal,
80
+ totalLabel: j?.totalLabel,
81
+ xField: j?.xField,
82
+ yField: j?.yField,
83
+ sizeField: j?.sizeField,
84
+ colorField: j?.colorField
85
+ }), [j, _.type]), G = W.type !== "funnel" && (W.type === "combo" || W.dualAxis === !0 || W.series?.some((e) => e.axis === "right" || e.type === "bar") && W.series?.some((e) => e.type === "line") || !1), K = y(() => !F.length || W.type === "pie" || W.type === "funnel" || W.type === "scatter" || W.type === "waterfall" ? [] : (G && W.selectedFields !== void 0 ? n(F, W).map((e) => e.field) : r(F, W.xAxisKey, W.selectedFields)).map((e, t) => ({
81
86
  dataKey: e,
82
- name: z.seriesNames?.[e] || e,
83
- color: z.colors?.[t] || T[t % T.length],
84
- hidden: j.includes(e)
87
+ name: W.seriesNames?.[e] || e,
88
+ color: W.colors?.[t] || E[t % E.length],
89
+ hidden: M.includes(e)
85
90
  })), [
86
- P,
87
- z,
88
- j,
89
- A?.selectedFields,
90
- B
91
- ]), H = _((e) => {
92
- M((t) => t.includes(e) ? t.filter((t) => t !== e) : [...t, e]);
93
- }, []), U = _((e, t) => {
94
- if (I) {
95
- let t = e[A?.labelField || "name"];
96
- F(e, t);
91
+ F,
92
+ W,
93
+ M,
94
+ j?.selectedFields,
95
+ G
96
+ ]), q = v((e) => {
97
+ N((t) => t.includes(e) ? t.filter((t) => t !== e) : [...t, e]);
98
+ }, []), J = v((e, t) => {
99
+ if (V) {
100
+ let t = e[j?.labelField || "name"];
101
+ B(e, t);
97
102
  }
98
- O ? O(e) : D && g.drilldowns?.length && D(e, t);
103
+ k ? k(e) : O && _.drilldowns?.length && O(e, t);
99
104
  }, [
100
- D,
101
105
  O,
102
- g.drilldowns,
103
- I,
104
- F,
105
- A?.labelField
106
- ]), W = () => {
107
- if (B) return /* @__PURE__ */ x(u, {
108
- data: P,
109
- config: z,
110
- hiddenSeries: j,
111
- onDataClick: U
106
+ k,
107
+ _.drilldowns,
108
+ V,
109
+ B,
110
+ j?.labelField
111
+ ]), Y = () => {
112
+ if (G) return /* @__PURE__ */ S(u, {
113
+ data: F,
114
+ config: W,
115
+ hiddenSeries: M,
116
+ onDataClick: J
112
117
  });
113
- switch (z.type) {
114
- case "waterfall": return /* @__PURE__ */ x(d, {
115
- data: P,
116
- config: z,
117
- onDataClick: U
118
+ switch (W.type) {
119
+ case "waterfall": return /* @__PURE__ */ S(d, {
120
+ data: F,
121
+ config: W,
122
+ onDataClick: J
118
123
  });
119
- case "scatter": return /* @__PURE__ */ x(f, {
120
- data: P,
121
- config: z,
122
- onDataClick: U
124
+ case "scatter": return /* @__PURE__ */ S(f, {
125
+ data: F,
126
+ config: W,
127
+ onDataClick: J
123
128
  });
124
- case "bar": return /* @__PURE__ */ x(a, {
125
- data: P,
126
- config: z,
127
- hiddenSeries: j,
128
- onDataClick: U
129
+ case "bar": return /* @__PURE__ */ S(a, {
130
+ data: F,
131
+ config: W,
132
+ hiddenSeries: M,
133
+ onDataClick: J
129
134
  });
130
- case "area": return /* @__PURE__ */ x(o, {
131
- data: P,
132
- config: z,
133
- hiddenSeries: j,
134
- onDataClick: U
135
+ case "area": return /* @__PURE__ */ S(o, {
136
+ data: F,
137
+ config: W,
138
+ hiddenSeries: M,
139
+ onDataClick: J
135
140
  });
136
- case "pie": return /* @__PURE__ */ x(s, {
137
- data: P,
138
- config: z,
139
- dataKey: A?.valueField || "value",
140
- nameKey: A?.labelField || "name",
141
- onDataClick: U
141
+ case "pie": return /* @__PURE__ */ S(s, {
142
+ data: z,
143
+ config: W,
144
+ dataKey: I,
145
+ nameKey: L,
146
+ onDataClick: J
142
147
  });
143
148
  case "funnel": {
144
- let e = l(P, {
145
- valueField: A?.valueField,
146
- labelField: A?.labelField
149
+ let e = l(F, {
150
+ valueField: j?.valueField,
151
+ labelField: j?.labelField
147
152
  });
148
- return /* @__PURE__ */ x(c, {
149
- data: P,
150
- config: z,
153
+ return /* @__PURE__ */ S(c, {
154
+ data: F,
155
+ config: W,
151
156
  dataKey: e.valueField,
152
157
  nameKey: e.labelField,
153
- onDataClick: U
158
+ onDataClick: J
154
159
  });
155
160
  }
156
- default: return /* @__PURE__ */ x(i, {
157
- data: P,
158
- config: z,
159
- hiddenSeries: j,
160
- onDataClick: U
161
+ default: return /* @__PURE__ */ S(i, {
162
+ data: F,
163
+ config: W,
164
+ hiddenSeries: M,
165
+ onDataClick: J
161
166
  });
162
167
  }
163
168
  };
164
- if (N.kind === "empty") return /* @__PURE__ */ x(m, {
169
+ if (P.kind === "empty") return /* @__PURE__ */ S(m, {
165
170
  widgetType: "chart",
166
171
  hasDataSource: !0
167
172
  });
168
- if (N.kind === "unsupported") {
169
- let e = w[N.shape];
170
- return /* @__PURE__ */ x(m, {
173
+ if (P.kind === "unsupported") {
174
+ let e = T[P.shape];
175
+ return /* @__PURE__ */ S(m, {
171
176
  widgetType: "chart",
172
177
  hasDataSource: !0,
173
- message: `${k(e.key, e.fallback)} ${k("bigconsole.widget.chart.unsupported.hint", "A chart needs a list of rows. Pick a parser that returns rows, or use a Metric Card for one number.")}`
178
+ message: `${A(e.key, e.fallback)} ${A("bigconsole.widget.chart.unsupported.hint", "A chart needs a list of rows. Pick a parser that returns rows, or use a Metric Card for one number.")}`
174
179
  });
175
180
  }
176
- return /* @__PURE__ */ S("div", {
181
+ return /* @__PURE__ */ C("div", {
177
182
  className: "flex flex-col h-full p-4",
178
183
  children: [
179
- R && /* @__PURE__ */ x("div", {
184
+ U && /* @__PURE__ */ S("div", {
180
185
  className: "flex items-center gap-2 mb-2 -mt-1",
181
- children: /* @__PURE__ */ S("button", {
186
+ children: /* @__PURE__ */ C("button", {
182
187
  type: "button",
183
188
  onClick: (e) => {
184
- e.stopPropagation(), L();
189
+ e.stopPropagation(), H();
185
190
  },
186
191
  className: "\n inline-flex items-center gap-1.5\n px-2.5 py-1 rounded-md\n text-xs font-medium\n bg-action-primary-bg/10 text-action-primary-text\n hover:bg-action-primary-bg/20\n transition-colors\n ",
187
- children: [/* @__PURE__ */ x("svg", {
192
+ children: [/* @__PURE__ */ S("svg", {
188
193
  className: "w-3.5 h-3.5",
189
194
  fill: "none",
190
195
  stroke: "currentColor",
191
196
  viewBox: "0 0 24 24",
192
- children: /* @__PURE__ */ x("path", {
197
+ children: /* @__PURE__ */ S("path", {
193
198
  strokeLinecap: "round",
194
199
  strokeLinejoin: "round",
195
200
  strokeWidth: 2,
@@ -198,21 +203,21 @@ var C = [], w = {
198
203
  }), "Clear Filter"]
199
204
  })
200
205
  }),
201
- z.legendPosition === "top" && V.length > 0 && /* @__PURE__ */ x(p, {
202
- items: V,
206
+ W.legendPosition === "top" && K.length > 0 && /* @__PURE__ */ S(p, {
207
+ items: K,
203
208
  position: "top",
204
- onItemClick: H
209
+ onItemClick: q
205
210
  }),
206
- /* @__PURE__ */ x("div", {
211
+ /* @__PURE__ */ S("div", {
207
212
  className: "flex-1 min-h-0",
208
- children: W()
213
+ children: Y()
209
214
  }),
210
- z.legendPosition === "bottom" && V.length > 0 && /* @__PURE__ */ x(p, {
211
- items: V,
215
+ W.legendPosition === "bottom" && K.length > 0 && /* @__PURE__ */ S(p, {
216
+ items: K,
212
217
  position: "bottom",
213
- onItemClick: H
218
+ onItemClick: q
214
219
  })
215
220
  ]
216
221
  });
217
222
  });
218
- export { E as ChartWidget, E as default };
223
+ export { D as ChartWidget, D as default };
@@ -11,3 +11,19 @@ export type ChartRowsResult = {
11
11
  readonly shape: UnsupportedChartShape;
12
12
  };
13
13
  export declare function classifyChartData(data: unknown): ChartRowsResult;
14
+ /**
15
+ * One slice per label: a pie bound to raw rows (`[{channel, brand, region,
16
+ * sales}, …]`) sums `valueField` by `labelField` (BOFF-10411).
17
+ *
18
+ * Drawing each raw row as its own slice repeated every label, and a dashboard
19
+ * filter that narrowed the rows only reshuffled duplicate slices, so the pie
20
+ * looked unchanged. Summing per label means the pie shows the filtered mix.
21
+ *
22
+ * Rows whose labels are already unique (a pre-aggregated `[{name, value}]`
23
+ * result) are returned unchanged, keeping every field for drilldown. Merged
24
+ * rows carry only the label and the summed value, because the other fields
25
+ * differ between the rows that were merged. Labels keep first-seen order; a
26
+ * row without a numeric value adds nothing to its slice. Rows that do not
27
+ * carry `labelField` at all are returned unchanged.
28
+ */
29
+ export declare function aggregatePieRows(rows: readonly ChartData[], labelField: string, valueField: string): ChartData[];
@@ -24,4 +24,36 @@ function t(t) {
24
24
  shape: "object"
25
25
  };
26
26
  }
27
- export { t as classifyChartData };
27
+ function n(e) {
28
+ if (typeof e == "number") return Number.isFinite(e) ? e : void 0;
29
+ if (typeof e == "string" && e.trim() !== "") {
30
+ let t = Number(e);
31
+ return Number.isFinite(t) ? t : void 0;
32
+ }
33
+ }
34
+ function r(e, t, r) {
35
+ if (!e.some((e) => e[t] !== void 0 && e[t] !== null)) return e;
36
+ let i = /* @__PURE__ */ new Set(), a = !1;
37
+ for (let n of e) {
38
+ let e = String(n[t] ?? "");
39
+ if (i.has(e)) {
40
+ a = !0;
41
+ break;
42
+ }
43
+ i.add(e);
44
+ }
45
+ if (!a) return e;
46
+ let o = /* @__PURE__ */ new Map();
47
+ for (let i of e) {
48
+ let e = String(i[t] ?? ""), a = o.get(e) ?? {
49
+ label: i[t],
50
+ total: 0
51
+ };
52
+ a.total += n(i[r]) ?? 0, o.set(e, a);
53
+ }
54
+ return Array.from(o.values(), ({ label: e, total: n }) => ({
55
+ [t]: e,
56
+ [r]: n
57
+ }));
58
+ }
59
+ export { r as aggregatePieRows, t as classifyChartData };
@@ -1,7 +1,6 @@
1
1
  import { FC } from 'react';
2
2
  import { Widget } from '../../../types';
3
- import { TrendDirection } from './TrendIndicator';
4
- import { SparklineDataPoint } from './SparklineChart';
3
+ import { MetricCardData } from './metricCardData';
5
4
  export interface MetricCardWidgetProps {
6
5
  /** Widget configuration */
7
6
  widget: Widget;
@@ -12,23 +11,6 @@ export interface MetricCardWidgetProps {
12
11
  /** Drilldown handler - receives metric data */
13
12
  onDrilldown?: (selectedData: Record<string, unknown>) => void;
14
13
  }
15
- export interface MetricCardData {
16
- /** Primary value to display */
17
- value: number | string;
18
- /** Previous value for comparison */
19
- previousValue?: number;
20
- /** Percentage change from previous */
21
- changePercent?: number;
22
- /** Trend direction override */
23
- trend?: TrendDirection;
24
- /** Sparkline data points */
25
- sparklineData?: SparklineDataPoint[];
26
- /** Target value for comparison */
27
- target?: number;
28
- /** Unit label (e.g., "users", "$") */
29
- unit?: string;
30
- /** Whether the metric is a currency */
31
- isCurrency?: boolean;
32
- }
14
+ export type { MetricCardData } from './metricCardData';
33
15
  export declare const MetricCardWidget: FC<MetricCardWidgetProps>;
34
16
  export default MetricCardWidget;
@@ -1,7 +1,8 @@
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 { formatValue as r, normalizeMetricData as i, resolveFormat as a } from "./metricData.js";
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";
@@ -14,7 +15,7 @@ function g(e, t) {
14
15
  return e === "flat" ? "muted" : (t ? e === "up" : e === "down") ? "success" : "error";
15
16
  }
16
17
  var _ = u(function({ widget: u, data: _, onClick: v, onDrilldown: y }) {
17
- let b = u.config, x = f(() => i(_, b), [_, 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 ? "—" : r(x.value, b, T), [
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), [
18
19
  x?.value,
19
20
  b,
20
21
  T
@@ -78,7 +79,7 @@ var _ = u(function({ widget: u, data: _, onClick: v, onDrilldown: y }) {
78
79
  className: "mb-3",
79
80
  children: [/* @__PURE__ */ m("div", {
80
81
  className: "flex justify-between text-xs text-text-secondary mb-1",
81
- children: [/* @__PURE__ */ m("span", { children: ["Target: ", r(x.target, b, T)] }), /* @__PURE__ */ m("span", { children: [D.toFixed(0), "%"] })]
82
+ children: [/* @__PURE__ */ m("span", { children: ["Target: ", i(x.target, b, T)] }), /* @__PURE__ */ m("span", { children: [D.toFixed(0), "%"] })]
82
83
  }), /* @__PURE__ */ p("div", {
83
84
  className: "h-1.5 bg-bg-sunken rounded-full overflow-hidden",
84
85
  children: /* @__PURE__ */ p("div", {
@@ -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 };
@@ -1,5 +1,5 @@
1
1
  import { MetricCardConfig } from '../../../types';
2
- import { MetricCardData } from './MetricCardWidget';
2
+ import { MetricCardData } from './metricCardData';
3
3
  export interface ResolvedFormat {
4
4
  style: 'currency' | 'percentage' | 'compact' | 'number';
5
5
  currency: string;
@@ -20,4 +20,11 @@ export declare function resolveFormat(config?: MetricCardConfig, data?: MetricCa
20
20
  * Format a number based on configuration
21
21
  */
22
22
  export declare function formatValue(value: number | string, config: MetricCardConfig | undefined, resolved: ResolvedFormat): string;
23
- export declare function normalizeMetricData(rawData: MetricCardData | undefined, config: MetricCardConfig | undefined): MetricCardData | undefined;
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;