@verikit/vue 0.24.2 → 0.24.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/form/use-verikit-schema-tree-form.d.ts +3 -1
  2. package/dist/form/use-verikit-schema-tree-form.d.ts.map +1 -1
  3. package/dist/form/use-verikit-schema-tree-form.js +8 -1
  4. package/dist/query/index.d.ts +2 -2
  5. package/dist/query/index.d.ts.map +1 -1
  6. package/dist/query/index.js +1 -1
  7. package/dist/query/use-resource-mutations.d.ts.map +1 -1
  8. package/dist/query/use-resource-mutations.js +1 -0
  9. package/dist/query/use-resource-queries.d.ts +7 -1
  10. package/dist/query/use-resource-queries.d.ts.map +1 -1
  11. package/dist/query/use-resource-queries.js +13 -0
  12. package/dist/query/use-resource-table.d.ts +9 -3
  13. package/dist/query/use-resource-table.d.ts.map +1 -1
  14. package/dist/query/use-resource-table.js +3 -1
  15. package/dist/resource/declared-action-button.d.ts +14 -0
  16. package/dist/resource/declared-action-button.d.ts.map +1 -0
  17. package/dist/resource/declared-action-button.js +24 -0
  18. package/dist/resource/index.d.ts +4 -0
  19. package/dist/resource/index.d.ts.map +1 -1
  20. package/dist/resource/index.js +2 -0
  21. package/dist/resource/resource-action-dialog.d.ts +103 -0
  22. package/dist/resource/resource-action-dialog.d.ts.map +1 -0
  23. package/dist/resource/resource-action-dialog.js +207 -0
  24. package/dist/resource/resource-detail.d.ts +98 -0
  25. package/dist/resource/resource-detail.d.ts.map +1 -0
  26. package/dist/resource/resource-detail.js +258 -0
  27. package/dist/resource/resource-table.d.ts +13 -0
  28. package/dist/resource/resource-table.d.ts.map +1 -1
  29. package/dist/resource/resource-table.js +108 -35
  30. package/package.json +6 -6
@@ -0,0 +1,98 @@
1
+ import { type PropType, type VNodeChild } from "vue";
2
+ import type { Resource, ResourceSchema } from "@verikit/core";
3
+ type DetailRecord = Record<string, unknown>;
4
+ /** Props for {@link ResourceDetail}. */
5
+ export interface ResourceDetailProps {
6
+ /** The resource (or its schema) whose fields and actions the page shows. */
7
+ resource: Resource | ResourceSchema;
8
+ /** Id of the record to show. */
9
+ id: string;
10
+ /**
11
+ * Renders the built-in Edit (opens a `ResourceForm` dialog pre-filled from the record) and Delete (opens a confirmation dialog) actions. One the server denies (403) is hidden for the rest of this component's lifetime.
12
+ */
13
+ actions?: boolean;
14
+ /**
15
+ * 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`.
16
+ */
17
+ resourceActions?: boolean;
18
+ /** Renders extra actions alongside the built-in and declared ones. */
19
+ renderActions?: (record: DetailRecord) => VNodeChild;
20
+ /**
21
+ * Called after the record is deleted through the built-in Delete action, e.g. to navigate away. The page shows a "deleted" message until then.
22
+ */
23
+ onDeleted?: (record: DetailRecord) => void;
24
+ /** Class name applied to the outer container. */
25
+ className?: string;
26
+ }
27
+ /**
28
+ * 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.
29
+ */
30
+ export declare const ResourceDetail: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
31
+ resource: {
32
+ type: PropType<ResourceDetailProps["resource"]>;
33
+ required: true;
34
+ };
35
+ id: {
36
+ type: StringConstructor;
37
+ required: true;
38
+ };
39
+ actions: {
40
+ type: BooleanConstructor;
41
+ default: boolean;
42
+ };
43
+ resourceActions: {
44
+ type: PropType<boolean | undefined>;
45
+ default: undefined;
46
+ };
47
+ renderActions: {
48
+ type: PropType<ResourceDetailProps["renderActions"]>;
49
+ default: undefined;
50
+ };
51
+ onDeleted: {
52
+ type: PropType<ResourceDetailProps["onDeleted"]>;
53
+ default: undefined;
54
+ };
55
+ className: {
56
+ type: PropType<string | undefined>;
57
+ default: undefined;
58
+ };
59
+ }>, () => string | number | boolean | void | import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
60
+ [key: string]: any;
61
+ }> | import("vue").VNodeArrayChildren | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
62
+ resource: {
63
+ type: PropType<ResourceDetailProps["resource"]>;
64
+ required: true;
65
+ };
66
+ id: {
67
+ type: StringConstructor;
68
+ required: true;
69
+ };
70
+ actions: {
71
+ type: BooleanConstructor;
72
+ default: boolean;
73
+ };
74
+ resourceActions: {
75
+ type: PropType<boolean | undefined>;
76
+ default: undefined;
77
+ };
78
+ renderActions: {
79
+ type: PropType<ResourceDetailProps["renderActions"]>;
80
+ default: undefined;
81
+ };
82
+ onDeleted: {
83
+ type: PropType<ResourceDetailProps["onDeleted"]>;
84
+ default: undefined;
85
+ };
86
+ className: {
87
+ type: PropType<string | undefined>;
88
+ default: undefined;
89
+ };
90
+ }>> & Readonly<{}>, {
91
+ className: string | undefined;
92
+ actions: boolean;
93
+ renderActions: ((record: DetailRecord) => VNodeChild) | undefined;
94
+ onDeleted: ((record: DetailRecord) => void) | undefined;
95
+ resourceActions: boolean | undefined;
96
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
97
+ export {};
98
+ //# sourceMappingURL=resource-detail.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource-detail.d.ts","sourceRoot":"","sources":["../../src/resource/resource-detail.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2B,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,KAAK,CAAC;AAa9E,OAAO,KAAK,EAAoB,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAmBhF,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE5C,wCAAwC;AACxC,MAAM,WAAW,mBAAmB;IAClC,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,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,sEAAsE;IACtE,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,UAAU,CAAC;IACrD;;OAEG;IACH,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,CAAC;IAC3C,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,cAAc;;cAIL,QAAQ,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;;;;;;;;;;;;cAMxC,QAAQ,CAAC,OAAO,GAAG,SAAS,CAAC;;;;cAI5B,QAAQ,CAAC,mBAAmB,CAAC,eAAe,CAAC,CAAC;;;;cAI9C,QAAQ,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;;;;cAI5C,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAC;;;;;;;cAlB5B,QAAQ,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;;;;;;;;;;;;cAMxC,QAAQ,CAAC,OAAO,GAAG,SAAS,CAAC;;;;cAI5B,QAAQ,CAAC,mBAAmB,CAAC,eAAe,CAAC,CAAC;;;;cAI9C,QAAQ,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;;;;cAI5C,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAC;;;;;;6BAlCvB,YAAY,KAAK,UAAU;yBAI/B,YAAY,KAAK,IAAI;;4EA4X1C,CAAC"}
@@ -0,0 +1,258 @@
1
+ import { defineComponent, h, ref } from "vue";
2
+ import { PencilIcon, Trash2Icon } from "lucide-vue-next";
3
+ import { Button } from "#components/button";
4
+ import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "#components/dialog";
5
+ import { cn } from "#lib/utils";
6
+ import { actionNeedsDialog, resourceActionSchemas, } from "@verikit/ui-core/actions/resource-actions";
7
+ import { resolveVerikitFields } from "@verikit/ui-core/form/resolve-fields";
8
+ import { formatFieldValue } from "@verikit/ui-core/layout/format-value";
9
+ import { useDeleteResource } from "../query/use-resource-mutations.js";
10
+ import { useResourceFindWithActions } from "../query/use-resource-queries.js";
11
+ import { declaredActionButton } from "./declared-action-button.js";
12
+ import { hasStatus, isActionDenied, isPermissionDenied, ResourceActionDialog, useRunResourceAction, } from "./resource-action-dialog.js";
13
+ import { ResourceForm } from "./resource-form.js";
14
+ /**
15
+ * 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
+ */
17
+ export const ResourceDetail = defineComponent({
18
+ name: "ResourceDetail",
19
+ props: {
20
+ resource: {
21
+ type: Object,
22
+ required: true,
23
+ },
24
+ id: { type: String, required: true },
25
+ actions: { type: Boolean, default: false },
26
+ resourceActions: {
27
+ type: Boolean,
28
+ default: undefined,
29
+ },
30
+ renderActions: {
31
+ type: Function,
32
+ default: undefined,
33
+ },
34
+ onDeleted: {
35
+ type: Function,
36
+ default: undefined,
37
+ },
38
+ className: {
39
+ type: String,
40
+ default: undefined,
41
+ },
42
+ },
43
+ setup(props) {
44
+ const deleted = ref(false);
45
+ const query = useResourceFindWithActions(props.resource.name, () => props.id, { enabled: () => !deleted.value });
46
+ const fields = resolveVerikitFields(props.resource);
47
+ const recordActions = (props.resourceActions ?? props.actions)
48
+ ? resourceActionSchemas(props.resource, "record")
49
+ : [];
50
+ const editOpen = ref(false);
51
+ const deleteOpen = ref(false);
52
+ const deniedUpdate = ref(false);
53
+ const deniedDelete = ref(false);
54
+ const deniedActions = ref({});
55
+ const activeAction = ref(null);
56
+ const actionError = ref(null);
57
+ function denyAction(action) {
58
+ deniedActions.value = { ...deniedActions.value, [action.name]: true };
59
+ }
60
+ const directAction = useRunResourceAction(props.resource.name, {
61
+ onSuccess: () => {
62
+ actionError.value = null;
63
+ },
64
+ onError: (mutationError, variables) => {
65
+ if (isActionDenied(mutationError, variables.recordId)) {
66
+ denyAction(variables.action);
67
+ }
68
+ else {
69
+ actionError.value = mutationError.message;
70
+ }
71
+ },
72
+ });
73
+ function startAction(action) {
74
+ actionError.value = null;
75
+ if (actionNeedsDialog(action)) {
76
+ activeAction.value = action;
77
+ }
78
+ else {
79
+ directAction.mutate({ action, recordId: props.id });
80
+ }
81
+ }
82
+ const deleteMutation = useDeleteResource(props.resource.name, {
83
+ onError: (mutationError) => {
84
+ if (isPermissionDenied(mutationError)) {
85
+ deniedDelete.value = true;
86
+ deleteOpen.value = false;
87
+ }
88
+ },
89
+ onSuccess: () => {
90
+ deleteOpen.value = false;
91
+ deleted.value = true;
92
+ props.onDeleted?.(query.data.value.record);
93
+ },
94
+ });
95
+ function statusMessage(message) {
96
+ return h("p", {
97
+ role: "status",
98
+ class: cn("text-sm text-muted-foreground", props.className),
99
+ }, message);
100
+ }
101
+ function actionBar(record) {
102
+ const unavailable = query.data.value.actions;
103
+ return h("div", { class: "flex flex-wrap items-center justify-end gap-2 pb-3" }, [
104
+ ...recordActions.map((action) => deniedActions.value[action.name]
105
+ ? null
106
+ : declaredActionButton({
107
+ action,
108
+ unavailable: unavailable[action.name],
109
+ variant: "outline",
110
+ disabled: directAction.isPending.value,
111
+ onClick: () => startAction(action),
112
+ })),
113
+ props.actions && !deniedUpdate.value
114
+ ? h(Button, {
115
+ type: "button",
116
+ variant: "outline",
117
+ size: "sm",
118
+ onClick: () => {
119
+ editOpen.value = true;
120
+ },
121
+ }, { default: () => [h(PencilIcon), "Edit"] })
122
+ : null,
123
+ props.actions && !deniedDelete.value
124
+ ? h(Button, {
125
+ type: "button",
126
+ variant: "outline",
127
+ size: "sm",
128
+ onClick: () => {
129
+ deleteMutation.reset();
130
+ deleteOpen.value = true;
131
+ },
132
+ }, { default: () => [h(Trash2Icon), "Delete"] })
133
+ : null,
134
+ props.renderActions ? props.renderActions(record) : null,
135
+ ]);
136
+ }
137
+ function editDialog(record) {
138
+ return h(Dialog, {
139
+ open: editOpen.value,
140
+ onOpenChange: (open) => {
141
+ editOpen.value = open;
142
+ },
143
+ }, {
144
+ default: () => h(DialogContent, {}, {
145
+ default: () => [
146
+ h(DialogHeader, {}, {
147
+ default: () => h(DialogTitle, {}, { default: () => `Edit ${props.resource.name}` }),
148
+ }),
149
+ h(ResourceForm, {
150
+ resource: props.resource,
151
+ id: props.id,
152
+ defaultValues: record,
153
+ onSuccess: () => {
154
+ editOpen.value = false;
155
+ },
156
+ onError: (mutationError) => {
157
+ if (isPermissionDenied(mutationError)) {
158
+ deniedUpdate.value = true;
159
+ editOpen.value = false;
160
+ }
161
+ },
162
+ submitLabel: "Save changes",
163
+ }),
164
+ ],
165
+ }),
166
+ });
167
+ }
168
+ function deleteDialog() {
169
+ return h(Dialog, {
170
+ open: deleteOpen.value,
171
+ onOpenChange: (open) => {
172
+ deleteOpen.value = open;
173
+ },
174
+ }, {
175
+ default: () => h(DialogContent, {}, {
176
+ default: () => [
177
+ h(DialogHeader, {}, {
178
+ default: () => [
179
+ h(DialogTitle, {}, {
180
+ default: () => `Delete this ${props.resource.name}?`,
181
+ }),
182
+ h(DialogDescription, {}, { default: () => "This can't be undone." }),
183
+ ],
184
+ }),
185
+ deleteMutation.error.value &&
186
+ !isPermissionDenied(deleteMutation.error.value)
187
+ ? h("p", { role: "alert", class: "text-sm text-destructive" }, deleteMutation.error.value.message)
188
+ : null,
189
+ h(DialogFooter, {}, {
190
+ default: () => [
191
+ h(DialogClose, { asChild: true }, {
192
+ default: () => h(Button, { type: "button", variant: "outline" }, { default: () => "Cancel" }),
193
+ }),
194
+ h(Button, {
195
+ type: "button",
196
+ variant: "destructive",
197
+ disabled: deleteMutation.isPending.value,
198
+ onClick: () => deleteMutation.mutate(props.id),
199
+ }, {
200
+ default: () => deleteMutation.isPending.value
201
+ ? "Deleting…"
202
+ : "Delete",
203
+ }),
204
+ ],
205
+ }),
206
+ ],
207
+ }),
208
+ });
209
+ }
210
+ return () => {
211
+ if (deleted.value) {
212
+ return statusMessage(`This ${props.resource.name} was deleted.`);
213
+ }
214
+ if (query.isPending.value) {
215
+ return h("p", { class: cn("text-sm text-muted-foreground", props.className) }, "Loading…");
216
+ }
217
+ if (query.isError.value) {
218
+ const error = query.error.value;
219
+ return hasStatus(error, 404)
220
+ ? statusMessage(`This ${props.resource.name} doesn't exist or you can't view it.`)
221
+ : h("p", {
222
+ role: "alert",
223
+ class: cn("text-sm text-destructive", props.className),
224
+ }, error.message);
225
+ }
226
+ const record = query.data.value.record;
227
+ const visibleFields = Object.values(fields).filter((field) => !field.hidden && Object.hasOwn(record, field.name));
228
+ const hasActions = props.actions ||
229
+ recordActions.length > 0 ||
230
+ Boolean(props.renderActions);
231
+ return h("div", { class: cn("w-full", props.className) }, [
232
+ hasActions ? actionBar(record) : null,
233
+ actionError.value
234
+ ? h("p", { role: "alert", class: "pb-3 text-sm text-destructive" }, actionError.value)
235
+ : null,
236
+ h("dl", {
237
+ class: "grid gap-x-6 gap-y-3 rounded-lg border border-border p-4 sm:grid-cols-[minmax(8rem,max-content)_1fr]",
238
+ }, visibleFields.map((field) => h("div", { key: field.name, class: "contents" }, [
239
+ h("dt", { class: "text-sm font-medium text-muted-foreground" }, field.label ?? field.name),
240
+ h("dd", { class: "text-sm break-words" }, formatFieldValue(record[field.name])),
241
+ ]))),
242
+ recordActions.length > 0
243
+ ? h(ResourceActionDialog, {
244
+ resourceName: props.resource.name,
245
+ action: activeAction.value,
246
+ recordId: props.id,
247
+ onClose: () => {
248
+ activeAction.value = null;
249
+ },
250
+ onDenied: denyAction,
251
+ })
252
+ : null,
253
+ props.actions ? editDialog(record) : null,
254
+ props.actions ? deleteDialog() : null,
255
+ ]);
256
+ };
257
+ },
258
+ });
@@ -10,6 +10,10 @@ export interface ResourceTableProps<TRecord extends RowData = Record<string, unk
10
10
  * Edit/Delete row actions.
11
11
  */
12
12
  actions?: boolean;
13
+ /**
14
+ * Renders the actions declared on the resource via `defineResource({ actions })`: record-scoped ones per row, collection-scoped ones in the toolbar. Labels, confirmations, and input forms come from each declaration; actions with neither a confirmation nor a form run on click. The table asks the server which of them the actor can't run on each page: 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 for a record action, which the server returns so as not to reveal whether the record exists) is hidden for the rest of this component's lifetime. Defaults to `actions`.
15
+ */
16
+ resourceActions?: boolean;
13
17
  /** Renders per-row actions (e.g. custom edit/delete buttons). */
14
18
  renderActions?: (record: TRecord) => VNodeChild;
15
19
  /** Renders custom actions for the current row selection. */
@@ -36,6 +40,10 @@ export declare const ResourceTable: import("vue").DefineComponent<import("vue").
36
40
  type: BooleanConstructor;
37
41
  default: boolean;
38
42
  };
43
+ resourceActions: {
44
+ type: PropType<boolean | undefined>;
45
+ default: undefined;
46
+ };
39
47
  renderActions: {
40
48
  type: PropType<ResourceTableProps["renderActions"]>;
41
49
  default: undefined;
@@ -67,6 +75,10 @@ export declare const ResourceTable: import("vue").DefineComponent<import("vue").
67
75
  type: BooleanConstructor;
68
76
  default: boolean;
69
77
  };
78
+ resourceActions: {
79
+ type: PropType<boolean | undefined>;
80
+ default: undefined;
81
+ };
70
82
  renderActions: {
71
83
  type: PropType<ResourceTableProps["renderActions"]>;
72
84
  default: undefined;
@@ -88,6 +100,7 @@ export declare const ResourceTable: import("vue").DefineComponent<import("vue").
88
100
  actions: boolean;
89
101
  pageSize: number | undefined;
90
102
  renderActions: ((record: Record<string, unknown>) => VNodeChild) | undefined;
103
+ resourceActions: boolean | undefined;
91
104
  renderBulkActions: ((records: Record<string, unknown>[], clearSelection: () => void) => VNodeChild) | undefined;
92
105
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
93
106
  //# sourceMappingURL=resource-table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,aAAa;;cAIJ,QAAQ,CAAC,sBAAsB,CAAC;;;;cAIhC,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAC;;;;;;;;cAK3B,QAAQ,CAAC,OAAO,GAAG,SAAS,CAAC;;;;cAI5B,QAAQ,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAC;;;;cAI7C,QAAQ,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;;;;cAI1C,QAAQ,CAAC,UAAU,CAAC;;;;cAI7B,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAC;;;;;;;cAzB5B,QAAQ,CAAC,sBAAsB,CAAC;;;;cAIhC,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAC;;;;;;;;cAK3B,QAAQ,CAAC,OAAO,GAAG,SAAS,CAAC;;;;cAI5B,QAAQ,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAC;;;;cAI7C,QAAQ,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;;;;cAI1C,QAAQ,CAAC,UAAU,CAAC;;;;cAI7B,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAC;;;;;;;yDAhEX,UAAU;;6EAI7B,MAAM,IAAI,KACvB,UAAU;4EA+7Bf,CAAC"}
@@ -5,37 +5,19 @@ import { Checkbox } from "#components/checkbox";
5
5
  import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "#components/dialog";
6
6
  import { Input } from "#components/input";
7
7
  import { cn } from "#lib/utils";
8
+ import { actionNeedsDialog, resourceActionSchemas, unavailableAction, } from "@verikit/ui-core/actions/resource-actions";
9
+ import { formatFieldValue } from "@verikit/ui-core/layout/format-value";
8
10
  import { recordId } from "@verikit/ui-core/query/optimistic";
9
11
  import { useDeleteResource } from "../query/use-resource-mutations.js";
10
12
  import { useResourceTable, } from "../query/use-resource-table.js";
13
+ import { isActionDenied, isPermissionDenied, ResourceActionDialog, useRunResourceAction, } from "./resource-action-dialog.js";
14
+ import { declaredActionButton } from "./declared-action-button.js";
11
15
  import { ResourceForm } from "./resource-form.js";
12
16
  import { filterableFields, ResourceTableFilterPanel, } from "./resource-table-filters.js";
13
- /**
14
- * True for an error whose `status` is 403 (permission denied). Duck-typed on
15
- * `status`, not `instanceof VerikitClientError`.
16
- */
17
- function isPermissionDenied(error) {
18
- return (typeof error === "object" &&
19
- error !== null &&
20
- "status" in error &&
21
- error.status === 403);
22
- }
23
17
  // `header` is always the field's required string label.
24
18
  function headerText(header) {
25
19
  return header.column.columnDef.header;
26
20
  }
27
- function cellText(value) {
28
- if (value === null || value === undefined) {
29
- return "";
30
- }
31
- if (value instanceof Date) {
32
- return value.toLocaleString();
33
- }
34
- if (typeof value === "boolean") {
35
- return value ? "Yes" : "No";
36
- }
37
- return String(value);
38
- }
39
21
  function sortIcon(direction) {
40
22
  if (direction === "asc") {
41
23
  return h(ArrowUpIcon, { class: "size-3.5" });
@@ -61,6 +43,10 @@ export const ResourceTable = defineComponent({
61
43
  default: undefined,
62
44
  },
63
45
  actions: { type: Boolean, default: false },
46
+ resourceActions: {
47
+ type: Boolean,
48
+ default: undefined,
49
+ },
64
50
  renderActions: {
65
51
  type: Function,
66
52
  default: undefined,
@@ -79,7 +65,17 @@ export const ResourceTable = defineComponent({
79
65
  },
80
66
  },
81
67
  setup(props) {
82
- const { table, isLoading, error, fields, filters, setFilters } = useResourceTable(props.resource, { pageSize: props.pageSize });
68
+ const showResourceActions = props.resourceActions ?? props.actions;
69
+ const recordActions = showResourceActions
70
+ ? resourceActionSchemas(props.resource, "record")
71
+ : [];
72
+ const collectionActions = showResourceActions
73
+ ? resourceActionSchemas(props.resource, "collection")
74
+ : [];
75
+ const { table, isLoading, error, fields, filters, setFilters, actions: actionAvailability, } = useResourceTable(props.resource, {
76
+ pageSize: props.pageSize,
77
+ includeActions: recordActions.length > 0 || collectionActions.length > 0,
78
+ });
83
79
  const createOpen = ref(false);
84
80
  const createDenied = ref(false);
85
81
  const editRecord = ref(null);
@@ -89,6 +85,61 @@ export const ResourceTable = defineComponent({
89
85
  const bulkDeleteOpen = ref(false);
90
86
  const bulkDeleteError = ref(null);
91
87
  const bulkDeleting = ref(false);
88
+ const activeAction = ref(null);
89
+ const deniedCollectionActions = ref({});
90
+ const actionError = ref(null);
91
+ function denyAction(action, id) {
92
+ if (id === undefined) {
93
+ deniedCollectionActions.value = {
94
+ ...deniedCollectionActions.value,
95
+ [action.name]: true,
96
+ };
97
+ return;
98
+ }
99
+ deniedRows.value = {
100
+ ...deniedRows.value,
101
+ [id]: {
102
+ ...deniedRows.value[id],
103
+ actions: { ...deniedRows.value[id]?.actions, [action.name]: true },
104
+ },
105
+ };
106
+ }
107
+ const directAction = useRunResourceAction(props.resource.name, {
108
+ onSuccess: () => {
109
+ actionError.value = null;
110
+ },
111
+ onError: (mutationError, variables) => {
112
+ if (isActionDenied(mutationError, variables.recordId)) {
113
+ denyAction(variables.action, variables.recordId);
114
+ }
115
+ else {
116
+ actionError.value = mutationError.message;
117
+ }
118
+ },
119
+ });
120
+ function startAction(action, id) {
121
+ actionError.value = null;
122
+ if (actionNeedsDialog(action)) {
123
+ activeAction.value = { action, recordId: id };
124
+ }
125
+ else {
126
+ directAction.mutate({ action, recordId: id });
127
+ }
128
+ }
129
+ function tableActionButton(action, variant, id) {
130
+ return declaredActionButton({
131
+ action,
132
+ unavailable: unavailableAction(actionAvailability.value, action.name, id),
133
+ variant,
134
+ disabled: directAction.isPending.value,
135
+ onClick: () => startAction(action, id),
136
+ });
137
+ }
138
+ function declaredRowActions(record) {
139
+ const id = recordId(record);
140
+ const denied = deniedRows.value[id]?.actions;
141
+ return recordActions.map((action) => denied?.[action.name] ? null : tableActionButton(action, "ghost", id));
142
+ }
92
143
  const deleteMutation = useDeleteResource(props.resource.name, {
93
144
  onError: (mutationError, id) => {
94
145
  if (isPermissionDenied(mutationError)) {
@@ -175,6 +226,7 @@ export const ResourceTable = defineComponent({
175
226
  }
176
227
  function rowActions(record) {
177
228
  return h("div", { class: "flex items-center justify-end gap-1" }, [
229
+ declaredRowActions(record),
178
230
  props.actions ? builtInRowActions(record) : null,
179
231
  props.renderActions ? props.renderActions(record) : null,
180
232
  ]);
@@ -187,7 +239,9 @@ export const ResourceTable = defineComponent({
187
239
  const deleteId = deleteRecord.value
188
240
  ? recordId(deleteRecord.value)
189
241
  : undefined;
190
- const hasActionsColumn = props.actions || Boolean(props.renderActions);
242
+ const hasActionsColumn = props.actions ||
243
+ Boolean(props.renderActions) ||
244
+ recordActions.length > 0;
191
245
  const hasSelectionColumn = props.actions || Boolean(props.renderBulkActions);
192
246
  const hasFilterableFields = filterableFields(fields).length > 0;
193
247
  const activeFilterCount = Object.keys(filters.value).length;
@@ -235,16 +289,24 @@ export const ResourceTable = defineComponent({
235
289
  }, { default: () => "Clear filters" })
236
290
  : null,
237
291
  ]),
238
- props.actions && !createDenied.value
239
- ? h(Button, {
240
- type: "button",
241
- size: "sm",
242
- onClick: () => {
243
- createOpen.value = true;
244
- },
245
- }, { default: () => [h(PlusIcon), "New"] })
246
- : null,
292
+ h("div", { class: "flex items-center gap-2" }, [
293
+ ...collectionActions.map((action) => deniedCollectionActions.value[action.name]
294
+ ? null
295
+ : tableActionButton(action, "outline")),
296
+ props.actions && !createDenied.value
297
+ ? h(Button, {
298
+ type: "button",
299
+ size: "sm",
300
+ onClick: () => {
301
+ createOpen.value = true;
302
+ },
303
+ }, { default: () => [h(PlusIcon), "New"] })
304
+ : null,
305
+ ]),
247
306
  ]),
307
+ actionError.value
308
+ ? h("p", { role: "alert", class: "pb-3 text-sm text-destructive" }, actionError.value)
309
+ : null,
248
310
  filtersOpen.value && hasFilterableFields
249
311
  ? h("div", { class: "pb-3" }, [
250
312
  h(ResourceTableFilterPanel, {
@@ -342,7 +404,7 @@ export const ResourceTable = defineComponent({
342
404
  : null,
343
405
  ...row
344
406
  .getAllCells()
345
- .map((cell) => h("td", { key: cell.id, class: "px-3 py-2" }, cellText(cell.getValue()))),
407
+ .map((cell) => h("td", { key: cell.id, class: "px-3 py-2" }, formatFieldValue(cell.getValue()))),
346
408
  hasActionsColumn
347
409
  ? h("td", { class: "px-3 py-2 text-right" }, [
348
410
  rowActions(row.original),
@@ -375,7 +437,7 @@ export const ResourceTable = defineComponent({
375
437
  class: "flex items-center justify-between gap-2 py-1 text-sm",
376
438
  }, [
377
439
  h("span", { class: "text-muted-foreground" }, headerText({ column: cell.column })),
378
- h("span", { class: "text-right" }, cellText(cell.getValue())),
440
+ h("span", { class: "text-right" }, formatFieldValue(cell.getValue())),
379
441
  ])),
380
442
  hasActionsColumn
381
443
  ? h("div", { class: "flex justify-end gap-2 pt-2" }, [
@@ -407,6 +469,17 @@ export const ResourceTable = defineComponent({
407
469
  }, { default: () => h(ChevronRightIcon) }),
408
470
  ]),
409
471
  ]),
472
+ recordActions.length > 0 || collectionActions.length > 0
473
+ ? h(ResourceActionDialog, {
474
+ resourceName: props.resource.name,
475
+ action: activeAction.value?.action ?? null,
476
+ recordId: activeAction.value?.recordId,
477
+ onClose: () => {
478
+ activeAction.value = null;
479
+ },
480
+ onDenied: (action) => denyAction(action, activeAction.value?.recordId),
481
+ })
482
+ : null,
410
483
  props.actions
411
484
  ? h(Dialog, {
412
485
  open: createOpen.value,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verikit/vue",
3
- "version": "0.24.2",
3
+ "version": "0.24.3",
4
4
  "description": "Vue UI bindings for Verikit resource workflows.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -61,11 +61,11 @@
61
61
  "lucide-vue-next": "^1.0.0",
62
62
  "reka-ui": "^2.10.3",
63
63
  "tailwind-merge": "^3.6.0",
64
- "@verikit/client": "0.24.2",
65
- "@verikit/core": "0.24.2",
66
- "@verikit/runtime": "0.24.2",
67
- "@verikit/theme": "0.24.2",
68
- "@verikit/ui-core": "0.24.2"
64
+ "@verikit/core": "0.24.3",
65
+ "@verikit/runtime": "0.24.3",
66
+ "@verikit/theme": "0.24.3",
67
+ "@verikit/ui-core": "0.24.3",
68
+ "@verikit/client": "0.24.3"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@types/jsdom": "^28.0.3",