@verikit/vue 0.24.2 → 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.
- package/dist/form/use-verikit-schema-tree-form.d.ts +3 -1
- package/dist/form/use-verikit-schema-tree-form.d.ts.map +1 -1
- package/dist/form/use-verikit-schema-tree-form.js +8 -1
- package/dist/query/index.d.ts +2 -2
- package/dist/query/index.d.ts.map +1 -1
- package/dist/query/index.js +1 -1
- package/dist/query/use-resource-mutations.d.ts.map +1 -1
- package/dist/query/use-resource-mutations.js +1 -0
- package/dist/query/use-resource-queries.d.ts +7 -1
- package/dist/query/use-resource-queries.d.ts.map +1 -1
- package/dist/query/use-resource-queries.js +13 -0
- package/dist/query/use-resource-table.d.ts +9 -3
- package/dist/query/use-resource-table.d.ts.map +1 -1
- package/dist/query/use-resource-table.js +3 -1
- package/dist/resource/declared-action-button.d.ts +14 -0
- package/dist/resource/declared-action-button.d.ts.map +1 -0
- package/dist/resource/declared-action-button.js +24 -0
- package/dist/resource/index.d.ts +4 -0
- package/dist/resource/index.d.ts.map +1 -1
- package/dist/resource/index.js +2 -0
- package/dist/resource/resource-action-dialog.d.ts +103 -0
- package/dist/resource/resource-action-dialog.d.ts.map +1 -0
- package/dist/resource/resource-action-dialog.js +207 -0
- package/dist/resource/resource-detail.d.ts +124 -0
- package/dist/resource/resource-detail.d.ts.map +1 -0
- package/dist/resource/resource-detail.js +273 -0
- package/dist/resource/resource-table.d.ts +13 -0
- package/dist/resource/resource-table.d.ts.map +1 -1
- package/dist/resource/resource-table.js +108 -35
- package/package.json +6 -6
|
@@ -10,7 +10,9 @@ export type VerikitSchemaTreeSource = Resource | ResourceSchema;
|
|
|
10
10
|
export interface UseVerikitSchemaTreeFormOptions<TResult = unknown> {
|
|
11
11
|
/** Resource builder or schema containing the tree to render. */
|
|
12
12
|
resource: VerikitSchemaTreeSource;
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Runtime actions whose forms should render for matching action nodes. Merged over the actions the resource declares via `defineResource({ actions })`, which are used by default.
|
|
15
|
+
*/
|
|
14
16
|
actions?: SchemaActionRegistry;
|
|
15
17
|
/** Initial values passed to TanStack Form. */
|
|
16
18
|
defaultValues?: VerikitFormValues;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-verikit-schema-tree-form.d.ts","sourceRoot":"","sources":["../../src/form/use-verikit-schema-tree-form.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE1E,OAAO,EAAW,KAAK,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAExE,OAAO,EAIL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,2BAA2B,EACjC,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAiB,KAAK,WAAW,EAAE,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AAChE,OAAO,KAAK,EACV,oBAAoB,EACpB,iBAAiB,EAClB,MAAM,oBAAoB,CAAC;AAE5B,0DAA0D;AAC1D,MAAM,MAAM,uBAAuB,GAAG,QAAQ,GAAG,cAAc,CAAC;AAEhE,mEAAmE;AACnE,MAAM,WAAW,+BAA+B,CAAC,OAAO,GAAG,OAAO;IAChE,gEAAgE;IAChE,QAAQ,EAAE,uBAAuB,CAAC;IAClC
|
|
1
|
+
{"version":3,"file":"use-verikit-schema-tree-form.d.ts","sourceRoot":"","sources":["../../src/form/use-verikit-schema-tree-form.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE1E,OAAO,EAAW,KAAK,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAExE,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,CAAC,EAAE,iBAAiB,KACvB,OAAO,CAAC,2BAA2B,CAAC,SAAS,CAAC,CAAC,CAAC;IACrD,6CAA6C;IAC7C,MAAM,EAAE,CACN,MAAM,CAAC,EAAE,iBAAiB,KACvB,OAAO,CAAC,2BAA2B,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC;IAC/D,yDAAyD;IACzD,aAAa,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,MAAM,GAAG,SAAS,CAAC;IACxD,uIAAuI;IACvI,SAAS,EAAE,WAAW,CAAC,4BAA4B,CAAC,CAAC;CACtD;AAiBD,gEAAgE;AAChE,wBAAgB,wBAAwB,CAAC,OAAO,GAAG,OAAO,EAAE,EAC1D,QAAQ,EACR,OAAO,EACP,aAAkB,EAClB,QAAQ,GACT,EAAE,+BAA+B,CAAC,OAAO,CAAC,GAAG,8BAA8B,CAAC,OAAO,CAAC,CAqHpF"}
|
|
@@ -7,9 +7,16 @@ import { computed, ref } from "vue";
|
|
|
7
7
|
function resolveVerikitTree(source) {
|
|
8
8
|
return isResource(source) ? source.toSchema().tree : source.tree;
|
|
9
9
|
}
|
|
10
|
+
function resolveActionRegistry(source, overrides) {
|
|
11
|
+
const declared = isResource(source)
|
|
12
|
+
? source.toSchema().actions
|
|
13
|
+
: source.actions;
|
|
14
|
+
return declared ? { ...declared, ...overrides } : overrides;
|
|
15
|
+
}
|
|
10
16
|
/** Creates a TanStack-backed form for a Verikit schema tree. */
|
|
11
17
|
export function useVerikitSchemaTreeForm({ resource, actions, defaultValues = {}, onSubmit, }) {
|
|
12
18
|
const tree = resolveVerikitTree(resource);
|
|
19
|
+
const actionRegistry = resolveActionRegistry(resource, actions);
|
|
13
20
|
const fieldErrors = ref({});
|
|
14
21
|
// Stable per-row ids for repeater rows, keyed by the repeater's own path. Grown
|
|
15
22
|
// lazily (per index, as `getRepeaterRowKey` is called during render) to cover rows
|
|
@@ -71,7 +78,7 @@ export function useVerikitSchemaTreeForm({ resource, actions, defaultValues = {}
|
|
|
71
78
|
const treeProps = computed(() => ({
|
|
72
79
|
values: values.value,
|
|
73
80
|
errors: errors.value,
|
|
74
|
-
actions,
|
|
81
|
+
actions: actionRegistry,
|
|
75
82
|
onFieldChange,
|
|
76
83
|
onFieldBlur,
|
|
77
84
|
onRepeaterAdd,
|
package/dist/query/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { useListResource, useResourceFind, useResourceRelationship, } from "./use-resource-queries.js";
|
|
2
|
-
export type { UseListResourceOptions, UseFindResourceOptions, UseResourceRelationshipOptions, } from "./use-resource-queries.js";
|
|
1
|
+
export { useListResource, useResourceFind, useResourceFindWithActions, useResourceRelationship, } from "./use-resource-queries.js";
|
|
2
|
+
export type { UseListResourceOptions, UseFindResourceOptions, UseFindWithActionsResourceOptions, UseResourceRelationshipOptions, } from "./use-resource-queries.js";
|
|
3
3
|
export { useCreateResource, useUpdateResource, useDeleteResource, useActionResource, } from "./use-resource-mutations.js";
|
|
4
4
|
export type { UseCreateResourceOptions, UpdateResourceVariables, UseUpdateResourceOptions, UseDeleteResourceOptions, ActionResourceVariables, UseActionResourceOptions, } from "./use-resource-mutations.js";
|
|
5
5
|
export { resourceQueryKeys } from "@verikit/ui-core/query/query-keys";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/query/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EACf,uBAAuB,GACxB,MAAM,2BAA2B,CAAC;AACnC,YAAY,EACV,sBAAsB,EACtB,sBAAsB,EACtB,8BAA8B,GAC/B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,6BAA6B,CAAC;AACrC,YAAY,EACV,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,GACzB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,YAAY,EACV,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAC/E,YAAY,EACV,gCAAgC,EAChC,+BAA+B,GAChC,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,EACV,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/query/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EACf,0BAA0B,EAC1B,uBAAuB,GACxB,MAAM,2BAA2B,CAAC;AACnC,YAAY,EACV,sBAAsB,EACtB,sBAAsB,EACtB,iCAAiC,EACjC,8BAA8B,GAC/B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,6BAA6B,CAAC;AACrC,YAAY,EACV,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,uBAAuB,EACvB,wBAAwB,GACzB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,YAAY,EACV,sBAAsB,EACtB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAC/E,YAAY,EACV,gCAAgC,EAChC,+BAA+B,GAChC,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,YAAY,EACV,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,yBAAyB,CAAC"}
|
package/dist/query/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { useListResource, useResourceFind, useResourceRelationship, } from "./use-resource-queries.js";
|
|
1
|
+
export { useListResource, useResourceFind, useResourceFindWithActions, useResourceRelationship, } from "./use-resource-queries.js";
|
|
2
2
|
export { useCreateResource, useUpdateResource, useDeleteResource, useActionResource, } from "./use-resource-mutations.js";
|
|
3
3
|
export { resourceQueryKeys } from "@verikit/ui-core/query/query-keys";
|
|
4
4
|
export { useResourceForm } from "./use-resource-form.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-resource-mutations.d.ts","sourceRoot":"","sources":["../../src/query/use-resource-mutations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EACf,qBAAqB,EACtB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEnE,OAAO,EAML,KAAK,qBAAqB,EAC3B,MAAM,mCAAmC,CAAC;AAG3C,MAAM,MAAM,wBAAwB,CAAC,OAAO,SAAS,MAAM,IAAI,IAAI,CACjE,eAAe,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACxD,YAAY,CACb,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAEhD,IAAI,EAAE,MA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BAAuB,EACvB,qBAAqB,CACtB,CAiEA;AAED,MAAM,MAAM,wBAAwB,GAAG,IAAI,CACzC,eAAe,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,EACpC,YAAY,CACb,CAAC;AAEF,UAAU,qBAAqB;IAC7B,QAAQ,EAAE,qBAAqB,CAAC;IAChC,MAAM,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,wBAAwB,GACjC,qBAAqB,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,qBAAqB,CAAC,CA4DnE;AAED,MAAM,WAAW,uBAAwB,SAAQ,aAAa;IAC5D,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED,MAAM,MAAM,wBAAwB,CAAC,OAAO,IAAI,IAAI,CAClD,eAAe,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,uBAAuB,CAAC,EACtE,YAAY,CACb,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,GAAG,OAAO,EACjD,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,wBAAwB,CAAC,OAAO,CAAC,GAC1C,qBAAqB,CACtB,YAAY,CAAC,OAAO,CAAC,EACrB,KAAK,EACL,uBAAuB,EACvB,OAAO,CACR,CAmBA"}
|
|
@@ -77,6 +77,7 @@ export function useDeleteResource(name, options) {
|
|
|
77
77
|
},
|
|
78
78
|
onSuccess: (data, id, onMutateResult, context) => {
|
|
79
79
|
queryClient.removeQueries({ queryKey: keys.find(id) });
|
|
80
|
+
queryClient.removeQueries({ queryKey: keys.findWithActions(id) });
|
|
80
81
|
return options?.onSuccess?.(data, id, onMutateResult?.caller, context);
|
|
81
82
|
},
|
|
82
83
|
// Always refetch after deletion to reconcile optimistic state with the server.
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type { UseQueryOptions, UseQueryReturnType } from "@tanstack/vue-query";
|
|
2
|
-
import type { ListParams, ListResponse } from "@verikit/client";
|
|
2
|
+
import type { FindWithActionsResponse, ListParams, ListResponse } from "@verikit/client";
|
|
3
|
+
import { type MaybeRefOrGetter } from "vue";
|
|
3
4
|
export type UseListResourceOptions<TRecord extends object> = Omit<UseQueryOptions<ListResponse<TRecord>, Error>, "queryKey" | "queryFn">;
|
|
4
5
|
/** Lists a resource's records, cached per resource name + params. */
|
|
5
6
|
export declare function useListResource<TRecord extends object = Record<string, unknown>>(name: string, params?: ListParams<TRecord>, options?: UseListResourceOptions<TRecord>): UseQueryReturnType<ListResponse<TRecord>, Error>;
|
|
6
7
|
export type UseFindResourceOptions<TRecord extends object> = Omit<UseQueryOptions<TRecord, Error>, "queryKey" | "queryFn">;
|
|
7
8
|
/** Fetches a single resource record by id, cached per resource name + id. */
|
|
8
9
|
export declare function useResourceFind<TRecord extends object = Record<string, unknown>>(name: string, id: string, options?: UseFindResourceOptions<TRecord>): UseQueryReturnType<TRecord, Error>;
|
|
10
|
+
export type UseFindWithActionsResourceOptions<TRecord extends object> = Omit<UseQueryOptions<FindWithActionsResponse<TRecord>, Error>, "queryKey" | "queryFn">;
|
|
11
|
+
/**
|
|
12
|
+
* Fetches a single record by id along with the record-scoped actions the caller can't run on it, cached per resource name + id. `id` may be a ref or getter, refetching when it changes.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useResourceFindWithActions<TRecord extends object = Record<string, unknown>>(name: string, id: MaybeRefOrGetter<string>, options?: UseFindWithActionsResourceOptions<TRecord>): UseQueryReturnType<FindWithActionsResponse<TRecord>, Error>;
|
|
9
15
|
export type UseResourceRelationshipOptions<TTarget extends object> = Omit<UseQueryOptions<ListResponse<TTarget>, Error>, "queryKey" | "queryFn">;
|
|
10
16
|
/**
|
|
11
17
|
* Lists selectable records for a `belongsTo` relationship, cached by
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-resource-queries.d.ts","sourceRoot":"","sources":["../../src/query/use-resource-queries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAE/E,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"use-resource-queries.d.ts","sourceRoot":"","sources":["../../src/query/use-resource-queries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAE/E,OAAO,KAAK,EACV,uBAAuB,EACvB,UAAU,EACV,YAAY,EACb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAqB,KAAK,gBAAgB,EAAE,MAAM,KAAK,CAAC;AAI/D,MAAM,MAAM,sBAAsB,CAAC,OAAO,SAAS,MAAM,IAAI,IAAI,CAC/D,eAAe,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,EAC7C,UAAU,GAAG,SAAS,CACvB,CAAC;AAEF,qEAAqE;AACrE,wBAAgB,eAAe,CAC7B,OAAO,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAEhD,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,UAAU,CAAC,OAAO,CAAM,EAChC,OAAO,CAAC,EAAE,sBAAsB,CAAC,OAAO,CAAC,GACxC,kBAAkB,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CASlD;AAED,MAAM,MAAM,sBAAsB,CAAC,OAAO,SAAS,MAAM,IAAI,IAAI,CAC/D,eAAe,CAAC,OAAO,EAAE,KAAK,CAAC,EAC/B,UAAU,GAAG,SAAS,CACvB,CAAC;AAEF,6EAA6E;AAC7E,wBAAgB,eAAe,CAC7B,OAAO,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAEhD,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,sBAAsB,CAAC,OAAO,CAAC,GACxC,kBAAkB,CAAC,OAAO,EAAE,KAAK,CAAC,CASpC;AAED,MAAM,MAAM,iCAAiC,CAAC,OAAO,SAAS,MAAM,IAAI,IAAI,CAC1E,eAAe,CAAC,uBAAuB,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,EACxD,UAAU,GAAG,SAAS,CACvB,CAAC;AAEF;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAEhD,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAC5B,OAAO,CAAC,EAAE,iCAAiC,CAAC,OAAO,CAAC,GACnD,kBAAkB,CAAC,uBAAuB,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAU7D;AAED,MAAM,MAAM,8BAA8B,CAAC,OAAO,SAAS,MAAM,IAAI,IAAI,CACvE,eAAe,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,EAC7C,UAAU,GAAG,SAAS,CACvB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAEhD,IAAI,EAAE,MAAM,EACZ,gBAAgB,EAAE,MAAM,EACxB,MAAM,GAAE,UAAU,CAAC,OAAO,CAAM,EAChC,OAAO,CAAC,EAAE,8BAA8B,CAAC,OAAO,CAAC,GAChD,kBAAkB,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAclD"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useQuery } from "@tanstack/vue-query";
|
|
2
|
+
import { computed, toValue } from "vue";
|
|
2
3
|
import { useVerikitClient } from "../client/use-verikit-client.js";
|
|
3
4
|
import { resourceQueryKeys } from "@verikit/ui-core/query/query-keys";
|
|
4
5
|
/** Lists a resource's records, cached per resource name + params. */
|
|
@@ -19,6 +20,18 @@ export function useResourceFind(name, id, options) {
|
|
|
19
20
|
...options,
|
|
20
21
|
});
|
|
21
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Fetches a single record by id along with the record-scoped actions the caller can't run on it, cached per resource name + id. `id` may be a ref or getter, refetching when it changes.
|
|
25
|
+
*/
|
|
26
|
+
export function useResourceFindWithActions(name, id, options) {
|
|
27
|
+
const client = useVerikitClient();
|
|
28
|
+
const keys = resourceQueryKeys(name, client);
|
|
29
|
+
return useQuery({
|
|
30
|
+
queryKey: computed(() => keys.findWithActions(toValue(id))),
|
|
31
|
+
queryFn: ({ signal }) => client.resource(name).findWithActions(toValue(id), { signal }),
|
|
32
|
+
...options,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
22
35
|
/**
|
|
23
36
|
* Lists selectable records for a `belongsTo` relationship, cached by
|
|
24
37
|
* resource, relationship, and params. Server-side permissions and scopes apply.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type RowData, type Table } from "@tanstack/vue-table";
|
|
2
2
|
import { type UseQueryReturnType } from "@tanstack/vue-query";
|
|
3
|
-
import type { ListParams, ListResponse } from "@verikit/client";
|
|
3
|
+
import type { ListActionAvailability, ListParams, ListResponse } from "@verikit/client";
|
|
4
4
|
import type { FieldSchema, Resource, ResourceSchema } from "@verikit/core";
|
|
5
|
-
import { type Ref } from "vue";
|
|
5
|
+
import { type ComputedRef, type Ref } from "vue";
|
|
6
6
|
declare const resourceTableFeatures: {
|
|
7
7
|
rowSortingFeature: import("@tanstack/vue-table").TableFeature;
|
|
8
8
|
rowPaginationFeature: import("@tanstack/vue-table").TableFeature;
|
|
@@ -19,6 +19,10 @@ export type ResourceTableFilters = NonNullable<ListParams["filters"]>;
|
|
|
19
19
|
export interface UseResourceTableOptions {
|
|
20
20
|
/** Initial page size, before the user (or caller) changes it. Defaults to 25. */
|
|
21
21
|
pageSize?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Also asks the server which actions the actor can't run on each page, returned as `actions`. Each action's permissions and availability guard run per record, so only set this when the actions are shown.
|
|
24
|
+
*/
|
|
25
|
+
includeActions?: boolean;
|
|
22
26
|
}
|
|
23
27
|
/** State and helpers returned by {@link useResourceTable}. */
|
|
24
28
|
export interface UseResourceTableResult<TRecord extends RowData = Record<string, unknown>> {
|
|
@@ -38,11 +42,13 @@ export interface UseResourceTableResult<TRecord extends RowData = Record<string,
|
|
|
38
42
|
filters: Ref<ResourceTableFilters>;
|
|
39
43
|
/** Replaces the active per-field filters wholesale. */
|
|
40
44
|
setFilters: (filters: ResourceTableFilters) => void;
|
|
45
|
+
/** The actions the actor can't run on the current page, when requested with `includeActions`. */
|
|
46
|
+
actions: ComputedRef<ListActionAvailability | undefined>;
|
|
41
47
|
}
|
|
42
48
|
/**
|
|
43
49
|
* Creates a TanStack Table from a resource's schema, with automatic columns
|
|
44
50
|
* and server-side pagination, sorting, and search.
|
|
45
51
|
*/
|
|
46
|
-
export declare function useResourceTable<TRecord extends RowData = Record<string, unknown>>(resource: UseResourceTableSource, { pageSize }?: UseResourceTableOptions): UseResourceTableResult<TRecord>;
|
|
52
|
+
export declare function useResourceTable<TRecord extends RowData = Record<string, unknown>>(resource: UseResourceTableSource, { pageSize, includeActions }?: UseResourceTableOptions): UseResourceTableResult<TRecord>;
|
|
47
53
|
export {};
|
|
48
54
|
//# sourceMappingURL=use-resource-table.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-resource-table.d.ts","sourceRoot":"","sources":["../../src/query/use-resource-table.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,KAAK,OAAO,EAGZ,KAAK,KAAK,EACX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAY,KAAK,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"use-resource-table.d.ts","sourceRoot":"","sources":["../../src/query/use-resource-table.ts"],"names":[],"mappings":"A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AAkB,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC;IACjE;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACpC,2DAA2D;IAC3D,OAAO,EAAE,GAAG,CAAC,oBAAoB,CAAC,CAAC;IACnC,uDAAuD;IACvD,UAAU,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAC;IACpD,iGAAiG;IACjG,OAAO,EAAE,WAAW,CAAC,sBAAsB,GAAG,SAAS,CAAC,CAAC;CAC1D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,SAAS,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAEjD,QAAQ,EAAE,sBAAsB,EAChC,EAAE,QAAa,EAAE,cAAsB,EAAE,GAAE,uBAA4B,GACtE,sBAAsB,CAAC,OAAO,CAAC,CAoGjC"}
|
|
@@ -18,7 +18,7 @@ const resourceTableFeatures = tableFeatures({
|
|
|
18
18
|
* Creates a TanStack Table from a resource's schema, with automatic columns
|
|
19
19
|
* and server-side pagination, sorting, and search.
|
|
20
20
|
*/
|
|
21
|
-
export function useResourceTable(resource, { pageSize = 25 } = {}) {
|
|
21
|
+
export function useResourceTable(resource, { pageSize = 25, includeActions = false } = {}) {
|
|
22
22
|
const client = useVerikitClient();
|
|
23
23
|
const fields = resolveVerikitFields(resource);
|
|
24
24
|
const columns = computed(() => Object.values(fields)
|
|
@@ -58,6 +58,7 @@ export function useResourceTable(resource, { pageSize = 25 } = {}) {
|
|
|
58
58
|
? { field: activeSort.id, direction: activeSort.desc ? "desc" : "asc" }
|
|
59
59
|
: undefined,
|
|
60
60
|
...(hasFilters ? { filters: filters.value } : {}),
|
|
61
|
+
...(includeActions ? { includeActions } : {}),
|
|
61
62
|
};
|
|
62
63
|
});
|
|
63
64
|
const list = useQuery({
|
|
@@ -100,5 +101,6 @@ export function useResourceTable(resource, { pageSize = 25 } = {}) {
|
|
|
100
101
|
fields,
|
|
101
102
|
filters,
|
|
102
103
|
setFilters: handleFiltersChange,
|
|
104
|
+
actions: computed(() => list.data.value?.actions),
|
|
103
105
|
};
|
|
104
106
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type VNodeChild } from "vue";
|
|
2
|
+
import type { UnavailableAction } from "@verikit/client";
|
|
3
|
+
import type { ActionSchemaLike } from "@verikit/core";
|
|
4
|
+
/**
|
|
5
|
+
* Renders a declared action's button. Hidden when the server reports the actor may not run it; disabled, with the reason as a tooltip, when it can't run right now.
|
|
6
|
+
*/
|
|
7
|
+
export declare function declaredActionButton(options: {
|
|
8
|
+
action: ActionSchemaLike;
|
|
9
|
+
unavailable: UnavailableAction | undefined;
|
|
10
|
+
variant: "ghost" | "outline";
|
|
11
|
+
disabled: boolean;
|
|
12
|
+
onClick: () => void;
|
|
13
|
+
}): VNodeChild;
|
|
14
|
+
//# sourceMappingURL=declared-action-button.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declared-action-button.d.ts","sourceRoot":"","sources":["../../src/resource/declared-action-button.ts"],"names":[],"mappings":"AAAA,OAAO,EAAK,KAAK,UAAU,EAAE,MAAM,KAAK,CAAC;AAEzC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGtD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE;IAC5C,MAAM,EAAE,gBAAgB,CAAC;IACzB,WAAW,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAC3C,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,GAAG,UAAU,CA4Bb"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { h } from "vue";
|
|
2
|
+
import { Button } from "#components/button";
|
|
3
|
+
import { actionLabel } from "@verikit/ui-core/actions/resource-actions";
|
|
4
|
+
/**
|
|
5
|
+
* Renders a declared action's button. Hidden when the server reports the actor may not run it; disabled, with the reason as a tooltip, when it can't run right now.
|
|
6
|
+
*/
|
|
7
|
+
export function declaredActionButton(options) {
|
|
8
|
+
const { action, unavailable } = options;
|
|
9
|
+
if (unavailable?.reason === "forbidden") {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const button = h(Button, {
|
|
13
|
+
key: action.name,
|
|
14
|
+
type: "button",
|
|
15
|
+
variant: action.variant === "danger" ? "destructive" : options.variant,
|
|
16
|
+
size: "sm",
|
|
17
|
+
disabled: options.disabled || unavailable !== undefined,
|
|
18
|
+
onClick: options.onClick,
|
|
19
|
+
}, { default: () => actionLabel(action) });
|
|
20
|
+
// Disabled buttons ignore pointer events, so the tooltip sits on a wrapper.
|
|
21
|
+
return unavailable
|
|
22
|
+
? h("span", { key: action.name, class: "inline-flex", title: unavailable.message }, [button])
|
|
23
|
+
: button;
|
|
24
|
+
}
|
package/dist/resource/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
export { ResourceDetail } from "./resource-detail.js";
|
|
2
|
+
export type { ResourceDetailProps } from "./resource-detail.js";
|
|
1
3
|
export { ResourceForm } from "./resource-form.js";
|
|
2
4
|
export type { ResourceFormProps } from "./resource-form.js";
|
|
3
5
|
export { ResourceTable } from "./resource-table.js";
|
|
4
6
|
export type { ResourceTableProps } from "./resource-table.js";
|
|
7
|
+
export { ResourceActionDialog, useRunResourceAction, } from "./resource-action-dialog.js";
|
|
8
|
+
export type { ResourceActionDialogProps, RunResourceActionVariables, } from "./resource-action-dialog.js";
|
|
5
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resource/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resource/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,YAAY,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EACL,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AACrC,YAAY,EACV,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,6BAA6B,CAAC"}
|
package/dist/resource/index.js
CHANGED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { UseMutationReturnType } from "@tanstack/vue-query";
|
|
2
|
+
import type { ActionSchemaLike } from "@verikit/core";
|
|
3
|
+
import { type ActionResult } from "@verikit/client";
|
|
4
|
+
import { type PropType } from "vue";
|
|
5
|
+
import type { VerikitFieldRegistry } from "../fields/types.js";
|
|
6
|
+
/** True for an error whose `status` matches, duck-typed like `ResourceTable`. */
|
|
7
|
+
export declare function hasStatus(error: unknown, status: number): boolean;
|
|
8
|
+
/** True for an error whose `status` is 403, duck-typed like `ResourceTable`. */
|
|
9
|
+
export declare function isPermissionDenied(error: unknown): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* True when the server denied running an action. The server denies record actions with 404 rather than 403 so it never reveals whether the record exists; the caller already holds that record, so a 404 there means the action can't run on it (denied, or the record is gone).
|
|
12
|
+
*/
|
|
13
|
+
export declare function isActionDenied(error: unknown, recordId: string | undefined): boolean;
|
|
14
|
+
/** Variables for {@link useRunResourceAction}. */
|
|
15
|
+
export interface RunResourceActionVariables {
|
|
16
|
+
action: ActionSchemaLike;
|
|
17
|
+
recordId?: string;
|
|
18
|
+
input?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Runs any declared action of a resource over `@verikit/client`, invalidating the resource's queries on success, or when the server reports the action unavailable. Sends `confirmed: true` for actions that declare a confirmation, since callers only run those after the user accepted it.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useRunResourceAction(resourceName: string, options?: {
|
|
24
|
+
onSuccess?: () => void;
|
|
25
|
+
onError?: (error: Error, variables: RunResourceActionVariables) => void;
|
|
26
|
+
}): UseMutationReturnType<ActionResult<unknown>, Error, RunResourceActionVariables, unknown>;
|
|
27
|
+
/** Props for {@link ResourceActionDialog}. */
|
|
28
|
+
export interface ResourceActionDialogProps {
|
|
29
|
+
/** Resource the action belongs to. */
|
|
30
|
+
resourceName: string;
|
|
31
|
+
/** Declared action to run; the dialog is open while this is set. */
|
|
32
|
+
action: ActionSchemaLike | null;
|
|
33
|
+
/** Record the action targets, for record-scoped actions. */
|
|
34
|
+
recordId?: string;
|
|
35
|
+
/** Called when the dialog closes, after success or cancel. */
|
|
36
|
+
onClose: () => void;
|
|
37
|
+
/** Called when the server denies the action (403, or 404 for a record action); the dialog then closes. */
|
|
38
|
+
onDenied?: (action: ActionSchemaLike) => void;
|
|
39
|
+
/** Optional renderer overrides for the action's form fields. */
|
|
40
|
+
registry?: Partial<VerikitFieldRegistry>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Confirms and collects input for a declared resource action, then runs it over `@verikit/client`. Labels, confirmation copy, and form fields all come from the action's declaration in `defineResource({ actions })`.
|
|
44
|
+
*/
|
|
45
|
+
export declare const ResourceActionDialog: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
46
|
+
resourceName: {
|
|
47
|
+
type: StringConstructor;
|
|
48
|
+
required: true;
|
|
49
|
+
};
|
|
50
|
+
action: {
|
|
51
|
+
type: PropType<ActionSchemaLike | null>;
|
|
52
|
+
default: null;
|
|
53
|
+
};
|
|
54
|
+
recordId: {
|
|
55
|
+
type: PropType<string | undefined>;
|
|
56
|
+
default: undefined;
|
|
57
|
+
};
|
|
58
|
+
onClose: {
|
|
59
|
+
type: PropType<() => void>;
|
|
60
|
+
required: true;
|
|
61
|
+
};
|
|
62
|
+
onDenied: {
|
|
63
|
+
type: PropType<ResourceActionDialogProps["onDenied"]>;
|
|
64
|
+
default: undefined;
|
|
65
|
+
};
|
|
66
|
+
registry: {
|
|
67
|
+
type: PropType<Partial<VerikitFieldRegistry> | undefined>;
|
|
68
|
+
default: undefined;
|
|
69
|
+
};
|
|
70
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
71
|
+
[key: string]: any;
|
|
72
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
73
|
+
resourceName: {
|
|
74
|
+
type: StringConstructor;
|
|
75
|
+
required: true;
|
|
76
|
+
};
|
|
77
|
+
action: {
|
|
78
|
+
type: PropType<ActionSchemaLike | null>;
|
|
79
|
+
default: null;
|
|
80
|
+
};
|
|
81
|
+
recordId: {
|
|
82
|
+
type: PropType<string | undefined>;
|
|
83
|
+
default: undefined;
|
|
84
|
+
};
|
|
85
|
+
onClose: {
|
|
86
|
+
type: PropType<() => void>;
|
|
87
|
+
required: true;
|
|
88
|
+
};
|
|
89
|
+
onDenied: {
|
|
90
|
+
type: PropType<ResourceActionDialogProps["onDenied"]>;
|
|
91
|
+
default: undefined;
|
|
92
|
+
};
|
|
93
|
+
registry: {
|
|
94
|
+
type: PropType<Partial<VerikitFieldRegistry> | undefined>;
|
|
95
|
+
default: undefined;
|
|
96
|
+
};
|
|
97
|
+
}>> & Readonly<{}>, {
|
|
98
|
+
registry: Partial<VerikitFieldRegistry> | undefined;
|
|
99
|
+
action: ActionSchemaLike | null;
|
|
100
|
+
recordId: string | undefined;
|
|
101
|
+
onDenied: ((action: ActionSchemaLike) => void) | undefined;
|
|
102
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
103
|
+
//# sourceMappingURL=resource-action-dialog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-action-dialog.d.ts","sourceRoot":"","sources":["../../src/resource/resource-action-dialog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAEjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAsB,KAAK,QAAQ,EAAE,MAAM,KAAK,CAAC;AAgBxD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAG/D,iFAAiF;AACjF,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAOjE;AAED,gFAAgF;AAChF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE1D;AAWD;;GAEG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC3B,OAAO,CAKT;AAED,kDAAkD;AAClD,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,gBAAgB,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED;;GAEG;AACH,wBAAgB,oBAA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AAO,CAAC,oBAAoB,CAAC,GAAG,SAAS,CAAC;;;;;;;wBApKnD,gBAAgB,KAAK,IAAI;4EA2M7C,CAAC"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { useMutation, useQueryClient } from "@tanstack/vue-query";
|
|
2
|
+
import { VerikitClientError } from "@verikit/client";
|
|
3
|
+
import { defineComponent, h } from "vue";
|
|
4
|
+
import { Button } from "#components/button";
|
|
5
|
+
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "#components/dialog";
|
|
6
|
+
import { actionLabel } from "@verikit/ui-core/actions/resource-actions";
|
|
7
|
+
import { resourceQueryKeys } from "@verikit/ui-core/query/query-keys";
|
|
8
|
+
import { validationIssuesToFieldErrors } from "@verikit/ui-core/form/submission";
|
|
9
|
+
import { useVerikitClient } from "../client/use-verikit-client.js";
|
|
10
|
+
import { RenderField } from "../fields/registry.js";
|
|
11
|
+
import { useVerikitForm } from "../form/use-verikit-form.js";
|
|
12
|
+
/** True for an error whose `status` matches, duck-typed like `ResourceTable`. */
|
|
13
|
+
export function hasStatus(error, status) {
|
|
14
|
+
return (typeof error === "object" &&
|
|
15
|
+
error !== null &&
|
|
16
|
+
"status" in error &&
|
|
17
|
+
error.status === status);
|
|
18
|
+
}
|
|
19
|
+
/** True for an error whose `status` is 403, duck-typed like `ResourceTable`. */
|
|
20
|
+
export function isPermissionDenied(error) {
|
|
21
|
+
return hasStatus(error, 403);
|
|
22
|
+
}
|
|
23
|
+
function isActionUnavailable(error) {
|
|
24
|
+
return (typeof error === "object" &&
|
|
25
|
+
error !== null &&
|
|
26
|
+
"code" in error &&
|
|
27
|
+
error.code === "ACTION_UNAVAILABLE");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* True when the server denied running an action. The server denies record actions with 404 rather than 403 so it never reveals whether the record exists; the caller already holds that record, so a 404 there means the action can't run on it (denied, or the record is gone).
|
|
31
|
+
*/
|
|
32
|
+
export function isActionDenied(error, recordId) {
|
|
33
|
+
return (isPermissionDenied(error) ||
|
|
34
|
+
(recordId !== undefined && hasStatus(error, 404)));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Runs any declared action of a resource over `@verikit/client`, invalidating the resource's queries on success, or when the server reports the action unavailable. Sends `confirmed: true` for actions that declare a confirmation, since callers only run those after the user accepted it.
|
|
38
|
+
*/
|
|
39
|
+
export function useRunResourceAction(resourceName, options = {}) {
|
|
40
|
+
const client = useVerikitClient();
|
|
41
|
+
const queryClient = useQueryClient();
|
|
42
|
+
const keys = resourceQueryKeys(resourceName, client);
|
|
43
|
+
return useMutation({
|
|
44
|
+
mutationFn: ({ action, recordId, input }) => client.resource(resourceName).action(action.name, input, {
|
|
45
|
+
recordId,
|
|
46
|
+
confirmed: action.confirmation ? true : undefined,
|
|
47
|
+
}),
|
|
48
|
+
onSuccess: () => {
|
|
49
|
+
void queryClient.invalidateQueries({ queryKey: keys.all });
|
|
50
|
+
options.onSuccess?.();
|
|
51
|
+
},
|
|
52
|
+
onError: (error, variables) => {
|
|
53
|
+
// The list's action availability is stale: refetch it so the action
|
|
54
|
+
// shows as unavailable.
|
|
55
|
+
if (isActionUnavailable(error)) {
|
|
56
|
+
void queryClient.invalidateQueries({ queryKey: keys.all });
|
|
57
|
+
}
|
|
58
|
+
options.onError?.(error, variables);
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const ActionDialogBody = defineComponent({
|
|
63
|
+
name: "ResourceActionDialogBody",
|
|
64
|
+
props: {
|
|
65
|
+
resourceName: { type: String, required: true },
|
|
66
|
+
action: {
|
|
67
|
+
type: Object,
|
|
68
|
+
required: true,
|
|
69
|
+
},
|
|
70
|
+
recordId: {
|
|
71
|
+
type: String,
|
|
72
|
+
default: undefined,
|
|
73
|
+
},
|
|
74
|
+
onClose: {
|
|
75
|
+
type: Function,
|
|
76
|
+
required: true,
|
|
77
|
+
},
|
|
78
|
+
onDenied: {
|
|
79
|
+
type: Function,
|
|
80
|
+
default: undefined,
|
|
81
|
+
},
|
|
82
|
+
registry: {
|
|
83
|
+
type: Object,
|
|
84
|
+
default: undefined,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
setup(props) {
|
|
88
|
+
const action = props.action;
|
|
89
|
+
const fields = action.form ?? {};
|
|
90
|
+
const run = useRunResourceAction(props.resourceName, {
|
|
91
|
+
onSuccess: () => props.onClose(),
|
|
92
|
+
onError: (error) => {
|
|
93
|
+
if (isActionDenied(error, props.recordId)) {
|
|
94
|
+
props.onDenied?.(action);
|
|
95
|
+
props.onClose();
|
|
96
|
+
}
|
|
97
|
+
else if (error instanceof VerikitClientError && error.issues) {
|
|
98
|
+
form.setFieldErrors(validationIssuesToFieldErrors(error.issues));
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
const form = useVerikitForm({
|
|
103
|
+
fields,
|
|
104
|
+
onSubmit: (input) => run.mutateAsync({ action, recordId: props.recordId, input }),
|
|
105
|
+
});
|
|
106
|
+
const description = action.confirmation?.message ?? action.description;
|
|
107
|
+
function handleSubmit(event) {
|
|
108
|
+
event.preventDefault();
|
|
109
|
+
event.stopPropagation();
|
|
110
|
+
// `run.error` already surfaces mutation failures; suppress the rejection here.
|
|
111
|
+
form.submit().catch(() => { });
|
|
112
|
+
}
|
|
113
|
+
return () => [
|
|
114
|
+
h(DialogHeader, {}, {
|
|
115
|
+
default: () => [
|
|
116
|
+
h(DialogTitle, {}, {
|
|
117
|
+
default: () => action.confirmation?.title ?? actionLabel(action),
|
|
118
|
+
}),
|
|
119
|
+
description
|
|
120
|
+
? h(DialogDescription, {}, { default: () => description })
|
|
121
|
+
: null,
|
|
122
|
+
],
|
|
123
|
+
}),
|
|
124
|
+
h("form", { class: "grid gap-4", onSubmit: handleSubmit, novalidate: true }, [
|
|
125
|
+
...Object.keys(fields).map((name) => RenderField({
|
|
126
|
+
registry: props.registry,
|
|
127
|
+
...form.getFieldProps(name),
|
|
128
|
+
})),
|
|
129
|
+
run.error.value && !isActionDenied(run.error.value, props.recordId)
|
|
130
|
+
? h("p", { role: "alert", class: "text-sm text-destructive" }, run.error.value.message)
|
|
131
|
+
: null,
|
|
132
|
+
h(DialogFooter, {}, {
|
|
133
|
+
default: () => [
|
|
134
|
+
h(DialogClose, { asChild: true }, {
|
|
135
|
+
default: () => h(Button, { type: "button", variant: "outline" }, {
|
|
136
|
+
default: () => action.confirmation?.cancelLabel ?? "Cancel",
|
|
137
|
+
}),
|
|
138
|
+
}),
|
|
139
|
+
h(Button, {
|
|
140
|
+
type: "submit",
|
|
141
|
+
variant: action.variant === "danger" ? "destructive" : "default",
|
|
142
|
+
disabled: run.isPending.value,
|
|
143
|
+
}, {
|
|
144
|
+
default: () => run.isPending.value
|
|
145
|
+
? "Running…"
|
|
146
|
+
: (action.confirmation?.confirmLabel ??
|
|
147
|
+
actionLabel(action)),
|
|
148
|
+
}),
|
|
149
|
+
],
|
|
150
|
+
}),
|
|
151
|
+
]),
|
|
152
|
+
];
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
/**
|
|
156
|
+
* Confirms and collects input for a declared resource action, then runs it over `@verikit/client`. Labels, confirmation copy, and form fields all come from the action's declaration in `defineResource({ actions })`.
|
|
157
|
+
*/
|
|
158
|
+
export const ResourceActionDialog = defineComponent({
|
|
159
|
+
name: "ResourceActionDialog",
|
|
160
|
+
props: {
|
|
161
|
+
resourceName: { type: String, required: true },
|
|
162
|
+
action: {
|
|
163
|
+
type: Object,
|
|
164
|
+
default: null,
|
|
165
|
+
},
|
|
166
|
+
recordId: {
|
|
167
|
+
type: String,
|
|
168
|
+
default: undefined,
|
|
169
|
+
},
|
|
170
|
+
onClose: {
|
|
171
|
+
type: Function,
|
|
172
|
+
required: true,
|
|
173
|
+
},
|
|
174
|
+
onDenied: {
|
|
175
|
+
type: Function,
|
|
176
|
+
default: undefined,
|
|
177
|
+
},
|
|
178
|
+
registry: {
|
|
179
|
+
type: Object,
|
|
180
|
+
default: undefined,
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
setup(props) {
|
|
184
|
+
return () => h(Dialog, {
|
|
185
|
+
open: props.action !== null,
|
|
186
|
+
onOpenChange: (open) => {
|
|
187
|
+
if (!open) {
|
|
188
|
+
props.onClose();
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
}, {
|
|
192
|
+
default: () => h(DialogContent, {}, {
|
|
193
|
+
default: () => props.action
|
|
194
|
+
? h(ActionDialogBody, {
|
|
195
|
+
key: `${props.action.name}:${props.recordId ?? ""}`,
|
|
196
|
+
resourceName: props.resourceName,
|
|
197
|
+
action: props.action,
|
|
198
|
+
recordId: props.recordId,
|
|
199
|
+
onClose: props.onClose,
|
|
200
|
+
onDenied: props.onDenied,
|
|
201
|
+
registry: props.registry,
|
|
202
|
+
})
|
|
203
|
+
: null,
|
|
204
|
+
}),
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
});
|