@altertable/data-app-react 0.78.0 → 0.79.0
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/chunks/{SectionHeading-BKvi7HVv.js → SectionHeading-BAZB-Fnf.js} +131 -643
- package/dist/chunks/SectionHeading-BAZB-Fnf.js.map +1 -0
- package/dist/index.js +483 -4
- package/dist/index.js.map +1 -1
- package/dist/types/chunks/DateTimeRangePicker.d.ts +2 -143
- package/dist/types/index.d.ts +187 -13
- package/dist/types/ui/index.d.ts +3 -15
- package/dist/ui/index.js +599 -426
- package/dist/ui/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/chunks/SectionHeading-BKvi7HVv.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import { $t as
|
|
1
|
+
import { $t as DateFormattingContext, At as SegmentedTab, B as useDeclaredResult, Bt as Tooltip, C as Stack, Ct as useDetailNavigation, Et as ownedSource, Ft as TabPanels, Gt as shortcuts, I as createDataHooks, It as Tabs, Jt as AppIcon, Kt as InspectionContext, L as AppViewResultsContext, M as IconButton, N as useDataAppAnnotations, Ot as mountDataApp, P as AnnotationTooltip, Pt as TabPanel, Q as dateTimeRangeLabel, Qt as classNames, R as assertAppFilters, Rt as Sheet, S as TextContent, St as DetailView, Vt as TooltipProvider, Wt as Kbd, X as DateTimeRangePicker, Xt as Button, Yt as EmptyState, Z as Select, _ as ContentSkeleton, a as DataTable, b as Notice, bt as DetailContent, ct as searchItems, dt as RegisteredBinding, en as useDateFormatting, et as Skeleton, ft as datasetTable, g as withWidgetBoundary, gt as DateTimeTooltip, h as DataWidget, ht as DateDisplay, i as chartColor, jt as SegmentedTabList, l as ExplorationActionControl, lt as sectionContent, mt as registeredEvidence, n as createDataContext, nn as injectDataAppStyles, o as DataTableEmptyRow, ot as SearchSuggestionsContext, pt as exportDatasets, qt as useInspectionDefaults, rn as injectStyles, t as SectionHeading, tn as useDataApp, ut as MetricRecords, v as ContentSkeletonBody, vt as resolveActions, wt as DataSectionBoundary, x as DataAppFrame, xt as DetailRoutes, y as getAnnotationProps, yt as breakdownState, z as getViewDefinition } from "./chunks/SectionHeading-BAZB-Fnf.js";
|
|
2
2
|
import { getDataAppTransport, navigateNewTab, navigateNewWindowOrTab } from "@altertable/data-app/client";
|
|
3
3
|
import { KEY_SEPARATOR, fixedUnitMilliseconds, invariant } from "@altertable/data-app/internal";
|
|
4
4
|
import { useCallback, useContext, useEffect, useEffectEvent, useImperativeHandle, useReducer, useRef, useState } from "react";
|
|
5
5
|
import { autoUpdate, flip, offset, shift, useFloating, useMergeRefs } from "@floating-ui/react";
|
|
6
6
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
7
7
|
import { Eye, EyeOff, GripVertical, LoaderCircle, Minus, Trash2, X } from "lucide-react";
|
|
8
|
-
import { formatCount, formatDateRange, formatDateTime, formatMetric, formatPercent, parseDateTime } from "@altertable/data-app/format";
|
|
8
|
+
import { formatCount, formatDateRange, formatDateTime, formatMetric, formatPercent, parseDateTime, pluralize } from "@altertable/data-app/format";
|
|
9
9
|
import { parseDataAppAnnotationDraft, parseExternalUrl } from "@altertable/data-app/contract";
|
|
10
10
|
import { createPortal } from "react-dom";
|
|
11
11
|
//#region src/ui/DataApp.tsx
|
|
12
|
-
/** Executes the primary view and its summary views, and owns controls, inspection, exports, and stories. */
|
|
13
12
|
function DataApp(props) {
|
|
13
|
+
if (!props.view) return /* @__PURE__ */ jsx(DataAppFrame, { ...props });
|
|
14
|
+
return /* @__PURE__ */ jsx(ViewDataApp, { ...props });
|
|
15
|
+
}
|
|
16
|
+
function ViewDataApp(props) {
|
|
14
17
|
const { summaryViews = [], ...appProps } = props;
|
|
15
18
|
const { clientFilters } = getViewDefinition(props.view);
|
|
16
19
|
return /* @__PURE__ */ jsx(AppFilterControls, {
|
|
@@ -85,6 +88,7 @@ function PrimaryDataApp(props) {
|
|
|
85
88
|
...controls,
|
|
86
89
|
queries: allResults.flatMap(({ queries }) => queries ?? []),
|
|
87
90
|
refreshing: allResults.some(({ refreshing }) => refreshing),
|
|
91
|
+
viewRefreshing: primary.refreshing,
|
|
88
92
|
refetch() {
|
|
89
93
|
for (const { refetch } of allResults) refetch();
|
|
90
94
|
},
|
|
@@ -123,7 +127,10 @@ function PrimaryDataApp(props) {
|
|
|
123
127
|
value: {
|
|
124
128
|
primaryView: view,
|
|
125
129
|
clientFilters,
|
|
126
|
-
results: new Map(results).set(view,
|
|
130
|
+
results: new Map(results).set(view, {
|
|
131
|
+
...result,
|
|
132
|
+
refreshing: primary.refreshing
|
|
133
|
+
})
|
|
127
134
|
},
|
|
128
135
|
children: /* @__PURE__ */ jsx(DetailRoutes, {
|
|
129
136
|
details,
|
|
@@ -168,6 +175,478 @@ function GridItem({ children, span = 1, className, ...props }) {
|
|
|
168
175
|
});
|
|
169
176
|
}
|
|
170
177
|
//#endregion
|
|
178
|
+
//#region src/ui/DataValue.tsx
|
|
179
|
+
/** Bind inline content to displayed data. Keep static wording outside this span. */
|
|
180
|
+
function DataValue$1({ reading, loadingFallback, children, ...props }) {
|
|
181
|
+
return /* @__PURE__ */ jsx("span", {
|
|
182
|
+
...props,
|
|
183
|
+
"aria-busy": reading.loading || props["aria-busy"],
|
|
184
|
+
children: reading.loading ? loadingFallback : children(reading.value)
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/ui/metric-comparison.ts
|
|
189
|
+
/** Label a comparison from the input that produced the displayed result. Null means the
|
|
190
|
+
* requested previous period has no comparable value; zero remains a measured value. */
|
|
191
|
+
function dateTimeMetricComparison(displayedInput, values, options = {}) {
|
|
192
|
+
if (!displayedInput.comparison) return void 0;
|
|
193
|
+
function label(range) {
|
|
194
|
+
return dateTimeRangeLabel(range, options);
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
current: {
|
|
198
|
+
value: values.current,
|
|
199
|
+
formattedValue: formatMetric(values.current, values.format),
|
|
200
|
+
periodLabel: label(displayedInput.range)
|
|
201
|
+
},
|
|
202
|
+
previous: {
|
|
203
|
+
value: values.previous,
|
|
204
|
+
formattedValue: values.previous === null ? "Not available" : formatMetric(values.previous, values.format),
|
|
205
|
+
periodLabel: label(displayedInput.comparison)
|
|
206
|
+
},
|
|
207
|
+
favorableDirection: values.favorableDirection
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/** A zero or missing baseline has no meaningful relative percentage. */
|
|
211
|
+
function comparisonChange({ current, previous, favorableDirection }) {
|
|
212
|
+
const percent = previous?.value ? (current.value - previous.value) / Math.abs(previous.value) * 100 : null;
|
|
213
|
+
const direction = percent === null || Math.abs(percent) < .05 ? "flat" : percent > 0 ? "up" : "down";
|
|
214
|
+
return {
|
|
215
|
+
percent,
|
|
216
|
+
direction,
|
|
217
|
+
tone: direction === "flat" || !favorableDirection ? "neutral" : direction === favorableDirection ? "good" : "bad",
|
|
218
|
+
icon: direction === "up" ? "trendUp" : direction === "down" ? "trendDown" : "trendFlat"
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src/ui/metric.ts
|
|
223
|
+
function metricComparison(metric, reading, options = {}) {
|
|
224
|
+
if (reading.loading || !reading.value.period) return void 0;
|
|
225
|
+
return dateTimeMetricComparison(reading.value.period, {
|
|
226
|
+
current: reading.value.current,
|
|
227
|
+
previous: reading.value.previous ?? null,
|
|
228
|
+
format: metric.format,
|
|
229
|
+
favorableDirection: metric.favorableDirection
|
|
230
|
+
}, options);
|
|
231
|
+
}
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region src/ui/widget-views.ts
|
|
234
|
+
function validateWidgetViews(views, selected) {
|
|
235
|
+
const ids = new Set(views.map((view) => view.id));
|
|
236
|
+
invariant(views.length > 0 && ids.size === views.length && views.every((view) => !!view.id.trim()), "Widget tab IDs must be nonempty and unique.");
|
|
237
|
+
invariant(ids.has(selected), `Unknown widget tab: ${selected}.`);
|
|
238
|
+
}
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/ui/WidgetViewTabs.tsx
|
|
241
|
+
function WidgetViewTabs({ label, views, selectedKey, onSelectionChange, className, ...props }) {
|
|
242
|
+
validateWidgetViews(views, selectedKey);
|
|
243
|
+
return /* @__PURE__ */ jsx("div", {
|
|
244
|
+
...props,
|
|
245
|
+
className: classNames("altertable-widget-view-tabs", className),
|
|
246
|
+
children: /* @__PURE__ */ jsxs(Tabs, {
|
|
247
|
+
selectedKey,
|
|
248
|
+
onSelectionChange: (key) => onSelectionChange(String(key)),
|
|
249
|
+
children: [/* @__PURE__ */ jsx(SegmentedTabList, {
|
|
250
|
+
"aria-label": label,
|
|
251
|
+
children: views.map((view) => /* @__PURE__ */ jsx(SegmentedTab, {
|
|
252
|
+
id: view.id,
|
|
253
|
+
children: view.label
|
|
254
|
+
}, view.id))
|
|
255
|
+
}), /* @__PURE__ */ jsx(TabPanels, { children: views.map((view) => /* @__PURE__ */ jsx(TabPanel, {
|
|
256
|
+
id: view.id,
|
|
257
|
+
children: view.isEmpty ? /* @__PURE__ */ jsx(EmptyState, { ...view.emptyFallback }) : view.content
|
|
258
|
+
}, view.id)) })]
|
|
259
|
+
})
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
//#endregion
|
|
263
|
+
//#region src/ui/VisualizationWidget.tsx
|
|
264
|
+
/** Compose an unframed visual with the shared heading and inspection. */
|
|
265
|
+
function VisualizationWidget$1(props) {
|
|
266
|
+
if ("views" in props && props.views) return /* @__PURE__ */ jsx(VisualizationWidgetWithViews, { ...props });
|
|
267
|
+
if ("reading" in props) {
|
|
268
|
+
const { reading, children, isEmpty, emptyFallback, skeleton, footer, ...shell } = props;
|
|
269
|
+
return /* @__PURE__ */ jsx(DataWidget, {
|
|
270
|
+
...shell,
|
|
271
|
+
reading,
|
|
272
|
+
isEmpty,
|
|
273
|
+
emptyFallback,
|
|
274
|
+
skeleton,
|
|
275
|
+
footer,
|
|
276
|
+
children: (data) => /* @__PURE__ */ jsx("div", {
|
|
277
|
+
className: "altertable-visualization-widget-content",
|
|
278
|
+
children: children(data)
|
|
279
|
+
})
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
const { visual, loading = false, loadingContent, footer, ...shell } = props;
|
|
283
|
+
if (loading) return /* @__PURE__ */ jsx(DataWidget, {
|
|
284
|
+
...shell,
|
|
285
|
+
footer,
|
|
286
|
+
"aria-busy": true,
|
|
287
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
288
|
+
className: "altertable-visualization-widget-content",
|
|
289
|
+
children: loadingContent ?? /* @__PURE__ */ jsx(ContentSkeletonBody, { variant: "panel" })
|
|
290
|
+
})
|
|
291
|
+
});
|
|
292
|
+
return /* @__PURE__ */ jsx(DataWidget, {
|
|
293
|
+
...shell,
|
|
294
|
+
footer,
|
|
295
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
296
|
+
className: "altertable-visualization-widget-content",
|
|
297
|
+
children: visual
|
|
298
|
+
})
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
function VisualizationWidgetWithViews({ reading, views, viewLabel, initialView, isEmpty, emptyFallback, skeleton, footer, ...shell }) {
|
|
302
|
+
const [selected, setSelected] = useState(initialView ?? views[0]?.id ?? "");
|
|
303
|
+
validateWidgetViews(views, selected);
|
|
304
|
+
return /* @__PURE__ */ jsx(DataWidget, {
|
|
305
|
+
...shell,
|
|
306
|
+
reading,
|
|
307
|
+
isEmpty,
|
|
308
|
+
emptyFallback,
|
|
309
|
+
skeleton,
|
|
310
|
+
footer,
|
|
311
|
+
children: (data) => /* @__PURE__ */ jsx("div", {
|
|
312
|
+
className: "altertable-visualization-widget-content",
|
|
313
|
+
children: /* @__PURE__ */ jsx(WidgetViewTabs, {
|
|
314
|
+
label: viewLabel,
|
|
315
|
+
views: views.map((view) => ({
|
|
316
|
+
id: view.id,
|
|
317
|
+
label: view.label,
|
|
318
|
+
content: view.render(data),
|
|
319
|
+
isEmpty: false,
|
|
320
|
+
emptyFallback
|
|
321
|
+
})),
|
|
322
|
+
selectedKey: selected,
|
|
323
|
+
onSelectionChange: setSelected
|
|
324
|
+
})
|
|
325
|
+
})
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
//#endregion
|
|
329
|
+
//#region src/ui/MetricWidget.tsx
|
|
330
|
+
function MetricWidget$1(props) {
|
|
331
|
+
const dateFormatting = useDateFormatting();
|
|
332
|
+
if ("metric" in props) {
|
|
333
|
+
const { metric, reading, ...rest } = props;
|
|
334
|
+
if (reading.loading) return /* @__PURE__ */ jsx(MetricWidgetContent$1, {
|
|
335
|
+
...rest,
|
|
336
|
+
label: metric.label,
|
|
337
|
+
evidence: metric.evidence,
|
|
338
|
+
loading: true
|
|
339
|
+
});
|
|
340
|
+
return /* @__PURE__ */ jsx(MetricWidgetContent$1, {
|
|
341
|
+
...rest,
|
|
342
|
+
label: metric.label,
|
|
343
|
+
value: reading.value.current,
|
|
344
|
+
format: metric.format,
|
|
345
|
+
evidence: metric.evidence,
|
|
346
|
+
comparison: metricComparison(metric, reading, dateFormatting)
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
return /* @__PURE__ */ jsx(MetricWidgetContent$1, { ...props });
|
|
350
|
+
}
|
|
351
|
+
function MetricWidgetContent$1({ label, annotationId, value, content, format, loading = false, description, comparison, evidence, records, action, status, visual, className, ...props }) {
|
|
352
|
+
return /* @__PURE__ */ jsx(VisualizationWidget$1, {
|
|
353
|
+
...props,
|
|
354
|
+
className: classNames("altertable-metric-widget", className),
|
|
355
|
+
title: label,
|
|
356
|
+
annotationId,
|
|
357
|
+
evidence,
|
|
358
|
+
records,
|
|
359
|
+
"aria-busy": loading || props["aria-busy"],
|
|
360
|
+
action,
|
|
361
|
+
status,
|
|
362
|
+
visual: /* @__PURE__ */ jsx(MetricVisual, {
|
|
363
|
+
loading,
|
|
364
|
+
value,
|
|
365
|
+
content,
|
|
366
|
+
format,
|
|
367
|
+
comparison,
|
|
368
|
+
description,
|
|
369
|
+
visual
|
|
370
|
+
})
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
function MetricVisual({ loading, value, content, format, comparison, description, visual }) {
|
|
374
|
+
const shownValue = format ? formatMetric(value, format) : content;
|
|
375
|
+
const change = comparison ? comparisonChange(comparison) : null;
|
|
376
|
+
const shownTrend = change?.percent != null ? /* @__PURE__ */ jsxs("span", {
|
|
377
|
+
className: "altertable-metric-change",
|
|
378
|
+
"data-tone": change.tone,
|
|
379
|
+
children: [
|
|
380
|
+
/* @__PURE__ */ jsx(AppIcon, {
|
|
381
|
+
name: change.icon,
|
|
382
|
+
size: 14
|
|
383
|
+
}),
|
|
384
|
+
Math.abs(change.percent).toFixed(1),
|
|
385
|
+
"% vs",
|
|
386
|
+
" ",
|
|
387
|
+
comparison?.previous?.periodLabel?.toLowerCase() ?? "previous period"
|
|
388
|
+
]
|
|
389
|
+
}) : comparison?.previous?.value === null ? /* @__PURE__ */ jsx("span", {
|
|
390
|
+
className: "altertable-metric-change",
|
|
391
|
+
"data-tone": "neutral",
|
|
392
|
+
children: "Previous period unavailable"
|
|
393
|
+
}) : null;
|
|
394
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
395
|
+
/* @__PURE__ */ jsxs("div", {
|
|
396
|
+
className: "altertable-metric-reading",
|
|
397
|
+
children: [/* @__PURE__ */ jsx("strong", {
|
|
398
|
+
className: "altertable-metric-value",
|
|
399
|
+
"data-unavailable": shownValue === "—" || void 0,
|
|
400
|
+
children: loading ? /* @__PURE__ */ jsx(Skeleton, { className: "altertable-metric-loading-value" }) : shownValue
|
|
401
|
+
}), shownTrend && /* @__PURE__ */ jsx("span", {
|
|
402
|
+
className: "altertable-metric-trend",
|
|
403
|
+
children: shownTrend
|
|
404
|
+
})]
|
|
405
|
+
}),
|
|
406
|
+
description && /* @__PURE__ */ jsx("small", {
|
|
407
|
+
className: "altertable-metric-description",
|
|
408
|
+
children: description
|
|
409
|
+
}),
|
|
410
|
+
visual && /* @__PURE__ */ jsx("div", {
|
|
411
|
+
className: "altertable-metric-visual",
|
|
412
|
+
children: visual
|
|
413
|
+
})
|
|
414
|
+
] });
|
|
415
|
+
}
|
|
416
|
+
//#endregion
|
|
417
|
+
//#region src/ui/TableWidget.tsx
|
|
418
|
+
function TableWidget$1(props) {
|
|
419
|
+
const { pagination, limit, columns } = props;
|
|
420
|
+
invariant(!pagination || Number.isSafeInteger(pagination.pageSize) && pagination.pageSize >= 1, "TableWidget pagination.pageSize must be a positive integer.");
|
|
421
|
+
invariant(limit === void 0 || Number.isSafeInteger(limit) && limit >= 1, "TableWidget limit must be a positive integer.");
|
|
422
|
+
const columnIds = columns.map((column) => column.id);
|
|
423
|
+
invariant(columnIds.length > 0 && columnIds.every((id) => !!id.trim()) && new Set(columnIds).size === columnIds.length, "TableWidget column IDs must be nonempty and unique.");
|
|
424
|
+
if (props.reading) {
|
|
425
|
+
const { reading, skeletonRows, ...rest } = props;
|
|
426
|
+
return /* @__PURE__ */ jsx(TableWidgetContent$1, {
|
|
427
|
+
...rest,
|
|
428
|
+
rows: reading.loading ? [] : reading.value,
|
|
429
|
+
loading: reading.loading,
|
|
430
|
+
skeletonRows
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
return /* @__PURE__ */ jsx(TableWidgetContent$1, { ...props });
|
|
434
|
+
}
|
|
435
|
+
function TableWidgetContent$1({ title, count, showCount = true, onClearFilters, description, columns, rows, rowKey, action, evidence, search, limit, pagination, emptyFallback, noMatchesFallback, loading = false, skeletonRows, ...props }) {
|
|
436
|
+
const keys = rows.map(rowKey);
|
|
437
|
+
invariant(keys.every((key) => typeof key === "string" ? !!key.trim() : Number.isFinite(key)) && new Set(keys.map(String)).size === keys.length, "TableWidget row keys must be nonempty and unique.");
|
|
438
|
+
const rowKeys = JSON.stringify(keys);
|
|
439
|
+
const pageSize = pagination === false || limit !== void 0 ? null : pagination?.pageSize ?? 10;
|
|
440
|
+
const [pageState, setPageState] = useState({
|
|
441
|
+
page: 0,
|
|
442
|
+
rowKeys,
|
|
443
|
+
searchValue: search?.value,
|
|
444
|
+
pageSize
|
|
445
|
+
});
|
|
446
|
+
if (pageState.rowKeys !== rowKeys || pageState.searchValue !== search?.value || pageState.pageSize !== pageSize) setPageState({
|
|
447
|
+
page: 0,
|
|
448
|
+
rowKeys,
|
|
449
|
+
searchValue: search?.value,
|
|
450
|
+
pageSize
|
|
451
|
+
});
|
|
452
|
+
const hits = search ? searchItems(rows, search.value, {
|
|
453
|
+
attributes: search.attributes,
|
|
454
|
+
mode: search.mode,
|
|
455
|
+
fuzzyThreshold: search.fuzzyThreshold
|
|
456
|
+
}) : rows.map((item) => ({
|
|
457
|
+
item,
|
|
458
|
+
score: 0,
|
|
459
|
+
matches: {}
|
|
460
|
+
}));
|
|
461
|
+
const pageCount = pageSize ? Math.max(1, Math.ceil(hits.length / pageSize)) : 1;
|
|
462
|
+
const page = Math.min(pageState.page, pageCount - 1);
|
|
463
|
+
const start = pageSize ? page * pageSize : 0;
|
|
464
|
+
const visible = hits.slice(start, pageSize ? start + pageSize : Math.max(0, limit ?? hits.length));
|
|
465
|
+
const pager = pageSize && pageCount > 1 && /* @__PURE__ */ jsxs("nav", {
|
|
466
|
+
className: "altertable-table-pagination",
|
|
467
|
+
"aria-label": "Table pages",
|
|
468
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
469
|
+
className: "altertable-table-pagination-range",
|
|
470
|
+
children: [
|
|
471
|
+
formatCount(start + 1),
|
|
472
|
+
"–",
|
|
473
|
+
formatCount(start + visible.length),
|
|
474
|
+
" of",
|
|
475
|
+
" ",
|
|
476
|
+
formatCount(hits.length),
|
|
477
|
+
" ",
|
|
478
|
+
pluralize(hits.length, "result")
|
|
479
|
+
]
|
|
480
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
481
|
+
className: "altertable-table-pagination-controls",
|
|
482
|
+
children: [
|
|
483
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
484
|
+
"Page ",
|
|
485
|
+
page + 1,
|
|
486
|
+
" of ",
|
|
487
|
+
pageCount
|
|
488
|
+
] }),
|
|
489
|
+
/* @__PURE__ */ jsx(Tooltip, {
|
|
490
|
+
content: "Previous page",
|
|
491
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
492
|
+
size: "icon-compact",
|
|
493
|
+
"aria-label": "Previous page",
|
|
494
|
+
disabled: page === 0,
|
|
495
|
+
onClick: () => setPageState({
|
|
496
|
+
page: page - 1,
|
|
497
|
+
rowKeys,
|
|
498
|
+
searchValue: search?.value,
|
|
499
|
+
pageSize
|
|
500
|
+
}),
|
|
501
|
+
children: /* @__PURE__ */ jsx(AppIcon, {
|
|
502
|
+
name: "previousMonth",
|
|
503
|
+
size: 16
|
|
504
|
+
})
|
|
505
|
+
})
|
|
506
|
+
}),
|
|
507
|
+
/* @__PURE__ */ jsx(Tooltip, {
|
|
508
|
+
content: "Next page",
|
|
509
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
510
|
+
size: "icon-compact",
|
|
511
|
+
"aria-label": "Next page",
|
|
512
|
+
disabled: page >= pageCount - 1,
|
|
513
|
+
onClick: () => setPageState({
|
|
514
|
+
page: page + 1,
|
|
515
|
+
rowKeys,
|
|
516
|
+
searchValue: search?.value,
|
|
517
|
+
pageSize
|
|
518
|
+
}),
|
|
519
|
+
children: /* @__PURE__ */ jsx(AppIcon, {
|
|
520
|
+
name: "nextMonth",
|
|
521
|
+
size: 16
|
|
522
|
+
})
|
|
523
|
+
})
|
|
524
|
+
})
|
|
525
|
+
]
|
|
526
|
+
})]
|
|
527
|
+
});
|
|
528
|
+
return /* @__PURE__ */ jsx(VisualizationWidget$1, {
|
|
529
|
+
...props,
|
|
530
|
+
className: classNames("altertable-table-widget", props.className),
|
|
531
|
+
title,
|
|
532
|
+
count: loading || !showCount ? void 0 : count ?? hits.length,
|
|
533
|
+
description,
|
|
534
|
+
action,
|
|
535
|
+
evidence,
|
|
536
|
+
"aria-busy": loading || props["aria-busy"],
|
|
537
|
+
footer: pager,
|
|
538
|
+
visual: /* @__PURE__ */ jsx("div", {
|
|
539
|
+
className: "altertable-table-widget-content",
|
|
540
|
+
children: /* @__PURE__ */ jsx(TableWidgetTable, {
|
|
541
|
+
columns,
|
|
542
|
+
visible,
|
|
543
|
+
rowKey,
|
|
544
|
+
rowCount: rows.length,
|
|
545
|
+
matchCount: hits.length,
|
|
546
|
+
search,
|
|
547
|
+
emptyFallback,
|
|
548
|
+
noMatchesFallback,
|
|
549
|
+
onClearFilters,
|
|
550
|
+
loading,
|
|
551
|
+
skeletonRows: skeletonRows ?? limit ?? (pagination ? pagination.pageSize : void 0) ?? 5
|
|
552
|
+
})
|
|
553
|
+
})
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
/** Each page or inspection mount owns its input and recovery focus. */
|
|
557
|
+
function TableWidgetTable({ columns, visible, rowKey, rowCount, matchCount, search, emptyFallback, noMatchesFallback, onClearFilters, loading, skeletonRows }) {
|
|
558
|
+
const tableRef = useRef(null);
|
|
559
|
+
const searchInputRef = useRef(null);
|
|
560
|
+
const searchRef = useMergeRefs([searchInputRef, search?.inputProps?.ref]);
|
|
561
|
+
const searchable = search && {
|
|
562
|
+
label: search.label,
|
|
563
|
+
placeholder: search.placeholder,
|
|
564
|
+
value: search.value,
|
|
565
|
+
onChange: search.onChange,
|
|
566
|
+
resetValue: search.resetValue,
|
|
567
|
+
inputProps: {
|
|
568
|
+
...search.inputProps,
|
|
569
|
+
ref: searchRef
|
|
570
|
+
},
|
|
571
|
+
itemCount: rowCount
|
|
572
|
+
};
|
|
573
|
+
const searchHasNoMatches = rowCount > 0 && matchCount === 0 && !!search;
|
|
574
|
+
const canClearSearch = searchHasNoMatches && search && search.value !== (search.resetValue ?? "");
|
|
575
|
+
function clearSearch() {
|
|
576
|
+
search?.onChange(search.resetValue ?? "");
|
|
577
|
+
requestAnimationFrame(() => (searchInputRef.current ?? tableRef.current)?.focus());
|
|
578
|
+
}
|
|
579
|
+
function clearFilters() {
|
|
580
|
+
onClearFilters?.();
|
|
581
|
+
tableRef.current?.focus();
|
|
582
|
+
}
|
|
583
|
+
const emptyContent = searchHasNoMatches || rowCount === 0 && !!onClearFilters ? noMatchesFallback ?? {
|
|
584
|
+
title: "No matching results",
|
|
585
|
+
description: searchHasNoMatches ? "Try a different search." : "Try different filters."
|
|
586
|
+
} : emptyFallback;
|
|
587
|
+
const recovery = canClearSearch ? /* @__PURE__ */ jsx(Button, {
|
|
588
|
+
onClick: clearSearch,
|
|
589
|
+
children: "Clear search"
|
|
590
|
+
}) : rowCount === 0 && onClearFilters ? /* @__PURE__ */ jsx(Button, {
|
|
591
|
+
onClick: clearFilters,
|
|
592
|
+
children: "Clear filters"
|
|
593
|
+
}) : void 0;
|
|
594
|
+
const emptyAction = recovery ? /* @__PURE__ */ jsxs(Fragment$1, { children: [emptyContent.action, recovery] }) : emptyContent.action;
|
|
595
|
+
return /* @__PURE__ */ jsxs(DataTable, {
|
|
596
|
+
ref: tableRef,
|
|
597
|
+
tabIndex: -1,
|
|
598
|
+
searchable: loading ? void 0 : searchable,
|
|
599
|
+
"aria-busy": loading || void 0,
|
|
600
|
+
children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: columns.map((column) => /* @__PURE__ */ jsx("th", {
|
|
601
|
+
scope: "col",
|
|
602
|
+
"data-type": column.type,
|
|
603
|
+
children: column.header
|
|
604
|
+
}, column.id)) }) }), /* @__PURE__ */ jsx("tbody", {
|
|
605
|
+
"aria-hidden": loading || void 0,
|
|
606
|
+
children: loading ? Array.from({ length: Math.min(100, Math.max(0, Math.trunc(skeletonRows) || 0)) }, (_, row) => /* @__PURE__ */ jsx("tr", { children: columns.map((column) => /* @__PURE__ */ jsx("td", {
|
|
607
|
+
"data-type": column.type,
|
|
608
|
+
children: /* @__PURE__ */ jsx(Skeleton, { style: {
|
|
609
|
+
width: "70%",
|
|
610
|
+
height: "1lh"
|
|
611
|
+
} })
|
|
612
|
+
}, column.id)) }, row)) : visible.length === 0 ? /* @__PURE__ */ jsx(DataTableEmptyRow, {
|
|
613
|
+
colSpan: columns.length,
|
|
614
|
+
...emptyContent,
|
|
615
|
+
action: emptyAction
|
|
616
|
+
}) : visible.map((hit) => /* @__PURE__ */ jsx("tr", { children: columns.map((column, index) => index === 0 ? /* @__PURE__ */ jsx("th", {
|
|
617
|
+
scope: "row",
|
|
618
|
+
"data-type": column.type,
|
|
619
|
+
children: column.cell(hit.item, hit)
|
|
620
|
+
}, column.id) : /* @__PURE__ */ jsx("td", {
|
|
621
|
+
"data-type": column.type,
|
|
622
|
+
children: column.cell(hit.item, hit)
|
|
623
|
+
}, column.id)) }, rowKey(hit.item)))
|
|
624
|
+
})]
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
//#endregion
|
|
628
|
+
//#region src/ui/TextWidget.tsx
|
|
629
|
+
function TextWidget$1(props) {
|
|
630
|
+
const content = props.reading ? props.reading.loading ? null : props.children(props.reading.value) : props.children;
|
|
631
|
+
const { reading, children: _, className, ...shell } = props;
|
|
632
|
+
const loading = reading?.loading === true;
|
|
633
|
+
return /* @__PURE__ */ jsx(DataWidget, {
|
|
634
|
+
...shell,
|
|
635
|
+
className: classNames("altertable-text-widget", className),
|
|
636
|
+
evidence: shell.evidence,
|
|
637
|
+
"aria-busy": loading || shell["aria-busy"],
|
|
638
|
+
children: /* @__PURE__ */ jsx(TextContent, { children: loading ? /* @__PURE__ */ jsxs("div", {
|
|
639
|
+
className: "altertable-text-widget-skeleton",
|
|
640
|
+
"aria-hidden": "true",
|
|
641
|
+
children: [
|
|
642
|
+
/* @__PURE__ */ jsx(Skeleton, {}),
|
|
643
|
+
/* @__PURE__ */ jsx(Skeleton, {}),
|
|
644
|
+
/* @__PURE__ */ jsx(Skeleton, {})
|
|
645
|
+
]
|
|
646
|
+
}) : content })
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
//#endregion
|
|
171
650
|
//#region src/widgets.tsx
|
|
172
651
|
function MetricWidgetContent({ metric, source, records, actions, action, ...presentation }) {
|
|
173
652
|
const navigation = useDetailNavigation();
|