@burdenoff/microfe-bigconsole 2026.1119.1 → 2026.1119.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.
Files changed (31) hide show
  1. package/dist/bigconsole/asof/AsOfBanner.js +28 -14
  2. package/dist/bigconsole/asof/AsOfControl.js +84 -16
  3. package/dist/bigconsole/asof/AsOfProvider.d.ts +7 -0
  4. package/dist/bigconsole/asof/AsOfProvider.js +74 -52
  5. package/dist/bigconsole/asof/index.d.ts +1 -1
  6. package/dist/bigconsole/asof/index.js +4 -4
  7. package/dist/bigconsole/compare/compareEngine.d.ts +104 -0
  8. package/dist/bigconsole/compare/compareEngine.js +172 -0
  9. package/dist/bigconsole/compare/compareParam.d.ts +9 -0
  10. package/dist/bigconsole/compare/compareParam.js +13 -0
  11. package/dist/bigconsole/compare/compareSide.d.ts +5 -0
  12. package/dist/bigconsole/compare/compareSide.js +39 -0
  13. package/dist/bigconsole/compare/index.d.ts +3 -0
  14. package/dist/bigconsole/components/widgets/WidgetCompareView.d.ts +12 -0
  15. package/dist/bigconsole/components/widgets/WidgetCompareView.js +215 -0
  16. package/dist/bigconsole/components/widgets/WidgetWrapper.js +371 -322
  17. package/dist/bigconsole/components/widgets/metric-card/MetricCardWidget.js +47 -148
  18. package/dist/bigconsole/components/widgets/metric-card/metricData.d.ts +23 -0
  19. package/dist/bigconsole/components/widgets/metric-card/metricData.js +105 -0
  20. package/dist/bigconsole/components/widgets/table/TableCell.d.ts +2 -1
  21. package/dist/bigconsole/components/widgets/table/TableCell.js +1 -1
  22. package/dist/bigconsole/components/widgets/table/TableWidget.js +142 -168
  23. package/dist/bigconsole/components/widgets/table/tableRows.d.ts +17 -0
  24. package/dist/bigconsole/components/widgets/table/tableRows.js +35 -0
  25. package/dist/bigconsole/hooks/index.d.ts +1 -0
  26. package/dist/bigconsole/hooks/index.js +25 -24
  27. package/dist/bigconsole/hooks/useWidgetCompareData.d.ts +8 -0
  28. package/dist/bigconsole/hooks/useWidgetCompareData.js +24 -0
  29. package/dist/bigconsole/utils/widgetDisplayData.d.ts +10 -0
  30. package/dist/bigconsole/utils/widgetDisplayData.js +8 -1
  31. package/package.json +1 -1
@@ -6,11 +6,13 @@ import { memo as r } from "react";
6
6
  import { History as i } from "lucide-react";
7
7
  import { Button as a } from "@burdenoff/fe-libs/ui";
8
8
  import { useI18n as o } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
9
- import { jsx as s } from "react/jsx-runtime";
9
+ import { jsx as s, jsxs as c } from "react/jsx-runtime";
10
10
  // src/bigconsole/asof/AsOfBanner.tsx
11
- var c = r(function() {
12
- let { t: r } = o(), { asOf: c, clearAsOf: l } = n();
13
- return c ? /* @__PURE__ */ s("div", {
11
+ var l = r(function() {
12
+ let { t: r } = o(), { asOf: l, clearAsOf: u, compareTo: d, clearCompare: f } = n();
13
+ if (!l) return null;
14
+ let p = d !== null, m = d instanceof Date ? t(d) : r("bigconsole.compare.banner.now", "now");
15
+ return /* @__PURE__ */ s("div", {
14
16
  role: "status",
15
17
  "aria-live": "polite",
16
18
  className: "mx-card-padding mt-control-gap flex-shrink-0",
@@ -23,16 +25,28 @@ var c = r(function() {
23
25
  className: "size-4",
24
26
  "aria-hidden": "true"
25
27
  }),
26
- title: r("bigconsole.asOf.banner.title", "Showing data as of {{date}}", { date: t(c) }),
27
- description: r("bigconsole.asOf.banner.description", "Parser versions are pinned to that date. The layout shown is the current one. This is not live data."),
28
- meta: /* @__PURE__ */ s(a, {
29
- variant: "outline",
30
- size: "sm",
31
- onClick: l,
32
- "data-testid": "as-of-banner-back",
33
- children: r("bigconsole.asOf.banner.back", "Back to now")
28
+ title: p ? r("bigconsole.compare.banner.title", "Comparing {{from}} with {{to}}", {
29
+ from: t(l),
30
+ to: m
31
+ }) : r("bigconsole.asOf.banner.title", "Showing data as of {{date}}", { date: t(l) }),
32
+ description: p ? r("bigconsole.compare.banner.description", "Each chart, table and metric card shows both times and the difference. Parser versions are pinned to each date. The layout shown is the current one.") : r("bigconsole.asOf.banner.description", "Parser versions are pinned to that date. The layout shown is the current one. This is not live data."),
33
+ meta: /* @__PURE__ */ c("div", {
34
+ className: "flex items-center gap-2",
35
+ children: [p && /* @__PURE__ */ s(a, {
36
+ variant: "outline",
37
+ size: "sm",
38
+ onClick: f,
39
+ "data-testid": "compare-banner-stop",
40
+ children: r("bigconsole.compare.picker.stop", "Stop comparing")
41
+ }), /* @__PURE__ */ s(a, {
42
+ variant: "outline",
43
+ size: "sm",
44
+ onClick: u,
45
+ "data-testid": "as-of-banner-back",
46
+ children: r("bigconsole.asOf.banner.back", "Back to now")
47
+ })]
34
48
  })
35
49
  })
36
- }) : null;
50
+ });
37
51
  });
38
- export { c as AsOfBanner, c as default };
52
+ export { l as AsOfBanner, l as default };
@@ -7,14 +7,23 @@ import { useI18n as f } from "@burdenoff/fe-libs/shared/providers/shell/I18nProv
7
7
  import { jsx as p, jsxs as m } from "react/jsx-runtime";
8
8
  // src/bigconsole/asof/AsOfControl.tsx
9
9
  var h = r(function() {
10
- let { t: r } = f(), { enabled: h, asOf: _, setAsOf: v, clearAsOf: y } = n(), [b, x] = a(!1), [S, C] = a(t(_)), [w, T] = a(!1);
10
+ let { t: r } = f(), { enabled: h, asOf: _, setAsOf: v, clearAsOf: y, compareTo: b, setCompareTo: x, clearCompare: S } = n(), [C, w] = a(!1), [T, E] = a(t(_)), [D, O] = a(!1), [k, A] = a(""), [j, M] = a(!1);
11
11
  if (i(() => {
12
- b && (C(t(_)), T(!1));
13
- }, [b, _]), !h) return null;
14
- let E = _ ? r("bigconsole.asOf.control.at", "As of: {{date}}", { date: g(_) }) : r("bigconsole.asOf.control.now", "As of: Now");
12
+ C && (E(t(_)), O(!1), A(b instanceof Date ? t(b) : ""), M(!1));
13
+ }, [
14
+ C,
15
+ _,
16
+ b
17
+ ]), !h) return null;
18
+ let N = _ ? r("bigconsole.asOf.control.at", "As of: {{date}}", { date: g(_) }) : r("bigconsole.asOf.control.now", "As of: Now"), P = () => {
19
+ let t = e(T);
20
+ t ? (v(t), w(!1)) : O(!0);
21
+ }, F = (e) => {
22
+ x(e), w(!1);
23
+ };
15
24
  return /* @__PURE__ */ m(l, {
16
- open: b,
17
- onOpenChange: x,
25
+ open: C,
26
+ onOpenChange: w,
18
27
  children: [/* @__PURE__ */ p(d, {
19
28
  asChild: !0,
20
29
  children: /* @__PURE__ */ m(s, {
@@ -27,7 +36,7 @@ var h = r(function() {
27
36
  "aria-hidden": "true"
28
37
  }), /* @__PURE__ */ p("span", {
29
38
  className: "ml-1",
30
- children: E
39
+ children: N
31
40
  })]
32
41
  })
33
42
  }), /* @__PURE__ */ m(u, {
@@ -44,16 +53,16 @@ var h = r(function() {
44
53
  })] }),
45
54
  /* @__PURE__ */ p(c, {
46
55
  type: "datetime-local",
47
- value: S,
56
+ value: T,
48
57
  max: t(/* @__PURE__ */ new Date()),
49
58
  onChange: (e) => {
50
- C(e.target.value), T(!1);
59
+ E(e.target.value), O(!1);
51
60
  },
52
61
  "aria-label": r("bigconsole.asOf.picker.input", "Date and time"),
53
- "aria-invalid": w,
62
+ "aria-invalid": D,
54
63
  "data-testid": "as-of-input"
55
64
  }),
56
- w && /* @__PURE__ */ p("p", {
65
+ D && /* @__PURE__ */ p("p", {
57
66
  role: "alert",
58
67
  className: "text-xs text-status-danger-text",
59
68
  "data-testid": "as-of-invalid",
@@ -66,19 +75,78 @@ var h = r(function() {
66
75
  size: "sm",
67
76
  disabled: !_,
68
77
  onClick: () => {
69
- y(), x(!1);
78
+ y(), w(!1);
70
79
  },
71
80
  "data-testid": "as-of-back-to-now",
72
81
  children: r("bigconsole.asOf.picker.back", "Back to now")
73
82
  }), /* @__PURE__ */ p(s, {
74
83
  size: "sm",
75
- onClick: () => {
76
- let t = e(S);
77
- t ? (v(t), x(!1)) : T(!0);
78
- },
84
+ onClick: P,
79
85
  "data-testid": "as-of-apply",
80
86
  children: r("bigconsole.asOf.picker.apply", "Show")
81
87
  })]
88
+ }),
89
+ _ && /* @__PURE__ */ m("div", {
90
+ className: "space-y-2 border-t border-border-subtle pt-3",
91
+ "data-testid": "compare-section",
92
+ children: [
93
+ /* @__PURE__ */ p("p", {
94
+ className: "text-sm font-medium text-text-primary",
95
+ children: r("bigconsole.compare.picker.title", "Compare with")
96
+ }),
97
+ /* @__PURE__ */ p("p", {
98
+ className: "text-xs text-text-muted",
99
+ children: r("bigconsole.compare.picker.hint", "See each chart, table and metric card at both times, with the difference.")
100
+ }),
101
+ /* @__PURE__ */ p(c, {
102
+ type: "datetime-local",
103
+ value: k,
104
+ min: t(_),
105
+ max: t(/* @__PURE__ */ new Date()),
106
+ onChange: (e) => {
107
+ A(e.target.value), M(!1);
108
+ },
109
+ "aria-label": r("bigconsole.compare.picker.input", "Second date and time"),
110
+ "aria-invalid": j,
111
+ "data-testid": "compare-input"
112
+ }),
113
+ j && /* @__PURE__ */ p("p", {
114
+ role: "alert",
115
+ className: "text-xs text-status-danger-text",
116
+ "data-testid": "compare-invalid",
117
+ children: r("bigconsole.compare.picker.invalid", "Pick a time that is after the first one and not in the future.")
118
+ }),
119
+ /* @__PURE__ */ m("div", {
120
+ className: "flex flex-wrap items-center justify-between gap-2",
121
+ children: [/* @__PURE__ */ p(s, {
122
+ variant: "ghost",
123
+ size: "sm",
124
+ disabled: !b,
125
+ onClick: () => {
126
+ S(), w(!1);
127
+ },
128
+ "data-testid": "compare-stop",
129
+ children: r("bigconsole.compare.picker.stop", "Stop comparing")
130
+ }), /* @__PURE__ */ m("div", {
131
+ className: "flex items-center gap-2",
132
+ children: [/* @__PURE__ */ p(s, {
133
+ variant: "outline",
134
+ size: "sm",
135
+ onClick: () => F("now"),
136
+ "data-testid": "compare-now",
137
+ children: r("bigconsole.compare.picker.now", "Compare with now")
138
+ }), /* @__PURE__ */ p(s, {
139
+ size: "sm",
140
+ onClick: () => {
141
+ let t = e(k);
142
+ !t || !_ || t.getTime() <= _.getTime() ? M(!0) : F(t);
143
+ },
144
+ "data-testid": "compare-apply",
145
+ children: r("bigconsole.compare.picker.apply", "Compare")
146
+ })]
147
+ })]
148
+ })
149
+ ]
82
150
  })
83
151
  ]
84
152
  })]
@@ -1,4 +1,5 @@
1
1
  import { FC, ReactNode } from 'react';
2
+ import { CompareTarget } from '../compare/compareParam';
2
3
  export interface AsOfState {
3
4
  /** The workspace has the as-of view on. */
4
5
  enabled: boolean;
@@ -8,6 +9,12 @@ export interface AsOfState {
8
9
  setAsOf: (date: Date) => void;
9
10
  /** Go back to live data. */
10
11
  clearAsOf: () => void;
12
+ /** What the board at `asOf` is compared with (BOFF-14758), or null when it is not a compare. */
13
+ compareTo: CompareTarget | null;
14
+ /** Compare the board at `asOf` with live data or another time. */
15
+ setCompareTo: (target: CompareTarget) => void;
16
+ /** Stop comparing; the board stays as of `asOf`. */
17
+ clearCompare: () => void;
11
18
  }
12
19
  export interface AsOfProviderProps {
13
20
  workspaceId?: string | null;
@@ -1,76 +1,98 @@
1
- import { AS_OF_FEATURE_FLAG as e, AS_OF_PARAM as t, flagStatusForScope as n, formatAsOf as r, parseAsOf as i, shouldWaitForFlag as a } from "./asOfParam.js";
2
- import { createContext as o, useCallback as s, useContext as c, useEffect as l, useMemo as u, useState as d } from "react";
3
- import { useSearchParams as f } from "react-router";
4
- import { FeatureFlagProvider as p, useFeatureFlag as m, useFeatureFlags as h } from "@burdenoff/fe-libs/shared/feature-flags";
5
- import { Spinner as g } from "@burdenoff/fe-libs/ui";
6
- import { Fragment as _, jsx as v, jsxs as y } from "react/jsx-runtime";
1
+ import { COMPARE_PARAM as e, formatCompareTarget as t, parseCompareTarget as n } from "../compare/compareParam.js";
2
+ import { AS_OF_FEATURE_FLAG as r, AS_OF_PARAM as i, flagStatusForScope as a, formatAsOf as o, parseAsOf as s, shouldWaitForFlag as c } from "./asOfParam.js";
3
+ import { createContext as l, useCallback as u, useContext as d, useEffect as f, useMemo as p, useState as m } from "react";
4
+ import { useSearchParams as h } from "react-router";
5
+ import { FeatureFlagProvider as g, useFeatureFlag as _, useFeatureFlags as v } from "@burdenoff/fe-libs/shared/feature-flags";
6
+ import { Spinner as y } from "@burdenoff/fe-libs/ui";
7
+ import { Fragment as b, jsx as x, jsxs as S } from "react/jsx-runtime";
7
8
  // src/bigconsole/asof/AsOfProvider.tsx
8
- var b = o({
9
+ var C = l({
9
10
  enabled: !1,
10
11
  asOf: null,
11
12
  setAsOf: () => {},
12
- clearAsOf: () => {}
13
- }), x = {
13
+ clearAsOf: () => {},
14
+ compareTo: null,
15
+ setCompareTo: () => {},
16
+ clearCompare: () => {}
17
+ }), w = {
14
18
  ready: !1,
15
19
  enabled: !1
16
- }, S = ({ onChange: t }) => {
17
- let n = m(e, !1) === !0, { isLoading: r } = h(), i = !r;
18
- return l(() => t({
20
+ }, T = ({ onChange: e }) => {
21
+ let t = _(r, !1) === !0, { isLoading: n } = v(), i = !n;
22
+ return f(() => e({
19
23
  ready: i,
20
- enabled: n
24
+ enabled: t
21
25
  }), [
22
26
  i,
23
- n,
24
- t
27
+ t,
28
+ e
25
29
  ]), null;
26
- }, C = ({ workspaceId: e, children: o }) => {
27
- let c = e ?? null, [l, m] = d({
28
- ...x,
29
- workspaceId: c
30
- }), { enabled: h, ready: _ } = n(l, c), C = s((e) => m({
30
+ }, E = ({ workspaceId: r, children: l }) => {
31
+ let d = r ?? null, [f, _] = m({
32
+ ...w,
33
+ workspaceId: d
34
+ }), { enabled: v, ready: b } = a(f, d), E = u((e) => _({
31
35
  ...e,
32
- workspaceId: c
33
- }), [c]), [w, T] = f(), E = w.get(t), D = a(_, E), O = u(() => h ? i(E) : null, [h, E]), k = s((e) => {
34
- T((n) => {
35
- let i = new URLSearchParams(n);
36
- return i.set(t, r(e)), i;
36
+ workspaceId: d
37
+ }), [d]), [D, O] = h(), k = D.get(i), A = c(b, k), j = p(() => v ? s(k) : null, [v, k]), M = D.get(e), N = p(() => n(M, j), [j, M]), P = u((r) => {
38
+ O((a) => {
39
+ let s = new URLSearchParams(a);
40
+ s.set(i, o(r));
41
+ let c = n(a.get(e), r);
42
+ return c ? s.set(e, t(c)) : s.delete(e), s;
37
43
  }, { replace: !0 });
38
- }, [T]), A = s(() => {
39
- T((e) => {
40
- let n = new URLSearchParams(e);
41
- return n.delete(t), n;
44
+ }, [O]), F = u(() => {
45
+ O((t) => {
46
+ let n = new URLSearchParams(t);
47
+ return n.delete(i), n.delete(e), n;
42
48
  }, { replace: !0 });
43
- }, [T]), j = u(() => ({
44
- enabled: h,
45
- asOf: O,
46
- setAsOf: k,
47
- clearAsOf: A
49
+ }, [O]), I = u((n) => {
50
+ O((r) => {
51
+ let i = new URLSearchParams(r);
52
+ return i.set(e, t(n)), i;
53
+ }, { replace: !0 });
54
+ }, [O]), L = u(() => {
55
+ O((t) => {
56
+ let n = new URLSearchParams(t);
57
+ return n.delete(e), n;
58
+ }, { replace: !0 });
59
+ }, [O]), R = p(() => ({
60
+ enabled: v,
61
+ asOf: j,
62
+ setAsOf: P,
63
+ clearAsOf: F,
64
+ compareTo: N,
65
+ setCompareTo: I,
66
+ clearCompare: L
48
67
  }), [
49
- h,
50
- O,
51
- k,
52
- A
68
+ v,
69
+ j,
70
+ P,
71
+ F,
72
+ N,
73
+ I,
74
+ L
53
75
  ]);
54
- return /* @__PURE__ */ y(b.Provider, {
55
- value: j,
56
- children: [/* @__PURE__ */ v(p, {
57
- workspaceId: c,
76
+ return /* @__PURE__ */ S(C.Provider, {
77
+ value: R,
78
+ children: [/* @__PURE__ */ x(g, {
79
+ workspaceId: d,
58
80
  gateway: "global",
59
81
  defaultEnabled: !1,
60
- children: /* @__PURE__ */ v(S, { onChange: C })
61
- }, c ?? "none"), D ? /* @__PURE__ */ v("div", {
82
+ children: /* @__PURE__ */ x(T, { onChange: E })
83
+ }, d ?? "none"), A ? /* @__PURE__ */ x("div", {
62
84
  className: "flex flex-1 items-center justify-center p-8",
63
85
  role: "status",
64
86
  "data-testid": "as-of-pending",
65
- children: /* @__PURE__ */ v(g, {})
66
- }) : o]
87
+ children: /* @__PURE__ */ x(y, {})
88
+ }) : l]
67
89
  });
68
90
  };
69
- function w() {
70
- return c(b);
91
+ function D() {
92
+ return d(C);
71
93
  }
72
- var T = ({ children: e }) => {
73
- let { asOf: t } = w();
74
- return t ? null : /* @__PURE__ */ v(_, { children: e });
94
+ var O = ({ children: e }) => {
95
+ let { asOf: t } = D();
96
+ return t ? null : /* @__PURE__ */ x(b, { children: e });
75
97
  };
76
- export { C as AsOfProvider, T as HideWhenAsOf, w as useAsOf };
98
+ export { E as AsOfProvider, O as HideWhenAsOf, D as useAsOf };
@@ -1,5 +1,5 @@
1
1
  export { AsOfBanner } from './AsOfBanner';
2
- export { AsOfControl } from './AsOfControl';
2
+ export { AsOfControl, formatWhen } from './AsOfControl';
3
3
  export { AsOfProvider, HideWhenAsOf, useAsOf } from './AsOfProvider';
4
4
  export type { AsOfState } from './AsOfProvider';
5
5
  export { AS_OF_FEATURE_FLAG, AS_OF_PARAM, formatAsOf, fromLocalInputValue, parseAsOf, toLocalInputValue, } from './asOfParam';
@@ -1,6 +1,6 @@
1
1
  import { AS_OF_PARAM as e, formatAsOf as t } from "./asOfParam.js";
2
2
  import { AsOfBanner as n } from "./AsOfBanner.js";
3
- import { AsOfControl as r } from "./AsOfControl.js";
4
- import { AsOfProvider as i, HideWhenAsOf as a, useAsOf as o } from "./AsOfProvider.js";
5
- import { asOfUnavailableMessage as s } from "./asOfMessage.js";
6
- export { e as AS_OF_PARAM, n as AsOfBanner, r as AsOfControl, i as AsOfProvider, a as HideWhenAsOf, s as asOfUnavailableMessage, t as formatAsOf, o as useAsOf };
3
+ import { AsOfControl as r, formatWhen as i } from "./AsOfControl.js";
4
+ import { AsOfProvider as a, HideWhenAsOf as o, useAsOf as s } from "./AsOfProvider.js";
5
+ import { asOfUnavailableMessage as c } from "./asOfMessage.js";
6
+ export { e as AS_OF_PARAM, n as AsOfBanner, r as AsOfControl, a as AsOfProvider, o as HideWhenAsOf, c as asOfUnavailableMessage, t as formatAsOf, i as formatWhen, s as useAsOf };
@@ -0,0 +1,104 @@
1
+ import { MetricCardData } from '../components/widgets/metric-card/MetricCardWidget';
2
+ /** What a widget returned at one of the two times. */
3
+ export type CompareSide =
4
+ /** The data source held data at that time. */
5
+ {
6
+ readonly available: true;
7
+ readonly data: unknown;
8
+ }
9
+ /** No data could be read at that time. The compare cannot say what changed. */
10
+ | {
11
+ readonly available: false;
12
+ };
13
+ export interface CompareInput {
14
+ /** The widget's `type`, for example `metric_card`. */
15
+ readonly widgetType: string;
16
+ /** The widget's saved config. */
17
+ readonly config: Record<string, unknown> | null | undefined;
18
+ /** The earlier time. */
19
+ readonly from: CompareSide;
20
+ /** The later time. */
21
+ readonly to: CompareSide;
22
+ }
23
+ /** The difference between two numbers. */
24
+ export interface Change {
25
+ /** `to - from`. Null when either side is not a number. */
26
+ readonly absolute: number | null;
27
+ /** `(to - from) / |from| × 100`. Null when `from` is 0 or either side is not a number. */
28
+ readonly percent: number | null;
29
+ readonly direction: 'up' | 'down' | 'same' | 'unknown';
30
+ }
31
+ export type CompareValue = number | string | null;
32
+ export interface ValuePair {
33
+ readonly from: CompareValue;
34
+ readonly to: CompareValue;
35
+ readonly change: Change;
36
+ }
37
+ export interface MetricCompare {
38
+ readonly kind: 'metric';
39
+ readonly value: ValuePair;
40
+ /** The card's data at each time as the card reads it (unit, currency flag), so the view can format it as the card does. */
41
+ readonly from: MetricCardData | null;
42
+ readonly to: MetricCardData | null;
43
+ }
44
+ export interface ChartComparePoint {
45
+ /** The x-axis label (a category, a date). */
46
+ readonly label: string;
47
+ /** One entry per series, in the order of `series`. */
48
+ readonly values: readonly ValuePair[];
49
+ }
50
+ export interface ChartCompare {
51
+ readonly kind: 'chart';
52
+ /** The numeric fields compared, for example `['revenue', 'orders']`. */
53
+ readonly series: readonly string[];
54
+ readonly points: readonly ChartComparePoint[];
55
+ }
56
+ export type TableRowStatus = 'added' | 'removed' | 'changed' | 'unchanged';
57
+ export interface TableCompareCell {
58
+ readonly column: string;
59
+ readonly from: unknown;
60
+ readonly to: unknown;
61
+ readonly changed: boolean;
62
+ /** The change for a numeric cell that moved. Unknown for text. */
63
+ readonly change: Change;
64
+ }
65
+ export interface TableCompareRow {
66
+ /** The value of the key column that matched this row across the two times. */
67
+ readonly key: string;
68
+ readonly status: TableRowStatus;
69
+ readonly cells: readonly TableCompareCell[];
70
+ }
71
+ export interface TableCompare {
72
+ readonly kind: 'table';
73
+ readonly columns: readonly string[];
74
+ /** The column whose value matches a row at the first time to the same row at the second. */
75
+ readonly keyColumn: string;
76
+ readonly rows: readonly TableCompareRow[];
77
+ readonly summary: Readonly<Record<TableRowStatus, number>>;
78
+ }
79
+ /** Why a widget cannot be compared right now. */
80
+ export type UnavailableReason =
81
+ /** No data at the earlier time. */
82
+ 'no_data_from'
83
+ /** No data at the later time. */
84
+ | 'no_data_to'
85
+ /** The widget returned something the compare cannot read as this widget type. */
86
+ | 'unreadable_data'
87
+ /** Two rows share the same key, so a row cannot be matched to one row at the other time. */
88
+ | 'duplicate_keys'
89
+ /** The table has no column to match rows on. */
90
+ | 'no_key_column';
91
+ export type CompareResult = MetricCompare | ChartCompare | TableCompare | {
92
+ readonly kind: 'unavailable';
93
+ readonly reason: UnavailableReason;
94
+ }
95
+ /** The compare does not cover this kind of widget (yet). */
96
+ | {
97
+ readonly kind: 'unsupported';
98
+ readonly widgetType: string;
99
+ };
100
+ /** The change from one value to another. Only numbers have one. */
101
+ export declare function changeBetween(from: unknown, to: unknown): Change;
102
+ /** Whether the compare covers this widget type at all. A chart of an unsupported kind is only known from its config. */
103
+ export declare function isCompareSupported(widgetType: string): boolean;
104
+ export declare function compareWidget(input: CompareInput): CompareResult;
@@ -0,0 +1,172 @@
1
+ import { numericSeriesKeys as e } from "../components/widgets/chart/charts/numericSeries.js";
2
+ import { classifyChartData as t } from "../components/widgets/chart/chartRows.js";
3
+ import { normalizeMetricData as n } from "../components/widgets/metric-card/metricData.js";
4
+ import { normalizeTableRows as r } from "../components/widgets/table/tableRows.js";
5
+ // src/bigconsole/compare/compareEngine.ts
6
+ var i = {
7
+ absolute: null,
8
+ percent: null,
9
+ direction: "unknown"
10
+ };
11
+ function a(e) {
12
+ if (typeof e == "number") return Number.isFinite(e) ? e : null;
13
+ if (typeof e == "string" && e.trim() !== "") {
14
+ let t = Number(e);
15
+ return Number.isFinite(t) ? t : null;
16
+ }
17
+ return null;
18
+ }
19
+ function o(e, t) {
20
+ let n = a(e), r = a(t);
21
+ if (n === null || r === null) return i;
22
+ let o = r - n;
23
+ return {
24
+ absolute: o,
25
+ percent: n === 0 ? null : o / Math.abs(n) * 100,
26
+ direction: o === 0 ? "same" : o > 0 ? "up" : "down"
27
+ };
28
+ }
29
+ var s = (e) => ({
30
+ kind: "unavailable",
31
+ reason: e
32
+ }), c = (e) => typeof e == "number" ? Number.isFinite(e) ? e : null : typeof e == "string" ? e : null, l = (e, t) => ({
33
+ from: c(e),
34
+ to: c(t),
35
+ change: o(e, t)
36
+ });
37
+ function u(e, t, r) {
38
+ let i = e ?? void 0, a = (e) => n(e, i), o = a(t), c = a(r);
39
+ return o === void 0 && c === void 0 ? s("unreadable_data") : {
40
+ kind: "metric",
41
+ value: l(o?.value, c?.value),
42
+ from: o ?? null,
43
+ to: c ?? null
44
+ };
45
+ }
46
+ var d = /* @__PURE__ */ new Set(["bar", "line"]);
47
+ function f(e) {
48
+ let n = t(e);
49
+ return n.kind === "rows" ? n.rows : n.kind === "empty" ? [] : null;
50
+ }
51
+ var p = (e, t) => {
52
+ let n = e[t];
53
+ return n == null ? "" : String(n);
54
+ };
55
+ function m(e, t) {
56
+ let n = /* @__PURE__ */ new Map();
57
+ for (let r of e) {
58
+ let e = p(r, t);
59
+ if (n.has(e)) return null;
60
+ n.set(e, r);
61
+ }
62
+ return n;
63
+ }
64
+ function h(t, n, r) {
65
+ let i = f(n), a = f(r);
66
+ if (i === null || a === null) return s("unreadable_data");
67
+ let o = String(t?.xAxisField || t?.labelField || "name"), c = Array.isArray(t?.selectedFields) ? t.selectedFields : void 0, u = [.../* @__PURE__ */ new Set([...e(a, o, c), ...e(i, o, c)])], d = m(i, o), p = m(a, o);
68
+ return d === null || p === null ? s("duplicate_keys") : {
69
+ kind: "chart",
70
+ series: u,
71
+ points: [.../* @__PURE__ */ new Set([...p.keys(), ...d.keys()])].map((e) => ({
72
+ label: e,
73
+ values: u.map((t) => l(d.get(e)?.[t], p.get(e)?.[t]))
74
+ }))
75
+ };
76
+ }
77
+ function g(e, t) {
78
+ let n = (Array.isArray(e?.columns) ? e.columns : []).flatMap((e) => {
79
+ if (typeof e == "string") return [e];
80
+ if (e && typeof e == "object") {
81
+ let t = e, n = t.key || t.field;
82
+ return typeof n == "string" && n !== "" ? [n] : [];
83
+ }
84
+ return [];
85
+ });
86
+ if (n.length > 0) return [...new Set(n)];
87
+ let r = t[0];
88
+ return r ? Object.keys(r) : [];
89
+ }
90
+ function _(e, t) {
91
+ if (e === t) return !0;
92
+ if (typeof e != "object" || typeof t != "object" || e === null || t === null) return !1;
93
+ if (Array.isArray(e) || Array.isArray(t)) return Array.isArray(e) && Array.isArray(t) && e.length === t.length && e.every((e, n) => _(e, t[n]));
94
+ let n = e, r = t, i = Object.keys(n);
95
+ return i.length === Object.keys(r).length && i.every((e) => e in r && _(n[e], r[e]));
96
+ }
97
+ var v = (e) => typeof e == "object" && !!e && !Array.isArray(e);
98
+ function y(e, t) {
99
+ return t.length > 0 && t.every((e) => e.id !== void 0 && e.id !== null) ? "id" : e[0] ?? null;
100
+ }
101
+ function b(e, t) {
102
+ let n = /* @__PURE__ */ new Map();
103
+ for (let r of e) {
104
+ let e = r[t], i = e == null ? "" : String(e);
105
+ if (n.has(i)) return null;
106
+ n.set(i, r);
107
+ }
108
+ return n;
109
+ }
110
+ function x(e, t, n) {
111
+ let a = r(t), c = r(n);
112
+ if (!a.every(v) || !c.every(v)) return s("unreadable_data");
113
+ let l = g(e, [...c, ...a]), u = y(l, [...c, ...a]);
114
+ if (u === null) return s("no_key_column");
115
+ let d = b(a, u), f = b(c, u);
116
+ if (d === null || f === null) return s("duplicate_keys");
117
+ let p = [.../* @__PURE__ */ new Set([...f.keys(), ...d.keys()])].map((e) => {
118
+ let t = d.get(e), n = f.get(e), r = l.map((e) => {
119
+ let r = t?.[e], a = n?.[e], s = t !== void 0 && n !== void 0 && !_(r, a);
120
+ return {
121
+ column: e,
122
+ from: r,
123
+ to: a,
124
+ changed: s,
125
+ change: s ? o(r, a) : i
126
+ };
127
+ });
128
+ return {
129
+ key: e,
130
+ status: t === void 0 ? "added" : n === void 0 ? "removed" : r.some((e) => e.changed) ? "changed" : "unchanged",
131
+ cells: r
132
+ };
133
+ }), m = {
134
+ added: 0,
135
+ removed: 0,
136
+ changed: 0,
137
+ unchanged: 0
138
+ };
139
+ for (let e of p) m[e.status] += 1;
140
+ return {
141
+ kind: "table",
142
+ columns: l,
143
+ keyColumn: u,
144
+ rows: p,
145
+ summary: m
146
+ };
147
+ }
148
+ function S(e) {
149
+ return e === "metric_card" || e === "chart" || e === "table";
150
+ }
151
+ function C(e) {
152
+ return typeof e?.chartType == "string" ? e.chartType.toLowerCase() : "line";
153
+ }
154
+ function w(e) {
155
+ if (!S(e.widgetType)) return {
156
+ kind: "unsupported",
157
+ widgetType: e.widgetType
158
+ };
159
+ if (e.widgetType === "chart" && !d.has(C(e.config))) return {
160
+ kind: "unsupported",
161
+ widgetType: `chart:${C(e.config)}`
162
+ };
163
+ let { from: t, to: n } = e;
164
+ if (!t.available) return s("no_data_from");
165
+ if (!n.available) return s("no_data_to");
166
+ switch (e.widgetType) {
167
+ case "metric_card": return u(e.config, t.data, n.data);
168
+ case "chart": return h(e.config, t.data, n.data);
169
+ default: return x(e.config, t.data, n.data);
170
+ }
171
+ }
172
+ export { o as changeBetween, w as compareWidget, S as isCompareSupported };