@telamonjs/ui 1.0.4 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +79 -0
- package/README.md +2 -2
- package/dist/components/business/CalendarWithEvents.d.ts +7 -1
- package/dist/components/business/CalendarWithEvents.js +8 -9
- package/dist/components/cards/stat-card.js +22 -3
- package/dist/components/charts/BarChart.d.ts +12 -1
- package/dist/components/charts/BarChart.js +11 -2
- package/dist/components/crud/crud-field.js +1 -0
- package/dist/components/data/DataTableActions.js +45 -77
- package/dist/components/data/action-access.d.ts +22 -0
- package/dist/components/data/action-access.js +33 -0
- package/dist/components/data/report-table.d.ts +3 -1
- package/dist/components/data/report-table.js +2 -1
- package/dist/components/dialog/DialogHeaderContent.js +1 -1
- package/dist/components/dialog/confirm-action-dialog.d.ts +86 -0
- package/dist/components/dialog/confirm-action-dialog.js +194 -0
- package/dist/components/dialog/crud-view-dialog.d.ts +7 -3
- package/dist/components/dialog/crud-view-dialog.js +3 -2
- package/dist/components/dialog/view-dialog.d.ts +9 -1
- package/dist/components/dialog/view-dialog.js +8 -3
- package/dist/components/forms/AdminForm.js +2 -1
- package/dist/components/forms/BaseForm.js +4 -3
- package/dist/components/forms/WizardForm.js +3 -2
- package/dist/components/forms/ZustandForm.js +5 -4
- package/dist/components/forms/admin-form/field-group.js +5 -4
- package/dist/components/forms/grid-classes.d.ts +4 -0
- package/dist/components/forms/grid-classes.js +40 -0
- package/dist/components/forms/validators/config-validator.js +2 -1
- package/dist/components/toolbar/TabToolbar.d.ts +6 -1
- package/dist/components/toolbar/TabToolbar.js +5 -3
- package/dist/data/InfiniteList.js +2 -4
- package/dist/data/MobileCard.js +4 -1
- package/dist/data/VirtualDataTable.js +4 -1
- package/dist/data/datatable/TableDesktopView.js +2 -5
- package/dist/data/row-click.d.ts +10 -0
- package/dist/data/row-click.js +11 -0
- package/dist/exports/data-crud.d.ts +1 -1
- package/dist/exports/pages-dialogs.d.ts +3 -1
- package/dist/exports/pages-dialogs.js +2 -0
- package/dist/exports/types-constants.d.ts +2 -2
- package/dist/exports/types-constants.js +1 -1
- package/dist/field-system/mask-presets.d.ts +5 -0
- package/dist/field-system/mask-presets.js +18 -0
- package/dist/field-system/renderers/advanced-renderers.js +2 -4
- package/dist/field-system/renderers/textarea-renderers.js +1 -1
- package/dist/hooks/useCrudMutations.js +28 -16
- package/dist/i18n/messages/en/index.d.ts +1 -0
- package/dist/i18n/messages/en/list.d.ts +1 -0
- package/dist/i18n/messages/en/list.js +1 -0
- package/dist/i18n/messages/en/queue.js +1 -1
- package/dist/i18n/messages/es/index.d.ts +1 -0
- package/dist/i18n/messages/es/list.d.ts +1 -0
- package/dist/i18n/messages/es/list.js +1 -0
- package/dist/i18n/messages/pt-BR/index.d.ts +8 -7
- package/dist/i18n/messages/pt-BR/list.d.ts +1 -0
- package/dist/i18n/messages/pt-BR/list.js +1 -0
- package/dist/i18n/messages/pt-BR/queue.d.ts +7 -7
- package/dist/i18n/messages/pt-BR/queue.js +7 -7
- package/dist/i18n/use-t.d.ts +8 -7
- package/dist/pages/ListPage.js +23 -14
- package/dist/pages/list-page/ListPageDialogs.d.ts +8 -3
- package/dist/pages/list-page/ListPageDialogs.js +36 -7
- package/dist/pages/list-page/ListPageTable.d.ts +1 -1
- package/dist/pages/list-page/ListPageTable.js +1 -1
- package/dist/pages/list-page/ListPageToolbar.js +10 -14
- package/dist/pages/list-page/apply-crud-permissions.d.ts +21 -0
- package/dist/pages/list-page/apply-crud-permissions.js +34 -0
- package/dist/pages/list-page/types.d.ts +21 -2
- package/dist/pages/list-page/useDialogUrlSync.d.ts +10 -4
- package/dist/pages/list-page/useDialogUrlSync.js +7 -11
- package/dist/pages/list-page/useListPageData.d.ts +3 -1
- package/dist/pages/list-page/useListPageData.js +2 -1
- package/dist/pages/list-page/useListPageDialogs.d.ts +1 -0
- package/dist/pages/list-page/useListPageDialogs.js +13 -4
- package/dist/pages/list-page/useListPageToolbar.d.ts +8 -5
- package/dist/pages/list-page/useListPageToolbar.js +14 -10
- package/dist/queue/components/DispatchJobModal.js +5 -2
- package/dist/queue/components/FailureGroupsModal.js +4 -3
- package/dist/queue/components/JobConfigDialog.js +9 -1
- package/dist/queue/components/JobDetailModal.js +3 -2
- package/dist/queue/components/JobDetailPage.d.ts +8 -0
- package/dist/queue/components/JobDetailPage.js +29 -13
- package/dist/queue/components/JobEventModal.js +3 -2
- package/dist/queue/components/QueueDashboard.js +3 -1
- package/dist/queue/components/QueueTabbedDashboard.d.ts +21 -2
- package/dist/queue/components/QueueTabbedDashboard.js +3 -2
- package/dist/queue/components/QueuesTable.d.ts +3 -2
- package/dist/queue/components/QueuesTable.js +357 -286
- package/dist/queue/components/job-shared.d.ts +2 -0
- package/dist/queue/components/job-shared.js +2 -0
- package/dist/queue/components/jobs-history-modal/fullscreen-modal.js +3 -2
- package/dist/queue/components/jobs-history-modal/job-detail-modal.js +3 -2
- package/dist/queue/components/jobs-list-modal/job-row.js +3 -2
- package/dist/queue/components/labels-context.d.ts +39 -0
- package/dist/queue/components/labels-context.js +35 -0
- package/dist/queue/components/labels-provider.d.ts +11 -0
- package/dist/queue/components/labels-provider.js +35 -0
- package/dist/queue/components/module-icon.d.ts +9 -0
- package/dist/queue/components/module-icon.js +14 -0
- package/dist/queue/components/tabs/ConfiguracaoTab.d.ts +2 -1
- package/dist/queue/components/tabs/ConfiguracaoTab.js +16 -12
- package/dist/queue/components/tabs/HistoricoTab.js +4 -3
- package/dist/queue/components/tabs/TempoRealTab.d.ts +3 -2
- package/dist/queue/components/tabs/TempoRealTab.js +5 -4
- package/dist/queue/components/tabs/historico/history-job-row.js +1 -1
- package/dist/queue/lib/action-message.d.ts +3 -2
- package/dist/queue/lib/action-message.js +2 -2
- package/dist/queue/types.d.ts +3 -0
- package/dist/types/actions.d.ts +51 -14
- package/dist/types/crud.d.ts +53 -9
- package/dist/types/dialog-header.d.ts +2 -2
- package/dist/types/forms/admin-form.d.ts +8 -1
- package/dist/utils/with-scope.js +5 -3
- package/package.json +2 -2
|
@@ -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,86 @@
|
|
|
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 (the trigger, never content: see `body`) */
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
/** Text, `msg()` or JSX. Default: localized "Confirm action" */
|
|
11
|
+
title?: I18nText | ReactNode;
|
|
12
|
+
/** Text, `msg()` or JSX (phrasing content: it renders inside a `<p>`) */
|
|
13
|
+
description?: I18nText | ReactNode;
|
|
14
|
+
/** Free content between the description and the buttons (fields, a summary, a warning) */
|
|
15
|
+
body?: ReactNode;
|
|
16
|
+
/** Default: localized "Confirm" */
|
|
17
|
+
confirmText?: I18nText;
|
|
18
|
+
/** Confirm label while pending. Default: `confirmText` */
|
|
19
|
+
pendingText?: I18nText;
|
|
20
|
+
/** Default: localized "Cancel" */
|
|
21
|
+
cancelText?: I18nText;
|
|
22
|
+
/** `'destructive'` paints the confirm button red */
|
|
23
|
+
variant?: 'default' | 'destructive';
|
|
24
|
+
/** Disables only the confirm button, e.g. until a confirmation word is typed */
|
|
25
|
+
confirmDisabled?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Caller-controlled pending state (usually `mutation.isPending`). Passing it,
|
|
28
|
+
* even `false`, hands the lifecycle to the caller: confirming never closes
|
|
29
|
+
* the dialog; close it yourself (`open`/`onOpenChange`) when the action
|
|
30
|
+
* settles. While `true`, both buttons are disabled, the confirm shows a
|
|
31
|
+
* spinner and `pendingText`, and the dialog cannot be dismissed.
|
|
32
|
+
*/
|
|
33
|
+
pending?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Fields asked before confirming; `required` and `validate` block the
|
|
36
|
+
* confirm while they fail
|
|
37
|
+
*/
|
|
38
|
+
inputs?: ConfirmDialogInput[];
|
|
39
|
+
/**
|
|
40
|
+
* Runs on confirm with the `inputs` values (`{}` without inputs). Without
|
|
41
|
+
* `pending`, the dialog stays open, buttons disabled, while the returned
|
|
42
|
+
* promise is pending; it closes when it resolves, and stays open showing
|
|
43
|
+
* the error message when it rejects. Resolve `false` to stay open without a
|
|
44
|
+
* message (an error you already reported, e.g. in a toast). With `pending`,
|
|
45
|
+
* a rejection still shows its message, but nothing closes the dialog.
|
|
46
|
+
*/
|
|
47
|
+
onConfirm: (values: Record<string, string>) => unknown;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* ConfirmActionDialog - confirmation for an action, async aware.
|
|
51
|
+
*
|
|
52
|
+
* @category Dialogs
|
|
53
|
+
* @status stable
|
|
54
|
+
*
|
|
55
|
+
* @description
|
|
56
|
+
* The dialog behind `confirmDialog` on row and menu actions, public for any
|
|
57
|
+
* other button. Optional `inputs` (text, textarea, select, date) are validated
|
|
58
|
+
* (`required`, `validate`) and handed to `onConfirm`; `body` adds free
|
|
59
|
+
* content. Two pending modes: by default the dialog awaits `onConfirm`
|
|
60
|
+
* (spinner, closes on success, shows the error on failure); with a `pending`
|
|
61
|
+
* prop the caller runs the action and closes the dialog itself.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```tsx
|
|
65
|
+
* // The dialog awaits the action
|
|
66
|
+
* <ConfirmActionDialog
|
|
67
|
+
* title='Reject request?'
|
|
68
|
+
* variant='destructive'
|
|
69
|
+
* inputs={[{ name: 'reason', label: 'Reason', type: 'textarea', required: true }]}
|
|
70
|
+
* onConfirm={({ reason }) => requestsApi.reject(id, reason)}
|
|
71
|
+
* >
|
|
72
|
+
* <Button variant='destructive'>Reject</Button>
|
|
73
|
+
* </ConfirmActionDialog>
|
|
74
|
+
*
|
|
75
|
+
* // The caller runs a mutation and closes on success
|
|
76
|
+
* <ConfirmActionDialog
|
|
77
|
+
* open={open}
|
|
78
|
+
* onOpenChange={setOpen}
|
|
79
|
+
* title={<>Publish <strong>{name}</strong>?</>}
|
|
80
|
+
* pending={publish.isPending}
|
|
81
|
+
* pendingText='Publishing...'
|
|
82
|
+
* onConfirm={() => publish.mutate(undefined, { onSuccess: () => setOpen(false) })}
|
|
83
|
+
* />
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare function ConfirmActionDialog({ open: openProp, onOpenChange, children, title, description, body, confirmText, pendingText, cancelText, variant, confirmDisabled, pending: pendingProp, inputs, onConfirm, }: ConfirmActionDialogProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/dialog/confirm-action-dialog.tsx
|
|
4
|
+
import { Loader2 } from "lucide-react";
|
|
5
|
+
import { useId, useState } from "react";
|
|
6
|
+
import {
|
|
7
|
+
AlertDialog,
|
|
8
|
+
AlertDialogAction,
|
|
9
|
+
AlertDialogCancel,
|
|
10
|
+
AlertDialogContent,
|
|
11
|
+
AlertDialogDescription,
|
|
12
|
+
AlertDialogFooter,
|
|
13
|
+
AlertDialogHeader,
|
|
14
|
+
AlertDialogTitle,
|
|
15
|
+
AlertDialogTrigger
|
|
16
|
+
} from "../../ui/alert-dialog.js";
|
|
17
|
+
import { Input } from "../../ui/input.js";
|
|
18
|
+
import { Label } from "../../ui/label.js";
|
|
19
|
+
import {
|
|
20
|
+
Select,
|
|
21
|
+
SelectContent,
|
|
22
|
+
SelectItem,
|
|
23
|
+
SelectTrigger,
|
|
24
|
+
SelectValue
|
|
25
|
+
} from "../../ui/select.js";
|
|
26
|
+
import { Textarea } from "../../ui/textarea.js";
|
|
27
|
+
import { useTelamonjsT, useText } from "../../i18n/use-t.js";
|
|
28
|
+
import { isMessageRef } from "../../i18n/msg.js";
|
|
29
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
30
|
+
var initialValues = (inputs = []) => Object.fromEntries(inputs.map((i) => [i.name, i.defaultValue ?? ""]));
|
|
31
|
+
function ConfirmActionDialog({
|
|
32
|
+
open: openProp,
|
|
33
|
+
onOpenChange,
|
|
34
|
+
children,
|
|
35
|
+
title,
|
|
36
|
+
description,
|
|
37
|
+
body,
|
|
38
|
+
confirmText,
|
|
39
|
+
pendingText,
|
|
40
|
+
cancelText,
|
|
41
|
+
variant = "default",
|
|
42
|
+
confirmDisabled = false,
|
|
43
|
+
pending: pendingProp,
|
|
44
|
+
inputs,
|
|
45
|
+
onConfirm
|
|
46
|
+
}) {
|
|
47
|
+
const t = useTelamonjsT();
|
|
48
|
+
const text = useText();
|
|
49
|
+
const idPrefix = useId();
|
|
50
|
+
const [innerOpen, setInnerOpen] = useState(false);
|
|
51
|
+
const open = openProp ?? innerOpen;
|
|
52
|
+
const [values, setValues] = useState(() => initialValues(inputs));
|
|
53
|
+
const [attempted, setAttempted] = useState(false);
|
|
54
|
+
const [error, setError] = useState(null);
|
|
55
|
+
const [innerPending, setInnerPending] = useState(false);
|
|
56
|
+
const callerOwnsPending = pendingProp !== void 0;
|
|
57
|
+
const pending = pendingProp ?? innerPending;
|
|
58
|
+
const [wasOpen, setWasOpen] = useState(open);
|
|
59
|
+
if (open !== wasOpen) {
|
|
60
|
+
setWasOpen(open);
|
|
61
|
+
if (open) {
|
|
62
|
+
setValues(initialValues(inputs));
|
|
63
|
+
setAttempted(false);
|
|
64
|
+
setError(null);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const node = (value) => isMessageRef(value) ? text(value) : value;
|
|
68
|
+
const fieldError = (input) => {
|
|
69
|
+
const value = values[input.name] ?? "";
|
|
70
|
+
if (input.required && !value.trim()) return t("validation.required");
|
|
71
|
+
return input.validate?.(value, values);
|
|
72
|
+
};
|
|
73
|
+
const setOpen = (next) => {
|
|
74
|
+
if (openProp === void 0) setInnerOpen(next);
|
|
75
|
+
onOpenChange?.(next);
|
|
76
|
+
};
|
|
77
|
+
const handleOpenChange = (next) => {
|
|
78
|
+
if (!next && pending) return;
|
|
79
|
+
setOpen(next);
|
|
80
|
+
};
|
|
81
|
+
const handleConfirm = async (event) => {
|
|
82
|
+
event.preventDefault();
|
|
83
|
+
setAttempted(true);
|
|
84
|
+
if ((inputs ?? []).some((input) => fieldError(input))) return;
|
|
85
|
+
setError(null);
|
|
86
|
+
if (!callerOwnsPending) setInnerPending(true);
|
|
87
|
+
try {
|
|
88
|
+
const result = await onConfirm(values);
|
|
89
|
+
if (callerOwnsPending) return;
|
|
90
|
+
setInnerPending(false);
|
|
91
|
+
if (result !== false) setOpen(false);
|
|
92
|
+
} catch (err) {
|
|
93
|
+
if (!callerOwnsPending) setInnerPending(false);
|
|
94
|
+
setError(
|
|
95
|
+
err instanceof Error && err.message ? err.message : t("toast.unknownError")
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const setValue = (name, value) => setValues((prev) => ({ ...prev, [name]: value }));
|
|
100
|
+
return /* @__PURE__ */ jsxs(AlertDialog, { open, onOpenChange: handleOpenChange, children: [
|
|
101
|
+
children && /* @__PURE__ */ jsx(AlertDialogTrigger, { asChild: true, children }),
|
|
102
|
+
/* @__PURE__ */ jsxs(AlertDialogContent, { children: [
|
|
103
|
+
/* @__PURE__ */ jsxs(AlertDialogHeader, { children: [
|
|
104
|
+
/* @__PURE__ */ jsx(AlertDialogTitle, { children: node(title) || t("dialog.confirmActionTitle") }),
|
|
105
|
+
description && /* @__PURE__ */ jsx(AlertDialogDescription, { children: node(description) })
|
|
106
|
+
] }),
|
|
107
|
+
body,
|
|
108
|
+
inputs && inputs.length > 0 && /* @__PURE__ */ jsx("div", { className: "grid gap-4", children: inputs.map((input) => {
|
|
109
|
+
const id = `${idPrefix}-${input.name}`;
|
|
110
|
+
const errorId = `${id}-error`;
|
|
111
|
+
const message = attempted ? fieldError(input) : void 0;
|
|
112
|
+
const common = {
|
|
113
|
+
id,
|
|
114
|
+
name: input.name,
|
|
115
|
+
required: input.required,
|
|
116
|
+
disabled: pending,
|
|
117
|
+
"aria-invalid": message ? true : void 0,
|
|
118
|
+
"aria-describedby": message ? errorId : void 0
|
|
119
|
+
};
|
|
120
|
+
return /* @__PURE__ */ jsxs("div", { className: "grid gap-1.5", children: [
|
|
121
|
+
/* @__PURE__ */ jsxs(Label, { htmlFor: id, children: [
|
|
122
|
+
text(input.label),
|
|
123
|
+
input.required && /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "text-destructive", children: " *" })
|
|
124
|
+
] }),
|
|
125
|
+
input.type === "textarea" ? /* @__PURE__ */ jsx(
|
|
126
|
+
Textarea,
|
|
127
|
+
{
|
|
128
|
+
...common,
|
|
129
|
+
value: values[input.name] ?? "",
|
|
130
|
+
onChange: (e) => setValue(input.name, e.target.value)
|
|
131
|
+
}
|
|
132
|
+
) : input.type === "select" ? /* @__PURE__ */ jsxs(
|
|
133
|
+
Select,
|
|
134
|
+
{
|
|
135
|
+
value: values[input.name] ?? "",
|
|
136
|
+
onValueChange: (v) => setValue(input.name, v),
|
|
137
|
+
disabled: pending,
|
|
138
|
+
children: [
|
|
139
|
+
/* @__PURE__ */ jsx(
|
|
140
|
+
SelectTrigger,
|
|
141
|
+
{
|
|
142
|
+
id,
|
|
143
|
+
"aria-invalid": common["aria-invalid"],
|
|
144
|
+
"aria-describedby": common["aria-describedby"],
|
|
145
|
+
children: /* @__PURE__ */ jsx(SelectValue, { placeholder: t("common.select") })
|
|
146
|
+
}
|
|
147
|
+
),
|
|
148
|
+
/* @__PURE__ */ jsx(SelectContent, { children: (input.options ?? []).map((option) => /* @__PURE__ */ jsx(SelectItem, { value: option, children: option }, option)) })
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
) : /* @__PURE__ */ jsx(
|
|
152
|
+
Input,
|
|
153
|
+
{
|
|
154
|
+
...common,
|
|
155
|
+
type: input.type === "date" ? "date" : "text",
|
|
156
|
+
value: values[input.name] ?? "",
|
|
157
|
+
onChange: (e) => setValue(input.name, e.target.value)
|
|
158
|
+
}
|
|
159
|
+
),
|
|
160
|
+
message && /* @__PURE__ */ jsx("p", { id: errorId, className: "text-sm text-destructive", children: text(message) })
|
|
161
|
+
] }, input.name);
|
|
162
|
+
}) }),
|
|
163
|
+
error && /* @__PURE__ */ jsx(
|
|
164
|
+
"p",
|
|
165
|
+
{
|
|
166
|
+
role: "alert",
|
|
167
|
+
"data-testid": "confirm-action-error",
|
|
168
|
+
className: "text-sm text-destructive",
|
|
169
|
+
children: error
|
|
170
|
+
}
|
|
171
|
+
),
|
|
172
|
+
/* @__PURE__ */ jsxs(AlertDialogFooter, { children: [
|
|
173
|
+
/* @__PURE__ */ jsx(AlertDialogCancel, { "data-testid": "modal-cancel", disabled: pending, children: text(cancelText) || t("common.cancel") }),
|
|
174
|
+
/* @__PURE__ */ jsxs(
|
|
175
|
+
AlertDialogAction,
|
|
176
|
+
{
|
|
177
|
+
"data-testid": "modal-confirm",
|
|
178
|
+
disabled: pending || confirmDisabled,
|
|
179
|
+
"aria-busy": pending || void 0,
|
|
180
|
+
className: variant === "destructive" ? "bg-red-500 text-white hover:bg-red-600" : "",
|
|
181
|
+
onClick: handleConfirm,
|
|
182
|
+
children: [
|
|
183
|
+
pending && /* @__PURE__ */ jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin", "aria-hidden": "true" }),
|
|
184
|
+
pending && text(pendingText) || text(confirmText) || t("common.confirm")
|
|
185
|
+
]
|
|
186
|
+
}
|
|
187
|
+
)
|
|
188
|
+
] })
|
|
189
|
+
] })
|
|
190
|
+
] });
|
|
191
|
+
}
|
|
192
|
+
export {
|
|
193
|
+
ConfirmActionDialog
|
|
194
|
+
};
|
|
@@ -2,13 +2,17 @@ import type { CrudConfigWithAnyForm } from '../../types/crud';
|
|
|
2
2
|
import type { ViewDialogProps } from './view-dialog';
|
|
3
3
|
type DialogData<T> = T & Record<string, unknown>;
|
|
4
4
|
export interface CrudViewDialogProps<TData> {
|
|
5
|
-
/**
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* The module's CrudConfig — uses `dialogs.view`, `mutations.getForView ?? getForEdit`,
|
|
7
|
+
* `form.validation`, and `permissions.edit` (checked like the row actions) to
|
|
8
|
+
* gate `portal.onSaveSection`
|
|
9
|
+
*/
|
|
10
|
+
config: Pick<CrudConfigWithAnyForm<TData>, 'dialogs' | 'mutations' | 'form' | 'permissions' | 'actionsConfig'>;
|
|
7
11
|
id: string | null;
|
|
8
12
|
open: boolean;
|
|
9
13
|
onOpenChange: (open: boolean) => void;
|
|
10
14
|
/** Footer actions of the classic ViewDialog (the portal variant has no footer) */
|
|
11
|
-
footer?: Pick<ViewDialogProps<DialogData<TData>>, 'onEdit' | 'onDelete' | 'deleteLabel' | 'deleteIcon' | 'deleteConfirmation'>;
|
|
15
|
+
footer?: Pick<ViewDialogProps<DialogData<TData>>, 'onEdit' | 'canEdit' | 'onDelete' | 'canDelete' | 'deleteLabel' | 'deleteIcon' | 'deleteConfirmation'>;
|
|
12
16
|
}
|
|
13
17
|
/**
|
|
14
18
|
* CrudViewDialog - the view dialog a CrudConfig declares (`dialogs.view`),
|
|
@@ -5,6 +5,7 @@ import { Suspense, lazy, useCallback } from "react";
|
|
|
5
5
|
import { useText } from "../../i18n/use-t.js";
|
|
6
6
|
import { withComponent } from "../../utils/logger.js";
|
|
7
7
|
import { resolveDialogTitle } from "./resolve-dialog-title.js";
|
|
8
|
+
import { crudGranted } from "../data/action-access.js";
|
|
8
9
|
import { jsx } from "react/jsx-runtime";
|
|
9
10
|
var logger = withComponent("CrudViewDialog");
|
|
10
11
|
var ViewDialog = lazy(
|
|
@@ -61,8 +62,8 @@ function CrudViewDialog({
|
|
|
61
62
|
sections: view.portal.sections,
|
|
62
63
|
defaultSection: view.portal.defaultSection,
|
|
63
64
|
columns: view.portal.columns,
|
|
64
|
-
validation: form
|
|
65
|
-
onSaveSection: view.portal.onSaveSection
|
|
65
|
+
validation: form?.validation,
|
|
66
|
+
onSaveSection: crudGranted(config, "edit") ? view.portal.onSaveSection : void 0
|
|
66
67
|
}
|
|
67
68
|
) : /* @__PURE__ */ jsx(
|
|
68
69
|
ViewDialog,
|
|
@@ -68,8 +68,16 @@ export interface ViewDialogProps<T extends Record<string, unknown>> {
|
|
|
68
68
|
forceDesktopMode?: boolean;
|
|
69
69
|
/** Optional edit action - opens EditDialog and closes ViewDialog */
|
|
70
70
|
onEdit?: () => void;
|
|
71
|
+
/**
|
|
72
|
+
* Per-record gate for the Edit button (with `onEdit`): it shows only when this
|
|
73
|
+
* returns true for the viewed item, and stays hidden while it loads. The
|
|
74
|
+
* ListPage passes the row edit action's `visible`/`enabled` here.
|
|
75
|
+
*/
|
|
76
|
+
canEdit?: (item: T) => boolean;
|
|
71
77
|
/** Optional delete action - shows confirmation before deleting */
|
|
72
78
|
onDelete?: () => Promise<void>;
|
|
79
|
+
/** Per-record gate for the Delete button (with `onDelete`), like `canEdit` */
|
|
80
|
+
canDelete?: (item: T) => boolean;
|
|
73
81
|
/** Delete confirmation config (if onDelete is provided) */
|
|
74
82
|
deleteConfirmation?: {
|
|
75
83
|
/** String, or a function that receives the viewed item */
|
|
@@ -132,4 +140,4 @@ export interface ViewDialogProps<T extends Record<string, unknown>> {
|
|
|
132
140
|
* />
|
|
133
141
|
* ```
|
|
134
142
|
*/
|
|
135
|
-
export declare function ViewDialog<T extends Record<string, unknown>>({ id, open, onOpenChange, fetchAction, title, description, renderContent, renderHeader: renderHeaderProp, headerConfig, dialogClassName, dialogHeight, size, forceDesktopMode, onEdit, onDelete, deleteConfirmation, deleteLabel, deleteIcon: DeleteIcon, }: ViewDialogProps<T>): React.JSX.Element;
|
|
143
|
+
export declare function ViewDialog<T extends Record<string, unknown>>({ id, open, onOpenChange, fetchAction, title, description, renderContent, renderHeader: renderHeaderProp, headerConfig, dialogClassName, dialogHeight, size, forceDesktopMode, onEdit, canEdit, onDelete, canDelete, deleteConfirmation, deleteLabel, deleteIcon: DeleteIcon, }: ViewDialogProps<T>): React.JSX.Element;
|
|
@@ -42,7 +42,9 @@ function ViewDialog({
|
|
|
42
42
|
size = "full",
|
|
43
43
|
forceDesktopMode = false,
|
|
44
44
|
onEdit,
|
|
45
|
+
canEdit,
|
|
45
46
|
onDelete,
|
|
47
|
+
canDelete,
|
|
46
48
|
deleteConfirmation,
|
|
47
49
|
deleteLabel,
|
|
48
50
|
deleteIcon: DeleteIcon = Trash2
|
|
@@ -62,6 +64,9 @@ function ViewDialog({
|
|
|
62
64
|
}
|
|
63
65
|
return title;
|
|
64
66
|
}, [title, data, t]);
|
|
67
|
+
const gate = (can) => !can || (data ? can(data) : false);
|
|
68
|
+
const showEdit = Boolean(onEdit) && gate(canEdit);
|
|
69
|
+
const showDelete = Boolean(onDelete) && gate(canDelete);
|
|
65
70
|
const handleEdit = () => {
|
|
66
71
|
if (onEdit) {
|
|
67
72
|
onOpenChange(false);
|
|
@@ -104,7 +109,7 @@ function ViewDialog({
|
|
|
104
109
|
return /* @__PURE__ */ jsx(RecordRefreshProvider, { refresh: refetchSilent, children: renderContent(data) });
|
|
105
110
|
};
|
|
106
111
|
const renderFooter = () => {
|
|
107
|
-
if (!
|
|
112
|
+
if (!showDelete && !showEdit) {
|
|
108
113
|
return null;
|
|
109
114
|
}
|
|
110
115
|
const resolve = (v) => typeof v === "function" ? data ? v(data) : "" : v;
|
|
@@ -112,7 +117,7 @@ function ViewDialog({
|
|
|
112
117
|
const confirmDescription = resolve(deleteConfirmation?.description) || t("dialog.confirmDeleteDescription");
|
|
113
118
|
const deleteText = resolve(deleteLabel) || t("common.delete");
|
|
114
119
|
return /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between border-t bg-muted/50 px-6 py-4", children: [
|
|
115
|
-
/* @__PURE__ */ jsx("div", { children:
|
|
120
|
+
/* @__PURE__ */ jsx("div", { children: showDelete ? /* @__PURE__ */ jsxs(
|
|
116
121
|
AlertDialog,
|
|
117
122
|
{
|
|
118
123
|
open: confirmDialogOpen,
|
|
@@ -167,7 +172,7 @@ function ViewDialog({
|
|
|
167
172
|
]
|
|
168
173
|
}
|
|
169
174
|
),
|
|
170
|
-
|
|
175
|
+
showEdit && /* @__PURE__ */ jsxs(Button, { onClick: handleEdit, "data-testid": "view-dialog-edit-button", children: [
|
|
171
176
|
/* @__PURE__ */ jsx(Pencil, { className: "mr-2 h-4 w-4" }),
|
|
172
177
|
t("common.edit")
|
|
173
178
|
] })
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
import { getFieldRenderer } from "../../field-system/field-registry.js";
|
|
20
20
|
import { Button } from "../../ui/button.js";
|
|
21
21
|
import { cn } from "../../utils/index.js";
|
|
22
|
+
import { colSpanClass, gridColsClass } from "./grid-classes.js";
|
|
22
23
|
import { ValidationErrors } from "./ValidationErrors.js";
|
|
23
24
|
import { ChevronLeft, ChevronRight, Loader2, Save, X } from "lucide-react";
|
|
24
25
|
import { useTelamonjsT, useText } from "../../i18n/use-t.js";
|
|
@@ -153,7 +154,7 @@ var FieldRenderer = memo(({ field, form, id }) => {
|
|
|
153
154
|
return /* @__PURE__ */ jsx(
|
|
154
155
|
"div",
|
|
155
156
|
{
|
|
156
|
-
className: cn("space-y-2", field.span &&
|
|
157
|
+
className: cn("space-y-2", field.span && colSpanClass(field.span)),
|
|
157
158
|
children: /* @__PURE__ */ jsx(
|
|
158
159
|
Controller,
|
|
159
160
|
{
|
|
@@ -374,7 +375,7 @@ function BaseForm({
|
|
|
374
375
|
{
|
|
375
376
|
className: cn(
|
|
376
377
|
"grid gap-4",
|
|
377
|
-
|
|
378
|
+
gridColsClass(currentSection.grid || grid)
|
|
378
379
|
),
|
|
379
380
|
role: "group",
|
|
380
381
|
"aria-label": currentSection.label || void 0,
|
|
@@ -407,7 +408,7 @@ function BaseForm({
|
|
|
407
408
|
{
|
|
408
409
|
className: cn(
|
|
409
410
|
"grid gap-4",
|
|
410
|
-
|
|
411
|
+
gridColsClass(currentSection2.grid || grid)
|
|
411
412
|
),
|
|
412
413
|
role: "group",
|
|
413
414
|
"aria-label": currentSection2.label || void 0,
|
|
@@ -7,6 +7,7 @@ import { useForm, FormProvider } from "react-hook-form";
|
|
|
7
7
|
import { Button } from "../../ui/button.js";
|
|
8
8
|
import { Label } from "../../ui/label.js";
|
|
9
9
|
import { cn } from "../../utils/index.js";
|
|
10
|
+
import { colSpanClass, gridColsClass } from "./grid-classes.js";
|
|
10
11
|
import { ChevronLeft, ChevronRight, Loader2, CheckCircle2 } from "lucide-react";
|
|
11
12
|
import { Stepper } from "./Stepper.js";
|
|
12
13
|
import { ReviewStep } from "./ReviewStep.js";
|
|
@@ -26,12 +27,12 @@ function WizardStepFields({
|
|
|
26
27
|
}) {
|
|
27
28
|
const text = useText();
|
|
28
29
|
const flatFields = Array.isArray(fields[0]) ? fields.flat() : fields;
|
|
29
|
-
return /* @__PURE__ */ jsx("div", { className: cn("grid gap-4",
|
|
30
|
+
return /* @__PURE__ */ jsx("div", { className: cn("grid gap-4", gridColsClass(grid)), role: "group", children: flatFields.map((field) => {
|
|
30
31
|
const error = form.formState.errors[field.name];
|
|
31
32
|
return /* @__PURE__ */ jsxs(
|
|
32
33
|
"div",
|
|
33
34
|
{
|
|
34
|
-
className: cn("space-y-2", field.span &&
|
|
35
|
+
className: cn("space-y-2", field.span && colSpanClass(field.span)),
|
|
35
36
|
children: [
|
|
36
37
|
field.type !== "space" && /* @__PURE__ */ jsxs(Label, { htmlFor: field.name, children: [
|
|
37
38
|
text(field.label),
|
|
@@ -6,6 +6,7 @@ import { useForm } from "../../stores/form-store.js";
|
|
|
6
6
|
import { Button } from "../../ui/button.js";
|
|
7
7
|
import { Label } from "../../ui/label.js";
|
|
8
8
|
import { cn } from "../../utils/index.js";
|
|
9
|
+
import { colSpanClass, gridColsClass } from "./grid-classes.js";
|
|
9
10
|
import {
|
|
10
11
|
Save,
|
|
11
12
|
X,
|
|
@@ -105,10 +106,10 @@ var SectionRenderer = memo(({ section, form, recordId }) => {
|
|
|
105
106
|
const filteredRow = filterFields(row);
|
|
106
107
|
if (filteredRow.length === 0) return null;
|
|
107
108
|
const useFlexbox = filteredRow.length > 6;
|
|
108
|
-
const gridCols2 = useFlexbox ? "" :
|
|
109
|
+
const gridCols2 = useFlexbox ? "" : gridColsClass(Math.min(filteredRow.length, 6));
|
|
109
110
|
const containerClass = useFlexbox ? "flex flex-wrap gap-3" : cn("grid gap-3", gridCols2);
|
|
110
111
|
return /* @__PURE__ */ jsx("div", { className: containerClass, children: filteredRow.map((field) => {
|
|
111
|
-
const spanClass = field.span ?
|
|
112
|
+
const spanClass = field.span ? colSpanClass(field.span) : field.type === "space" || field.type === "crud" ? useFlexbox ? "w-full" : colSpanClass(row.length) : useFlexbox ? "flex-1 min-w-0" : "";
|
|
112
113
|
return /* @__PURE__ */ jsx("div", { className: cn("space-y-1", spanClass), children: /* @__PURE__ */ jsx(
|
|
113
114
|
FieldRenderer,
|
|
114
115
|
{
|
|
@@ -123,9 +124,9 @@ var SectionRenderer = memo(({ section, form, recordId }) => {
|
|
|
123
124
|
const fields = filterFields(section.fields);
|
|
124
125
|
if (fields.length === 0) return null;
|
|
125
126
|
const gridValue = section.grid || "2";
|
|
126
|
-
const gridCols =
|
|
127
|
+
const gridCols = gridColsClass(gridValue);
|
|
127
128
|
return /* @__PURE__ */ jsx("div", { className: cn("grid gap-4", gridCols), children: fields.map((field) => {
|
|
128
|
-
const spanClass = field.span ?
|
|
129
|
+
const spanClass = field.span ? colSpanClass(field.span) : field.type === "space" || field.type === "crud" ? colSpanClass(gridValue) : "";
|
|
129
130
|
return /* @__PURE__ */ jsx("div", { className: cn("space-y-2", spanClass), children: /* @__PURE__ */ jsx(FieldRenderer, { field, form, recordId }) }, field.name);
|
|
130
131
|
}) });
|
|
131
132
|
});
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/components/forms/admin-form/field-group.tsx
|
|
4
4
|
import { cn } from "../../../utils/index.js";
|
|
5
|
+
import { colSpanClass, gridColsClass } from "../grid-classes.js";
|
|
5
6
|
import { Label } from "../../../ui/label.js";
|
|
6
7
|
import { TEST_IDS } from "../../../utils/test-ids.js";
|
|
7
8
|
import { hasCrudFields, getFieldError as lookupFieldError } from "./helpers.js";
|
|
@@ -60,11 +61,11 @@ function renderFieldGroup(ctx, fieldsToRender, section) {
|
|
|
60
61
|
const filteredRow = filterFields(row);
|
|
61
62
|
if (filteredRow.length === 0) return null;
|
|
62
63
|
const useFlexbox = filteredRow.length > 6;
|
|
63
|
-
const gridCols2 = useFlexbox ? "" :
|
|
64
|
+
const gridCols2 = useFlexbox ? "" : gridColsClass(Math.min(filteredRow.length, 6));
|
|
64
65
|
const containerClass = useFlexbox ? "flex flex-wrap gap-3" : cn("grid gap-3", gridCols2);
|
|
65
66
|
return /* @__PURE__ */ jsx("div", { className: containerClass, children: filteredRow.map((field) => {
|
|
66
67
|
const hasError = !!getFieldError(field.name);
|
|
67
|
-
const spanClass = field.span ?
|
|
68
|
+
const spanClass = field.span ? colSpanClass(field.span) : field.type === "space" || field.type === "crud" ? useFlexbox ? "w-full" : colSpanClass(row.length) : useFlexbox ? "flex-1 min-w-0" : "";
|
|
68
69
|
return gate(
|
|
69
70
|
field,
|
|
70
71
|
/* @__PURE__ */ jsxs("div", { className: cn("space-y-1", spanClass), children: [
|
|
@@ -144,7 +145,7 @@ function renderFieldGroup(ctx, fieldsToRender, section) {
|
|
|
144
145
|
);
|
|
145
146
|
}
|
|
146
147
|
const gridValue = section?.grid || ctx.grid || "2";
|
|
147
|
-
const gridCols =
|
|
148
|
+
const gridCols = gridColsClass(gridValue);
|
|
148
149
|
return /* @__PURE__ */ jsx(
|
|
149
150
|
"div",
|
|
150
151
|
{
|
|
@@ -153,7 +154,7 @@ function renderFieldGroup(ctx, fieldsToRender, section) {
|
|
|
153
154
|
"aria-label": section?.label || ctx.t("form.fieldsAriaLabel"),
|
|
154
155
|
children: fields.map((field) => {
|
|
155
156
|
const hasError = !!getFieldError(field.name);
|
|
156
|
-
const spanClass = field.span ?
|
|
157
|
+
const spanClass = field.span ? colSpanClass(field.span) : field.type === "space" || field.type === "crud" ? colSpanClass(gridValue) : "";
|
|
157
158
|
return gate(
|
|
158
159
|
field,
|
|
159
160
|
/* @__PURE__ */ jsxs("div", { className: cn("space-y-2", spanClass), children: [
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Responsive grid columns for a form grid of `cols` columns. */
|
|
2
|
+
export declare function gridColsClass(cols: string | number): string;
|
|
3
|
+
/** Responsive column span for a field's `span` (`'1'`–`'12'` or `'full'`). */
|
|
4
|
+
export declare function colSpanClass(span: string | number): string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// src/components/forms/grid-classes.ts
|
|
2
|
+
var GRID_COLS = {
|
|
3
|
+
"1": "grid-cols-1",
|
|
4
|
+
"2": "grid-cols-1 sm:grid-cols-2",
|
|
5
|
+
"3": "grid-cols-1 sm:grid-cols-3",
|
|
6
|
+
"4": "grid-cols-1 sm:grid-cols-4",
|
|
7
|
+
"5": "grid-cols-1 sm:grid-cols-5",
|
|
8
|
+
"6": "grid-cols-1 sm:grid-cols-6",
|
|
9
|
+
"7": "grid-cols-1 sm:grid-cols-7",
|
|
10
|
+
"8": "grid-cols-1 sm:grid-cols-8",
|
|
11
|
+
"9": "grid-cols-1 sm:grid-cols-9",
|
|
12
|
+
"10": "grid-cols-1 sm:grid-cols-10",
|
|
13
|
+
"11": "grid-cols-1 sm:grid-cols-11",
|
|
14
|
+
"12": "grid-cols-1 sm:grid-cols-12"
|
|
15
|
+
};
|
|
16
|
+
var COL_SPAN = {
|
|
17
|
+
"1": "sm:col-span-1",
|
|
18
|
+
"2": "sm:col-span-2",
|
|
19
|
+
"3": "sm:col-span-3",
|
|
20
|
+
"4": "sm:col-span-4",
|
|
21
|
+
"5": "sm:col-span-5",
|
|
22
|
+
"6": "sm:col-span-6",
|
|
23
|
+
"7": "sm:col-span-7",
|
|
24
|
+
"8": "sm:col-span-8",
|
|
25
|
+
"9": "sm:col-span-9",
|
|
26
|
+
"10": "sm:col-span-10",
|
|
27
|
+
"11": "sm:col-span-11",
|
|
28
|
+
"12": "sm:col-span-12",
|
|
29
|
+
full: "col-span-full"
|
|
30
|
+
};
|
|
31
|
+
function gridColsClass(cols) {
|
|
32
|
+
return GRID_COLS[String(cols)] ?? `grid-cols-${cols}`;
|
|
33
|
+
}
|
|
34
|
+
function colSpanClass(span) {
|
|
35
|
+
return COL_SPAN[String(span)] ?? `col-span-${span}`;
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
colSpanClass,
|
|
39
|
+
gridColsClass
|
|
40
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/components/forms/validators/config-validator.ts
|
|
2
2
|
import { logger } from "../../../utils/logger.js";
|
|
3
3
|
import { fieldRegistry } from "../../../field-system/field-registry.js";
|
|
4
|
+
import { isMaskPreset } from "../../../field-system/mask-presets.js";
|
|
4
5
|
function validateFormField(field) {
|
|
5
6
|
const errors = [];
|
|
6
7
|
const warnings = [];
|
|
@@ -37,7 +38,7 @@ function validateFormField(field) {
|
|
|
37
38
|
}
|
|
38
39
|
if (field.type === "masked") {
|
|
39
40
|
if (!field.mask) {
|
|
40
|
-
if (field.maskType
|
|
41
|
+
if (!isMaskPreset(field.maskType)) {
|
|
41
42
|
errors.push(
|
|
42
43
|
`Field '${field.name}' with type 'masked' requires 'mask' prop`
|
|
43
44
|
);
|
|
@@ -89,11 +89,16 @@ export interface FilterButtonOption {
|
|
|
89
89
|
/** CSS class applied when active */
|
|
90
90
|
activeClass?: string;
|
|
91
91
|
}
|
|
92
|
-
declare function TabToolbarFilterButtons({ options, value, onChange, className, }: {
|
|
92
|
+
declare function TabToolbarFilterButtons({ options, value, onChange, className, allValue, }: {
|
|
93
93
|
options: FilterButtonOption[];
|
|
94
94
|
value: string;
|
|
95
95
|
onChange: (value: string) => void;
|
|
96
96
|
className?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Value meaning "no filter": its option is not rendered and an active button
|
|
99
|
+
* toggles back to it. Default: the first option's value.
|
|
100
|
+
*/
|
|
101
|
+
allValue?: string;
|
|
97
102
|
}): React.JSX.Element | null;
|
|
98
103
|
export interface FilterSelectOption {
|
|
99
104
|
value: string;
|