@telamonjs/ui 1.2.1 → 1.3.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 +33 -0
- package/README.md +1 -1
- package/dist/components/data/DataTableActions.js +1 -0
- package/dist/components/data/action-access.d.ts +9 -2
- package/dist/components/data/action-access.js +10 -3
- package/dist/components/dialog/CrudDialogShell.d.ts +2 -0
- package/dist/components/dialog/CrudDialogShell.js +9 -7
- package/dist/components/dialog/DialogLoadingState.d.ts +16 -0
- package/dist/components/dialog/DialogLoadingState.js +16 -0
- package/dist/components/dialog/confirm-action-dialog.d.ts +12 -4
- package/dist/components/dialog/confirm-action-dialog.js +75 -14
- package/dist/components/dialog/create-dialog.js +1 -12
- package/dist/components/dialog/edit-dialog.js +5 -4
- package/dist/components/dialog/index.d.ts +1 -1
- package/dist/components/dialog/index.js +1 -2
- package/dist/components/dialog/view-dialog.js +5 -4
- package/dist/components/utilities/QueryErrorState.d.ts +47 -0
- package/dist/components/utilities/QueryErrorState.js +85 -0
- package/dist/data/DataTable.d.ts +2 -2
- package/dist/data/DataTable.js +2 -0
- package/dist/data/ExportMenu.d.ts +30 -3
- package/dist/data/ExportMenu.js +69 -5
- package/dist/data/datatable/TableToolbar.d.ts +3 -2
- package/dist/data/datatable/TableToolbar.js +30 -13
- package/dist/data/datatable/types.d.ts +9 -0
- package/dist/data/fetch-all-pages.d.ts +30 -0
- package/dist/data/fetch-all-pages.js +44 -0
- package/dist/exports/data-crud.d.ts +7 -3
- package/dist/exports/data-crud.js +4 -0
- package/dist/exports/types-constants.d.ts +2 -2
- package/dist/exports/types-constants.js +1 -1
- package/dist/i18n/messages/en/data.d.ts +3 -0
- package/dist/i18n/messages/en/data.js +3 -0
- package/dist/i18n/messages/en/index.d.ts +5 -0
- package/dist/i18n/messages/en/validation.d.ts +2 -0
- package/dist/i18n/messages/en/validation.js +2 -0
- package/dist/i18n/messages/es/data.d.ts +3 -0
- package/dist/i18n/messages/es/data.js +3 -0
- package/dist/i18n/messages/es/index.d.ts +5 -0
- package/dist/i18n/messages/es/validation.d.ts +2 -0
- package/dist/i18n/messages/es/validation.js +2 -0
- package/dist/i18n/messages/pt-BR/data.d.ts +3 -0
- package/dist/i18n/messages/pt-BR/data.js +3 -0
- package/dist/i18n/messages/pt-BR/index.d.ts +5 -0
- package/dist/i18n/messages/pt-BR/validation.d.ts +2 -0
- package/dist/i18n/messages/pt-BR/validation.js +2 -0
- package/dist/i18n/use-t.d.ts +5 -0
- package/dist/pages/ListPage.js +9 -13
- package/dist/pages/list-page/ListPageTable.d.ts +4 -2
- package/dist/pages/list-page/ListPageTable.js +3 -3
- package/dist/pages/list-page/ListPageToolbar.d.ts +4 -1
- package/dist/pages/list-page/ListPageToolbar.js +10 -4
- package/dist/pages/list-page/apply-crud-permissions.d.ts +4 -1
- package/dist/pages/list-page/apply-crud-permissions.js +20 -3
- package/dist/pages/list-page/types.d.ts +2 -16
- package/dist/pages/list-page/useListPageExport.d.ts +24 -0
- package/dist/pages/list-page/useListPageExport.js +54 -0
- package/dist/types/actions.d.ts +43 -4
- package/dist/types/crud.d.ts +48 -2
- package/package.json +1 -1
- package/dist/components/dialog/DialogErrorState.d.ts +0 -44
- package/dist/components/dialog/DialogErrorState.js +0 -57
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5a8b1b6: `ConfirmActionDialog` and `confirmDialog.inputs`: length, date and native field options, and an opt-in "disabled until valid" mode.
|
|
8
|
+
|
|
9
|
+
- `ConfirmDialogInput` gains `minLength`/`maxLength` (on the trimmed value; `minLength` checks an optional field only once it is filled), `min`/`max` for `date` (set on the native input and validated), `options` as `{ value, label }` (new `ConfirmDialogOption`; plain strings still work), `placeholder`, `description` (help text announced with the field), `rows` for `textarea`, `suggestions` for `text` (a native `<datalist>`) and the native `inputMode`/`autoComplete`.
|
|
10
|
+
- A `minLength`/`maxLength` input shows how many characters are missing or over as the user types, before any confirm attempt (new `validation.charactersMissing`/`charactersOver` messages in pt-BR, en and es).
|
|
11
|
+
- New `disableUntilValid` (on `ConfirmActionDialog` and on `ConfirmDialogConfig`): the confirm stays disabled while any input fails, and every failing field shows its message live — muted until edited, as an error once edited or after an attempt — so the reason is always visible. Without it, nothing changes: the confirm stays enabled and messages show from the first attempt, as in 1.2.
|
|
12
|
+
|
|
13
|
+
- 0429b6c: `CrudConfig.permissions` no longer fails open silently.
|
|
14
|
+
|
|
15
|
+
- In development, `ListPage` warns once per config when `permissions` declares operations but there is no way to check them (neither `permissions.can`, `actionsConfig.can` nor `actionsConfig.userPermissions`), which means every write button shows. Production behaviour is unchanged.
|
|
16
|
+
- New opt-in `permissions.failClosed` (same name and meaning as in `@telamonjs/permissions`): with no checker, every declared operation and every action `permission` is denied instead of allowed — useful while the session that feeds `can` is still loading. Default `false`.
|
|
17
|
+
- `applyCrudPermissions` now checks against the `actionsConfig` the list actually uses (it read `config.actionsConfig` for the dialogs only).
|
|
18
|
+
|
|
19
|
+
- 6349bde: `ListPage` export can cover every matching row, or hand the export to the app. The default is unchanged: "All" exports the rows already loaded.
|
|
20
|
+
|
|
21
|
+
- `list.exportAll: true | { pageSize?, maxRows? }`: "All" fetches every row matching the current search, filters and sort through `query.queryFn`, page by page and sequentially, honoring `totalPages`. A progress toast offers Cancel. Rows are capped at `maxRows` (default 10 000), with a warning when the file holds fewer rows than the server total. Requests use `exportAll.pageSize`, else `defaultPageSize` (50).
|
|
22
|
+
- `list.onExport(state: ListQueryState, format)`: an app-side export (e.g. a server-generated file). The menu lists the formats only and calls it with the same query `toolbarContent` receives. It wins over `exportAll`, shows the menu without `enableExport`, and errors show the export error toast.
|
|
23
|
+
- `list.exportFormats` picks the formats offered.
|
|
24
|
+
- `ExportMenu` gains `loadAll` (+ `allCount`) and `onServerExport`, and `DataTable` gains `exportMenuProps` to pass them through. New public `fetchAllPages()` helper and `ExportFormat`, `ExportLoadAllContext`, `ExportAllOptions`, `FetchAllPagesOptions`, `DataTableExportMenuProps` types.
|
|
25
|
+
|
|
26
|
+
Fix: the paginated `ListPage` (`infiniteScroll: false`) no longer exports through a raw `Object.values` CSV without headers. It uses the same Excel/CSV/PDF menu as the infinite list, with the list's columns and filename, now also available below `lg` through a compact trigger.
|
|
27
|
+
|
|
28
|
+
- df92415: New public `QueryErrorState`: the error state for screens that run their own `useQuery`, so apps stop keeping a local `QueryErrorAlert`.
|
|
29
|
+
|
|
30
|
+
- `error` (an `Error`, a string or any object with a string `message`) becomes the description; `title` and `description` take `I18nText`, with a localized "Failed to load data" default.
|
|
31
|
+
- `onRetry` shows a "Try again" button, called with no arguments (`onRetry={refetch}` is safe), pending (disabled, spinner, `aria-busy`) while the promise it returns runs; `retrying` drives the same state from the caller. The button is `type="button"`.
|
|
32
|
+
- It is now the single implementation behind the CRUD view/edit dialogs' load error, which gain a working "Try again" (they had none). The internal `DialogErrorState` is gone, and so is the never-set error branch of `CreateDialog`.
|
|
33
|
+
|
|
34
|
+
Migrating a local `QueryErrorAlert({ message, onRetry })`: `message` → `title` (or `description`), `onRetry={() => refetch()}` → `onRetry={refetch}`, and add `className='mb-4'` where the layout relied on the local copy's margin.
|
|
35
|
+
|
|
3
36
|
## 1.2.1
|
|
4
37
|
|
|
5
38
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -89,7 +89,7 @@ async `loadField`), `'multiselect'`, `'richtext'` and 31 more; there is no
|
|
|
89
89
|
| Forms | `AdminForm`, `CreateForm`, `EditForm`, `Stepper`, `FileUpload`, `useUnsavedChangesGuard` |
|
|
90
90
|
| Field system | 36 field types; `registerFieldRenderer` adds your own |
|
|
91
91
|
| Shell | `AdminShell` (sidebar, breadcrumb, header, Cmd+K palette fed from your menu), `ShellPage`, `AdminTabs`, `ImpersonationBanner` |
|
|
92
|
-
| Data | `DataTable`, `VirtualDataTable`, `InfiniteList`, bulk actions, Excel/CSV/PDF export |
|
|
92
|
+
| Data | `DataTable`, `VirtualDataTable`, `InfiniteList`, bulk actions, Excel/CSV/PDF export, `QueryErrorState` (error + pending "Try again" for your own `useQuery`) |
|
|
93
93
|
| Dashboards and charts | `DashboardGrid`, `DashboardShell`, `StatCard`, `ChartWidget`, `LineChart`, `BarChart`, `PieChart`, `AreaChart`, `KPICard` |
|
|
94
94
|
| Queue UI | `@telamonjs/ui/queue`: `QueueTabbedDashboard`, `QueueApiProvider`, `createNestJSAdapter`, a frontend for `@telamonjs/queue` |
|
|
95
95
|
| Server | `@telamonjs/ui/server`: `createPaginationContext`, `buildPrismaOrderBy`, `createPaginatedResponse`, `revalidatePathAction` |
|
|
@@ -10,12 +10,19 @@ import type { CrudConfig, CrudPermissions } from '../../types/crud';
|
|
|
10
10
|
* `userPermissions`. Neither = everything allowed.
|
|
11
11
|
*/
|
|
12
12
|
export declare function actionGranted(permission: ActionConfig['permission'], userPermissions: readonly string[] | ReadonlySet<string> | undefined, can?: (permission: string) => boolean): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The permission checker a CrudConfig resolves to: `actionsConfig.can`, else
|
|
15
|
+
* `permissions.can`. With neither and no `actionsConfig.userPermissions`, it is
|
|
16
|
+
* `undefined` (everything allowed) — or a checker that denies everything when
|
|
17
|
+
* `permissions.failClosed` is set.
|
|
18
|
+
*/
|
|
19
|
+
export declare function crudChecker(config: Pick<CrudConfig, 'permissions' | 'actionsConfig'>): ((permission: string) => boolean) | undefined;
|
|
13
20
|
/**
|
|
14
21
|
* A CrudConfig operation (`permissions.create`, …) against the same checker the
|
|
15
22
|
* row actions use: `permissions.can` or `actionsConfig.can`, else
|
|
16
|
-
* `actionsConfig.userPermissions
|
|
23
|
+
* `actionsConfig.userPermissions` (see `crudChecker` for `failClosed`).
|
|
17
24
|
*/
|
|
18
|
-
export declare function crudGranted(config: Pick<CrudConfig, 'permissions' | 'actionsConfig'>, operation: keyof
|
|
25
|
+
export declare function crudGranted(config: Pick<CrudConfig, 'permissions' | 'actionsConfig'>, operation: Exclude<keyof CrudPermissions, 'can' | 'failClosed'>): boolean;
|
|
19
26
|
/** `visible` for this row (`undefined` = visible). */
|
|
20
27
|
export declare function actionVisible<TData>(action: Pick<ActionConfig<TData>, 'visible'>, row: TData): boolean;
|
|
21
28
|
/** `enabled` for this row (`undefined` = enabled). */
|
|
@@ -7,12 +7,18 @@ function actionGranted(permission, userPermissions, can) {
|
|
|
7
7
|
const granted = userPermissions instanceof Set ? userPermissions : new Set(userPermissions);
|
|
8
8
|
return required.some((perm) => granted.has(perm));
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
var denyAll = () => false;
|
|
11
|
+
function crudChecker(config) {
|
|
11
12
|
const actions = config.actionsConfig || void 0;
|
|
13
|
+
const can = actions?.can ?? config.permissions?.can;
|
|
14
|
+
if (can || actions?.userPermissions) return can;
|
|
15
|
+
return config.permissions?.failClosed ? denyAll : void 0;
|
|
16
|
+
}
|
|
17
|
+
function crudGranted(config, operation) {
|
|
12
18
|
return actionGranted(
|
|
13
19
|
config.permissions?.[operation],
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
(config.actionsConfig || void 0)?.userPermissions,
|
|
21
|
+
crudChecker(config)
|
|
16
22
|
);
|
|
17
23
|
}
|
|
18
24
|
function actionVisible(action, row) {
|
|
@@ -29,5 +35,6 @@ export {
|
|
|
29
35
|
actionEnabled,
|
|
30
36
|
actionGranted,
|
|
31
37
|
actionVisible,
|
|
38
|
+
crudChecker,
|
|
32
39
|
crudGranted
|
|
33
40
|
};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
// src/components/dialog/CrudDialogShell.tsx
|
|
4
|
-
import { AlertCircle } from "lucide-react";
|
|
5
4
|
import { useIsMobile } from "../../hooks/use-mobile.js";
|
|
6
5
|
import {
|
|
7
6
|
Dialog,
|
|
@@ -18,8 +17,8 @@ import {
|
|
|
18
17
|
SheetTitle
|
|
19
18
|
} from "../../ui/sheet.js";
|
|
20
19
|
import { cn } from "../../utils/index.js";
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
20
|
+
import { DialogLoadingState } from "./DialogLoadingState.js";
|
|
21
|
+
import { QueryErrorState } from "../utilities/QueryErrorState.js";
|
|
23
22
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
24
23
|
function CrudDialogShell({
|
|
25
24
|
open,
|
|
@@ -69,10 +68,13 @@ function CrudDialogShell({
|
|
|
69
68
|
children: [
|
|
70
69
|
/* @__PURE__ */ jsx(DialogTitle, { className: "sr-only", children: title }),
|
|
71
70
|
desktopStatus.isLoading && /* @__PURE__ */ jsx(DialogLoadingState, {}),
|
|
72
|
-
desktopStatus.error && /* @__PURE__ */ jsx("div", { className: "py-8 w-full px-6", children: /* @__PURE__ */
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
desktopStatus.error && /* @__PURE__ */ jsx("div", { className: "py-8 w-full px-6", children: /* @__PURE__ */ jsx(
|
|
72
|
+
QueryErrorState,
|
|
73
|
+
{
|
|
74
|
+
error: desktopStatus.error,
|
|
75
|
+
onRetry: desktopStatus.onRetry
|
|
76
|
+
}
|
|
77
|
+
) })
|
|
76
78
|
]
|
|
77
79
|
}
|
|
78
80
|
) });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface DialogLoadingStateProps {
|
|
2
|
+
/** Loading message */
|
|
3
|
+
message?: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* DialogLoadingState - Renders loading spinner with optional message.
|
|
7
|
+
*
|
|
8
|
+
* Consolidates the duplicated loading spinner rendering from EditDialog and ViewDialog.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* {isLoading && <DialogLoadingState />}
|
|
13
|
+
* {isLoading && <DialogLoadingState message="Buscando dados..." />}
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function DialogLoadingState({ message }: DialogLoadingStateProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/dialog/DialogLoadingState.tsx
|
|
4
|
+
import { Loader2 } from "lucide-react";
|
|
5
|
+
import { useTelamonjsT } from "../../i18n/use-t.js";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
function DialogLoadingState({ message }) {
|
|
8
|
+
const t = useTelamonjsT();
|
|
9
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center py-12 space-y-4", children: [
|
|
10
|
+
/* @__PURE__ */ jsx(Loader2, { className: "h-8 w-8 animate-spin text-primary" }),
|
|
11
|
+
/* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: message ?? t("dialog.loadingData") })
|
|
12
|
+
] });
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
DialogLoadingState
|
|
16
|
+
};
|
|
@@ -32,10 +32,17 @@ export interface ConfirmActionDialogProps {
|
|
|
32
32
|
*/
|
|
33
33
|
pending?: boolean;
|
|
34
34
|
/**
|
|
35
|
-
* Fields asked before confirming; `required`
|
|
36
|
-
* confirm while they fail
|
|
35
|
+
* Fields asked before confirming; `required`, `minLength`, `maxLength`,
|
|
36
|
+
* `min`/`max` and `validate` block the confirm while they fail
|
|
37
37
|
*/
|
|
38
38
|
inputs?: ConfirmDialogInput[];
|
|
39
|
+
/**
|
|
40
|
+
* Keep the confirm disabled while any input fails, each failing field
|
|
41
|
+
* showing its message live (muted until edited), so the reason is always
|
|
42
|
+
* visible. Default: the confirm stays enabled and messages show from the
|
|
43
|
+
* first attempt (`minLength`/`maxLength` counts show live in both modes).
|
|
44
|
+
*/
|
|
45
|
+
disableUntilValid?: boolean;
|
|
39
46
|
/**
|
|
40
47
|
* Runs on confirm with the `inputs` values (`{}` without inputs). Without
|
|
41
48
|
* `pending`, the dialog stays open, buttons disabled, while the returned
|
|
@@ -55,7 +62,8 @@ export interface ConfirmActionDialogProps {
|
|
|
55
62
|
* @description
|
|
56
63
|
* The dialog behind `confirmDialog` on row and menu actions, public for any
|
|
57
64
|
* other button. Optional `inputs` (text, textarea, select, date) are validated
|
|
58
|
-
* (`required`, `validate`) and handed to
|
|
65
|
+
* (`required`, `minLength`/`maxLength`, `min`/`max`, `validate`) and handed to
|
|
66
|
+
* `onConfirm`; `disableUntilValid` keeps the confirm off until they pass; `body` adds free
|
|
59
67
|
* content. Two pending modes: by default the dialog awaits `onConfirm`
|
|
60
68
|
* (spinner, closes on success, shows the error on failure); with a `pending`
|
|
61
69
|
* prop the caller runs the action and closes the dialog itself.
|
|
@@ -83,4 +91,4 @@ export interface ConfirmActionDialogProps {
|
|
|
83
91
|
* />
|
|
84
92
|
* ```
|
|
85
93
|
*/
|
|
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;
|
|
94
|
+
export declare function ConfirmActionDialog({ open: openProp, onOpenChange, children, title, description, body, confirmText, pendingText, cancelText, variant, confirmDisabled, pending: pendingProp, inputs, disableUntilValid, onConfirm, }: ConfirmActionDialogProps): import("react").JSX.Element;
|
|
@@ -26,8 +26,13 @@ import {
|
|
|
26
26
|
import { Textarea } from "../../ui/textarea.js";
|
|
27
27
|
import { useTelamonjsT, useText } from "../../i18n/use-t.js";
|
|
28
28
|
import { isMessageRef } from "../../i18n/msg.js";
|
|
29
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
29
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
30
30
|
var initialValues = (inputs = []) => Object.fromEntries(inputs.map((i) => [i.name, i.defaultValue ?? ""]));
|
|
31
|
+
var asOption = (o) => typeof o === "string" ? { value: o, label: o } : o;
|
|
32
|
+
var calendarDate = (iso) => {
|
|
33
|
+
const [y, m, d] = iso.split("-").map(Number);
|
|
34
|
+
return new Date(Date.UTC(y, m - 1, d, 12));
|
|
35
|
+
};
|
|
31
36
|
function ConfirmActionDialog({
|
|
32
37
|
open: openProp,
|
|
33
38
|
onOpenChange,
|
|
@@ -42,6 +47,7 @@ function ConfirmActionDialog({
|
|
|
42
47
|
confirmDisabled = false,
|
|
43
48
|
pending: pendingProp,
|
|
44
49
|
inputs,
|
|
50
|
+
disableUntilValid = false,
|
|
45
51
|
onConfirm
|
|
46
52
|
}) {
|
|
47
53
|
const t = useTelamonjsT();
|
|
@@ -51,6 +57,7 @@ function ConfirmActionDialog({
|
|
|
51
57
|
const open = openProp ?? innerOpen;
|
|
52
58
|
const [values, setValues] = useState(() => initialValues(inputs));
|
|
53
59
|
const [attempted, setAttempted] = useState(false);
|
|
60
|
+
const [touched, setTouched] = useState({});
|
|
54
61
|
const [error, setError] = useState(null);
|
|
55
62
|
const [innerPending, setInnerPending] = useState(false);
|
|
56
63
|
const callerOwnsPending = pendingProp !== void 0;
|
|
@@ -61,15 +68,33 @@ function ConfirmActionDialog({
|
|
|
61
68
|
if (open) {
|
|
62
69
|
setValues(initialValues(inputs));
|
|
63
70
|
setAttempted(false);
|
|
71
|
+
setTouched({});
|
|
64
72
|
setError(null);
|
|
65
73
|
}
|
|
66
74
|
}
|
|
67
75
|
const node = (value) => isMessageRef(value) ? text(value) : value;
|
|
76
|
+
const lengthMessage = (input) => {
|
|
77
|
+
const length = (values[input.name] ?? "").trim().length;
|
|
78
|
+
if (input.minLength && length < input.minLength && (length > 0 || input.required))
|
|
79
|
+
return t("validation.charactersMissing", { count: input.minLength - length });
|
|
80
|
+
if (input.maxLength && length > input.maxLength)
|
|
81
|
+
return t("validation.charactersOver", { count: length - input.maxLength });
|
|
82
|
+
return void 0;
|
|
83
|
+
};
|
|
68
84
|
const fieldError = (input) => {
|
|
69
85
|
const value = values[input.name] ?? "";
|
|
86
|
+
const length = lengthMessage(input);
|
|
87
|
+
if (length) return length;
|
|
70
88
|
if (input.required && !value.trim()) return t("validation.required");
|
|
89
|
+
if (input.type === "date" && value) {
|
|
90
|
+
if (input.min && value < input.min)
|
|
91
|
+
return t("validation.tooSmallDate", { min: calendarDate(input.min) });
|
|
92
|
+
if (input.max && value > input.max)
|
|
93
|
+
return t("validation.tooBigDate", { max: calendarDate(input.max) });
|
|
94
|
+
}
|
|
71
95
|
return input.validate?.(value, values);
|
|
72
96
|
};
|
|
97
|
+
const invalid = (inputs ?? []).some((input) => fieldError(input));
|
|
73
98
|
const setOpen = (next) => {
|
|
74
99
|
if (openProp === void 0) setInnerOpen(next);
|
|
75
100
|
onOpenChange?.(next);
|
|
@@ -81,7 +106,7 @@ function ConfirmActionDialog({
|
|
|
81
106
|
const handleConfirm = async (event) => {
|
|
82
107
|
event.preventDefault();
|
|
83
108
|
setAttempted(true);
|
|
84
|
-
if (
|
|
109
|
+
if (invalid) return;
|
|
85
110
|
setError(null);
|
|
86
111
|
if (!callerOwnsPending) setInnerPending(true);
|
|
87
112
|
try {
|
|
@@ -96,7 +121,10 @@ function ConfirmActionDialog({
|
|
|
96
121
|
);
|
|
97
122
|
}
|
|
98
123
|
};
|
|
99
|
-
const setValue = (name, value) =>
|
|
124
|
+
const setValue = (name, value) => {
|
|
125
|
+
setValues((prev) => ({ ...prev, [name]: value }));
|
|
126
|
+
setTouched((prev) => prev[name] ? prev : { ...prev, [name]: true });
|
|
127
|
+
};
|
|
100
128
|
return /* @__PURE__ */ jsxs(AlertDialog, { open, onOpenChange: handleOpenChange, children: [
|
|
101
129
|
children && /* @__PURE__ */ jsx(AlertDialogTrigger, { asChild: true, children }),
|
|
102
130
|
/* @__PURE__ */ jsxs(AlertDialogContent, { children: [
|
|
@@ -108,14 +136,23 @@ function ConfirmActionDialog({
|
|
|
108
136
|
inputs && inputs.length > 0 && /* @__PURE__ */ jsx("div", { className: "grid gap-4", children: inputs.map((input) => {
|
|
109
137
|
const id = `${idPrefix}-${input.name}`;
|
|
110
138
|
const errorId = `${id}-error`;
|
|
111
|
-
const
|
|
139
|
+
const helpId = `${id}-help`;
|
|
140
|
+
const listId = `${id}-suggestions`;
|
|
141
|
+
const message = fieldError(input);
|
|
142
|
+
const asError = !!message && (attempted || disableUntilValid && !!touched[input.name]);
|
|
143
|
+
const shown = asError || !!message && (disableUntilValid || !!lengthMessage(input));
|
|
144
|
+
const describedBy = [input.description && helpId, shown && errorId].filter(Boolean).join(" ") || void 0;
|
|
145
|
+
const placeholder = text(input.placeholder);
|
|
112
146
|
const common = {
|
|
113
147
|
id,
|
|
114
148
|
name: input.name,
|
|
115
149
|
required: input.required,
|
|
116
150
|
disabled: pending,
|
|
117
|
-
|
|
118
|
-
|
|
151
|
+
placeholder,
|
|
152
|
+
inputMode: input.inputMode,
|
|
153
|
+
autoComplete: input.autoComplete,
|
|
154
|
+
"aria-invalid": asError ? true : void 0,
|
|
155
|
+
"aria-describedby": describedBy
|
|
119
156
|
};
|
|
120
157
|
return /* @__PURE__ */ jsxs("div", { className: "grid gap-1.5", children: [
|
|
121
158
|
/* @__PURE__ */ jsxs(Label, { htmlFor: id, children: [
|
|
@@ -126,6 +163,7 @@ function ConfirmActionDialog({
|
|
|
126
163
|
Textarea,
|
|
127
164
|
{
|
|
128
165
|
...common,
|
|
166
|
+
rows: input.rows,
|
|
129
167
|
value: values[input.name] ?? "",
|
|
130
168
|
onChange: (e) => setValue(input.name, e.target.value)
|
|
131
169
|
}
|
|
@@ -141,23 +179,46 @@ function ConfirmActionDialog({
|
|
|
141
179
|
{
|
|
142
180
|
id,
|
|
143
181
|
"aria-invalid": common["aria-invalid"],
|
|
144
|
-
"aria-describedby":
|
|
145
|
-
children: /* @__PURE__ */ jsx(SelectValue, { placeholder: t("common.select") })
|
|
182
|
+
"aria-describedby": describedBy,
|
|
183
|
+
children: /* @__PURE__ */ jsx(SelectValue, { placeholder: placeholder || t("common.select") })
|
|
146
184
|
}
|
|
147
185
|
),
|
|
148
|
-
/* @__PURE__ */ jsx(SelectContent, { children: (input.options ?? []).map((option) => /* @__PURE__ */ jsx(SelectItem, { value: option, children: option }, option)) })
|
|
186
|
+
/* @__PURE__ */ jsx(SelectContent, { children: (input.options ?? []).map(asOption).map((option) => /* @__PURE__ */ jsx(SelectItem, { value: option.value, children: text(option.label) }, option.value)) })
|
|
149
187
|
]
|
|
150
188
|
}
|
|
151
|
-
) : /* @__PURE__ */ jsx(
|
|
189
|
+
) : input.type === "date" ? /* @__PURE__ */ jsx(
|
|
152
190
|
Input,
|
|
153
191
|
{
|
|
154
192
|
...common,
|
|
155
|
-
type:
|
|
193
|
+
type: "date",
|
|
194
|
+
min: input.min,
|
|
195
|
+
max: input.max,
|
|
156
196
|
value: values[input.name] ?? "",
|
|
157
197
|
onChange: (e) => setValue(input.name, e.target.value)
|
|
158
198
|
}
|
|
159
|
-
),
|
|
160
|
-
|
|
199
|
+
) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
200
|
+
/* @__PURE__ */ jsx(
|
|
201
|
+
Input,
|
|
202
|
+
{
|
|
203
|
+
...common,
|
|
204
|
+
type: "text",
|
|
205
|
+
list: input.suggestions?.length ? listId : void 0,
|
|
206
|
+
value: values[input.name] ?? "",
|
|
207
|
+
onChange: (e) => setValue(input.name, e.target.value)
|
|
208
|
+
}
|
|
209
|
+
),
|
|
210
|
+
input.suggestions?.length ? /* @__PURE__ */ jsx("datalist", { id: listId, children: input.suggestions.map((s) => /* @__PURE__ */ jsx("option", { value: s }, s)) }) : null
|
|
211
|
+
] }),
|
|
212
|
+
input.description && /* @__PURE__ */ jsx("p", { id: helpId, className: "text-xs text-muted-foreground", children: text(input.description) }),
|
|
213
|
+
shown && message && /* @__PURE__ */ jsx(
|
|
214
|
+
"p",
|
|
215
|
+
{
|
|
216
|
+
id: errorId,
|
|
217
|
+
"data-state": asError ? "error" : "hint",
|
|
218
|
+
className: asError ? "text-sm text-destructive" : "text-sm text-muted-foreground",
|
|
219
|
+
children: text(message)
|
|
220
|
+
}
|
|
221
|
+
)
|
|
161
222
|
] }, input.name);
|
|
162
223
|
}) }),
|
|
163
224
|
error && /* @__PURE__ */ jsx(
|
|
@@ -175,7 +236,7 @@ function ConfirmActionDialog({
|
|
|
175
236
|
AlertDialogAction,
|
|
176
237
|
{
|
|
177
238
|
"data-testid": "modal-confirm",
|
|
178
|
-
disabled: pending || confirmDisabled,
|
|
239
|
+
disabled: pending || confirmDisabled || disableUntilValid && invalid,
|
|
179
240
|
"aria-busy": pending || void 0,
|
|
180
241
|
className: variant === "destructive" ? "bg-red-500 text-white hover:bg-red-600" : "",
|
|
181
242
|
onClick: handleConfirm,
|
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
} from "../../utils/spacing.js";
|
|
17
17
|
import { createCreateHeaderRenderer } from "./DialogHeaderContent.js";
|
|
18
18
|
import { formHeaderConfig } from "./form-header-config.js";
|
|
19
|
-
import { DialogErrorState } from "./DialogErrorState.js";
|
|
20
19
|
import { CrudDialogShell } from "./CrudDialogShell.js";
|
|
21
20
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
22
21
|
function CreateDialog({
|
|
@@ -42,7 +41,6 @@ function CreateDialog({
|
|
|
42
41
|
const t = useTelamonjsT();
|
|
43
42
|
const resolvedSubmitText = submitText ?? t("dialog.createSubmit");
|
|
44
43
|
const renderHeader = renderHeaderProp || (headerConfig ? createCreateHeaderRenderer(formHeaderConfig(headerConfig)) : void 0);
|
|
45
|
-
const [error, setError] = React.useState(null);
|
|
46
44
|
const guard = useUnsavedChangesGuard();
|
|
47
45
|
const resolvedTitle = typeof title === "string" ? title : t("common.create");
|
|
48
46
|
const hasCustomHeader = Boolean(renderHeader);
|
|
@@ -73,15 +71,6 @@ function CreateDialog({
|
|
|
73
71
|
onOpenChange(false);
|
|
74
72
|
}
|
|
75
73
|
}, [onSuccess, onOpenChange, guard]);
|
|
76
|
-
React.useEffect(() => {
|
|
77
|
-
if (!open) {
|
|
78
|
-
const timer = setTimeout(() => {
|
|
79
|
-
setError(null);
|
|
80
|
-
}, 200);
|
|
81
|
-
return () => clearTimeout(timer);
|
|
82
|
-
}
|
|
83
|
-
return void 0;
|
|
84
|
-
}, [open]);
|
|
85
74
|
const handleCancel = React.useCallback(() => {
|
|
86
75
|
guard.guard(() => onOpenChange(false));
|
|
87
76
|
}, [guard, onOpenChange]);
|
|
@@ -128,7 +117,7 @@ function CreateDialog({
|
|
|
128
117
|
!hasCustomHeader && "overflow-y-auto -mx-6 px-6 mt-4"
|
|
129
118
|
),
|
|
130
119
|
wrapDesktopCustomHeader: true,
|
|
131
|
-
children:
|
|
120
|
+
children: /* @__PURE__ */ jsx(
|
|
132
121
|
CreateForm,
|
|
133
122
|
{
|
|
134
123
|
sections: formSections,
|
|
@@ -17,7 +17,8 @@ import {
|
|
|
17
17
|
resolveDialogSize,
|
|
18
18
|
withWideFormGrid
|
|
19
19
|
} from "../../utils/spacing.js";
|
|
20
|
-
import {
|
|
20
|
+
import { DialogLoadingState } from "./DialogLoadingState.js";
|
|
21
|
+
import { QueryErrorState } from "../utilities/QueryErrorState.js";
|
|
21
22
|
import { createHeaderRenderer } from "./DialogHeaderContent.js";
|
|
22
23
|
import { formHeaderConfig } from "./form-header-config.js";
|
|
23
24
|
import { lockSectionFields } from "./lock-section-fields.js";
|
|
@@ -60,7 +61,7 @@ function EditDialog({
|
|
|
60
61
|
const renderHeader = renderHeaderProp || (headerConfig ? createHeaderRenderer(formHeaderConfig(headerConfig), "edit") : void 0);
|
|
61
62
|
const router = useRouter();
|
|
62
63
|
const guard = useUnsavedChangesGuard();
|
|
63
|
-
const { data, isLoading, error, refetchSilent } = useDialogData(
|
|
64
|
+
const { data, isLoading, error, refetch, refetchSilent } = useDialogData(
|
|
64
65
|
id,
|
|
65
66
|
fetchAction,
|
|
66
67
|
open
|
|
@@ -123,7 +124,7 @@ function EditDialog({
|
|
|
123
124
|
return /* @__PURE__ */ jsx(DialogLoadingState, {});
|
|
124
125
|
}
|
|
125
126
|
if (error) {
|
|
126
|
-
return /* @__PURE__ */ jsx(
|
|
127
|
+
return /* @__PURE__ */ jsx(QueryErrorState, { error, onRetry: refetch, className: "my-8" });
|
|
127
128
|
}
|
|
128
129
|
if (!data || !id) {
|
|
129
130
|
return null;
|
|
@@ -155,7 +156,7 @@ function EditDialog({
|
|
|
155
156
|
hasMultipleSections: effectiveUseTabs,
|
|
156
157
|
sections
|
|
157
158
|
});
|
|
158
|
-
const desktopStatus = isLoading || error || !data ? { sizeClass, isLoading, error } : void 0;
|
|
159
|
+
const desktopStatus = isLoading || error || !data ? { sizeClass, isLoading, error, onRetry: refetch } : void 0;
|
|
159
160
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
160
161
|
/* @__PURE__ */ jsx(
|
|
161
162
|
CrudDialogShell,
|
|
@@ -7,4 +7,4 @@ export { DialogHeaderContent, createHeaderRenderer, createCreateHeaderRenderer }
|
|
|
7
7
|
export { StatsGrid } from './StatsGrid';
|
|
8
8
|
export { DialogFrame } from './DialogFrame';
|
|
9
9
|
export { SplitDialogFrame } from './SplitDialogFrame';
|
|
10
|
-
export {
|
|
10
|
+
export { DialogLoadingState } from './DialogLoadingState';
|
|
@@ -3,9 +3,8 @@ import { DialogHeaderContent, createHeaderRenderer, createCreateHeaderRenderer }
|
|
|
3
3
|
import { StatsGrid } from "./StatsGrid.js";
|
|
4
4
|
import { DialogFrame } from "./DialogFrame.js";
|
|
5
5
|
import { SplitDialogFrame } from "./SplitDialogFrame.js";
|
|
6
|
-
import {
|
|
6
|
+
import { DialogLoadingState } from "./DialogLoadingState.js";
|
|
7
7
|
export {
|
|
8
|
-
DialogErrorState,
|
|
9
8
|
DialogFrame,
|
|
10
9
|
DialogHeaderContent,
|
|
11
10
|
DialogLoadingState,
|
|
@@ -22,7 +22,8 @@ import {
|
|
|
22
22
|
getDialogClassName,
|
|
23
23
|
getSheetClassName
|
|
24
24
|
} from "../../utils/spacing.js";
|
|
25
|
-
import {
|
|
25
|
+
import { DialogLoadingState } from "./DialogLoadingState.js";
|
|
26
|
+
import { QueryErrorState } from "../utilities/QueryErrorState.js";
|
|
26
27
|
import { logger } from "../../utils/logger.js";
|
|
27
28
|
import { createHeaderRenderer } from "./DialogHeaderContent.js";
|
|
28
29
|
import { CrudDialogShell } from "./CrudDialogShell.js";
|
|
@@ -51,7 +52,7 @@ function ViewDialog({
|
|
|
51
52
|
}) {
|
|
52
53
|
const t = useTelamonjsT();
|
|
53
54
|
const renderHeader = renderHeaderProp || (headerConfig ? createHeaderRenderer(headerConfig, "view") : void 0);
|
|
54
|
-
const { data, isLoading, error, refetchSilent } = useDialogData(
|
|
55
|
+
const { data, isLoading, error, refetch, refetchSilent } = useDialogData(
|
|
55
56
|
id,
|
|
56
57
|
fetchAction,
|
|
57
58
|
open
|
|
@@ -101,7 +102,7 @@ function ViewDialog({
|
|
|
101
102
|
return /* @__PURE__ */ jsx(DialogLoadingState, {});
|
|
102
103
|
}
|
|
103
104
|
if (error) {
|
|
104
|
-
return /* @__PURE__ */ jsx(
|
|
105
|
+
return /* @__PURE__ */ jsx(QueryErrorState, { error, onRetry: refetch, className: "my-8" });
|
|
105
106
|
}
|
|
106
107
|
if (!data || !id) {
|
|
107
108
|
return null;
|
|
@@ -185,7 +186,7 @@ function ViewDialog({
|
|
|
185
186
|
dialogClassName,
|
|
186
187
|
hasCustomHeader: false
|
|
187
188
|
});
|
|
188
|
-
const desktopStatus = isLoading || error || !data ? { sizeClass, isLoading, error } : void 0;
|
|
189
|
+
const desktopStatus = isLoading || error || !data ? { sizeClass, isLoading, error, onRetry: refetch } : void 0;
|
|
189
190
|
const hasCustomHeader = Boolean(renderHeader && data);
|
|
190
191
|
return /* @__PURE__ */ jsx(
|
|
191
192
|
CrudDialogShell,
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { I18nText } from '../../i18n/msg';
|
|
2
|
+
export interface QueryErrorStateProps {
|
|
3
|
+
/**
|
|
4
|
+
* What failed: an `Error`, a string, or any object carrying a string
|
|
5
|
+
* `message` (API client errors). Its message becomes the description unless
|
|
6
|
+
* `description` is given; anything without a usable message shows the title only.
|
|
7
|
+
*/
|
|
8
|
+
error?: unknown;
|
|
9
|
+
/** Headline. Default: localized "Failed to load data". */
|
|
10
|
+
title?: I18nText;
|
|
11
|
+
/** Replaces the message extracted from `error` (e.g. a friendlier text). */
|
|
12
|
+
description?: I18nText;
|
|
13
|
+
/**
|
|
14
|
+
* Shows the retry button. Called with no arguments, so `onRetry={refetch}` is
|
|
15
|
+
* safe; when it returns a promise the button stays pending until it settles.
|
|
16
|
+
*/
|
|
17
|
+
onRetry?: () => unknown;
|
|
18
|
+
/** Caller-driven pending state, e.g. `retrying={query.isFetching}`. */
|
|
19
|
+
retrying?: boolean;
|
|
20
|
+
/** Retry button label. Default: localized "Try again". */
|
|
21
|
+
retryLabel?: I18nText;
|
|
22
|
+
className?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* QueryErrorState - error state of a query, with an optional "Try again".
|
|
26
|
+
*
|
|
27
|
+
* The error UI for screens that run their own `useQuery` (and the one the CRUD
|
|
28
|
+
* dialogs use): a destructive alert with a localized title, the error's message
|
|
29
|
+
* and a retry button that stays pending while `onRetry` runs.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```tsx
|
|
33
|
+
* const { data, error, isError, refetch } = useQuery(...)
|
|
34
|
+
* if (isError) return <QueryErrorState error={error} onRetry={refetch} />
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* Context-specific title, several queries retried together:
|
|
39
|
+
* ```tsx
|
|
40
|
+
* <QueryErrorState
|
|
41
|
+
* title="Could not load the grading sheet"
|
|
42
|
+
* error={sheet.error ?? files.error}
|
|
43
|
+
* onRetry={() => Promise.all([sheet.refetch(), files.refetch()])}
|
|
44
|
+
* />
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function QueryErrorState({ error, title, description, onRetry, retrying, retryLabel, className, }: QueryErrorStateProps): import("react").JSX.Element;
|