@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.
- package/CHANGELOG.md +53 -0
- 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 +6 -1
- package/dist/components/crud/crud-field.js +1 -0
- package/dist/components/data/DataTableActions.js +89 -85
- 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 +54 -0
- package/dist/components/dialog/confirm-action-dialog.js +182 -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/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/admin-form/visibility.js +2 -0
- 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/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/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/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/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/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.js +10 -2
- package/dist/queue/components/JobEventModal.js +3 -2
- package/dist/queue/components/QueueTabbedDashboard.d.ts +25 -2
- package/dist/queue/components/QueueTabbedDashboard.js +37 -5
- package/dist/queue/components/QueuesTable.d.ts +3 -2
- package/dist/queue/components/QueuesTable.js +31 -27
- 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 +31 -0
- package/dist/queue/components/labels-context.js +34 -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 +13 -9
- package/dist/queue/components/tabs/HistoricoTab.js +4 -3
- package/dist/queue/components/tabs/TempoRealTab.d.ts +8 -3
- package/dist/queue/components/tabs/TempoRealTab.js +13 -7
- package/dist/queue/hooks/use-queue-events-timeline.d.ts +19 -1
- package/dist/queue/hooks/use-queue-events-timeline.js +23 -3
- package/dist/server/pagination/factory.js +8 -1
- package/dist/server/pagination/types.d.ts +6 -0
- package/dist/server/pagination/utils.d.ts +13 -0
- package/dist/server/pagination/utils.js +27 -16
- package/dist/types/actions.d.ts +43 -14
- package/dist/types/crud.d.ts +47 -6
- 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
|
@@ -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;
|
|
@@ -0,0 +1,182 @@
|
|
|
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 { jsx, jsxs } from "react/jsx-runtime";
|
|
29
|
+
var initialValues = (inputs = []) => Object.fromEntries(inputs.map((i) => [i.name, i.defaultValue ?? ""]));
|
|
30
|
+
function ConfirmActionDialog({
|
|
31
|
+
open: openProp,
|
|
32
|
+
onOpenChange,
|
|
33
|
+
children,
|
|
34
|
+
title,
|
|
35
|
+
description,
|
|
36
|
+
confirmText,
|
|
37
|
+
cancelText,
|
|
38
|
+
variant = "default",
|
|
39
|
+
inputs,
|
|
40
|
+
onConfirm
|
|
41
|
+
}) {
|
|
42
|
+
const t = useTelamonjsT();
|
|
43
|
+
const text = useText();
|
|
44
|
+
const idPrefix = useId();
|
|
45
|
+
const [innerOpen, setInnerOpen] = useState(false);
|
|
46
|
+
const open = openProp ?? innerOpen;
|
|
47
|
+
const [values, setValues] = useState(() => initialValues(inputs));
|
|
48
|
+
const [missing, setMissing] = useState([]);
|
|
49
|
+
const [error, setError] = useState(null);
|
|
50
|
+
const [pending, setPending] = useState(false);
|
|
51
|
+
const [wasOpen, setWasOpen] = useState(open);
|
|
52
|
+
if (open !== wasOpen) {
|
|
53
|
+
setWasOpen(open);
|
|
54
|
+
if (open) {
|
|
55
|
+
setValues(initialValues(inputs));
|
|
56
|
+
setMissing([]);
|
|
57
|
+
setError(null);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const setOpen = (next) => {
|
|
61
|
+
if (openProp === void 0) setInnerOpen(next);
|
|
62
|
+
onOpenChange?.(next);
|
|
63
|
+
};
|
|
64
|
+
const handleOpenChange = (next) => {
|
|
65
|
+
if (!next && pending) return;
|
|
66
|
+
setOpen(next);
|
|
67
|
+
};
|
|
68
|
+
const handleConfirm = async (event) => {
|
|
69
|
+
event.preventDefault();
|
|
70
|
+
const empty = (inputs ?? []).filter((i) => i.required && !values[i.name]?.trim()).map((i) => i.name);
|
|
71
|
+
setMissing(empty);
|
|
72
|
+
if (empty.length > 0) return;
|
|
73
|
+
setError(null);
|
|
74
|
+
setPending(true);
|
|
75
|
+
try {
|
|
76
|
+
const result = await onConfirm(values);
|
|
77
|
+
setPending(false);
|
|
78
|
+
if (result !== false) setOpen(false);
|
|
79
|
+
} catch (err) {
|
|
80
|
+
setPending(false);
|
|
81
|
+
setError(
|
|
82
|
+
err instanceof Error && err.message ? err.message : t("toast.unknownError")
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const setValue = (name, value) => {
|
|
87
|
+
setValues((prev) => ({ ...prev, [name]: value }));
|
|
88
|
+
if (missing.includes(name)) setMissing((prev) => prev.filter((n) => n !== name));
|
|
89
|
+
};
|
|
90
|
+
return /* @__PURE__ */ jsxs(AlertDialog, { open, onOpenChange: handleOpenChange, children: [
|
|
91
|
+
children && /* @__PURE__ */ jsx(AlertDialogTrigger, { asChild: true, children }),
|
|
92
|
+
/* @__PURE__ */ jsxs(AlertDialogContent, { children: [
|
|
93
|
+
/* @__PURE__ */ jsxs(AlertDialogHeader, { children: [
|
|
94
|
+
/* @__PURE__ */ jsx(AlertDialogTitle, { children: text(title) || t("dialog.confirmActionTitle") }),
|
|
95
|
+
description && /* @__PURE__ */ jsx(AlertDialogDescription, { children: text(description) })
|
|
96
|
+
] }),
|
|
97
|
+
inputs && inputs.length > 0 && /* @__PURE__ */ jsx("div", { className: "grid gap-4", children: inputs.map((input) => {
|
|
98
|
+
const id = `${idPrefix}-${input.name}`;
|
|
99
|
+
const errorId = `${id}-error`;
|
|
100
|
+
const invalid = missing.includes(input.name);
|
|
101
|
+
const common = {
|
|
102
|
+
id,
|
|
103
|
+
name: input.name,
|
|
104
|
+
required: input.required,
|
|
105
|
+
disabled: pending,
|
|
106
|
+
"aria-invalid": invalid || void 0,
|
|
107
|
+
"aria-describedby": invalid ? errorId : void 0
|
|
108
|
+
};
|
|
109
|
+
return /* @__PURE__ */ jsxs("div", { className: "grid gap-1.5", children: [
|
|
110
|
+
/* @__PURE__ */ jsxs(Label, { htmlFor: id, children: [
|
|
111
|
+
text(input.label),
|
|
112
|
+
input.required && /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "text-destructive", children: " *" })
|
|
113
|
+
] }),
|
|
114
|
+
input.type === "textarea" ? /* @__PURE__ */ jsx(
|
|
115
|
+
Textarea,
|
|
116
|
+
{
|
|
117
|
+
...common,
|
|
118
|
+
value: values[input.name] ?? "",
|
|
119
|
+
onChange: (e) => setValue(input.name, e.target.value)
|
|
120
|
+
}
|
|
121
|
+
) : input.type === "select" ? /* @__PURE__ */ jsxs(
|
|
122
|
+
Select,
|
|
123
|
+
{
|
|
124
|
+
value: values[input.name] ?? "",
|
|
125
|
+
onValueChange: (v) => setValue(input.name, v),
|
|
126
|
+
disabled: pending,
|
|
127
|
+
children: [
|
|
128
|
+
/* @__PURE__ */ jsx(
|
|
129
|
+
SelectTrigger,
|
|
130
|
+
{
|
|
131
|
+
id,
|
|
132
|
+
"aria-invalid": common["aria-invalid"],
|
|
133
|
+
"aria-describedby": common["aria-describedby"],
|
|
134
|
+
children: /* @__PURE__ */ jsx(SelectValue, { placeholder: t("common.select") })
|
|
135
|
+
}
|
|
136
|
+
),
|
|
137
|
+
/* @__PURE__ */ jsx(SelectContent, { children: (input.options ?? []).map((option) => /* @__PURE__ */ jsx(SelectItem, { value: option, children: option }, option)) })
|
|
138
|
+
]
|
|
139
|
+
}
|
|
140
|
+
) : /* @__PURE__ */ jsx(
|
|
141
|
+
Input,
|
|
142
|
+
{
|
|
143
|
+
...common,
|
|
144
|
+
value: values[input.name] ?? "",
|
|
145
|
+
onChange: (e) => setValue(input.name, e.target.value)
|
|
146
|
+
}
|
|
147
|
+
),
|
|
148
|
+
invalid && /* @__PURE__ */ jsx("p", { id: errorId, className: "text-sm text-destructive", children: t("validation.required") })
|
|
149
|
+
] }, input.name);
|
|
150
|
+
}) }),
|
|
151
|
+
error && /* @__PURE__ */ jsx(
|
|
152
|
+
"p",
|
|
153
|
+
{
|
|
154
|
+
role: "alert",
|
|
155
|
+
"data-testid": "confirm-action-error",
|
|
156
|
+
className: "text-sm text-destructive",
|
|
157
|
+
children: error
|
|
158
|
+
}
|
|
159
|
+
),
|
|
160
|
+
/* @__PURE__ */ jsxs(AlertDialogFooter, { children: [
|
|
161
|
+
/* @__PURE__ */ jsx(AlertDialogCancel, { "data-testid": "modal-cancel", disabled: pending, children: text(cancelText) || t("common.cancel") }),
|
|
162
|
+
/* @__PURE__ */ jsxs(
|
|
163
|
+
AlertDialogAction,
|
|
164
|
+
{
|
|
165
|
+
"data-testid": "modal-confirm",
|
|
166
|
+
disabled: pending,
|
|
167
|
+
"aria-busy": pending || void 0,
|
|
168
|
+
className: variant === "destructive" ? "bg-red-500 text-white hover:bg-red-600" : "",
|
|
169
|
+
onClick: handleConfirm,
|
|
170
|
+
children: [
|
|
171
|
+
pending && /* @__PURE__ */ jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin", "aria-hidden": "true" }),
|
|
172
|
+
text(confirmText) || t("common.confirm")
|
|
173
|
+
]
|
|
174
|
+
}
|
|
175
|
+
)
|
|
176
|
+
] })
|
|
177
|
+
] })
|
|
178
|
+
] });
|
|
179
|
+
}
|
|
180
|
+
export {
|
|
181
|
+
ConfirmActionDialog
|
|
182
|
+
};
|
|
@@ -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: [
|
|
@@ -19,8 +19,10 @@ function collectHiddenFieldNames(config, values) {
|
|
|
19
19
|
}
|
|
20
20
|
return hidden;
|
|
21
21
|
}
|
|
22
|
+
var UNSAFE_PATH_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
22
23
|
function deleteAtPath(obj, path) {
|
|
23
24
|
const parts = path.split(".");
|
|
25
|
+
if (parts.some((p) => UNSAFE_PATH_SEGMENTS.has(p))) return;
|
|
24
26
|
let target = obj;
|
|
25
27
|
for (let i = 0; i < parts.length - 1; i++) {
|
|
26
28
|
const next = target[parts[i]];
|
|
@@ -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;
|
|
@@ -272,9 +272,11 @@ function TabToolbarFilterButtons({
|
|
|
272
272
|
options,
|
|
273
273
|
value,
|
|
274
274
|
onChange,
|
|
275
|
-
className
|
|
275
|
+
className,
|
|
276
|
+
allValue
|
|
276
277
|
}) {
|
|
277
|
-
const
|
|
278
|
+
const resetValue = allValue ?? options[0]?.value ?? "";
|
|
279
|
+
const toggleOptions = allValue === void 0 ? options.slice(1) : options.filter((o) => o.value !== allValue);
|
|
278
280
|
if (toggleOptions.length === 0) return null;
|
|
279
281
|
return /* @__PURE__ */ jsx(
|
|
280
282
|
"div",
|
|
@@ -290,7 +292,7 @@ function TabToolbarFilterButtons({
|
|
|
290
292
|
{
|
|
291
293
|
variant: "outline",
|
|
292
294
|
size: "sm",
|
|
293
|
-
onClick: () => onChange(isActive ?
|
|
295
|
+
onClick: () => onChange(isActive ? resetValue : opt.value),
|
|
294
296
|
className: cn(
|
|
295
297
|
"h-8 rounded-none gap-1.5",
|
|
296
298
|
isFirst && "rounded-l-md",
|
|
@@ -12,7 +12,7 @@ export { ExportMenu } from '../data/ExportMenu';
|
|
|
12
12
|
export type { ExportMenuProps } from '../data/ExportMenu';
|
|
13
13
|
export { exportToExcel, exportToCSV, exportToPDF, exportTableData, } from '../data/exportUtils';
|
|
14
14
|
export type { ExportOptions, PDFExportOptions } from '../data/exportUtils';
|
|
15
|
-
export type { DataTableActionsConfig, ActionConfig, CustomAction, StandardActionsConfig, ActionsDisplayConfig, ConfirmDialogConfig, TooltipConfig, ButtonVariant, BadgeVariant, } from '../types/actions';
|
|
15
|
+
export type { DataTableActionsConfig, ActionConfig, CustomAction, StandardActionsConfig, ActionsDisplayConfig, ConfirmDialogConfig, ConfirmDialogInput, ActionContext, TooltipConfig, ButtonVariant, BadgeVariant, } from '../types/actions';
|
|
16
16
|
export { VirtualDataTable } from '../data/VirtualDataTable';
|
|
17
17
|
export { withScope } from '../utils/with-scope';
|
|
18
18
|
export type { CrudScope } from '../utils/with-scope';
|
|
@@ -2,7 +2,7 @@ export { BaseFormPage } from '../pages/BaseFormPage';
|
|
|
2
2
|
export type { BaseFormPageProps } from '../pages/BaseFormPage';
|
|
3
3
|
export { DetailPage } from '../pages/DetailPage';
|
|
4
4
|
export { ListPage } from '../pages/ListPage';
|
|
5
|
-
export type { ActiveFilterChip } from '../pages/list-page/types';
|
|
5
|
+
export type { ActiveFilterChip, ListQueryState } from '../pages/list-page/types';
|
|
6
6
|
export { EditPage } from '../pages/EditPage';
|
|
7
7
|
export type { EditPageProps } from '../pages/EditPage';
|
|
8
8
|
export { CreatePage } from '../pages/CreatePage';
|
|
@@ -15,6 +15,8 @@ export { CreateDialog } from '../components/dialog/create-dialog';
|
|
|
15
15
|
export type { CreateDialogProps } from '../components/dialog/create-dialog';
|
|
16
16
|
export { ViewPortalDialog } from '../components/dialog/view-portal-dialog';
|
|
17
17
|
export { CrudViewDialog } from '../components/dialog/crud-view-dialog';
|
|
18
|
+
export { ConfirmActionDialog } from '../components/dialog/confirm-action-dialog';
|
|
19
|
+
export type { ConfirmActionDialogProps } from '../components/dialog/confirm-action-dialog';
|
|
18
20
|
export type { CrudViewDialogProps } from '../components/dialog/crud-view-dialog';
|
|
19
21
|
export type { ViewPortalDialogProps, ViewPortalSection, PortalSectionEdit, } from '../components/dialog/view-portal-dialog';
|
|
20
22
|
export { DialogHeaderContent } from '../components/dialog';
|
|
@@ -9,6 +9,7 @@ import { ViewDialog } from "../components/dialog/view-dialog.js";
|
|
|
9
9
|
import { CreateDialog } from "../components/dialog/create-dialog.js";
|
|
10
10
|
import { ViewPortalDialog } from "../components/dialog/view-portal-dialog.js";
|
|
11
11
|
import { CrudViewDialog } from "../components/dialog/crud-view-dialog.js";
|
|
12
|
+
import { ConfirmActionDialog } from "../components/dialog/confirm-action-dialog.js";
|
|
12
13
|
import { DialogHeaderContent } from "../components/dialog/index.js";
|
|
13
14
|
import { StatsGrid } from "../components/dialog/index.js";
|
|
14
15
|
import { DialogFrame } from "../components/dialog/index.js";
|
|
@@ -16,6 +17,7 @@ import { SplitDialogFrame } from "../components/dialog/index.js";
|
|
|
16
17
|
import { PageContent } from "../layouts/PageContent.js";
|
|
17
18
|
export {
|
|
18
19
|
BaseFormPage,
|
|
20
|
+
ConfirmActionDialog,
|
|
19
21
|
CreateDialog,
|
|
20
22
|
CreatePage,
|
|
21
23
|
CrudViewDialog,
|