@telamonjs/ui 1.2.1 → 1.3.1

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 (62) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +1 -1
  3. package/dist/components/data/DataTableActions.js +1 -0
  4. package/dist/components/data/action-access.d.ts +9 -2
  5. package/dist/components/data/action-access.js +10 -3
  6. package/dist/components/dialog/CrudDialogShell.d.ts +2 -0
  7. package/dist/components/dialog/CrudDialogShell.js +9 -7
  8. package/dist/components/dialog/DialogLoadingState.d.ts +16 -0
  9. package/dist/components/dialog/DialogLoadingState.js +16 -0
  10. package/dist/components/dialog/confirm-action-dialog.d.ts +12 -4
  11. package/dist/components/dialog/confirm-action-dialog.js +156 -82
  12. package/dist/components/dialog/create-dialog.js +1 -12
  13. package/dist/components/dialog/edit-dialog.js +5 -4
  14. package/dist/components/dialog/index.d.ts +1 -1
  15. package/dist/components/dialog/index.js +1 -2
  16. package/dist/components/dialog/view-dialog.js +5 -4
  17. package/dist/components/utilities/QueryErrorState.d.ts +47 -0
  18. package/dist/components/utilities/QueryErrorState.js +85 -0
  19. package/dist/data/DataTable.d.ts +2 -2
  20. package/dist/data/DataTable.js +2 -0
  21. package/dist/data/ExportMenu.d.ts +30 -3
  22. package/dist/data/ExportMenu.js +69 -5
  23. package/dist/data/datatable/TableToolbar.d.ts +3 -2
  24. package/dist/data/datatable/TableToolbar.js +30 -13
  25. package/dist/data/datatable/types.d.ts +9 -0
  26. package/dist/data/fetch-all-pages.d.ts +30 -0
  27. package/dist/data/fetch-all-pages.js +44 -0
  28. package/dist/exports/data-crud.d.ts +7 -3
  29. package/dist/exports/data-crud.js +4 -0
  30. package/dist/exports/types-constants.d.ts +2 -2
  31. package/dist/exports/types-constants.js +1 -1
  32. package/dist/i18n/messages/en/data.d.ts +3 -0
  33. package/dist/i18n/messages/en/data.js +3 -0
  34. package/dist/i18n/messages/en/index.d.ts +5 -0
  35. package/dist/i18n/messages/en/validation.d.ts +2 -0
  36. package/dist/i18n/messages/en/validation.js +2 -0
  37. package/dist/i18n/messages/es/data.d.ts +3 -0
  38. package/dist/i18n/messages/es/data.js +3 -0
  39. package/dist/i18n/messages/es/index.d.ts +5 -0
  40. package/dist/i18n/messages/es/validation.d.ts +2 -0
  41. package/dist/i18n/messages/es/validation.js +2 -0
  42. package/dist/i18n/messages/pt-BR/data.d.ts +3 -0
  43. package/dist/i18n/messages/pt-BR/data.js +3 -0
  44. package/dist/i18n/messages/pt-BR/index.d.ts +5 -0
  45. package/dist/i18n/messages/pt-BR/validation.d.ts +2 -0
  46. package/dist/i18n/messages/pt-BR/validation.js +2 -0
  47. package/dist/i18n/use-t.d.ts +5 -0
  48. package/dist/pages/ListPage.js +9 -13
  49. package/dist/pages/list-page/ListPageTable.d.ts +4 -2
  50. package/dist/pages/list-page/ListPageTable.js +3 -3
  51. package/dist/pages/list-page/ListPageToolbar.d.ts +4 -1
  52. package/dist/pages/list-page/ListPageToolbar.js +10 -4
  53. package/dist/pages/list-page/apply-crud-permissions.d.ts +4 -1
  54. package/dist/pages/list-page/apply-crud-permissions.js +20 -3
  55. package/dist/pages/list-page/types.d.ts +2 -16
  56. package/dist/pages/list-page/useListPageExport.d.ts +24 -0
  57. package/dist/pages/list-page/useListPageExport.js +54 -0
  58. package/dist/types/actions.d.ts +43 -4
  59. package/dist/types/crud.d.ts +48 -2
  60. package/package.json +1 -1
  61. package/dist/components/dialog/DialogErrorState.d.ts +0 -44
  62. package/dist/components/dialog/DialogErrorState.js +0 -57
@@ -22,7 +22,8 @@ import {
22
22
  getDialogClassName,
23
23
  getSheetClassName
24
24
  } from "../../utils/spacing.js";
25
- import { DialogErrorState, DialogLoadingState } from "./DialogErrorState.js";
25
+ import { DialogLoadingState } from "./DialogLoadingState.js";
26
+ import { QueryErrorState } from "../utilities/QueryErrorState.js";
26
27
  import { logger } from "../../utils/logger.js";
27
28
  import { createHeaderRenderer } from "./DialogHeaderContent.js";
28
29
  import { CrudDialogShell } from "./CrudDialogShell.js";
@@ -51,7 +52,7 @@ function ViewDialog({
51
52
  }) {
52
53
  const t = useTelamonjsT();
53
54
  const renderHeader = renderHeaderProp || (headerConfig ? createHeaderRenderer(headerConfig, "view") : void 0);
54
- const { data, isLoading, error, refetchSilent } = useDialogData(
55
+ const { data, isLoading, error, refetch, refetchSilent } = useDialogData(
55
56
  id,
56
57
  fetchAction,
57
58
  open
@@ -101,7 +102,7 @@ function ViewDialog({
101
102
  return /* @__PURE__ */ jsx(DialogLoadingState, {});
102
103
  }
103
104
  if (error) {
104
- return /* @__PURE__ */ jsx(DialogErrorState, { error });
105
+ return /* @__PURE__ */ jsx(QueryErrorState, { error, onRetry: refetch, className: "my-8" });
105
106
  }
106
107
  if (!data || !id) {
107
108
  return null;
@@ -185,7 +186,7 @@ function ViewDialog({
185
186
  dialogClassName,
186
187
  hasCustomHeader: false
187
188
  });
188
- const desktopStatus = isLoading || error || !data ? { sizeClass, isLoading, error } : void 0;
189
+ const desktopStatus = isLoading || error || !data ? { sizeClass, isLoading, error, onRetry: refetch } : void 0;
189
190
  const hasCustomHeader = Boolean(renderHeader && data);
190
191
  return /* @__PURE__ */ jsx(
191
192
  CrudDialogShell,
@@ -0,0 +1,47 @@
1
+ import type { I18nText } from '../../i18n/msg';
2
+ export interface QueryErrorStateProps {
3
+ /**
4
+ * What failed: an `Error`, a string, or any object carrying a string
5
+ * `message` (API client errors). Its message becomes the description unless
6
+ * `description` is given; anything without a usable message shows the title only.
7
+ */
8
+ error?: unknown;
9
+ /** Headline. Default: localized "Failed to load data". */
10
+ title?: I18nText;
11
+ /** Replaces the message extracted from `error` (e.g. a friendlier text). */
12
+ description?: I18nText;
13
+ /**
14
+ * Shows the retry button. Called with no arguments, so `onRetry={refetch}` is
15
+ * safe; when it returns a promise the button stays pending until it settles.
16
+ */
17
+ onRetry?: () => unknown;
18
+ /** Caller-driven pending state, e.g. `retrying={query.isFetching}`. */
19
+ retrying?: boolean;
20
+ /** Retry button label. Default: localized "Try again". */
21
+ retryLabel?: I18nText;
22
+ className?: string;
23
+ }
24
+ /**
25
+ * QueryErrorState - error state of a query, with an optional "Try again".
26
+ *
27
+ * The error UI for screens that run their own `useQuery` (and the one the CRUD
28
+ * dialogs use): a destructive alert with a localized title, the error's message
29
+ * and a retry button that stays pending while `onRetry` runs.
30
+ *
31
+ * @example
32
+ * ```tsx
33
+ * const { data, error, isError, refetch } = useQuery(...)
34
+ * if (isError) return <QueryErrorState error={error} onRetry={refetch} />
35
+ * ```
36
+ *
37
+ * @example
38
+ * Context-specific title, several queries retried together:
39
+ * ```tsx
40
+ * <QueryErrorState
41
+ * title="Could not load the grading sheet"
42
+ * error={sheet.error ?? files.error}
43
+ * onRetry={() => Promise.all([sheet.refetch(), files.refetch()])}
44
+ * />
45
+ * ```
46
+ */
47
+ export declare function QueryErrorState({ error, title, description, onRetry, retrying, retryLabel, className, }: QueryErrorStateProps): import("react").JSX.Element;
@@ -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
+ };
@@ -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;
@@ -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?: Array<'excel' | 'csv' | 'pdf'>;
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: 'excel' | 'csv' | 'pdf', rows: T[], columns: ColumnDef<T>[]) => Promise<void> | void;
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;
@@ -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
- dataToExport = data;
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(DropdownMenuSub, { children: [
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
- data.length > 0 && /* @__PURE__ */ jsx("span", { className: "ml-auto text-xs text-muted-foreground", children: t("data.recordCount", { count: data.length }) })
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
- enableExport && !onExport && /* @__PURE__ */ jsx(
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.2.1";
10
+ export declare const version = "1.3.1";