@telamonjs/ui 1.0.3 → 1.1.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.
Files changed (87) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/dist/components/business/CalendarWithEvents.d.ts +7 -1
  3. package/dist/components/business/CalendarWithEvents.js +8 -9
  4. package/dist/components/cards/stat-card.js +22 -3
  5. package/dist/components/charts/BarChart.d.ts +12 -1
  6. package/dist/components/charts/BarChart.js +6 -1
  7. package/dist/components/crud/crud-field.js +1 -0
  8. package/dist/components/data/DataTableActions.js +89 -85
  9. package/dist/components/data/action-access.d.ts +22 -0
  10. package/dist/components/data/action-access.js +33 -0
  11. package/dist/components/data/report-table.d.ts +3 -1
  12. package/dist/components/data/report-table.js +2 -1
  13. package/dist/components/dialog/DialogHeaderContent.js +1 -1
  14. package/dist/components/dialog/confirm-action-dialog.d.ts +54 -0
  15. package/dist/components/dialog/confirm-action-dialog.js +182 -0
  16. package/dist/components/dialog/crud-view-dialog.d.ts +7 -3
  17. package/dist/components/dialog/crud-view-dialog.js +3 -2
  18. package/dist/components/dialog/view-dialog.d.ts +9 -1
  19. package/dist/components/dialog/view-dialog.js +8 -3
  20. package/dist/components/forms/BaseForm.js +4 -3
  21. package/dist/components/forms/WizardForm.js +3 -2
  22. package/dist/components/forms/ZustandForm.js +5 -4
  23. package/dist/components/forms/admin-form/field-group.js +5 -4
  24. package/dist/components/forms/admin-form/visibility.js +2 -0
  25. package/dist/components/forms/grid-classes.d.ts +4 -0
  26. package/dist/components/forms/grid-classes.js +40 -0
  27. package/dist/components/forms/validators/config-validator.js +2 -1
  28. package/dist/components/toolbar/TabToolbar.d.ts +6 -1
  29. package/dist/components/toolbar/TabToolbar.js +5 -3
  30. package/dist/exports/data-crud.d.ts +1 -1
  31. package/dist/exports/pages-dialogs.d.ts +3 -1
  32. package/dist/exports/pages-dialogs.js +2 -0
  33. package/dist/exports/types-constants.d.ts +2 -2
  34. package/dist/exports/types-constants.js +1 -1
  35. package/dist/field-system/mask-presets.d.ts +5 -0
  36. package/dist/field-system/mask-presets.js +18 -0
  37. package/dist/field-system/renderers/advanced-renderers.js +2 -4
  38. package/dist/field-system/renderers/textarea-renderers.js +1 -1
  39. package/dist/hooks/useCrudMutations.js +28 -16
  40. package/dist/pages/ListPage.js +23 -14
  41. package/dist/pages/list-page/ListPageDialogs.d.ts +8 -3
  42. package/dist/pages/list-page/ListPageDialogs.js +36 -7
  43. package/dist/pages/list-page/ListPageToolbar.js +10 -14
  44. package/dist/pages/list-page/apply-crud-permissions.d.ts +21 -0
  45. package/dist/pages/list-page/apply-crud-permissions.js +34 -0
  46. package/dist/pages/list-page/types.d.ts +21 -2
  47. package/dist/pages/list-page/useListPageData.d.ts +3 -1
  48. package/dist/pages/list-page/useListPageData.js +2 -1
  49. package/dist/pages/list-page/useListPageDialogs.d.ts +1 -0
  50. package/dist/pages/list-page/useListPageDialogs.js +13 -4
  51. package/dist/pages/list-page/useListPageToolbar.d.ts +8 -5
  52. package/dist/pages/list-page/useListPageToolbar.js +14 -10
  53. package/dist/queue/components/FailureGroupsModal.js +4 -3
  54. package/dist/queue/components/JobConfigDialog.js +9 -1
  55. package/dist/queue/components/JobDetailModal.js +3 -2
  56. package/dist/queue/components/JobDetailPage.js +10 -2
  57. package/dist/queue/components/JobEventModal.js +3 -2
  58. package/dist/queue/components/QueueTabbedDashboard.d.ts +25 -2
  59. package/dist/queue/components/QueueTabbedDashboard.js +37 -5
  60. package/dist/queue/components/QueuesTable.d.ts +3 -2
  61. package/dist/queue/components/QueuesTable.js +31 -27
  62. package/dist/queue/components/job-shared.d.ts +2 -0
  63. package/dist/queue/components/job-shared.js +2 -0
  64. package/dist/queue/components/jobs-history-modal/fullscreen-modal.js +3 -2
  65. package/dist/queue/components/jobs-history-modal/job-detail-modal.js +3 -2
  66. package/dist/queue/components/jobs-list-modal/job-row.js +3 -2
  67. package/dist/queue/components/labels-context.d.ts +31 -0
  68. package/dist/queue/components/labels-context.js +34 -0
  69. package/dist/queue/components/module-icon.d.ts +9 -0
  70. package/dist/queue/components/module-icon.js +14 -0
  71. package/dist/queue/components/tabs/ConfiguracaoTab.d.ts +2 -1
  72. package/dist/queue/components/tabs/ConfiguracaoTab.js +13 -9
  73. package/dist/queue/components/tabs/HistoricoTab.js +4 -3
  74. package/dist/queue/components/tabs/TempoRealTab.d.ts +8 -3
  75. package/dist/queue/components/tabs/TempoRealTab.js +13 -7
  76. package/dist/queue/hooks/use-queue-events-timeline.d.ts +19 -1
  77. package/dist/queue/hooks/use-queue-events-timeline.js +23 -3
  78. package/dist/server/pagination/factory.js +8 -1
  79. package/dist/server/pagination/types.d.ts +6 -0
  80. package/dist/server/pagination/utils.d.ts +13 -0
  81. package/dist/server/pagination/utils.js +27 -16
  82. package/dist/types/actions.d.ts +43 -14
  83. package/dist/types/crud.d.ts +47 -6
  84. package/dist/types/dialog-header.d.ts +2 -2
  85. package/dist/types/forms/admin-form.d.ts +8 -1
  86. package/dist/utils/with-scope.js +5 -3
  87. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,58 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c3537bb: New public `ConfirmActionDialog`: the confirmation behind `confirmDialog` on row and menu actions, now exported for any button. It stays open while `onConfirm` is pending (spinner, disabled buttons, no dismiss), closes when it resolves, and stays open showing the error when it rejects (resolve `false` to stay open without a message). It also renders optional `inputs`.
8
+
9
+ `confirmDialog.inputs` (`ConfirmDialogInput`: `text`, `textarea`, `select`) were typed but never rendered; they now render, required ones block the confirm while empty, and their values reach the action as a second argument — `handler(row, { inputs })` / `onClick(row, { inputs })` (`ActionContext`), passed only when inputs are declared so existing handlers keep receiving the row alone. `ConfirmDialogInput.label` accepts `I18nText`. A row action whose confirmed run fails keeps its error toast and now leaves the dialog open for a retry instead of closing it.
10
+
11
+ - 500114c: `CrudConfig` gains an optional `permissions` model (`CrudPermissions`): `create`, `edit`, `delete` and `view` name the permission each operation needs, checked with `can` (e.g. `perm => checker.can(user, perm)` from `@telamonjs/permissions`, so bypass roles and wildcards work) or, without it, against `actionsConfig.userPermissions`. It gates the "New" button and the create dialog, the row view/edit/delete (including the edit/view actions `ListPage` injects for `dialogs.edit`/`dialogs.view`), the view dialog footer, the edit dialog, the `?create`/`?edit`/`?view` deep links and `dialogs.view.portal.onSaveSection` (also in `CrudViewDialog`). `DataTableActionsConfig` gains `can`, which decides every action `permission` instead of the exact lookup in `userPermissions`.
12
+
13
+ `CrudConfig.form` and `FormConfig.validation` are now optional. A read-only list drops `form` (no more `validation: undefined as any`): `ListPage` then offers no "New" button and no create or edit dialog. Configs without `permissions` and with a `form` behave exactly as before.
14
+
15
+ - a936899: Queue dashboard: module and job labels (#7).
16
+
17
+ - `QueueTabbedDashboard` takes `moduleLabels` (module key → `I18nText`), used as the group titles in the Real-time and Configuration tabs. Its key order is the group order.
18
+ - Job labels prefer the job contract's `displayName` over the formatted job name, in queue rows, timeline and history rows, job details and modal titles. A new `jobLabel` prop overrides both.
19
+ - `moduleIcons` also accepts React nodes and icon components (e.g. Lucide icons), not only emoji strings.
20
+ - Both tabs now order module groups the same way (`moduleLabels` order, then alphabetically). The queues table has fixed column widths, so columns line up across groups.
21
+ - The "Disabled"/"Inactive" job badges are neutral instead of the blue `secondary` variant.
22
+
23
+ - c5bf250: `ListPage`'s `toolbarContent` also accepts a function that receives the list's current query (`ListQueryState`: `search`, `filters`, `sorting` and the `params` the list passes to `query.queryFn`), so an app's own export/PDF button can fetch exactly what the list shows. The plain `ReactNode` form keeps working.
24
+ - dd1a1a4: Toolbar filters (`list.toolbar.filters`) gain `allValue`, the explicit "no filter" value: it is dropped from the query, shown when nothing is selected and targeted by resets (chips, toggling a button off). With it, the first option is an ordinary option (rendered as a button), `'todos'`/`'all'` are ordinary values, and `defaultValue` applies even when it equals the first option. `TabToolbar.FilterButtons` accepts the same `allValue`. Filters without `allValue` keep the previous rules.
25
+ - bcb74d5: Close small component gaps found in consumer workarounds:
26
+
27
+ - `masked` fields: `maskType` gains the `'cpf'`, `'cnpj'` and `'cep'` presets next to `'tel'` and is typed as that union (any other string still falls back to `mask`).
28
+ - `textarea` fields: optional `rows` (default 4).
29
+ - `StatCard`: truncated label, subtitle and `tinted` value carry their full text in a `title` tooltip.
30
+ - `BarChart`: `allowDecimals` for the value axis and `categoryAxisWidth` for the category axis in `vertical` layout.
31
+ - `CalendarWithEvents`: `onMonthChange(month)` fires with the first day of the month the user navigates to.
32
+ - `ReportTable`: `showFooter` (default `true`) hides the "Showing X of Y records" line.
33
+ - Form grids (`AdminForm`, `BaseForm`, `ZustandForm`, `WizardForm`) collapse to one column below `sm`, and every `grid`/`span` value now ships as a static class (`col-span-3`/`col-span-4` were never generated). Desktop layout is unchanged.
34
+ - `useCrudMutations`: the mutation resolves after the invalidated list's first refetch attempt, so dialogs close over a fresh list; a failing refetch still settles on its first failure instead of waiting for retries.
35
+ - Dialog header `badge.getLabel` may return an `I18nText` (a `msg()` is resolved), like `badge.labels`.
36
+
37
+ ### Patch Changes
38
+
39
+ - a461d05: The view dialog footer now follows the row actions: **Edit** is hidden when `standard.edit` is `false`, and both **Edit** and **Delete** honor the action's `permission` (against `userPermissions`) and its `visible`/`enabled` for the record — evaluated against the list row, or the fetched record on a deep link. Before, the footer offered Edit whenever `dialogs.edit` existed and Delete whenever `standard.delete` was set, so users who could not edit or delete a row from the table still got the buttons in the dialog. `ViewDialog` gains the optional `canEdit`/`canDelete` gates (also accepted by `CrudViewDialog`'s `footer`).
40
+
41
+ ## 1.0.4
42
+
43
+ ### Patch Changes
44
+
45
+ - 7177dfb: Server pagination, row actions, queue polling and form-path hardening:
46
+
47
+ - `createPaginatedService`: `baseWhere`, visibility rules and search/filters are now always combined with `AND`. Before, a `baseWhere` with its own `AND` replaced the search conditions, and a visibility rule with a top-level `AND`/`OR` dropped `baseWhere`'s other keys (e.g. `deletedAt: null`), which could show hidden rows.
48
+ - `createPaginatedService`: an invalid `sortOrder` falls back to `defaultOrderDirection` instead of reaching Prisma, and the new optional `sortableFields` option ignores any `sortBy` outside the list (the default sort applies).
49
+ - Row actions in the "…" menu now honour `confirmDialog` (including a standard delete moved to the menu by `display.mode: 'dropdown'`). They used to run straight away.
50
+ - `QueueTabbedDashboard`: the real-time timeline polls only as a 30s safety net while SSE is connected and stops polling while another tab is open. The new optional `pollInterval` prop (default 2000 ms) sets the interval used while SSE is down.
51
+ - Form visibility helpers ignore field paths that go through `__proto__`, `constructor` or `prototype`.
52
+
53
+ - Updated dependencies [a599b51]
54
+ - @telamonjs/logger@1.0.2
55
+
3
56
  ## 1.0.3
4
57
 
5
58
  ### Patch Changes
@@ -18,6 +18,12 @@ export interface CalendarWithEventsProps {
18
18
  onEventClick?: (event: CalendarEvent) => void;
19
19
  className?: string;
20
20
  defaultDate?: Date;
21
+ /**
22
+ * Called with the first day of the newly shown month whenever the user
23
+ * navigates (previous/next/today) — fetch that month's events here. Not
24
+ * called on mount: load the `defaultDate` month yourself
25
+ */
26
+ onMonthChange?: (month: Date) => void;
21
27
  }
22
28
  /**
23
29
  * CalendarWithEvents - Calendar with events and navigation
@@ -37,4 +43,4 @@ export interface CalendarWithEventsProps {
37
43
  * />
38
44
  * ```
39
45
  */
40
- export declare function CalendarWithEvents({ events, onDateClick, onEventClick, className, defaultDate, }: CalendarWithEventsProps): import("react").JSX.Element;
46
+ export declare function CalendarWithEvents({ events, onDateClick, onEventClick, className, defaultDate, onMonthChange, }: CalendarWithEventsProps): import("react").JSX.Element;
@@ -28,7 +28,8 @@ function CalendarWithEvents({
28
28
  onDateClick,
29
29
  onEventClick,
30
30
  className,
31
- defaultDate = /* @__PURE__ */ new Date()
31
+ defaultDate = /* @__PURE__ */ new Date(),
32
+ onMonthChange
32
33
  }) {
33
34
  const t = useTelamonjsT();
34
35
  const dateFnsLocale = useDateFnsLocale();
@@ -53,15 +54,13 @@ function CalendarWithEvents({
53
54
  const getEventsForDay = (date) => {
54
55
  return events.filter((event) => isSameDay(event.date, date));
55
56
  };
56
- const handlePrevMonth = () => {
57
- setCurrentMonth(subMonths(currentMonth, 1));
58
- };
59
- const handleNextMonth = () => {
60
- setCurrentMonth(addMonths(currentMonth, 1));
61
- };
62
- const handleToday = () => {
63
- setCurrentMonth(/* @__PURE__ */ new Date());
57
+ const goToMonth = (month) => {
58
+ setCurrentMonth(month);
59
+ if (!isSameMonth(month, currentMonth)) onMonthChange?.(startOfMonth(month));
64
60
  };
61
+ const handlePrevMonth = () => goToMonth(subMonths(currentMonth, 1));
62
+ const handleNextMonth = () => goToMonth(addMonths(currentMonth, 1));
63
+ const handleToday = () => goToMonth(/* @__PURE__ */ new Date());
65
64
  return /* @__PURE__ */ jsxs(Card, { className, children: [
66
65
  /* @__PURE__ */ jsx(CardHeader, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
67
66
  /* @__PURE__ */ jsx(CardTitle, { className: "text-xl", children: format(currentMonth, "MMMM yyyy", { locale: dateFnsLocale }) }),
@@ -35,6 +35,7 @@ var TintedCard = memo(function TintedCard2({
35
35
  const { number } = useFormat();
36
36
  const Icon = resolveIcon(icon);
37
37
  const styles = cardColors.tinted[color];
38
+ const shownValue = formatValue(value, formatNumber, number);
38
39
  const isMini = size === "mini";
39
40
  const isCompact = size === "compact" || isMini;
40
41
  return /* @__PURE__ */ jsxs(
@@ -86,7 +87,8 @@ var TintedCard = memo(function TintedCard2({
86
87
  styles.value,
87
88
  isMini ? "text-xs" : isCompact ? "text-sm" : "text-lg"
88
89
  ),
89
- children: formatValue(value, formatNumber, number)
90
+ title: shownValue,
91
+ children: shownValue
90
92
  }
91
93
  ),
92
94
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
@@ -102,7 +104,14 @@ var TintedCard = memo(function TintedCard2({
102
104
  ),
103
105
  pulse && Number(value) > 0 && /* @__PURE__ */ jsx(PulseDot, {})
104
106
  ] }),
105
- subtitle && !isMini && /* @__PURE__ */ jsx("p", { className: "text-[10px] text-muted-foreground truncate", children: subtitle })
107
+ subtitle && !isMini && /* @__PURE__ */ jsx(
108
+ "p",
109
+ {
110
+ className: "text-[10px] text-muted-foreground truncate",
111
+ title: subtitle,
112
+ children: subtitle
113
+ }
114
+ )
106
115
  ] })
107
116
  ]
108
117
  }
@@ -158,13 +167,21 @@ var OutlinedCard = memo(function OutlinedCard2({
158
167
  "text-[11px] font-medium text-muted-foreground",
159
168
  wrapLabel ? "break-words" : "truncate"
160
169
  ),
170
+ title: wrapLabel ? void 0 : label,
161
171
  children: label
162
172
  }
163
173
  ),
164
174
  pulse && Number(value) > 0 && /* @__PURE__ */ jsx(PulseDot, {})
165
175
  ] }),
166
176
  /* @__PURE__ */ jsx("p", { className: "text-lg font-bold tabular-nums leading-tight text-foreground", children: formatValue(value, formatNumber, number) }),
167
- subtitle && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground truncate", children: subtitle }),
177
+ subtitle && /* @__PURE__ */ jsx(
178
+ "p",
179
+ {
180
+ className: "text-xs text-muted-foreground truncate",
181
+ title: subtitle,
182
+ children: subtitle
183
+ }
184
+ ),
168
185
  badge && /* @__PURE__ */ jsx(
169
186
  Badge,
170
187
  {
@@ -259,6 +276,7 @@ var AccentCard = memo(function AccentCard2({
259
276
  wrapLabel ? "break-words" : "truncate",
260
277
  isCompact ? "text-[11px]" : "text-sm"
261
278
  ),
279
+ title: wrapLabel ? void 0 : label,
262
280
  children: label
263
281
  }
264
282
  ),
@@ -271,6 +289,7 @@ var AccentCard = memo(function AccentCard2({
271
289
  "text-muted-foreground truncate",
272
290
  isCompact ? "text-[10px]" : "text-xs"
273
291
  ),
292
+ title: subtitle,
274
293
  children: subtitle
275
294
  }
276
295
  ),
@@ -13,6 +13,17 @@ export interface BarChartProps {
13
13
  xAxisLabel?: string;
14
14
  yAxisLabel?: string;
15
15
  layout?: 'horizontal' | 'vertical';
16
+ /**
17
+ * Whether the value axis may show fractional ticks (recharts
18
+ * `allowDecimals`). Pass `false` for counts. Default: `true`
19
+ */
20
+ allowDecimals?: boolean;
21
+ /**
22
+ * Width in px of the category axis (the `name` labels) in `vertical`
23
+ * layout — widen it for long labels. In `horizontal` layout the category
24
+ * axis is the X axis and this is ignored. Default: recharts' 60
25
+ */
26
+ categoryAxisWidth?: number;
16
27
  }
17
28
  /**
18
29
  * BarChart - Responsive bar chart
@@ -29,4 +40,4 @@ export interface BarChartProps {
29
40
  * />
30
41
  * ```
31
42
  */
32
- export declare function BarChart({ data, dataKeys, colors, height, showGrid, showLegend, className, xAxisLabel, yAxisLabel, layout, }: BarChartProps): import("react").JSX.Element;
43
+ export declare function BarChart({ data, dataKeys, colors, height, showGrid, showLegend, className, xAxisLabel, yAxisLabel, layout, allowDecimals, categoryAxisWidth, }: BarChartProps): import("react").JSX.Element;
@@ -37,7 +37,9 @@ function BarChart({
37
37
  className,
38
38
  xAxisLabel,
39
39
  yAxisLabel,
40
- layout = "horizontal"
40
+ layout = "horizontal",
41
+ allowDecimals = true,
42
+ categoryAxisWidth
41
43
  }) {
42
44
  return /* @__PURE__ */ jsx("div", { className: cn("w-full", className), children: /* @__PURE__ */ jsx(ResponsiveContainer, { width: "100%", height, children: /* @__PURE__ */ jsxs(
43
45
  RechartsBarChart,
@@ -67,6 +69,7 @@ function BarChart({
67
69
  /* @__PURE__ */ jsx(
68
70
  YAxis,
69
71
  {
72
+ allowDecimals,
70
73
  label: yAxisLabel ? { value: yAxisLabel, angle: -90, position: "insideLeft" } : void 0
71
74
  }
72
75
  )
@@ -75,6 +78,7 @@ function BarChart({
75
78
  XAxis,
76
79
  {
77
80
  type: "number",
81
+ allowDecimals,
78
82
  label: xAxisLabel ? {
79
83
  value: xAxisLabel,
80
84
  position: "insideBottom",
@@ -87,6 +91,7 @@ function BarChart({
87
91
  {
88
92
  dataKey: "name",
89
93
  type: "category",
94
+ width: categoryAxisWidth,
90
95
  label: yAxisLabel ? { value: yAxisLabel, angle: -90, position: "insideLeft" } : void 0
91
96
  }
92
97
  )
@@ -59,6 +59,7 @@ function convertSingleField(field) {
59
59
  if (fieldObj.dependsOn) converted.dependsOn = fieldObj.dependsOn;
60
60
  if (fieldObj.mask) converted.mask = fieldObj.mask;
61
61
  if (fieldObj.maskType) converted.maskType = fieldObj.maskType;
62
+ if (fieldObj.rows) converted.rows = fieldObj.rows;
62
63
  if (fieldObj.uploadFn)
63
64
  converted.uploadFn = fieldObj.uploadFn;
64
65
  if (fieldObj.path) converted.path = fieldObj.path;
@@ -4,17 +4,7 @@
4
4
  import { MoreHorizontal } from "lucide-react";
5
5
  import { usePathname, useRouter } from "next/navigation";
6
6
  import React, { useCallback, useMemo, useState } from "react";
7
- import {
8
- AlertDialog,
9
- AlertDialogAction,
10
- AlertDialogCancel,
11
- AlertDialogContent,
12
- AlertDialogDescription,
13
- AlertDialogFooter,
14
- AlertDialogHeader,
15
- AlertDialogTitle,
16
- AlertDialogTrigger
17
- } from "../../ui/alert-dialog.js";
7
+ import { ConfirmActionDialog } from "../dialog/confirm-action-dialog.js";
18
8
  import { Badge } from "../../ui/badge.js";
19
9
  import { Button } from "../../ui/button.js";
20
10
  import {
@@ -26,6 +16,7 @@ import {
26
16
  } from "../../ui/dropdown-menu.js";
27
17
  import { toast } from "sonner";
28
18
  import { wasToasted } from "../../utils/toasted-error.js";
19
+ import { actionEnabled, actionGranted, actionVisible } from "./action-access.js";
29
20
  import { getIconFromName } from "../../utils/icon.js";
30
21
  import { TEST_IDS, getActionAccessibilityAttrs } from "../../utils/test-ids.js";
31
22
  import { useTelamonjsT, useText } from "../../i18n/use-t.js";
@@ -42,22 +33,23 @@ async function runAction({
42
33
  router,
43
34
  onActionComplete,
44
35
  onLoadingChange,
45
- onSettled,
36
+ ctx,
46
37
  text,
47
38
  fallbackError
48
39
  }) {
49
40
  onLoadingChange?.(true);
41
+ const args = (arg) => ctx ? [arg, ctx] : [arg];
50
42
  try {
51
43
  let result;
52
44
  if (action.href) {
53
45
  const href = typeof action.href === "function" ? action.href(row) : action.href;
54
46
  router.push(href);
55
- return;
47
+ return true;
56
48
  } else if (action.onClick) {
57
- result = await action.onClick(row);
49
+ result = await action.onClick(...args(row));
58
50
  } else if (action.handler) {
59
51
  const handlerArg = actionId === "delete" ? row.id : row;
60
- result = await action.handler(handlerArg);
52
+ result = await action.handler(...args(handlerArg));
61
53
  }
62
54
  if (action.onSuccess) {
63
55
  action.onSuccess(row, result);
@@ -69,6 +61,7 @@ async function runAction({
69
61
  if (onActionComplete) {
70
62
  await onActionComplete(actionId, row, result);
71
63
  }
64
+ return true;
72
65
  } catch (error) {
73
66
  const err = error;
74
67
  if (action.onError) {
@@ -76,11 +69,39 @@ async function runAction({
76
69
  }
77
70
  const errorMessage = action.errorMessage ? typeof action.errorMessage === "function" ? action.errorMessage(row, err) : action.errorMessage : err.message || fallbackError;
78
71
  if (action.errorMessage || !wasToasted(err)) toast.error(text(errorMessage));
72
+ return false;
79
73
  } finally {
80
74
  onLoadingChange?.(false);
81
- onSettled?.();
82
75
  }
83
76
  }
77
+ function RowConfirmDialog({
78
+ action,
79
+ row,
80
+ open,
81
+ onOpenChange,
82
+ onRun,
83
+ children
84
+ }) {
85
+ const t = useTelamonjsT();
86
+ const config = typeof action.confirmDialog === "object" ? action.confirmDialog : void 0;
87
+ const inputs = config?.inputs?.length ? config.inputs : void 0;
88
+ const ofRow = (v) => typeof v === "function" ? v(row) : v;
89
+ return /* @__PURE__ */ jsx(
90
+ ConfirmActionDialog,
91
+ {
92
+ open,
93
+ onOpenChange,
94
+ title: ofRow(config?.title),
95
+ description: config ? ofRow(config.description) : t("dialog.confirmActionDescription"),
96
+ confirmText: config?.confirmText,
97
+ cancelText: config?.cancelText,
98
+ variant: config?.variant,
99
+ inputs,
100
+ onConfirm: (values) => onRun(inputs ? { inputs: values } : void 0),
101
+ children
102
+ }
103
+ );
104
+ }
84
105
  function ActionButton({
85
106
  action,
86
107
  row,
@@ -94,14 +115,8 @@ function ActionButton({
94
115
  const [confirmDialogOpen, setConfirmDialogOpen] = useState(false);
95
116
  const { visible, enabled, loading, tooltip, badge } = action;
96
117
  const resolvedLabel = text(action.label);
97
- const isVisible = useMemo(() => {
98
- if (visible === void 0) return true;
99
- return typeof visible === "function" ? visible(row) : visible;
100
- }, [visible, row]);
101
- const isEnabled = useMemo(() => {
102
- if (enabled === void 0) return true;
103
- return typeof enabled === "function" ? enabled(row) : enabled;
104
- }, [enabled, row]);
118
+ const isVisible = useMemo(() => actionVisible({ visible }, row), [visible, row]);
119
+ const isEnabled = useMemo(() => actionEnabled({ enabled }, row), [enabled, row]);
105
120
  const isActionLoading = useMemo(() => {
106
121
  if (loading === void 0) return isLoading;
107
122
  return typeof loading === "function" ? loading(row) : loading;
@@ -138,14 +153,14 @@ function ActionButton({
138
153
  });
139
154
  }, [actionId, accessibleName, resolvedLabel, row, isActionLoading]);
140
155
  const executeAction = useCallback(
141
- () => runAction({
156
+ (ctx) => runAction({
142
157
  action,
143
158
  row,
144
159
  actionId,
145
160
  router,
146
161
  onActionComplete,
147
162
  onLoadingChange: setIsLoading,
148
- onSettled: () => setConfirmDialogOpen(false),
163
+ ctx,
149
164
  text,
150
165
  fallbackError: t("toast.unknownError")
151
166
  }),
@@ -159,20 +174,6 @@ function ActionButton({
159
174
  }
160
175
  }, [action.confirmDialog, executeAction]);
161
176
  if (!isVisible) return null;
162
- const getConfirmDialogConfig = () => {
163
- if (!action.confirmDialog) return {};
164
- if (action.confirmDialog === true) {
165
- return {
166
- title: t("dialog.confirmActionTitle"),
167
- description: t("dialog.confirmActionDescription"),
168
- confirmText: t("common.confirm"),
169
- cancelText: t("common.cancel"),
170
- variant: "default"
171
- };
172
- }
173
- return action.confirmDialog;
174
- };
175
- const confirmConfig = getConfirmDialogConfig();
176
177
  const buttonContent = /* @__PURE__ */ jsxs(Fragment, { children: [
177
178
  action.icon && !isActionLoading && /* @__PURE__ */ jsx(action.icon, {}),
178
179
  resolvedLabel && /* @__PURE__ */ jsx("span", { className: "ml-1.5", children: resolvedLabel }),
@@ -203,31 +204,17 @@ function ActionButton({
203
204
  const withDisabledHint = (node) => !isEnabled && tooltipContent ? /* @__PURE__ */ jsx("span", { className: "inline-flex", "data-tooltip-text": tooltipContent, children: node }) : node;
204
205
  if (action.confirmDialog) {
205
206
  return withDisabledHint(
206
- /* @__PURE__ */ jsxs(AlertDialog, { open: confirmDialogOpen, onOpenChange: setConfirmDialogOpen, children: [
207
- /* @__PURE__ */ jsx(AlertDialogTrigger, { asChild: true, children: button }),
208
- /* @__PURE__ */ jsxs(AlertDialogContent, { children: [
209
- /* @__PURE__ */ jsxs(AlertDialogHeader, { children: [
210
- /* @__PURE__ */ jsx(AlertDialogTitle, { children: text(
211
- typeof confirmConfig.title === "function" ? confirmConfig.title(row) : confirmConfig.title
212
- ) }),
213
- confirmConfig.description && /* @__PURE__ */ jsx(AlertDialogDescription, { children: text(
214
- typeof confirmConfig.description === "function" ? confirmConfig.description(row) : confirmConfig.description
215
- ) })
216
- ] }),
217
- /* @__PURE__ */ jsxs(AlertDialogFooter, { children: [
218
- /* @__PURE__ */ jsx(AlertDialogCancel, { "data-testid": "modal-cancel", children: text(confirmConfig.cancelText) || t("common.cancel") }),
219
- /* @__PURE__ */ jsx(
220
- AlertDialogAction,
221
- {
222
- "data-testid": "modal-confirm",
223
- className: confirmConfig.variant === "destructive" ? "bg-red-500 text-white hover:bg-red-600" : "",
224
- onClick: executeAction,
225
- children: text(confirmConfig.confirmText) || t("common.confirm")
226
- }
227
- )
228
- ] })
229
- ] })
230
- ] })
207
+ /* @__PURE__ */ jsx(
208
+ RowConfirmDialog,
209
+ {
210
+ action,
211
+ row,
212
+ open: confirmDialogOpen,
213
+ onOpenChange: setConfirmDialogOpen,
214
+ onRun: executeAction,
215
+ children: button
216
+ }
217
+ )
231
218
  );
232
219
  }
233
220
  return withDisabledHint(button);
@@ -318,19 +305,29 @@ function DataTableActions({
318
305
  [config]
319
306
  );
320
307
  const { filteredInlineActions, filteredDropdownActions } = useMemo(() => {
321
- const granted = config.userPermissions ? new Set(config.userPermissions) : null;
322
- const allowed = (action) => {
323
- if (!action.permission || !granted) return true;
324
- const required = Array.isArray(action.permission) ? action.permission : [action.permission];
325
- return required.some((perm) => granted.has(perm));
326
- };
308
+ const granted = config.userPermissions ? new Set(config.userPermissions) : void 0;
309
+ const allowed = (action) => actionGranted(action.permission, granted, config.can);
327
310
  return {
328
311
  filteredInlineActions: allActions.inline.filter((a) => allowed(a.config)),
329
312
  filteredDropdownActions: allActions.dropdown.filter(
330
313
  (a) => allowed(a.config)
331
314
  )
332
315
  };
333
- }, [allActions, config.userPermissions]);
316
+ }, [allActions, config.userPermissions, config.can]);
317
+ const [pendingConfirm, setPendingConfirm] = useState(null);
318
+ const runMenuAction = useCallback(
319
+ (actionId, action, ctx) => runAction({
320
+ action,
321
+ row: row.original,
322
+ actionId,
323
+ router,
324
+ onActionComplete: handleActionComplete,
325
+ ctx,
326
+ text,
327
+ fallbackError: t("toast.unknownError")
328
+ }),
329
+ [row.original, router, handleActionComplete, text, t]
330
+ );
334
331
  const displayMode = config.display?.mode || "inline";
335
332
  const maxInline = config.display?.maxInline || 999;
336
333
  const spacing = config.display?.spacing || "normal";
@@ -379,9 +376,8 @@ function DataTableActions({
379
376
  }
380
377
  ) }),
381
378
  /* @__PURE__ */ jsx(DropdownMenuContent, { align: "end", children: overflowActions.map(({ id, config: actionConfig }, index) => {
382
- const isVisible = actionConfig.visible === void 0 || (typeof actionConfig.visible === "function" ? actionConfig.visible(row.original) : actionConfig.visible);
383
- if (!isVisible) return null;
384
- const isEnabled = actionConfig.enabled === void 0 || (typeof actionConfig.enabled === "function" ? actionConfig.enabled(row.original) : actionConfig.enabled);
379
+ if (!actionVisible(actionConfig, row.original)) return null;
380
+ const isEnabled = actionEnabled(actionConfig, row.original);
385
381
  const tooltip = actionConfig.tooltip;
386
382
  const tooltipText = typeof tooltip === "function" ? tooltip(row.original) : typeof tooltip === "string" || isMessageRef(tooltip) ? text(tooltip) : tooltip ? text(tooltip.content) : "";
387
383
  const label = text(actionConfig.label) || tooltipText || id;
@@ -395,15 +391,11 @@ function DataTableActions({
395
391
  disabled: !isEnabled,
396
392
  onClick: (event) => {
397
393
  event.stopPropagation();
398
- void runAction({
399
- action: actionConfig,
400
- row: row.original,
401
- actionId: id,
402
- router,
403
- onActionComplete: handleActionComplete,
404
- text,
405
- fallbackError: t("toast.unknownError")
406
- });
394
+ if (actionConfig.confirmDialog) {
395
+ setPendingConfirm({ id, config: actionConfig });
396
+ } else {
397
+ void runMenuAction(id, actionConfig);
398
+ }
407
399
  },
408
400
  children: [
409
401
  actionConfig.icon && /* @__PURE__ */ jsx("span", { className: "mr-2 h-4 w-4 shrink-0 [&_svg]:size-4", children: React.createElement(actionConfig.icon) }),
@@ -421,7 +413,19 @@ function DataTableActions({
421
413
  )
422
414
  ] }, id);
423
415
  }) })
424
- ] })
416
+ ] }),
417
+ pendingConfirm && /* @__PURE__ */ jsx(
418
+ RowConfirmDialog,
419
+ {
420
+ action: pendingConfirm.config,
421
+ row: row.original,
422
+ open: true,
423
+ onOpenChange: (open) => {
424
+ if (!open) setPendingConfirm(null);
425
+ },
426
+ onRun: (ctx) => runMenuAction(pendingConfirm.id, pendingConfirm.config, ctx)
427
+ }
428
+ )
425
429
  ] });
426
430
  }
427
431
  export {
@@ -0,0 +1,22 @@
1
+ import type { ActionConfig } from '../../types/actions';
2
+ import type { CrudConfig, CrudPermissions } from '../../types/crud';
3
+ /**
4
+ * Access rules of a row action, shared by every surface that offers it: the row
5
+ * buttons and menu (`DataTableActions`) and the view dialog footer (`ListPage`).
6
+ * One rule, so the footer never offers what the row hides.
7
+ */
8
+ /**
9
+ * `permission` (any of them) against `can` when given, else against
10
+ * `userPermissions`. Neither = everything allowed.
11
+ */
12
+ export declare function actionGranted(permission: ActionConfig['permission'], userPermissions: readonly string[] | ReadonlySet<string> | undefined, can?: (permission: string) => boolean): boolean;
13
+ /**
14
+ * A CrudConfig operation (`permissions.create`, …) against the same checker the
15
+ * row actions use: `permissions.can` or `actionsConfig.can`, else
16
+ * `actionsConfig.userPermissions`.
17
+ */
18
+ export declare function crudGranted(config: Pick<CrudConfig, 'permissions' | 'actionsConfig'>, operation: keyof Omit<CrudPermissions, 'can'>): boolean;
19
+ /** `visible` for this row (`undefined` = visible). */
20
+ export declare function actionVisible<TData>(action: Pick<ActionConfig<TData>, 'visible'>, row: TData): boolean;
21
+ /** `enabled` for this row (`undefined` = enabled). */
22
+ export declare function actionEnabled<TData>(action: Pick<ActionConfig<TData>, 'enabled'>, row: TData): boolean;
@@ -0,0 +1,33 @@
1
+ // src/components/data/action-access.ts
2
+ function actionGranted(permission, userPermissions, can) {
3
+ if (!permission) return true;
4
+ const required = Array.isArray(permission) ? permission : [permission];
5
+ if (can) return required.some((perm) => can(perm));
6
+ if (!userPermissions) return true;
7
+ const granted = userPermissions instanceof Set ? userPermissions : new Set(userPermissions);
8
+ return required.some((perm) => granted.has(perm));
9
+ }
10
+ function crudGranted(config, operation) {
11
+ const actions = config.actionsConfig || void 0;
12
+ return actionGranted(
13
+ config.permissions?.[operation],
14
+ actions?.userPermissions,
15
+ actions?.can ?? config.permissions?.can
16
+ );
17
+ }
18
+ function actionVisible(action, row) {
19
+ const { visible } = action;
20
+ if (visible === void 0) return true;
21
+ return typeof visible === "function" ? visible(row) : visible;
22
+ }
23
+ function actionEnabled(action, row) {
24
+ const { enabled } = action;
25
+ if (enabled === void 0) return true;
26
+ return typeof enabled === "function" ? enabled(row) : enabled;
27
+ }
28
+ export {
29
+ actionEnabled,
30
+ actionGranted,
31
+ actionVisible,
32
+ crudGranted
33
+ };
@@ -21,6 +21,8 @@ export interface ReportTableProps<T> {
21
21
  className?: string;
22
22
  stickyHeader?: boolean;
23
23
  labels?: Partial<ReportTableLabels>;
24
+ /** Show the "Showing X of Y records" line under the table. Default: `true` */
25
+ showFooter?: boolean;
24
26
  /**
25
27
  * Attributes for the scroll box (the `maxHeight` container). Pass
26
28
  * `{ tabIndex: 0, role: 'region', 'aria-label': '…' }` so keyboard users
@@ -38,5 +40,5 @@ export interface ReportTableProps<T> {
38
40
  *
39
41
  * @category Data
40
42
  */
41
- export declare function ReportTable<T extends Record<string, unknown>>({ data, columns, pageSize, maxHeight, emptyMessage, className, stickyHeader, labels: labelOverrides, scrollProps, }: ReportTableProps<T>): import("react").JSX.Element;
43
+ export declare function ReportTable<T extends Record<string, unknown>>({ data, columns, pageSize, maxHeight, emptyMessage, className, stickyHeader, labels: labelOverrides, showFooter, scrollProps, }: ReportTableProps<T>): import("react").JSX.Element;
42
44
  export { ReportTable as SimpleTable };
@@ -17,6 +17,7 @@ function ReportTable({
17
17
  className,
18
18
  stickyHeader = true,
19
19
  labels: labelOverrides,
20
+ showFooter = true,
20
21
  scrollProps
21
22
  }) {
22
23
  const t = useTelamonjsT();
@@ -102,7 +103,7 @@ function ReportTable({
102
103
  ]
103
104
  }
104
105
  ) }),
105
- /* @__PURE__ */ jsxs("div", { className: "mt-2 text-center text-xs text-muted-foreground", children: [
106
+ showFooter && /* @__PURE__ */ jsxs("div", { className: "mt-2 text-center text-xs text-muted-foreground", children: [
106
107
  labels.showing,
107
108
  " ",
108
109
  displayedData.length,
@@ -48,7 +48,7 @@ function DialogHeaderContent({
48
48
  const fieldValue = getNestedValue(item, field);
49
49
  const fieldKey = String(fieldValue);
50
50
  const variant = getVariant ? getVariant(item) : variants[fieldKey] || "secondary";
51
- const label = getLabel ? getLabel(item) : text(labels?.[fieldKey]) || fieldKey;
51
+ const label = getLabel ? text(getLabel(item)) : text(labels?.[fieldKey]) || fieldKey;
52
52
  return /* @__PURE__ */ jsx(Badge, { variant, className: "ml-2", children: label });
53
53
  };
54
54
  return /* @__PURE__ */ jsx(