@verikit/react 0.24.3 → 0.24.4
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.
|
@@ -7,9 +7,17 @@ export interface ResourceDetailProps<TRecord extends Record<string, unknown> = R
|
|
|
7
7
|
/** Id of the record to show. */
|
|
8
8
|
id: string;
|
|
9
9
|
/**
|
|
10
|
-
* Renders the built-in Edit
|
|
10
|
+
* Renders the built-in Edit and Delete actions, and the default for `editAction`, `deleteAction`, and `resourceActions`.
|
|
11
11
|
*/
|
|
12
12
|
actions?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Renders the built-in Edit action, which opens a `ResourceForm` dialog pre-filled from the record. Hidden when the server reports the actor can't update the record, or when an update is denied (403 or 404) for the rest of this component's lifetime. Defaults to `actions`.
|
|
15
|
+
*/
|
|
16
|
+
editAction?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Renders the built-in Delete action, which opens a confirmation dialog. Hidden when the server reports the actor can't delete the record, or when a delete is denied (403 or 404) for the rest of this component's lifetime. Defaults to `actions`.
|
|
19
|
+
*/
|
|
20
|
+
deleteAction?: boolean;
|
|
13
21
|
/**
|
|
14
22
|
* Renders the record-scoped actions declared on the resource via `defineResource({ actions })`. The page asks the server which of them the actor can't run on this record: those it may not run are hidden, and those that can't run right now are disabled, with the reason as a tooltip. An action denied when run (403 or 404) is hidden for the rest of this component's lifetime. Defaults to `actions`.
|
|
15
23
|
*/
|
|
@@ -24,7 +32,7 @@ export interface ResourceDetailProps<TRecord extends Record<string, unknown> = R
|
|
|
24
32
|
className?: string;
|
|
25
33
|
}
|
|
26
34
|
/**
|
|
27
|
-
* Shows one record's fields as a label/value list, with its actions: the built-in Edit and Delete, and the record-scoped actions declared on the resource. Fields marked `.hidden()`, or left out by the server because the actor can't read them, aren't shown. A record the actor can't read shows as not found, as the server doesn't reveal whether it exists.
|
|
35
|
+
* Shows one record's fields as a label/value list, with its actions: the built-in Edit and Delete, and the record-scoped actions declared on the resource. Edit and Delete are hidden up front when the server reports the actor can't update or delete the record. Fields marked `.hidden()`, or left out by the server because the actor can't read them, aren't shown. A record the actor can't read shows as not found, as the server doesn't reveal whether it exists.
|
|
28
36
|
*/
|
|
29
|
-
export declare function ResourceDetail<TRecord extends Record<string, unknown> = Record<string, unknown>>({ resource, id, actions, resourceActions, renderActions, onDeleted, className, }: ResourceDetailProps<TRecord>): ReactElement;
|
|
37
|
+
export declare function ResourceDetail<TRecord extends Record<string, unknown> = Record<string, unknown>>({ resource, id, actions, editAction, deleteAction, resourceActions, renderActions, onDeleted, className, }: ResourceDetailProps<TRecord>): ReactElement;
|
|
30
38
|
//# sourceMappingURL=resource-detail.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-detail.d.ts","sourceRoot":"","sources":["../../src/resource/resource-detail.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAapE,OAAO,KAAK,EAAoB,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"resource-detail.d.ts","sourceRoot":"","sources":["../../src/resource/resource-detail.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAapE,OAAO,KAAK,EAAoB,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAkBhF,wCAAwC;AACxC,MAAM,WAAW,mBAAmB,CAClC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAEjE,4EAA4E;IAC5E,QAAQ,EAAE,QAAQ,GAAG,cAAc,CAAC;IACpC,gCAAgC;IAChC,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,sEAAsE;IACtE,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,SAAS,CAAC;IAC/C;;OAEG;IACH,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjE,EACA,QAAQ,EACR,EAAE,EACF,OAAe,EACf,UAAoB,EACpB,YAAsB,EACtB,eAAyB,EACzB,aAAa,EACb,SAAS,EACT,SAAS,GACV,EAAE,mBAAmB,CAAC,OAAO,CAAC,GAAG,YAAY,CAoP7C"}
|
|
@@ -10,12 +10,12 @@ import { formatFieldValue } from "@verikit/ui-core/layout/format-value";
|
|
|
10
10
|
import { useDeleteResource } from "../query/use-resource-mutations.js";
|
|
11
11
|
import { useResourceFindWithActions } from "../query/use-resource-queries.js";
|
|
12
12
|
import { DeclaredActionButton } from "./declared-action-button.js";
|
|
13
|
-
import { hasStatus, isActionDenied,
|
|
13
|
+
import { hasStatus, isActionDenied, ResourceActionDialog, useRunResourceAction, } from "./resource-action-dialog.js";
|
|
14
14
|
import { ResourceForm } from "./resource-form.js";
|
|
15
15
|
/**
|
|
16
|
-
* Shows one record's fields as a label/value list, with its actions: the built-in Edit and Delete, and the record-scoped actions declared on the resource. Fields marked `.hidden()`, or left out by the server because the actor can't read them, aren't shown. A record the actor can't read shows as not found, as the server doesn't reveal whether it exists.
|
|
16
|
+
* Shows one record's fields as a label/value list, with its actions: the built-in Edit and Delete, and the record-scoped actions declared on the resource. Edit and Delete are hidden up front when the server reports the actor can't update or delete the record. Fields marked `.hidden()`, or left out by the server because the actor can't read them, aren't shown. A record the actor can't read shows as not found, as the server doesn't reveal whether it exists.
|
|
17
17
|
*/
|
|
18
|
-
export function ResourceDetail({ resource, id, actions = false, resourceActions = actions, renderActions, onDeleted, className, }) {
|
|
18
|
+
export function ResourceDetail({ resource, id, actions = false, editAction = actions, deleteAction = actions, resourceActions = actions, renderActions, onDeleted, className, }) {
|
|
19
19
|
const [deleted, setDeleted] = useState(false);
|
|
20
20
|
const query = useResourceFindWithActions(resource.name, id, {
|
|
21
21
|
enabled: !deleted,
|
|
@@ -57,7 +57,9 @@ export function ResourceDetail({ resource, id, actions = false, resourceActions
|
|
|
57
57
|
}
|
|
58
58
|
const deleteMutation = useDeleteResource(resource.name, {
|
|
59
59
|
onError: (mutationError) => {
|
|
60
|
-
|
|
60
|
+
// The server answers a denied delete with 404 so as not to reveal
|
|
61
|
+
// whether the record exists, the same as a denied record action.
|
|
62
|
+
if (isActionDenied(mutationError, id)) {
|
|
61
63
|
setDenied((current) => ({ ...current, delete: true }));
|
|
62
64
|
setDeleteOpen(false);
|
|
63
65
|
}
|
|
@@ -77,17 +79,22 @@ export function ResourceDetail({ resource, id, actions = false, resourceActions
|
|
|
77
79
|
if (query.isError) {
|
|
78
80
|
return hasStatus(query.error, 404) ? (_jsxs("p", { role: "status", className: cn("text-sm text-muted-foreground", className), children: ["This ", resource.name, " doesn't exist or you can't view it."] })) : (_jsx("p", { role: "alert", className: cn("text-sm text-destructive", className), children: query.error.message }));
|
|
79
81
|
}
|
|
80
|
-
const { record, actions: unavailable } = query.data;
|
|
82
|
+
const { record, actions: unavailable, operations } = query.data;
|
|
83
|
+
const showEdit = editAction && !denied.update && !operations.update;
|
|
84
|
+
const showDelete = deleteAction && !denied.delete && !operations.delete;
|
|
81
85
|
const visibleFields = Object.values(fields).filter((field) => !field.hidden && Object.hasOwn(record, field.name));
|
|
82
|
-
const hasActions =
|
|
83
|
-
|
|
86
|
+
const hasActions = showEdit ||
|
|
87
|
+
showDelete ||
|
|
88
|
+
recordActions.length > 0 ||
|
|
89
|
+
Boolean(renderActions);
|
|
90
|
+
return (_jsxs("div", { className: cn("w-full", className), children: [hasActions ? (_jsxs("div", { className: "flex flex-wrap items-center justify-end gap-2 pb-3", children: [recordActions.map((action) => denied.actions[action.name] ? null : (_jsx(DeclaredActionButton, { action: action, unavailable: unavailable[action.name], variant: action.variant === "danger" ? "destructive" : "outline", disabled: directAction.isPending, onClick: () => startAction(action) }, action.name))), showEdit ? (_jsxs(Button, { type: "button", variant: "outline", size: "sm", onClick: () => setEditOpen(true), children: [_jsx(PencilIcon, {}), "Edit"] })) : null, showDelete ? (_jsxs(Button, { type: "button", variant: "outline", size: "sm", onClick: () => {
|
|
84
91
|
deleteMutation.reset();
|
|
85
92
|
setDeleteOpen(true);
|
|
86
|
-
}, children: [_jsx(Trash2Icon, {}), "Delete"] })) : null, renderActions ? renderActions(record) : null] })) : null, actionError ? (_jsx("p", { role: "alert", className: "pb-3 text-sm text-destructive", children: actionError })) : null, _jsx("dl", { className: "grid gap-x-6 gap-y-3 rounded-lg border border-border p-4 sm:grid-cols-[minmax(8rem,max-content)_1fr]", children: visibleFields.map((field) => (_jsxs("div", { className: "contents", children: [_jsx("dt", { className: "text-sm font-medium text-muted-foreground", children: field.label ?? field.name }), _jsx("dd", { className: "text-sm wrap-break-word", children: formatFieldValue(record[field.name]) })] }, field.name))) }), recordActions.length > 0 ? (_jsx(ResourceActionDialog, { resourceName: resource.name, action: activeAction, recordId: id, onClose: () => setActiveAction(null), onDenied: denyAction })) : null,
|
|
87
|
-
if (
|
|
93
|
+
}, children: [_jsx(Trash2Icon, {}), "Delete"] })) : null, renderActions ? renderActions(record) : null] })) : null, actionError ? (_jsx("p", { role: "alert", className: "pb-3 text-sm text-destructive", children: actionError })) : null, _jsx("dl", { className: "grid gap-x-6 gap-y-3 rounded-lg border border-border p-4 sm:grid-cols-[minmax(8rem,max-content)_1fr]", children: visibleFields.map((field) => (_jsxs("div", { className: "contents", children: [_jsx("dt", { className: "text-sm font-medium text-muted-foreground", children: field.label ?? field.name }), _jsx("dd", { className: "text-sm wrap-break-word", children: formatFieldValue(record[field.name]) })] }, field.name))) }), recordActions.length > 0 ? (_jsx(ResourceActionDialog, { resourceName: resource.name, action: activeAction, recordId: id, onClose: () => setActiveAction(null), onDenied: denyAction })) : null, editAction ? (_jsx(Dialog, { open: editOpen, onOpenChange: setEditOpen, children: _jsxs(DialogContent, { children: [_jsx(DialogHeader, { children: _jsxs(DialogTitle, { children: ["Edit ", resource.name] }) }), _jsx(ResourceForm, { resource: resource, id: id, defaultValues: record, onSuccess: () => setEditOpen(false), onError: (mutationError) => {
|
|
94
|
+
if (isActionDenied(mutationError, id)) {
|
|
88
95
|
setDenied((current) => ({ ...current, update: true }));
|
|
89
96
|
setEditOpen(false);
|
|
90
97
|
}
|
|
91
|
-
}, submitLabel: "Save changes" })] }) })) : null,
|
|
92
|
-
!
|
|
98
|
+
}, submitLabel: "Save changes" })] }) })) : null, deleteAction ? (_jsx(Dialog, { open: deleteOpen, onOpenChange: setDeleteOpen, children: _jsxs(DialogContent, { children: [_jsxs(DialogHeader, { children: [_jsxs(DialogTitle, { children: ["Delete this ", resource.name, "?"] }), _jsx(DialogDescription, { children: "This can't be undone." })] }), deleteMutation.error &&
|
|
99
|
+
!isActionDenied(deleteMutation.error, id) ? (_jsx("p", { role: "alert", className: "text-sm text-destructive", children: deleteMutation.error.message })) : null, _jsxs(DialogFooter, { children: [_jsx(DialogClose, { render: _jsx(Button, { type: "button", variant: "outline", children: "Cancel" }) }), _jsx(Button, { type: "button", variant: "destructive", disabled: deleteMutation.isPending, onClick: () => deleteMutation.mutate(id), children: deleteMutation.isPending ? "Deleting…" : "Delete" })] })] }) })) : null] }));
|
|
93
100
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verikit/react",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.4",
|
|
4
4
|
"description": "React UI bindings for Verikit resource workflows.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -57,11 +57,11 @@
|
|
|
57
57
|
"clsx": "^2.1.1",
|
|
58
58
|
"lucide-react": "^1.26.0",
|
|
59
59
|
"tailwind-merge": "^3.6.0",
|
|
60
|
-
"@verikit/
|
|
61
|
-
"@verikit/
|
|
62
|
-
"@verikit/
|
|
63
|
-
"@verikit/
|
|
64
|
-
"@verikit/
|
|
60
|
+
"@verikit/client": "0.24.4",
|
|
61
|
+
"@verikit/core": "0.24.4",
|
|
62
|
+
"@verikit/runtime": "0.24.4",
|
|
63
|
+
"@verikit/theme": "0.24.4",
|
|
64
|
+
"@verikit/ui-core": "0.24.4"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@base-ui/react": "^1.6.0",
|