@nivaro/react 0.3.45 → 0.3.46

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 (40) hide show
  1. package/dist/full.css +1 -1
  2. package/dist/hooks/useSessionRecorder.js +1 -1
  3. package/dist/index.d.ts +42 -7
  4. package/dist/shared/components/BaseMap.js +149 -103
  5. package/dist/shared/components/command-center/CommandCenterView.js +313 -69
  6. package/dist/shared/components/command-center/Customize.js +353 -0
  7. package/dist/shared/components/command-center/Header.js +279 -53
  8. package/dist/shared/components/command-center/KioskLinks.js +198 -0
  9. package/dist/shared/components/command-center/PeekPanel.js +143 -3
  10. package/dist/shared/components/command-center/announce.js +13 -0
  11. package/dist/shared/components/command-center/board-prefs.js +99 -0
  12. package/dist/shared/components/command-center/freshness.js +29 -0
  13. package/dist/shared/components/command-center/layout.js +56 -0
  14. package/dist/shared/components/command-center/panels/AttentionPanel.js +132 -3
  15. package/dist/shared/components/command-center/panels/Banner.js +75 -0
  16. package/dist/shared/components/command-center/panels/BoardSettings.js +223 -0
  17. package/dist/shared/components/command-center/panels/FeedPanel.js +145 -29
  18. package/dist/shared/components/command-center/panels/FlowPanel.js +154 -56
  19. package/dist/shared/components/command-center/panels/ForecastPanel.js +244 -3
  20. package/dist/shared/components/command-center/panels/MapLegend.js +266 -0
  21. package/dist/shared/components/command-center/panels/MapPanel.js +216 -66
  22. package/dist/shared/components/command-center/panels/PartnersPanel.js +49 -3
  23. package/dist/shared/components/command-center/panels/PeoplePanel.js +257 -40
  24. package/dist/shared/components/command-center/panels/RegionPicker.js +88 -3
  25. package/dist/shared/components/command-center/panels/SystemPanel.js +158 -38
  26. package/dist/shared/components/command-center/panels/ThroughputPanel.js +307 -3
  27. package/dist/shared/components/command-center/panels/TimeBar.js +227 -6
  28. package/dist/shared/components/command-center/panels/TrafficPanel.js +12 -8
  29. package/dist/shared/components/command-center/panels/WorkloadPanel.js +82 -3
  30. package/dist/shared/components/command-center/panels/attention-actions.js +267 -0
  31. package/dist/shared/components/command-center/panels/map-shared.js +95 -0
  32. package/dist/shared/components/command-center/panels/registry.js +87 -19
  33. package/dist/shared/components/command-center/shell-hooks.js +118 -0
  34. package/dist/shared/components/command-center/shortcuts.js +37 -0
  35. package/dist/shared/components/command-center/theme.js +39 -21
  36. package/dist/shared/components/command-center/time.js +52 -0
  37. package/dist/shared/components/command-center/url-state.js +54 -0
  38. package/dist/shared/components/command-center/work-links.js +32 -0
  39. package/dist/shared/components/monitoring/TrafficMiniMap.js +111 -70
  40. package/package.json +1 -1
@@ -1,8 +1,8 @@
1
- import { jsxs as n, jsx as a } from "react/jsx-runtime";
2
- import { useQuery as b } from "@tanstack/react-query";
3
- import { useNivaroClient as g, useNavigation as k } from "../../context.js";
4
- import { get as q } from "../../lib/commands.js";
5
- const N = {
1
+ import { jsxs as l, jsx as n } from "react/jsx-runtime";
2
+ import { useQuery as M } from "@tanstack/react-query";
3
+ import { useNivaroClient as _, useNavigation as L } from "../../context.js";
4
+ import { get as A } from "../../lib/commands.js";
5
+ const C = {
6
6
  items: "Collections",
7
7
  widgets: "Widgets",
8
8
  pages: "Pages",
@@ -14,44 +14,44 @@ const N = {
14
14
  system: "System",
15
15
  other: "Other"
16
16
  };
17
- function v(e, d = 4, p = 3) {
18
- const c = /* @__PURE__ */ new Map();
17
+ function F(e, o = 4, s = 3) {
18
+ const m = /* @__PURE__ */ new Map();
19
19
  for (const t of e.entities) {
20
- let r = c.get(t.lane);
21
- r || (r = { req: 0, series: new Array(t.series.length).fill(0) }, c.set(t.lane, r)), r.req += t.req, t.series.forEach((i, m) => {
22
- r.series[m] = (r.series[m] ?? 0) + i;
20
+ let i = m.get(t.lane);
21
+ i || (i = { req: 0, series: new Array(t.series.length).fill(0) }, m.set(t.lane, i)), i.req += t.req, t.series.forEach((p, a) => {
22
+ i.series[a] = (i.series[a] ?? 0) + p;
23
23
  });
24
24
  }
25
- const l = e.totals.req;
25
+ const d = e.totals.req;
26
26
  return {
27
- rpm: e.window_s ? l * 60 / e.window_s : 0,
28
- req: l,
27
+ rpm: e.window_s ? d * 60 / e.window_s : 0,
28
+ req: d,
29
29
  errors: e.totals.error,
30
- errPct: l ? 100 * e.totals.error / l : 0,
30
+ errPct: d ? 100 * e.totals.error / d : 0,
31
31
  p95: e.totals.p95,
32
- lanes: [...c].filter(([, t]) => t.req > 0).sort((t, r) => r[1].req - t[1].req).slice(0, d).map(([t, r]) => ({
32
+ lanes: [...m].filter(([, t]) => t.req > 0).sort((t, i) => i[1].req - t[1].req).slice(0, o).map(([t, i]) => ({
33
33
  lane: t,
34
- label: N[t] ?? t,
35
- req: r.req,
36
- series: r.series
34
+ label: C[t] ?? t,
35
+ req: i.req,
36
+ series: i.series
37
37
  })),
38
- top: e.entities.filter((t) => t.req > 0 && !t.key.endsWith("/__other__")).sort((t, r) => r.req - t.req).slice(0, p).map((t) => ({ key: t.key, label: t.label, req: t.req }))
38
+ top: e.entities.filter((t) => t.req > 0 && !t.key.endsWith("/__other__")).sort((t, i) => i.req - t.req).slice(0, s).map((t) => ({ key: t.key, label: t.label, req: t.req }))
39
39
  };
40
40
  }
41
- function w({ data: e, className: d }) {
42
- const l = Math.max(1, ...e), t = e.map(
43
- (r, i) => `${(i / Math.max(1, e.length - 1) * 96).toFixed(1)},${(20 - r / l * 18 - 1).toFixed(1)}`
41
+ function k({ data: e, className: o }) {
42
+ const d = Math.max(1, ...e), t = e.map(
43
+ (i, p) => `${(p / Math.max(1, e.length - 1) * 96).toFixed(1)},${(20 - i / d * 18 - 1).toFixed(1)}`
44
44
  ).join(" ");
45
- return /* @__PURE__ */ a(
45
+ return /* @__PURE__ */ n(
46
46
  "svg",
47
47
  {
48
48
  viewBox: "0 0 96 20",
49
49
  width: 96,
50
50
  height: 20,
51
- className: d,
51
+ className: o,
52
52
  "aria-hidden": "true",
53
53
  preserveAspectRatio: "none",
54
- children: /* @__PURE__ */ a(
54
+ children: /* @__PURE__ */ n(
55
55
  "polyline",
56
56
  {
57
57
  points: t,
@@ -64,7 +64,16 @@ function w({ data: e, className: d }) {
64
64
  }
65
65
  );
66
66
  }
67
- const h = (e) => Math.round(e).toLocaleString(), $ = (e) => e < 10 ? e.toFixed(1) : h(e), y = (e) => e ? e >= 1e3 ? `${(e / 1e3).toFixed(1)} s` : `${Math.round(e)} ms` : "—", _ = {
67
+ function N(e, o, s, m) {
68
+ const d = s * 1e3 / Math.max(1, o), t = m - s * 1e3 + (e + 0.5) * d;
69
+ return Math.floor(t / 6e4) * 6e4;
70
+ }
71
+ function q(e) {
72
+ let o = 0;
73
+ for (let s = 0; s < e.length; s++) e[s] >= e[o] && (o = s);
74
+ return o;
75
+ }
76
+ const f = (e) => Math.round(e).toLocaleString(), T = (e) => e < 10 ? e.toFixed(1) : f(e), j = (e) => e ? e >= 1e3 ? `${(e / 1e3).toFixed(1)} s` : `${Math.round(e)} ms` : "—", S = {
68
77
  // always dark (Command Center)
69
78
  dark: {
70
79
  card: "rounded-lg border border-white/10 bg-[#101828] text-[#e2e8f0]",
@@ -84,83 +93,115 @@ const h = (e) => Math.round(e).toLocaleString(), $ = (e) => e < 10 ? e.toFixed(1
84
93
  link: "text-[#0e7490] hover:underline dark:text-[#67e8f9] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#0891b2]"
85
94
  }
86
95
  };
87
- function A({
96
+ function P({
88
97
  window: e = 300,
89
- tone: d = "auto",
90
- href: p,
91
- refreshMs: c = 15e3,
92
- className: l
98
+ tone: o = "auto",
99
+ href: s,
100
+ refreshMs: m = 15e3,
101
+ className: d,
102
+ onPickTime: t
93
103
  }) {
94
- const t = g(), { navigate: r } = k(), i = _[d], m = b({
104
+ const i = _(), { navigate: p } = L(), a = S[o], h = M({
95
105
  queryKey: ["traffic-mini-map", e],
96
- queryFn: () => t.request(q("/traffic-map/snapshot", { window: e })).then((s) => s.data).catch(() => null),
106
+ queryFn: () => i.request(A("/traffic-map/snapshot", { window: e })).then((r) => r.data).catch(() => null),
97
107
  // not an administrator, or no map here: render nothing
98
- refetchInterval: c,
99
- staleTime: c / 2
108
+ refetchInterval: m,
109
+ staleTime: m / 2
100
110
  });
101
- if (!m.data) return null;
102
- const o = v(m.data), f = p ?? "/traffic-map", u = /^https?:\/\//.test(f), x = e === 60 ? "last minute" : `last ${e / 60} min`;
103
- return /* @__PURE__ */ n(
111
+ if (!h.data) return null;
112
+ const c = F(h.data), w = h.data.window_s, u = s ?? "/traffic-map", x = /^https?:\/\//.test(u), $ = e === 60 ? "last minute" : `last ${e / 60} min`;
113
+ return /* @__PURE__ */ l(
104
114
  "section",
105
115
  {
106
- className: `${i.card} ${l ?? ""}`,
116
+ className: `${a.card} ${d ?? ""}`,
107
117
  "aria-label": "Traffic",
108
118
  "data-traffic-mini-map": "",
109
119
  children: [
110
- /* @__PURE__ */ n("div", { className: `flex items-center justify-between gap-2 px-3 py-2 ${i.head}`, children: [
111
- /* @__PURE__ */ n("h3", { className: "text-[12.5px] font-semibold", children: [
120
+ /* @__PURE__ */ l("div", { className: `flex items-center justify-between gap-2 px-3 py-2 ${a.head}`, children: [
121
+ /* @__PURE__ */ l("h3", { className: "text-[12.5px] font-semibold", children: [
112
122
  "Traffic ",
113
- /* @__PURE__ */ n("span", { className: `font-normal ${i.muted}`, children: [
123
+ /* @__PURE__ */ l("span", { className: `font-normal ${a.muted}`, children: [
114
124
  "· ",
115
- x
125
+ $
116
126
  ] })
117
127
  ] }),
118
- f ? /* @__PURE__ */ a(
128
+ u ? /* @__PURE__ */ n(
119
129
  "a",
120
130
  {
121
- href: f,
122
- target: u ? "_blank" : void 0,
123
- rel: u ? "noreferrer" : void 0,
124
- className: `rounded text-[12px] font-medium ${i.link}`,
125
- onClick: (s) => {
126
- u || s.metaKey || s.ctrlKey || (s.preventDefault(), r(f));
131
+ href: u,
132
+ target: x ? "_blank" : void 0,
133
+ rel: x ? "noreferrer" : void 0,
134
+ className: `rounded text-[12px] font-medium ${a.link}`,
135
+ onClick: (r) => {
136
+ x || r.metaKey || r.ctrlKey || (r.preventDefault(), p(u));
127
137
  },
128
138
  "data-traffic-mini-open": "",
129
139
  children: "Open map"
130
140
  }
131
141
  ) : null
132
142
  ] }),
133
- /* @__PURE__ */ n("div", { className: "grid grid-cols-3 gap-2 px-3 pt-2.5 text-[12px] tabular-nums", children: [
134
- /* @__PURE__ */ n("div", { children: [
135
- /* @__PURE__ */ a("p", { className: "text-[18px] font-semibold leading-tight", "data-traffic-mini-rpm": "", children: $(o.rpm) }),
136
- /* @__PURE__ */ a("p", { className: i.muted, children: "requests/min" })
143
+ /* @__PURE__ */ l("div", { className: "grid grid-cols-3 gap-2 px-3 pt-2.5 text-[12px] tabular-nums", children: [
144
+ /* @__PURE__ */ l("div", { children: [
145
+ /* @__PURE__ */ n("p", { className: "text-[18px] font-semibold leading-tight", "data-traffic-mini-rpm": "", children: T(c.rpm) }),
146
+ /* @__PURE__ */ n("p", { className: a.muted, children: "requests/min" })
137
147
  ] }),
138
- /* @__PURE__ */ n("div", { children: [
139
- /* @__PURE__ */ a("p", { className: `text-[18px] font-semibold leading-tight ${o.errors ? i.error : ""}`, children: h(o.errors) }),
140
- /* @__PURE__ */ n("p", { className: i.muted, children: [
148
+ /* @__PURE__ */ l("div", { children: [
149
+ /* @__PURE__ */ n("p", { className: `text-[18px] font-semibold leading-tight ${c.errors ? a.error : ""}`, children: f(c.errors) }),
150
+ /* @__PURE__ */ l("p", { className: a.muted, children: [
141
151
  "errors",
142
- o.req ? ` · ${o.errPct.toFixed(1)}%` : ""
152
+ c.req ? ` · ${c.errPct.toFixed(1)}%` : ""
143
153
  ] })
144
154
  ] }),
145
- /* @__PURE__ */ n("div", { children: [
146
- /* @__PURE__ */ a("p", { className: "text-[18px] font-semibold leading-tight", children: y(o.p95) }),
147
- /* @__PURE__ */ a("p", { className: i.muted, children: "p95" })
155
+ /* @__PURE__ */ l("div", { children: [
156
+ /* @__PURE__ */ n("p", { className: "text-[18px] font-semibold leading-tight", children: j(c.p95) }),
157
+ /* @__PURE__ */ n("p", { className: a.muted, children: "p95" })
148
158
  ] })
149
159
  ] }),
150
- o.lanes.length === 0 ? /* @__PURE__ */ a("p", { className: `px-3 py-2.5 text-[12px] ${i.muted}`, children: "No API traffic in the window." }) : /* @__PURE__ */ a("ul", { className: "space-y-1 px-3 pb-1 pt-2.5 text-[12px]", children: o.lanes.map((s) => /* @__PURE__ */ n("li", { className: "flex items-center gap-2", "data-traffic-mini-lane": s.lane, children: [
151
- /* @__PURE__ */ a("span", { className: "w-[84px] shrink-0 truncate", children: s.label }),
152
- /* @__PURE__ */ a(w, { data: s.series, className: `min-w-0 flex-1 ${i.spark}` }),
153
- /* @__PURE__ */ a("span", { className: `w-[52px] shrink-0 text-right tabular-nums ${i.muted}`, children: h(s.req) })
154
- ] }, s.lane)) }),
155
- o.top.length > 0 && /* @__PURE__ */ n("p", { className: `truncate px-3 pb-2.5 pt-1 text-[11.5px] ${i.muted}`, children: [
160
+ c.lanes.length === 0 ? /* @__PURE__ */ n("p", { className: `px-3 py-2.5 text-[12px] ${a.muted}`, children: "No API traffic in the window." }) : /* @__PURE__ */ n("ul", { className: "space-y-1 px-3 pb-1 pt-2.5 text-[12px]", children: c.lanes.map((r) => /* @__PURE__ */ l("li", { className: "flex items-center gap-2", "data-traffic-mini-lane": r.lane, children: [
161
+ /* @__PURE__ */ n("span", { className: "w-[84px] shrink-0 truncate", children: r.label }),
162
+ t ? /* @__PURE__ */ n(
163
+ "button",
164
+ {
165
+ type: "button",
166
+ className: `min-w-0 flex-1 rounded ${a.link}`,
167
+ "aria-label": `Rewind to the busiest minute for ${r.label} (${new Date(
168
+ N(
169
+ q(r.series),
170
+ r.series.length,
171
+ w,
172
+ h.dataUpdatedAt || Date.now()
173
+ )
174
+ ).toLocaleTimeString([], { hour: "numeric", minute: "2-digit" })})`,
175
+ "data-tip": "Click a point to rewind the board to that minute",
176
+ "data-traffic-mini-pick": r.lane,
177
+ onClick: (b) => {
178
+ const v = h.dataUpdatedAt || Date.now(), g = b.currentTarget.getBoundingClientRect(), y = b.detail === 0 || g.width === 0 ? q(r.series) : Math.max(
179
+ 0,
180
+ Math.min(
181
+ r.series.length - 1,
182
+ Math.round(
183
+ (b.clientX - g.left) / g.width * (r.series.length - 1)
184
+ )
185
+ )
186
+ );
187
+ t(N(y, r.series.length, w, v));
188
+ },
189
+ children: /* @__PURE__ */ n(k, { data: r.series, className: `w-full ${a.spark}` })
190
+ }
191
+ ) : /* @__PURE__ */ n(k, { data: r.series, className: `min-w-0 flex-1 ${a.spark}` }),
192
+ /* @__PURE__ */ n("span", { className: `w-[52px] shrink-0 text-right tabular-nums ${a.muted}`, children: f(r.req) })
193
+ ] }, r.lane)) }),
194
+ c.top.length > 0 && /* @__PURE__ */ l("p", { className: `truncate px-3 pb-2.5 pt-1 text-[11.5px] ${a.muted}`, children: [
156
195
  "Busiest: ",
157
- o.top.map((s) => `${s.label} (${h(s.req)})`).join(", ")
196
+ c.top.map((r) => `${r.label} (${f(r.req)})`).join(", ")
158
197
  ] })
159
198
  ]
160
199
  }
161
200
  );
162
201
  }
163
202
  export {
164
- A as TrafficMiniMap,
165
- v as miniMapSummary
203
+ P as TrafficMiniMap,
204
+ F as miniMapSummary,
205
+ N as sparkPointTime,
206
+ q as spikeIndex
166
207
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivaro/react",
3
- "version": "0.3.45",
3
+ "version": "0.3.46",
4
4
  "description": "React hooks and components for Nivaro CMS forms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",