@telamonjs/ui 1.0.4 → 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 (80) hide show
  1. package/CHANGELOG.md +38 -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 +45 -77
  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/grid-classes.d.ts +4 -0
  25. package/dist/components/forms/grid-classes.js +40 -0
  26. package/dist/components/forms/validators/config-validator.js +2 -1
  27. package/dist/components/toolbar/TabToolbar.d.ts +6 -1
  28. package/dist/components/toolbar/TabToolbar.js +5 -3
  29. package/dist/exports/data-crud.d.ts +1 -1
  30. package/dist/exports/pages-dialogs.d.ts +3 -1
  31. package/dist/exports/pages-dialogs.js +2 -0
  32. package/dist/exports/types-constants.d.ts +2 -2
  33. package/dist/exports/types-constants.js +1 -1
  34. package/dist/field-system/mask-presets.d.ts +5 -0
  35. package/dist/field-system/mask-presets.js +18 -0
  36. package/dist/field-system/renderers/advanced-renderers.js +2 -4
  37. package/dist/field-system/renderers/textarea-renderers.js +1 -1
  38. package/dist/hooks/useCrudMutations.js +28 -16
  39. package/dist/pages/ListPage.js +23 -14
  40. package/dist/pages/list-page/ListPageDialogs.d.ts +8 -3
  41. package/dist/pages/list-page/ListPageDialogs.js +36 -7
  42. package/dist/pages/list-page/ListPageToolbar.js +10 -14
  43. package/dist/pages/list-page/apply-crud-permissions.d.ts +21 -0
  44. package/dist/pages/list-page/apply-crud-permissions.js +34 -0
  45. package/dist/pages/list-page/types.d.ts +21 -2
  46. package/dist/pages/list-page/useListPageData.d.ts +3 -1
  47. package/dist/pages/list-page/useListPageData.js +2 -1
  48. package/dist/pages/list-page/useListPageDialogs.d.ts +1 -0
  49. package/dist/pages/list-page/useListPageDialogs.js +13 -4
  50. package/dist/pages/list-page/useListPageToolbar.d.ts +8 -5
  51. package/dist/pages/list-page/useListPageToolbar.js +14 -10
  52. package/dist/queue/components/FailureGroupsModal.js +4 -3
  53. package/dist/queue/components/JobConfigDialog.js +9 -1
  54. package/dist/queue/components/JobDetailModal.js +3 -2
  55. package/dist/queue/components/JobDetailPage.js +10 -2
  56. package/dist/queue/components/JobEventModal.js +3 -2
  57. package/dist/queue/components/QueueTabbedDashboard.d.ts +20 -2
  58. package/dist/queue/components/QueueTabbedDashboard.js +26 -3
  59. package/dist/queue/components/QueuesTable.d.ts +3 -2
  60. package/dist/queue/components/QueuesTable.js +31 -27
  61. package/dist/queue/components/job-shared.d.ts +2 -0
  62. package/dist/queue/components/job-shared.js +2 -0
  63. package/dist/queue/components/jobs-history-modal/fullscreen-modal.js +3 -2
  64. package/dist/queue/components/jobs-history-modal/job-detail-modal.js +3 -2
  65. package/dist/queue/components/jobs-list-modal/job-row.js +3 -2
  66. package/dist/queue/components/labels-context.d.ts +31 -0
  67. package/dist/queue/components/labels-context.js +34 -0
  68. package/dist/queue/components/module-icon.d.ts +9 -0
  69. package/dist/queue/components/module-icon.js +14 -0
  70. package/dist/queue/components/tabs/ConfiguracaoTab.d.ts +2 -1
  71. package/dist/queue/components/tabs/ConfiguracaoTab.js +13 -9
  72. package/dist/queue/components/tabs/HistoricoTab.js +4 -3
  73. package/dist/queue/components/tabs/TempoRealTab.d.ts +3 -2
  74. package/dist/queue/components/tabs/TempoRealTab.js +2 -2
  75. package/dist/types/actions.d.ts +43 -14
  76. package/dist/types/crud.d.ts +47 -6
  77. package/dist/types/dialog-header.d.ts +2 -2
  78. package/dist/types/forms/admin-form.d.ts +8 -1
  79. package/dist/utils/with-scope.js +5 -3
  80. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,43 @@
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
+
3
41
  ## 1.0.4
4
42
 
5
43
  ### 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,53 +69,38 @@ 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
  }
84
- function ConfirmActionDialog({
77
+ function RowConfirmDialog({
85
78
  action,
86
79
  row,
87
80
  open,
88
81
  onOpenChange,
89
- onConfirm,
82
+ onRun,
90
83
  children
91
84
  }) {
92
85
  const t = useTelamonjsT();
93
- const text = useText();
94
- const confirmConfig = action.confirmDialog === true ? {
95
- title: t("dialog.confirmActionTitle"),
96
- description: t("dialog.confirmActionDescription"),
97
- confirmText: t("common.confirm"),
98
- cancelText: t("common.cancel"),
99
- variant: "default"
100
- } : action.confirmDialog || {};
101
- return /* @__PURE__ */ jsxs(AlertDialog, { open, onOpenChange, children: [
102
- children && /* @__PURE__ */ jsx(AlertDialogTrigger, { asChild: true, children }),
103
- /* @__PURE__ */ jsxs(AlertDialogContent, { children: [
104
- /* @__PURE__ */ jsxs(AlertDialogHeader, { children: [
105
- /* @__PURE__ */ jsx(AlertDialogTitle, { children: text(
106
- typeof confirmConfig.title === "function" ? confirmConfig.title(row) : confirmConfig.title
107
- ) }),
108
- confirmConfig.description && /* @__PURE__ */ jsx(AlertDialogDescription, { children: text(
109
- typeof confirmConfig.description === "function" ? confirmConfig.description(row) : confirmConfig.description
110
- ) })
111
- ] }),
112
- /* @__PURE__ */ jsxs(AlertDialogFooter, { children: [
113
- /* @__PURE__ */ jsx(AlertDialogCancel, { "data-testid": "modal-cancel", children: text(confirmConfig.cancelText) || t("common.cancel") }),
114
- /* @__PURE__ */ jsx(
115
- AlertDialogAction,
116
- {
117
- "data-testid": "modal-confirm",
118
- className: confirmConfig.variant === "destructive" ? "bg-red-500 text-white hover:bg-red-600" : "",
119
- onClick: onConfirm,
120
- children: text(confirmConfig.confirmText) || t("common.confirm")
121
- }
122
- )
123
- ] })
124
- ] })
125
- ] });
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
+ );
126
104
  }
127
105
  function ActionButton({
128
106
  action,
@@ -137,14 +115,8 @@ function ActionButton({
137
115
  const [confirmDialogOpen, setConfirmDialogOpen] = useState(false);
138
116
  const { visible, enabled, loading, tooltip, badge } = action;
139
117
  const resolvedLabel = text(action.label);
140
- const isVisible = useMemo(() => {
141
- if (visible === void 0) return true;
142
- return typeof visible === "function" ? visible(row) : visible;
143
- }, [visible, row]);
144
- const isEnabled = useMemo(() => {
145
- if (enabled === void 0) return true;
146
- return typeof enabled === "function" ? enabled(row) : enabled;
147
- }, [enabled, row]);
118
+ const isVisible = useMemo(() => actionVisible({ visible }, row), [visible, row]);
119
+ const isEnabled = useMemo(() => actionEnabled({ enabled }, row), [enabled, row]);
148
120
  const isActionLoading = useMemo(() => {
149
121
  if (loading === void 0) return isLoading;
150
122
  return typeof loading === "function" ? loading(row) : loading;
@@ -181,14 +153,14 @@ function ActionButton({
181
153
  });
182
154
  }, [actionId, accessibleName, resolvedLabel, row, isActionLoading]);
183
155
  const executeAction = useCallback(
184
- () => runAction({
156
+ (ctx) => runAction({
185
157
  action,
186
158
  row,
187
159
  actionId,
188
160
  router,
189
161
  onActionComplete,
190
162
  onLoadingChange: setIsLoading,
191
- onSettled: () => setConfirmDialogOpen(false),
163
+ ctx,
192
164
  text,
193
165
  fallbackError: t("toast.unknownError")
194
166
  }),
@@ -233,13 +205,13 @@ function ActionButton({
233
205
  if (action.confirmDialog) {
234
206
  return withDisabledHint(
235
207
  /* @__PURE__ */ jsx(
236
- ConfirmActionDialog,
208
+ RowConfirmDialog,
237
209
  {
238
210
  action,
239
211
  row,
240
212
  open: confirmDialogOpen,
241
213
  onOpenChange: setConfirmDialogOpen,
242
- onConfirm: executeAction,
214
+ onRun: executeAction,
243
215
  children: button
244
216
  }
245
217
  )
@@ -333,27 +305,24 @@ function DataTableActions({
333
305
  [config]
334
306
  );
335
307
  const { filteredInlineActions, filteredDropdownActions } = useMemo(() => {
336
- const granted = config.userPermissions ? new Set(config.userPermissions) : null;
337
- const allowed = (action) => {
338
- if (!action.permission || !granted) return true;
339
- const required = Array.isArray(action.permission) ? action.permission : [action.permission];
340
- return required.some((perm) => granted.has(perm));
341
- };
308
+ const granted = config.userPermissions ? new Set(config.userPermissions) : void 0;
309
+ const allowed = (action) => actionGranted(action.permission, granted, config.can);
342
310
  return {
343
311
  filteredInlineActions: allActions.inline.filter((a) => allowed(a.config)),
344
312
  filteredDropdownActions: allActions.dropdown.filter(
345
313
  (a) => allowed(a.config)
346
314
  )
347
315
  };
348
- }, [allActions, config.userPermissions]);
316
+ }, [allActions, config.userPermissions, config.can]);
349
317
  const [pendingConfirm, setPendingConfirm] = useState(null);
350
318
  const runMenuAction = useCallback(
351
- (actionId, action) => void runAction({
319
+ (actionId, action, ctx) => runAction({
352
320
  action,
353
321
  row: row.original,
354
322
  actionId,
355
323
  router,
356
324
  onActionComplete: handleActionComplete,
325
+ ctx,
357
326
  text,
358
327
  fallbackError: t("toast.unknownError")
359
328
  }),
@@ -407,9 +376,8 @@ function DataTableActions({
407
376
  }
408
377
  ) }),
409
378
  /* @__PURE__ */ jsx(DropdownMenuContent, { align: "end", children: overflowActions.map(({ id, config: actionConfig }, index) => {
410
- const isVisible = actionConfig.visible === void 0 || (typeof actionConfig.visible === "function" ? actionConfig.visible(row.original) : actionConfig.visible);
411
- if (!isVisible) return null;
412
- 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);
413
381
  const tooltip = actionConfig.tooltip;
414
382
  const tooltipText = typeof tooltip === "function" ? tooltip(row.original) : typeof tooltip === "string" || isMessageRef(tooltip) ? text(tooltip) : tooltip ? text(tooltip.content) : "";
415
383
  const label = text(actionConfig.label) || tooltipText || id;
@@ -426,7 +394,7 @@ function DataTableActions({
426
394
  if (actionConfig.confirmDialog) {
427
395
  setPendingConfirm({ id, config: actionConfig });
428
396
  } else {
429
- runMenuAction(id, actionConfig);
397
+ void runMenuAction(id, actionConfig);
430
398
  }
431
399
  },
432
400
  children: [
@@ -447,7 +415,7 @@ function DataTableActions({
447
415
  }) })
448
416
  ] }),
449
417
  pendingConfirm && /* @__PURE__ */ jsx(
450
- ConfirmActionDialog,
418
+ RowConfirmDialog,
451
419
  {
452
420
  action: pendingConfirm.config,
453
421
  row: row.original,
@@ -455,7 +423,7 @@ function DataTableActions({
455
423
  onOpenChange: (open) => {
456
424
  if (!open) setPendingConfirm(null);
457
425
  },
458
- onConfirm: () => runMenuAction(pendingConfirm.id, pendingConfirm.config)
426
+ onRun: (ctx) => runMenuAction(pendingConfirm.id, pendingConfirm.config, ctx)
459
427
  }
460
428
  )
461
429
  ] });
@@ -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(
@@ -0,0 +1,54 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { I18nText } from '../../i18n/msg';
3
+ import type { ConfirmDialogInput } from '../../types/actions';
4
+ export interface ConfirmActionDialogProps {
5
+ /** Controlled open state. Omit it (with a `children` trigger) to let the dialog own it */
6
+ open?: boolean;
7
+ onOpenChange?: (open: boolean) => void;
8
+ /** Element that opens the dialog on click */
9
+ children?: ReactNode;
10
+ /** Default: localized "Confirm action" */
11
+ title?: I18nText;
12
+ description?: I18nText;
13
+ /** Default: localized "Confirm" */
14
+ confirmText?: I18nText;
15
+ /** Default: localized "Cancel" */
16
+ cancelText?: I18nText;
17
+ /** `'destructive'` paints the confirm button red */
18
+ variant?: 'default' | 'destructive';
19
+ /** Fields asked before confirming; required ones block the confirm while empty */
20
+ inputs?: ConfirmDialogInput[];
21
+ /**
22
+ * Runs on confirm with the `inputs` values (`{}` without inputs). The dialog
23
+ * stays open, buttons disabled, while it is pending; it closes when it
24
+ * resolves, and stays open showing the error message when it rejects.
25
+ * Resolve `false` to stay open without a message (an error you already
26
+ * reported, e.g. in a toast).
27
+ */
28
+ onConfirm: (values: Record<string, string>) => unknown;
29
+ }
30
+ /**
31
+ * ConfirmActionDialog - confirmation for an action, async aware.
32
+ *
33
+ * @category Dialogs
34
+ * @status stable
35
+ *
36
+ * @description
37
+ * The dialog behind `confirmDialog` on row and menu actions, public for any
38
+ * other button. Optional `inputs` (text, textarea, select) are validated and
39
+ * handed to `onConfirm`; while `onConfirm` is pending the dialog stays open
40
+ * with a spinner, it closes on success and shows the error on failure.
41
+ *
42
+ * @example
43
+ * ```tsx
44
+ * <ConfirmActionDialog
45
+ * title='Reject request?'
46
+ * variant='destructive'
47
+ * inputs={[{ name: 'reason', label: 'Reason', type: 'textarea', required: true }]}
48
+ * onConfirm={({ reason }) => requestsApi.reject(id, reason)}
49
+ * >
50
+ * <Button variant='destructive'>Reject</Button>
51
+ * </ConfirmActionDialog>
52
+ * ```
53
+ */
54
+ export declare function ConfirmActionDialog({ open: openProp, onOpenChange, children, title, description, confirmText, cancelText, variant, inputs, onConfirm, }: ConfirmActionDialogProps): import("react").JSX.Element;