@telamonjs/ui 1.2.1 → 1.3.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/CHANGELOG.md +33 -0
- package/README.md +1 -1
- package/dist/components/data/DataTableActions.js +1 -0
- package/dist/components/data/action-access.d.ts +9 -2
- package/dist/components/data/action-access.js +10 -3
- package/dist/components/dialog/CrudDialogShell.d.ts +2 -0
- package/dist/components/dialog/CrudDialogShell.js +9 -7
- package/dist/components/dialog/DialogLoadingState.d.ts +16 -0
- package/dist/components/dialog/DialogLoadingState.js +16 -0
- package/dist/components/dialog/confirm-action-dialog.d.ts +12 -4
- package/dist/components/dialog/confirm-action-dialog.js +75 -14
- package/dist/components/dialog/create-dialog.js +1 -12
- package/dist/components/dialog/edit-dialog.js +5 -4
- package/dist/components/dialog/index.d.ts +1 -1
- package/dist/components/dialog/index.js +1 -2
- package/dist/components/dialog/view-dialog.js +5 -4
- package/dist/components/utilities/QueryErrorState.d.ts +47 -0
- package/dist/components/utilities/QueryErrorState.js +85 -0
- package/dist/data/DataTable.d.ts +2 -2
- package/dist/data/DataTable.js +2 -0
- package/dist/data/ExportMenu.d.ts +30 -3
- package/dist/data/ExportMenu.js +69 -5
- package/dist/data/datatable/TableToolbar.d.ts +3 -2
- package/dist/data/datatable/TableToolbar.js +30 -13
- package/dist/data/datatable/types.d.ts +9 -0
- package/dist/data/fetch-all-pages.d.ts +30 -0
- package/dist/data/fetch-all-pages.js +44 -0
- package/dist/exports/data-crud.d.ts +7 -3
- package/dist/exports/data-crud.js +4 -0
- package/dist/exports/types-constants.d.ts +2 -2
- package/dist/exports/types-constants.js +1 -1
- package/dist/i18n/messages/en/data.d.ts +3 -0
- package/dist/i18n/messages/en/data.js +3 -0
- package/dist/i18n/messages/en/index.d.ts +5 -0
- package/dist/i18n/messages/en/validation.d.ts +2 -0
- package/dist/i18n/messages/en/validation.js +2 -0
- package/dist/i18n/messages/es/data.d.ts +3 -0
- package/dist/i18n/messages/es/data.js +3 -0
- package/dist/i18n/messages/es/index.d.ts +5 -0
- package/dist/i18n/messages/es/validation.d.ts +2 -0
- package/dist/i18n/messages/es/validation.js +2 -0
- package/dist/i18n/messages/pt-BR/data.d.ts +3 -0
- package/dist/i18n/messages/pt-BR/data.js +3 -0
- package/dist/i18n/messages/pt-BR/index.d.ts +5 -0
- package/dist/i18n/messages/pt-BR/validation.d.ts +2 -0
- package/dist/i18n/messages/pt-BR/validation.js +2 -0
- package/dist/i18n/use-t.d.ts +5 -0
- package/dist/pages/ListPage.js +9 -13
- package/dist/pages/list-page/ListPageTable.d.ts +4 -2
- package/dist/pages/list-page/ListPageTable.js +3 -3
- package/dist/pages/list-page/ListPageToolbar.d.ts +4 -1
- package/dist/pages/list-page/ListPageToolbar.js +10 -4
- package/dist/pages/list-page/apply-crud-permissions.d.ts +4 -1
- package/dist/pages/list-page/apply-crud-permissions.js +20 -3
- package/dist/pages/list-page/types.d.ts +2 -16
- package/dist/pages/list-page/useListPageExport.d.ts +24 -0
- package/dist/pages/list-page/useListPageExport.js +54 -0
- package/dist/types/actions.d.ts +43 -4
- package/dist/types/crud.d.ts +48 -2
- package/package.json +1 -1
- package/dist/components/dialog/DialogErrorState.d.ts +0 -44
- package/dist/components/dialog/DialogErrorState.js +0 -57
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/utilities/QueryErrorState.tsx
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { AlertCircle, RefreshCw } from "lucide-react";
|
|
6
|
+
import { useTelamonjsT, useText } from "../../i18n/use-t.js";
|
|
7
|
+
import { Alert } from "../../ui/alert.js";
|
|
8
|
+
import { Button } from "../../ui/button.js";
|
|
9
|
+
import { logger } from "../../utils/logger.js";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
function messageOf(error) {
|
|
12
|
+
const message = typeof error === "string" ? error : typeof error === "object" && error !== null && "message" in error ? error.message : void 0;
|
|
13
|
+
return typeof message === "string" && message.trim() ? message : void 0;
|
|
14
|
+
}
|
|
15
|
+
function QueryErrorState({
|
|
16
|
+
error,
|
|
17
|
+
title,
|
|
18
|
+
description,
|
|
19
|
+
onRetry,
|
|
20
|
+
retrying,
|
|
21
|
+
retryLabel,
|
|
22
|
+
className
|
|
23
|
+
}) {
|
|
24
|
+
const t = useTelamonjsT();
|
|
25
|
+
const text = useText();
|
|
26
|
+
const [running, setRunning] = useState(false);
|
|
27
|
+
const pending = Boolean(retrying) || running;
|
|
28
|
+
const detail = text(description) ?? messageOf(error);
|
|
29
|
+
const retry = async () => {
|
|
30
|
+
if (!onRetry || pending) return;
|
|
31
|
+
setRunning(true);
|
|
32
|
+
try {
|
|
33
|
+
await onRetry();
|
|
34
|
+
} catch (err) {
|
|
35
|
+
logger.error("[QueryErrorState] onRetry failed", {
|
|
36
|
+
error: err instanceof Error ? err : String(err)
|
|
37
|
+
});
|
|
38
|
+
} finally {
|
|
39
|
+
setRunning(false);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
return /* @__PURE__ */ jsxs(
|
|
43
|
+
Alert,
|
|
44
|
+
{
|
|
45
|
+
variant: "destructive",
|
|
46
|
+
className,
|
|
47
|
+
"data-testid": "query-error-state",
|
|
48
|
+
children: [
|
|
49
|
+
/* @__PURE__ */ jsx(AlertCircle, { className: "h-4 w-4", "aria-hidden": "true" }),
|
|
50
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [
|
|
51
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0 space-y-1", children: [
|
|
52
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm font-medium leading-none", children: text(title) ?? t("dialog.loadDataError") }),
|
|
53
|
+
detail && /* @__PURE__ */ jsx(
|
|
54
|
+
"p",
|
|
55
|
+
{
|
|
56
|
+
className: "text-sm break-words opacity-90",
|
|
57
|
+
"data-testid": "query-error-description",
|
|
58
|
+
children: detail
|
|
59
|
+
}
|
|
60
|
+
)
|
|
61
|
+
] }),
|
|
62
|
+
onRetry && /* @__PURE__ */ jsxs(
|
|
63
|
+
Button,
|
|
64
|
+
{
|
|
65
|
+
type: "button",
|
|
66
|
+
variant: "outline",
|
|
67
|
+
size: "sm",
|
|
68
|
+
onClick: () => void retry(),
|
|
69
|
+
loading: pending,
|
|
70
|
+
className: "shrink-0 gap-1.5 bg-card text-foreground hover:bg-muted/50",
|
|
71
|
+
"data-testid": "query-error-retry",
|
|
72
|
+
children: [
|
|
73
|
+
!pending && /* @__PURE__ */ jsx(RefreshCw, { className: "h-4 w-4", "aria-hidden": "true" }),
|
|
74
|
+
text(retryLabel) ?? t("common.retry")
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
)
|
|
78
|
+
] })
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
export {
|
|
84
|
+
QueryErrorState
|
|
85
|
+
};
|
package/dist/data/DataTable.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { DataTableProps } from './datatable/types';
|
|
3
|
-
export type { DataTableProps } from './datatable/types';
|
|
3
|
+
export type { DataTableProps, DataTableExportMenuProps } from './datatable/types';
|
|
4
4
|
/**
|
|
5
5
|
* DataTable - Advanced data table component with TanStack Table
|
|
6
6
|
*
|
|
@@ -205,4 +205,4 @@ export type { DataTableProps } from './datatable/types';
|
|
|
205
205
|
*
|
|
206
206
|
* @see {@link /apps/docs/content/docs/patterns/listpage-pattern.mdx | ListPage Pattern}
|
|
207
207
|
*/
|
|
208
|
-
export declare function DataTable<TData, TValue>({ columns, data, tableId: providedTableId, title, description, searchPlaceholder: searchPlaceholderProp, enableSearch, enableFilters, enableExport, exportFormats, exportFilename, exportPdfOptions, enableSavedViews, enableAdd, enableRefresh, enableColumnVisibility, enableSelection, enablePagination, pageSize, readOnly, loading, error, emptyTitle: emptyTitleProp, emptyDescription: emptyDescriptionProp, onAdd, onRefresh, onExport, onRowClick, rowClickNavigation, className, enableDensity, defaultDensity, enableFullscreen, enableBulkActions, bulkActions, enableRowSelection, headerActions, enableMobileCards, defaultViewMode, cardActions, cardComponent, manualPagination, pageCount, currentPage, totalItems, onPaginationChange, onSearchChange, onSortChange, onColumnFiltersChange, enableMultiSort, filterOptions, enableActions, actionsConfig, enableQueryBuilder, queryBuilderFields, onQueryBuilderChange, enableExpandableRows, expandableRowContent, hideToolbar, hideTitleSection, }: DataTableProps<TData, TValue>): React.JSX.Element;
|
|
208
|
+
export declare function DataTable<TData, TValue>({ columns, data, tableId: providedTableId, title, description, searchPlaceholder: searchPlaceholderProp, enableSearch, enableFilters, enableExport, exportFormats, exportFilename, exportPdfOptions, exportMenuProps, enableSavedViews, enableAdd, enableRefresh, enableColumnVisibility, enableSelection, enablePagination, pageSize, readOnly, loading, error, emptyTitle: emptyTitleProp, emptyDescription: emptyDescriptionProp, onAdd, onRefresh, onExport, onRowClick, rowClickNavigation, className, enableDensity, defaultDensity, enableFullscreen, enableBulkActions, bulkActions, enableRowSelection, headerActions, enableMobileCards, defaultViewMode, cardActions, cardComponent, manualPagination, pageCount, currentPage, totalItems, onPaginationChange, onSearchChange, onSortChange, onColumnFiltersChange, enableMultiSort, filterOptions, enableActions, actionsConfig, enableQueryBuilder, queryBuilderFields, onQueryBuilderChange, enableExpandableRows, expandableRowContent, hideToolbar, hideTitleSection, }: DataTableProps<TData, TValue>): React.JSX.Element;
|
package/dist/data/DataTable.js
CHANGED
|
@@ -31,6 +31,7 @@ function DataTable({
|
|
|
31
31
|
exportFormats = ["excel", "csv", "pdf"],
|
|
32
32
|
exportFilename = "export",
|
|
33
33
|
exportPdfOptions = {},
|
|
34
|
+
exportMenuProps,
|
|
34
35
|
enableSavedViews = false,
|
|
35
36
|
enableAdd = true,
|
|
36
37
|
enableRefresh = true,
|
|
@@ -241,6 +242,7 @@ function DataTable({
|
|
|
241
242
|
exportFormats,
|
|
242
243
|
exportFilename,
|
|
243
244
|
exportPdfOptions,
|
|
245
|
+
exportMenuProps,
|
|
244
246
|
onExport,
|
|
245
247
|
enableSavedViews,
|
|
246
248
|
savedViews,
|
|
@@ -7,13 +7,21 @@
|
|
|
7
7
|
import { type ReactNode } from 'react';
|
|
8
8
|
import { ColumnDef } from '@tanstack/react-table';
|
|
9
9
|
import type { PDFExportOptions } from './exportUtils';
|
|
10
|
+
export type ExportFormat = 'excel' | 'csv' | 'pdf';
|
|
11
|
+
/** What `ExportMenu.loadAll` receives: the user's Cancel, and a progress reporter. */
|
|
12
|
+
export interface ExportLoadAllContext {
|
|
13
|
+
/** Aborted when the user cancels or the menu unmounts */
|
|
14
|
+
signal: AbortSignal;
|
|
15
|
+
/** Rows fetched so far, out of `target` — updates the progress toast */
|
|
16
|
+
onProgress: (loaded: number, target: number) => void;
|
|
17
|
+
}
|
|
10
18
|
export interface ExportMenuProps<T> {
|
|
11
19
|
data: T[];
|
|
12
20
|
columns: ColumnDef<T>[];
|
|
13
21
|
selectedRows?: T[];
|
|
14
22
|
currentPageRows?: T[];
|
|
15
23
|
filename?: string;
|
|
16
|
-
formats?:
|
|
24
|
+
formats?: ExportFormat[];
|
|
17
25
|
/** Excel sheet name (default: localized "Data"). */
|
|
18
26
|
sheetName?: string;
|
|
19
27
|
/** Append `_YYYY-MM-DD` to the filename, once (default `true`). */
|
|
@@ -23,7 +31,26 @@ export interface ExportMenuProps<T> {
|
|
|
23
31
|
* Custom generator: when present the menu only orchestrates (loading state, toast,
|
|
24
32
|
* callbacks) and the built-in Excel/CSV/PDF generation is skipped.
|
|
25
33
|
*/
|
|
26
|
-
onExport?: (format:
|
|
34
|
+
onExport?: (format: ExportFormat, rows: T[], columns: ColumnDef<T>[]) => Promise<void> | void;
|
|
35
|
+
/**
|
|
36
|
+
* Source of the "All" scope instead of `data` — e.g. every page of a server
|
|
37
|
+
* query (`fetchAllPages`). While it runs, a progress toast offers Cancel
|
|
38
|
+
* (aborting `signal`). Resolve the rows and the server total: fewer rows
|
|
39
|
+
* than `total` (a row cap) shows a warning.
|
|
40
|
+
*/
|
|
41
|
+
loadAll?: (ctx: ExportLoadAllContext) => Promise<{
|
|
42
|
+
rows: T[];
|
|
43
|
+
total: number;
|
|
44
|
+
}>;
|
|
45
|
+
/** Count shown next to "All" when `loadAll` is set (the rows matching on the server). */
|
|
46
|
+
allCount?: number;
|
|
47
|
+
/**
|
|
48
|
+
* App-side export (e.g. a file generated by the server): the menu lists the
|
|
49
|
+
* formats only — no scopes, no rows — and calls this with the chosen one,
|
|
50
|
+
* pending until it settles. Failures show the export error toast; success is
|
|
51
|
+
* the handler's to announce.
|
|
52
|
+
*/
|
|
53
|
+
onServerExport?: (format: ExportFormat) => unknown;
|
|
27
54
|
onExportStart?: () => void;
|
|
28
55
|
onExportComplete?: () => void;
|
|
29
56
|
onExportError?: (error: Error) => void;
|
|
@@ -37,4 +64,4 @@ export interface ExportMenuProps<T> {
|
|
|
37
64
|
/** Extra items above the export section (e.g. "Refresh") */
|
|
38
65
|
children?: ReactNode;
|
|
39
66
|
}
|
|
40
|
-
export declare function ExportMenu<T>({ data, columns, selectedRows, currentPageRows, filename, formats, sheetName, appendDate, pdfOptions, onExport, onExportStart, onExportComplete, onExportError, disabled, className, trigger, children, }: ExportMenuProps<T>): import("react").JSX.Element;
|
|
67
|
+
export declare function ExportMenu<T>({ data, columns, selectedRows, currentPageRows, filename, formats, sheetName, appendDate, pdfOptions, onExport, loadAll, allCount, onServerExport, onExportStart, onExportComplete, onExportError, disabled, className, trigger, children, }: ExportMenuProps<T>): import("react").JSX.Element;
|
package/dist/data/ExportMenu.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
// src/data/ExportMenu.tsx
|
|
4
|
-
import { useState } from "react";
|
|
4
|
+
import { useEffect, useRef, useState } from "react";
|
|
5
5
|
import { useLocale } from "next-intl";
|
|
6
6
|
import { logger } from "../utils/logger.js";
|
|
7
7
|
import { useTelamonjsT } from "../i18n/use-t.js";
|
|
@@ -38,6 +38,9 @@ function ExportMenu({
|
|
|
38
38
|
appendDate,
|
|
39
39
|
pdfOptions = {},
|
|
40
40
|
onExport,
|
|
41
|
+
loadAll,
|
|
42
|
+
allCount,
|
|
43
|
+
onServerExport,
|
|
41
44
|
onExportStart,
|
|
42
45
|
onExportComplete,
|
|
43
46
|
onExportError,
|
|
@@ -49,9 +52,54 @@ function ExportMenu({
|
|
|
49
52
|
const t = useTelamonjsT();
|
|
50
53
|
const locale = useLocale();
|
|
51
54
|
const [isExporting, setIsExporting] = useState(false);
|
|
55
|
+
const loadAllRef = useRef(null);
|
|
56
|
+
useEffect(() => () => loadAllRef.current?.abort(), []);
|
|
52
57
|
const { open, setOpen, triggerProps, contentProps } = useHoverPopover({
|
|
53
58
|
disabled: disabled || isExporting
|
|
54
59
|
});
|
|
60
|
+
const loadAllRows = async (load) => {
|
|
61
|
+
const controller = new AbortController();
|
|
62
|
+
loadAllRef.current = controller;
|
|
63
|
+
const action = { label: t("common.cancel"), onClick: () => controller.abort() };
|
|
64
|
+
const toastId = toast.loading(t("common.loading"), { action });
|
|
65
|
+
try {
|
|
66
|
+
const { rows, total } = await load({
|
|
67
|
+
signal: controller.signal,
|
|
68
|
+
onProgress: (loaded, target) => toast.loading(t("data.exportFetching", { loaded, total: target }), {
|
|
69
|
+
id: toastId,
|
|
70
|
+
action
|
|
71
|
+
})
|
|
72
|
+
});
|
|
73
|
+
if (controller.signal.aborted) throw new DOMException("", "AbortError");
|
|
74
|
+
if (rows.length < total) {
|
|
75
|
+
toast.warning(t("data.exportTruncated", { count: rows.length, total }));
|
|
76
|
+
}
|
|
77
|
+
return rows;
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (!controller.signal.aborted) throw error;
|
|
80
|
+
toast.info(t("data.exportCancelled"));
|
|
81
|
+
return null;
|
|
82
|
+
} finally {
|
|
83
|
+
toast.dismiss(toastId);
|
|
84
|
+
loadAllRef.current = null;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const handleServerExport = async (run, format) => {
|
|
88
|
+
try {
|
|
89
|
+
setIsExporting(true);
|
|
90
|
+
onExportStart?.();
|
|
91
|
+
await run(format);
|
|
92
|
+
onExportComplete?.();
|
|
93
|
+
} catch (error) {
|
|
94
|
+
logger.error("Export error", {
|
|
95
|
+
error: error instanceof Error ? error : String(error)
|
|
96
|
+
});
|
|
97
|
+
toast.error(t("data.exportError"));
|
|
98
|
+
onExportError?.(error);
|
|
99
|
+
} finally {
|
|
100
|
+
setIsExporting(false);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
55
103
|
const handleExport = async (format, scope) => {
|
|
56
104
|
try {
|
|
57
105
|
setIsExporting(true);
|
|
@@ -76,10 +124,13 @@ function ExportMenu({
|
|
|
76
124
|
scopeLabel = t("data.scopeCurrentPage");
|
|
77
125
|
break;
|
|
78
126
|
case "all":
|
|
79
|
-
default:
|
|
80
|
-
|
|
127
|
+
default: {
|
|
128
|
+
const rows = loadAll ? await loadAllRows(loadAll) : data;
|
|
129
|
+
if (!rows) return;
|
|
130
|
+
dataToExport = rows;
|
|
81
131
|
scopeLabel = t("data.scopeAll");
|
|
82
132
|
break;
|
|
133
|
+
}
|
|
83
134
|
}
|
|
84
135
|
if (dataToExport.length === 0) {
|
|
85
136
|
toast.error(t("data.noDataToExport"));
|
|
@@ -148,6 +199,7 @@ function ExportMenu({
|
|
|
148
199
|
return t("data.pdfFormat");
|
|
149
200
|
}
|
|
150
201
|
};
|
|
202
|
+
const allLabelCount = loadAll ? allCount ?? 0 : data.length;
|
|
151
203
|
const hasSelectedRows = selectedRows.length > 0;
|
|
152
204
|
const hasCurrentPageRows = currentPageRows.length > 0;
|
|
153
205
|
return /* @__PURE__ */ jsxs(DropdownMenu, { open, onOpenChange: setOpen, modal: false, children: [
|
|
@@ -172,7 +224,19 @@ function ExportMenu({
|
|
|
172
224
|
] }),
|
|
173
225
|
/* @__PURE__ */ jsx(DropdownMenuLabel, { children: t("data.exportFormatLabel") }),
|
|
174
226
|
/* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
|
|
175
|
-
formats.map((format) => /* @__PURE__ */ jsxs(
|
|
227
|
+
onServerExport && formats.map((format) => /* @__PURE__ */ jsxs(
|
|
228
|
+
DropdownMenuItem,
|
|
229
|
+
{
|
|
230
|
+
onClick: () => void handleServerExport(onServerExport, format),
|
|
231
|
+
disabled: isExporting,
|
|
232
|
+
children: [
|
|
233
|
+
getFormatIcon(format),
|
|
234
|
+
/* @__PURE__ */ jsx("span", { className: "ml-2", children: getFormatLabel(format) })
|
|
235
|
+
]
|
|
236
|
+
},
|
|
237
|
+
format
|
|
238
|
+
)),
|
|
239
|
+
!onServerExport && formats.map((format) => /* @__PURE__ */ jsxs(DropdownMenuSub, { children: [
|
|
176
240
|
/* @__PURE__ */ jsxs(DropdownMenuSubTrigger, { children: [
|
|
177
241
|
getFormatIcon(format),
|
|
178
242
|
/* @__PURE__ */ jsx("span", { className: "ml-2", children: getFormatLabel(format) })
|
|
@@ -185,7 +249,7 @@ function ExportMenu({
|
|
|
185
249
|
disabled: isExporting,
|
|
186
250
|
children: [
|
|
187
251
|
/* @__PURE__ */ jsx("span", { className: "text-sm", children: t("data.exportAll") }),
|
|
188
|
-
|
|
252
|
+
allLabelCount > 0 && /* @__PURE__ */ jsx("span", { className: "ml-auto text-xs text-muted-foreground", children: t("data.recordCount", { count: allLabelCount }) })
|
|
189
253
|
]
|
|
190
254
|
}
|
|
191
255
|
),
|
|
@@ -4,7 +4,7 @@ import { SortField } from '../../types/pagination';
|
|
|
4
4
|
import { QueryBuilderField } from '../QueryBuilder';
|
|
5
5
|
import { BulkAction } from '../BulkActionsToolbar';
|
|
6
6
|
import { PDFExportOptions } from '../exportUtils';
|
|
7
|
-
import { DataTableHeaderActions, ViewMode } from './types';
|
|
7
|
+
import { DataTableExportMenuProps, DataTableHeaderActions, ViewMode } from './types';
|
|
8
8
|
import { QueryBuilderControl } from './useQueryBuilderControl';
|
|
9
9
|
import { SavedViewsControl } from './useSavedViewsControl';
|
|
10
10
|
export interface TableToolbarProps<TData, TValue> {
|
|
@@ -36,6 +36,7 @@ export interface TableToolbarProps<TData, TValue> {
|
|
|
36
36
|
exportFormats: Array<'excel' | 'csv' | 'pdf'>;
|
|
37
37
|
exportFilename: string;
|
|
38
38
|
exportPdfOptions: Omit<PDFExportOptions, 'filename' | 't' | 'locale'>;
|
|
39
|
+
exportMenuProps?: DataTableExportMenuProps<TData>;
|
|
39
40
|
onExport?: () => void;
|
|
40
41
|
enableSavedViews: boolean;
|
|
41
42
|
savedViews: SavedViewsControl;
|
|
@@ -64,4 +65,4 @@ export interface TableToolbarProps<TData, TValue> {
|
|
|
64
65
|
*
|
|
65
66
|
* @internal Extracted from DataTable.tsx (toolbar render)
|
|
66
67
|
*/
|
|
67
|
-
export declare function TableToolbar<TData, TValue>({ tableId, table, columns, sorting, selectedRowCount, isFiltered, enableSearch, searchPlaceholder, storeGlobalFilter, setGlobalFilter, isSearching, manualPagination, clearFilters, setStoreSorting, enableBulkActions, bulkActions, setRowSelection, enableFilters, showFilters, setShowFilters, enableQueryBuilder, queryBuilderFields, queryBuilder, enableExport, exportFormats, exportFilename, exportPdfOptions, onExport, enableSavedViews, savedViews, enableColumnVisibility, currentViewMode, headerActions, enableRefresh, onRefresh, loading, enableAdd, readOnly, handleAdd, enableMobileCards, setCurrentViewMode, viewMode, setViewMode, enableDensity, enableFullscreen, toggleFullscreen, isFullscreen, }: TableToolbarProps<TData, TValue>): React.JSX.Element;
|
|
68
|
+
export declare function TableToolbar<TData, TValue>({ tableId, table, columns, sorting, selectedRowCount, isFiltered, enableSearch, searchPlaceholder, storeGlobalFilter, setGlobalFilter, isSearching, manualPagination, clearFilters, setStoreSorting, enableBulkActions, bulkActions, setRowSelection, enableFilters, showFilters, setShowFilters, enableQueryBuilder, queryBuilderFields, queryBuilder, enableExport, exportFormats, exportFilename, exportPdfOptions, exportMenuProps, onExport, enableSavedViews, savedViews, enableColumnVisibility, currentViewMode, headerActions, enableRefresh, onRefresh, loading, enableAdd, readOnly, handleAdd, enableMobileCards, setCurrentViewMode, viewMode, setViewMode, enableDensity, enableFullscreen, toggleFullscreen, isFullscreen, }: TableToolbarProps<TData, TValue>): React.JSX.Element;
|
|
@@ -64,6 +64,7 @@ function TableToolbar({
|
|
|
64
64
|
exportFormats,
|
|
65
65
|
exportFilename,
|
|
66
66
|
exportPdfOptions,
|
|
67
|
+
exportMenuProps,
|
|
67
68
|
onExport,
|
|
68
69
|
enableSavedViews,
|
|
69
70
|
savedViews,
|
|
@@ -95,6 +96,16 @@ function TableToolbar({
|
|
|
95
96
|
handleQueryBuilderClear
|
|
96
97
|
} = queryBuilder;
|
|
97
98
|
const { getCurrentViewConfig, handleLoadView, handleResetToDefault } = savedViews;
|
|
99
|
+
const exportMenu = enableExport && !onExport ? {
|
|
100
|
+
data: table.getFilteredRowModel().rows.map((row) => row.original),
|
|
101
|
+
columns,
|
|
102
|
+
selectedRows: table.getFilteredSelectedRowModel().rows.map((row) => row.original),
|
|
103
|
+
currentPageRows: table.getRowModel().rows.map((row) => row.original),
|
|
104
|
+
filename: exportFilename,
|
|
105
|
+
formats: exportFormats,
|
|
106
|
+
pdfOptions: exportPdfOptions,
|
|
107
|
+
...exportMenuProps
|
|
108
|
+
} : void 0;
|
|
98
109
|
return /* @__PURE__ */ jsxs("div", { className: "flex flex-row items-center justify-between gap-2", children: [
|
|
99
110
|
/* @__PURE__ */ jsxs("div", { className: "flex flex-1 items-center space-x-2", children: [
|
|
100
111
|
enableSearch && /* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
@@ -244,19 +255,7 @@ function TableToolbar({
|
|
|
244
255
|
] })
|
|
245
256
|
] })
|
|
246
257
|
] }),
|
|
247
|
-
|
|
248
|
-
ExportMenu,
|
|
249
|
-
{
|
|
250
|
-
data: table.getFilteredRowModel().rows.map((row) => row.original),
|
|
251
|
-
columns,
|
|
252
|
-
selectedRows: table.getFilteredSelectedRowModel().rows.map((row) => row.original),
|
|
253
|
-
currentPageRows: table.getRowModel().rows.map((row) => row.original),
|
|
254
|
-
filename: exportFilename,
|
|
255
|
-
formats: exportFormats,
|
|
256
|
-
pdfOptions: exportPdfOptions,
|
|
257
|
-
className: "h-8"
|
|
258
|
-
}
|
|
259
|
-
),
|
|
258
|
+
exportMenu && /* @__PURE__ */ jsx(ExportMenu, { ...exportMenu, className: "h-8" }),
|
|
260
259
|
enableExport && onExport && /* @__PURE__ */ jsxs(
|
|
261
260
|
Button,
|
|
262
261
|
{
|
|
@@ -385,6 +384,24 @@ function TableToolbar({
|
|
|
385
384
|
]
|
|
386
385
|
}
|
|
387
386
|
),
|
|
387
|
+
exportMenu && /* @__PURE__ */ jsx("div", { className: "lg:hidden", children: /* @__PURE__ */ jsx(
|
|
388
|
+
ExportMenu,
|
|
389
|
+
{
|
|
390
|
+
...exportMenu,
|
|
391
|
+
trigger: /* @__PURE__ */ jsx(
|
|
392
|
+
Button,
|
|
393
|
+
{
|
|
394
|
+
variant: "outline",
|
|
395
|
+
size: "sm",
|
|
396
|
+
className: "h-8 w-8 p-0",
|
|
397
|
+
"aria-label": t("data.export"),
|
|
398
|
+
title: t("data.export"),
|
|
399
|
+
"data-testid": "toolbar-export-menu-compact",
|
|
400
|
+
children: /* @__PURE__ */ jsx(Download, { className: "h-4 w-4" })
|
|
401
|
+
}
|
|
402
|
+
)
|
|
403
|
+
}
|
|
404
|
+
) }),
|
|
388
405
|
/* @__PURE__ */ jsx(
|
|
389
406
|
ToolbarActionsMenu,
|
|
390
407
|
{
|
|
@@ -6,6 +6,9 @@ import { DataTableActionsConfig } from '../../types/actions';
|
|
|
6
6
|
import { BulkAction } from '../BulkActionsToolbar';
|
|
7
7
|
import { QueryBuilderField } from '../QueryBuilder';
|
|
8
8
|
import { PDFExportOptions } from '../exportUtils';
|
|
9
|
+
import type { ExportMenuProps } from '../ExportMenu';
|
|
10
|
+
/** `DataTable.exportMenuProps`: what the built-in export menu takes beyond the table rows. */
|
|
11
|
+
export type DataTableExportMenuProps<TData> = Partial<Pick<ExportMenuProps<TData>, 'loadAll' | 'allCount' | 'onServerExport' | 'formats' | 'filename'>>;
|
|
9
12
|
/**
|
|
10
13
|
* DataTableProps - Configuration for DataTable component
|
|
11
14
|
*
|
|
@@ -43,6 +46,12 @@ export interface DataTableProps<TData, TValue> {
|
|
|
43
46
|
exportFilename?: string;
|
|
44
47
|
/** PDF export options (orientation, page size, etc.). */
|
|
45
48
|
exportPdfOptions?: Omit<PDFExportOptions, 'filename' | 't' | 'locale'>;
|
|
49
|
+
/**
|
|
50
|
+
* Extra props for the built-in export menu: `loadAll` (+ `allCount`) to export every
|
|
51
|
+
* server page instead of the table rows, `onServerExport` for an app-side export.
|
|
52
|
+
* `formats`/`filename` here win over `exportFormats`/`exportFilename`.
|
|
53
|
+
*/
|
|
54
|
+
exportMenuProps?: DataTableExportMenuProps<TData>;
|
|
46
55
|
/** Enable saved views functionality (save/load column visibility, sorting, filters). Default: false */
|
|
47
56
|
enableSavedViews?: boolean;
|
|
48
57
|
/** Name of default view to load on mount */
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { PaginatedResponse, PaginationParams } from '../types/pagination';
|
|
2
|
+
export interface FetchAllPagesOptions<T> {
|
|
3
|
+
/** The list's own `query.queryFn` */
|
|
4
|
+
queryFn: (params: PaginationParams) => Promise<PaginatedResponse<T>>;
|
|
5
|
+
/** The list's current query (search, filters, sort); `page`/`pageSize` are replaced */
|
|
6
|
+
params: PaginationParams;
|
|
7
|
+
/** Rows per request */
|
|
8
|
+
pageSize: number;
|
|
9
|
+
/** Stop once this many rows are collected */
|
|
10
|
+
maxRows: number;
|
|
11
|
+
/** Aborting stops before the next request (the one in flight cannot be cancelled) */
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
/** After each page: rows collected so far, and the target (`min(total, maxRows)`) */
|
|
14
|
+
onProgress?: (loaded: number, target: number) => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Every row matching a list query, fetched page by page through its `queryFn`
|
|
18
|
+
* — what "Export all" of a ListPage with `list.exportAll` exports.
|
|
19
|
+
*
|
|
20
|
+
* Sequential on purpose: one request at a time keeps the load on the backend
|
|
21
|
+
* the same as scrolling the list. Stops at `totalPages`, at `maxRows`, or on an
|
|
22
|
+
* empty page (a backend whose `totalPages` is wrong cannot loop forever).
|
|
23
|
+
* Rows repeated across pages (same `id`) are dropped, as in the infinite list.
|
|
24
|
+
*
|
|
25
|
+
* ponytail: sequential pages; fetch a few in parallel if large exports get slow.
|
|
26
|
+
*/
|
|
27
|
+
export declare function fetchAllPages<T>({ queryFn, params, pageSize, maxRows, signal, onProgress, }: FetchAllPagesOptions<T>): Promise<{
|
|
28
|
+
rows: T[];
|
|
29
|
+
total: number;
|
|
30
|
+
}>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// src/data/fetch-all-pages.ts
|
|
2
|
+
function assertNotAborted(signal) {
|
|
3
|
+
if (signal?.aborted) throw new DOMException("Export cancelled", "AbortError");
|
|
4
|
+
}
|
|
5
|
+
async function fetchAllPages({
|
|
6
|
+
queryFn,
|
|
7
|
+
params,
|
|
8
|
+
pageSize,
|
|
9
|
+
maxRows,
|
|
10
|
+
signal,
|
|
11
|
+
onProgress
|
|
12
|
+
}) {
|
|
13
|
+
const sort = Array.isArray(params.sortBy) ? params.sortBy[0] : void 0;
|
|
14
|
+
const query = {
|
|
15
|
+
...params,
|
|
16
|
+
sortBy: Array.isArray(params.sortBy) ? sort?.field : params.sortBy,
|
|
17
|
+
sortOrder: Array.isArray(params.sortBy) ? sort?.order : params.sortOrder
|
|
18
|
+
};
|
|
19
|
+
const rows = [];
|
|
20
|
+
const seen = /* @__PURE__ */ new Set();
|
|
21
|
+
let total = 0;
|
|
22
|
+
for (let page = 1; ; page++) {
|
|
23
|
+
assertNotAborted(signal);
|
|
24
|
+
const result = await queryFn({ ...query, page, pageSize });
|
|
25
|
+
assertNotAborted(signal);
|
|
26
|
+
total = result.total;
|
|
27
|
+
for (const row of result.data) {
|
|
28
|
+
const id = row?.id?.toString();
|
|
29
|
+
if (id !== void 0) {
|
|
30
|
+
if (seen.has(id)) continue;
|
|
31
|
+
seen.add(id);
|
|
32
|
+
}
|
|
33
|
+
rows.push(row);
|
|
34
|
+
}
|
|
35
|
+
const target = Math.min(total, maxRows);
|
|
36
|
+
onProgress?.(Math.min(rows.length, target), target);
|
|
37
|
+
if (rows.length >= maxRows || page >= result.totalPages || result.data.length === 0)
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
return { rows: rows.slice(0, maxRows), total };
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
fetchAllPages
|
|
44
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { DataTable } from '../data/DataTable';
|
|
2
|
-
export type { DataTableProps } from '../data/DataTable';
|
|
2
|
+
export type { DataTableProps, DataTableExportMenuProps } from '../data/DataTable';
|
|
3
3
|
export { InfiniteList } from '../data/InfiniteList';
|
|
4
4
|
export type { InfiniteListProps } from '../data/InfiniteList';
|
|
5
5
|
export { useInfiniteListQuery } from '../hooks/useInfiniteListQuery';
|
|
@@ -9,10 +9,12 @@ export type { BulkAction } from '../data/BulkActionsToolbar';
|
|
|
9
9
|
export type { QueryBuilderField } from '../data/QueryBuilder';
|
|
10
10
|
export type { FieldType as QueryBuilderFieldType } from '../data/queryBuilderUtils';
|
|
11
11
|
export { ExportMenu } from '../data/ExportMenu';
|
|
12
|
-
export type { ExportMenuProps } from '../data/ExportMenu';
|
|
12
|
+
export type { ExportMenuProps, ExportFormat, ExportLoadAllContext, } from '../data/ExportMenu';
|
|
13
|
+
export { fetchAllPages } from '../data/fetch-all-pages';
|
|
14
|
+
export type { FetchAllPagesOptions } from '../data/fetch-all-pages';
|
|
13
15
|
export { exportToExcel, exportToCSV, exportToPDF, exportTableData, } from '../data/exportUtils';
|
|
14
16
|
export type { ExportOptions, PDFExportOptions } from '../data/exportUtils';
|
|
15
|
-
export type { DataTableActionsConfig, ActionConfig, CustomAction, StandardActionsConfig, ActionsDisplayConfig, ConfirmDialogConfig, ConfirmDialogInput, ActionContext, TooltipConfig, ButtonVariant, BadgeVariant, } from '../types/actions';
|
|
17
|
+
export type { DataTableActionsConfig, ActionConfig, CustomAction, StandardActionsConfig, ActionsDisplayConfig, ConfirmDialogConfig, ConfirmDialogInput, ConfirmDialogOption, ActionContext, TooltipConfig, ButtonVariant, BadgeVariant, } from '../types/actions';
|
|
16
18
|
export { VirtualDataTable } from '../data/VirtualDataTable';
|
|
17
19
|
export { withScope } from '../utils/with-scope';
|
|
18
20
|
export type { CrudScope } from '../utils/with-scope';
|
|
@@ -20,6 +22,8 @@ export { SubList } from '../components/crud/sub-list';
|
|
|
20
22
|
export type { SubListField, SubListProps } from '../components/crud/sub-list';
|
|
21
23
|
export { EmptyState } from '../components/crud/empty-state';
|
|
22
24
|
export type { EmptyStateProps } from '../components/crud/empty-state';
|
|
25
|
+
export { QueryErrorState } from '../components/utilities/QueryErrorState';
|
|
26
|
+
export type { QueryErrorStateProps } from '../components/utilities/QueryErrorState';
|
|
23
27
|
export { DataBoundary } from '../components/data/DataBoundary';
|
|
24
28
|
export type { DataBoundaryProps } from '../components/data/DataBoundary';
|
|
25
29
|
export { PopoverSelector } from '../components/selectors';
|
|
@@ -4,6 +4,7 @@ import { InfiniteList } from "../data/InfiniteList.js";
|
|
|
4
4
|
import { useInfiniteListQuery } from "../hooks/useInfiniteListQuery.js";
|
|
5
5
|
import { MobileCard } from "../data/MobileCard.js";
|
|
6
6
|
import { ExportMenu } from "../data/ExportMenu.js";
|
|
7
|
+
import { fetchAllPages } from "../data/fetch-all-pages.js";
|
|
7
8
|
import {
|
|
8
9
|
exportToExcel,
|
|
9
10
|
exportToCSV,
|
|
@@ -14,6 +15,7 @@ import { VirtualDataTable } from "../data/VirtualDataTable.js";
|
|
|
14
15
|
import { withScope } from "../utils/with-scope.js";
|
|
15
16
|
import { SubList } from "../components/crud/sub-list.js";
|
|
16
17
|
import { EmptyState } from "../components/crud/empty-state.js";
|
|
18
|
+
import { QueryErrorState } from "../components/utilities/QueryErrorState.js";
|
|
17
19
|
import { DataBoundary } from "../components/data/DataBoundary.js";
|
|
18
20
|
import { PopoverSelector } from "../components/selectors/index.js";
|
|
19
21
|
import { RichSelector, RichSelectorField } from "../components/selectors/index.js";
|
|
@@ -41,6 +43,7 @@ export {
|
|
|
41
43
|
InfiniteList,
|
|
42
44
|
MobileCard,
|
|
43
45
|
PopoverSelector,
|
|
46
|
+
QueryErrorState,
|
|
44
47
|
ReportTable,
|
|
45
48
|
RichSelector,
|
|
46
49
|
RichSelectorField,
|
|
@@ -51,6 +54,7 @@ export {
|
|
|
51
54
|
exportToCSV,
|
|
52
55
|
exportToExcel,
|
|
53
56
|
exportToPDF,
|
|
57
|
+
fetchAllPages,
|
|
54
58
|
useInfiniteListQuery,
|
|
55
59
|
withScope
|
|
56
60
|
};
|
|
@@ -3,8 +3,8 @@ export type { IconName } from '../utils/icon';
|
|
|
3
3
|
export type { PaginationParams, PaginatedResponse, SortField, } from '../types/pagination';
|
|
4
4
|
export { createPaginatedResponse, asQueryFn } from '../types/pagination';
|
|
5
5
|
export type { FilterOption, ColumnFilterConfig } from '../types/filters';
|
|
6
|
-
export type { ModuleMetadata, ListConfig, CrudColumnDef, FormConfig, QueryConfig, MutationConfig, MutationsConfig, DialogConfig, DialogsConfig, PagesConfig, CrudConfig, CrudConfigWithAnyForm, CrudPermissions, ToolbarFilterOption, ToolbarFilterConfig, ToolbarConfig, } from '../types/crud';
|
|
6
|
+
export type { ModuleMetadata, ListConfig, ExportAllOptions, CrudColumnDef, FormConfig, QueryConfig, MutationConfig, MutationsConfig, DialogConfig, DialogsConfig, PagesConfig, CrudConfig, CrudConfigWithAnyForm, CrudPermissions, ToolbarFilterOption, ToolbarFilterConfig, ToolbarConfig, } from '../types/crud';
|
|
7
7
|
export type { ColorPreset, StatItem, HeaderBadgeConfig, HeaderStatsConfig, DialogHeaderConfig, DialogHeaderProps, StatsGridProps, } from '../types/dialog-header';
|
|
8
8
|
export type { MenuItem, SingleMenuItem, GroupMenuItem, SeparatorMenuItem, MenuItemType, MenuVariant, IconComponent, } from '../types/menu';
|
|
9
9
|
export type { Density, GapSize, DialogSize, DialogHeight, FieldLayout, CardFieldLayout, } from '../utils/spacing';
|
|
10
|
-
export declare const version = "1.
|
|
10
|
+
export declare const version = "1.3.0";
|
|
@@ -15,6 +15,9 @@ export declare const data: {
|
|
|
15
15
|
noDataToExport: string;
|
|
16
16
|
exportSuccess: string;
|
|
17
17
|
exportError: string;
|
|
18
|
+
exportFetching: string;
|
|
19
|
+
exportCancelled: string;
|
|
20
|
+
exportTruncated: string;
|
|
18
21
|
scopeAll: string;
|
|
19
22
|
scopeSelected: string;
|
|
20
23
|
scopeCurrentPage: string;
|
|
@@ -16,6 +16,9 @@ var data = {
|
|
|
16
16
|
noDataToExport: "No data to export",
|
|
17
17
|
exportSuccess: "{format} exported successfully ({scope})",
|
|
18
18
|
exportError: "Error exporting data",
|
|
19
|
+
exportFetching: "Fetching records to export: {loaded, number} of {total, number}",
|
|
20
|
+
exportCancelled: "Export cancelled",
|
|
21
|
+
exportTruncated: "Exported the first {count, number} of {total, number} records (export limit)",
|
|
19
22
|
scopeAll: "all data",
|
|
20
23
|
scopeSelected: "{count, plural, one {# row selected} other {# rows selected}}",
|
|
21
24
|
scopeCurrentPage: "current page",
|
|
@@ -211,6 +211,9 @@ export declare const en: {
|
|
|
211
211
|
noDataToExport: string;
|
|
212
212
|
exportSuccess: string;
|
|
213
213
|
exportError: string;
|
|
214
|
+
exportFetching: string;
|
|
215
|
+
exportCancelled: string;
|
|
216
|
+
exportTruncated: string;
|
|
214
217
|
scopeAll: string;
|
|
215
218
|
scopeSelected: string;
|
|
216
219
|
scopeCurrentPage: string;
|
|
@@ -402,6 +405,8 @@ export declare const en: {
|
|
|
402
405
|
invalidOption: string;
|
|
403
406
|
tooSmallString: string;
|
|
404
407
|
tooBigString: string;
|
|
408
|
+
charactersMissing: string;
|
|
409
|
+
charactersOver: string;
|
|
405
410
|
tooSmallNumber: string;
|
|
406
411
|
tooBigNumber: string;
|
|
407
412
|
tooSmallArray: string;
|
|
@@ -9,6 +9,8 @@ var validation = {
|
|
|
9
9
|
invalidOption: "Invalid option",
|
|
10
10
|
tooSmallString: "{min, plural, one {At least # character} other {At least # characters}}",
|
|
11
11
|
tooBigString: "{max, plural, one {At most # character} other {At most # characters}}",
|
|
12
|
+
charactersMissing: "{count, plural, one {# more character needed} other {# more characters needed}}",
|
|
13
|
+
charactersOver: "{count, plural, one {# character too many} other {# characters too many}}",
|
|
12
14
|
tooSmallNumber: "Must be at least {min, number}",
|
|
13
15
|
tooBigNumber: "Must be at most {max, number}",
|
|
14
16
|
tooSmallArray: "{min, plural, one {Select at least # item} other {Select at least # items}}",
|
|
@@ -15,6 +15,9 @@ export declare const data: {
|
|
|
15
15
|
noDataToExport: string;
|
|
16
16
|
exportSuccess: string;
|
|
17
17
|
exportError: string;
|
|
18
|
+
exportFetching: string;
|
|
19
|
+
exportCancelled: string;
|
|
20
|
+
exportTruncated: string;
|
|
18
21
|
scopeAll: string;
|
|
19
22
|
scopeSelected: string;
|
|
20
23
|
scopeCurrentPage: string;
|