@verikit/react 0.24.4 → 0.25.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/README.md +5 -1
- package/dist/components/combobox.d.ts +17 -0
- package/dist/components/combobox.d.ts.map +1 -0
- package/dist/components/combobox.js +27 -0
- package/dist/fields/inputs.d.ts.map +1 -1
- package/dist/fields/inputs.js +6 -1
- package/dist/layout/render-schema-node.d.ts.map +1 -1
- package/dist/layout/render-schema-node.js +2 -2
- package/dist/layout/types.d.ts +5 -0
- package/dist/layout/types.d.ts.map +1 -1
- package/dist/query/use-resource-table.d.ts +7 -2
- package/dist/query/use-resource-table.d.ts.map +1 -1
- package/dist/query/use-resource-table.js +24 -8
- package/dist/relationships/belongs-to-field.d.ts +18 -8
- package/dist/relationships/belongs-to-field.d.ts.map +1 -1
- package/dist/relationships/belongs-to-field.js +36 -20
- package/dist/relationships/use-relationship-picker.d.ts +40 -0
- package/dist/relationships/use-relationship-picker.d.ts.map +1 -0
- package/dist/relationships/use-relationship-picker.js +72 -0
- package/dist/resource/resource-detail.d.ts +6 -2
- package/dist/resource/resource-detail.d.ts.map +1 -1
- package/dist/resource/resource-detail.js +27 -8
- package/dist/resource/resource-form.d.ts.map +1 -1
- package/dist/resource/resource-form.js +1 -1
- package/dist/resource/resource-table-filters.d.ts.map +1 -1
- package/dist/resource/resource-table-filters.js +14 -2
- package/dist/resource/resource-table.d.ts +18 -1
- package/dist/resource/resource-table.d.ts.map +1 -1
- package/dist/resource/resource-table.js +24 -8
- package/package.json +27 -11
- package/tailwind-sources.css +3 -0
package/README.md
CHANGED
|
@@ -4,7 +4,11 @@ React UI bindings for VeriKit resource workflows.
|
|
|
4
4
|
|
|
5
5
|
See the [VeriKit documentation](https://verikit.dev) for setup and usage.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Production
|
|
8
|
+
|
|
9
|
+
You don't need this to get started. Read it before you deploy.
|
|
10
|
+
|
|
11
|
+
### Cache identity
|
|
8
12
|
|
|
9
13
|
Queries, mutations, and optimistic updates are isolated by client. Keep the client
|
|
10
14
|
stable during a session; replace it when the account, tenant, or access identity
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Combobox as ComboboxPrimitive } from "@base-ui/react/combobox";
|
|
2
|
+
/** shadcn-compatible combobox root built on Base UI. */
|
|
3
|
+
declare const Combobox: typeof ComboboxPrimitive.Root;
|
|
4
|
+
/** The combobox's text input, with a toggle and an optional clear button. */
|
|
5
|
+
declare function ComboboxInput({ className, showClear, ...props }: ComboboxPrimitive.Input.Props & {
|
|
6
|
+
showClear?: boolean;
|
|
7
|
+
}): import("react").JSX.Element;
|
|
8
|
+
/** Renders the combobox popup, positioned under its input. */
|
|
9
|
+
declare function ComboboxContent({ className, children, ...props }: ComboboxPrimitive.Popup.Props): import("react").JSX.Element;
|
|
10
|
+
/** Lists the combobox's items. */
|
|
11
|
+
declare function ComboboxList({ className, ...props }: ComboboxPrimitive.List.Props): import("react").JSX.Element;
|
|
12
|
+
/** Renders a selectable item, with a check when it's the current value. */
|
|
13
|
+
declare function ComboboxItem({ className, children, ...props }: ComboboxPrimitive.Item.Props): import("react").JSX.Element;
|
|
14
|
+
/** Shown in place of the list when it has no items. */
|
|
15
|
+
declare function ComboboxEmpty({ className, ...props }: ComboboxPrimitive.Empty.Props): import("react").JSX.Element;
|
|
16
|
+
export { Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList, };
|
|
17
|
+
//# sourceMappingURL=combobox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combobox.d.ts","sourceRoot":"","sources":["../../src/components/combobox.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAKxE,wDAAwD;AACxD,QAAA,MAAM,QAAQ,+BAAyB,CAAC;AAExC,6EAA6E;AAC7E,iBAAS,aAAa,CAAC,EACrB,SAAS,EACT,SAAiB,EACjB,GAAG,KAAK,EACT,EAAE,iBAAiB,CAAC,KAAK,CAAC,KAAK,GAAG;IAAE,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,+BAkCzD;AAED,8DAA8D;AAC9D,iBAAS,eAAe,CAAC,EACvB,SAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,iBAAiB,CAAC,KAAK,CAAC,KAAK,+BAiB/B;AAED,kCAAkC;AAClC,iBAAS,YAAY,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,iBAAiB,CAAC,IAAI,CAAC,KAAK,+BAQ1E;AAED,2EAA2E;AAC3E,iBAAS,YAAY,CAAC,EACpB,SAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,iBAAiB,CAAC,IAAI,CAAC,KAAK,+BAgB9B;AAED,uDAAuD;AACvD,iBAAS,aAAa,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,iBAAiB,CAAC,KAAK,CAAC,KAAK,+BAW5E;AAED,OAAO,EACL,QAAQ,EACR,eAAe,EACf,aAAa,EACb,aAAa,EACb,YAAY,EACZ,YAAY,GACb,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Combobox as ComboboxPrimitive } from "@base-ui/react/combobox";
|
|
3
|
+
import { CheckIcon, ChevronDownIcon, XIcon } from "lucide-react";
|
|
4
|
+
import { cn } from "#lib/utils";
|
|
5
|
+
/** shadcn-compatible combobox root built on Base UI. */
|
|
6
|
+
const Combobox = ComboboxPrimitive.Root;
|
|
7
|
+
/** The combobox's text input, with a toggle and an optional clear button. */
|
|
8
|
+
function ComboboxInput({ className, showClear = false, ...props }) {
|
|
9
|
+
return (_jsxs("div", { "data-slot": "combobox-input-group", className: "relative flex w-full items-center", children: [_jsx(ComboboxPrimitive.Input, { "data-slot": "combobox-input", className: cn("h-8 w-full min-w-0 rounded-lg border border-input bg-transparent py-1 pr-14 pl-2.5 text-base transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40", className), ...props }), _jsxs("div", { className: "absolute right-1 flex items-center gap-0.5 text-muted-foreground", children: [showClear ? (_jsx(ComboboxPrimitive.Clear, { "data-slot": "combobox-clear", "aria-label": "Clear", className: "flex size-6 items-center justify-center rounded-md hover:text-foreground", children: _jsx(XIcon, { className: "size-3.5" }) })) : null, _jsx(ComboboxPrimitive.Trigger, { "data-slot": "combobox-trigger", "aria-label": "Show options", className: "flex size-6 items-center justify-center rounded-md hover:text-foreground", children: _jsx(ChevronDownIcon, { className: "size-4" }) })] })] }));
|
|
10
|
+
}
|
|
11
|
+
/** Renders the combobox popup, positioned under its input. */
|
|
12
|
+
function ComboboxContent({ className, children, ...props }) {
|
|
13
|
+
return (_jsx(ComboboxPrimitive.Portal, { children: _jsx(ComboboxPrimitive.Positioner, { sideOffset: 4, className: "isolate z-50", children: _jsx(ComboboxPrimitive.Popup, { "data-slot": "combobox-content", className: cn("max-h-(--available-height) w-(--anchor-width) min-w-36 origin-(--transform-origin) overflow-y-auto rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", className), ...props, children: children }) }) }));
|
|
14
|
+
}
|
|
15
|
+
/** Lists the combobox's items. */
|
|
16
|
+
function ComboboxList({ className, ...props }) {
|
|
17
|
+
return (_jsx(ComboboxPrimitive.List, { "data-slot": "combobox-list", className: cn("outline-none", className), ...props }));
|
|
18
|
+
}
|
|
19
|
+
/** Renders a selectable item, with a check when it's the current value. */
|
|
20
|
+
function ComboboxItem({ className, children, ...props }) {
|
|
21
|
+
return (_jsxs(ComboboxPrimitive.Item, { "data-slot": "combobox-item", className: cn("relative flex w-full cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 data-highlighted:bg-accent data-highlighted:text-accent-foreground", className), ...props, children: [children, _jsx(ComboboxPrimitive.ItemIndicator, { className: "pointer-events-none absolute right-2 flex size-4 items-center justify-center", children: _jsx(CheckIcon, { className: "size-4" }) })] }));
|
|
22
|
+
}
|
|
23
|
+
/** Shown in place of the list when it has no items. */
|
|
24
|
+
function ComboboxEmpty({ className, ...props }) {
|
|
25
|
+
return (_jsx(ComboboxPrimitive.Empty, { "data-slot": "combobox-empty", className: cn("px-1.5 py-1 text-sm text-muted-foreground empty:hidden", className), ...props }));
|
|
26
|
+
}
|
|
27
|
+
export { Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList, };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../../src/fields/inputs.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AA6E7D,kCAAkC;AAClC,wBAAgB,SAAS,CAAC,KAAK,EAAE,0BAA0B,+BAE1D;AAED,oCAAoC;AACpC,wBAAgB,UAAU,CAAC,KAAK,EAAE,0BAA0B,+BAE3D;AAED,qCAAqC;AACrC,wBAAgB,WAAW,CAAC,KAAK,EAAE,0BAA0B,+BAE5D;AAED,kCAAkC;AAClC,wBAAgB,SAAS,CAAC,KAAK,EAAE,0BAA0B,+BAE1D;AAED,uCAAuC;AACvC,wBAAgB,aAAa,CAAC,KAAK,EAAE,0BAA0B,+BAE9D;AAmDD,gCAAgC;AAChC,wBAAgB,aAAa,CAAC,EAC5B,KAAK,EACL,EAAE,EACF,IAAI,EACJ,KAAK,E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,EACF,IAAI,EACJ,KAAK,EACL,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,cAAc,EACd,aAAa,GACd,EAAE,0BAA0B,+BAsB5B;AAED,mCAAmC;AACnC,wBAAgB,SAAS,CAAC,KAAK,EAAE,0BAA0B,+BAE1D;AAED,qCAAqC;AACrC,wBAAgB,UAAU,CAAC,KAAK,EAAE,0BAA0B,+BAE3D"}
|
package/dist/fields/inputs.js
CHANGED
|
@@ -102,7 +102,12 @@ export function SelectField({ field, id, name, value, error, disabled, readOnly,
|
|
|
102
102
|
const inputId = fieldId(field, id);
|
|
103
103
|
const options = field.options ?? [];
|
|
104
104
|
const valuesByKey = new Map(options.map((option) => [String(option.value), option.value]));
|
|
105
|
-
return (_jsx(FieldShell, { field: field, id: inputId, error: error, className: className, children: _jsxs(Select, { name: name ?? field.name, value: textValue(value),
|
|
105
|
+
return (_jsx(FieldShell, { field: field, id: inputId, error: error, className: className, children: _jsxs(Select, { name: name ?? field.name, value: textValue(value),
|
|
106
|
+
// Lets the closed trigger show the selected option's label, not its raw value.
|
|
107
|
+
items: options.map((option) => ({
|
|
108
|
+
value: String(option.value),
|
|
109
|
+
label: option.label,
|
|
110
|
+
})), disabled: commonDisabled(field, disabled), readOnly: commonReadOnly(field, readOnly), onValueChange: (nextValue) => {
|
|
106
111
|
if (nextValue === null) {
|
|
107
112
|
onValueChange?.(null);
|
|
108
113
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-schema-node.d.ts","sourceRoot":"","sources":["../../src/layout/render-schema-node.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"render-schema-node.d.ts","sourceRoot":"","sources":["../../src/layout/render-schema-node.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAiB,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAUpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAqW/E;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,SAAS,CAsBxE;AAED,8CAA8C;AAC9C,wBAAgB,gBAAgB,CAAC,EAC/B,KAAK,EACL,GAAG,IAAI,EACR,EAAE,qBAAqB,GAAG,YAAY,CAYtC"}
|
|
@@ -78,13 +78,13 @@ function renderRelationshipNode(node, props, path) {
|
|
|
78
78
|
return null;
|
|
79
79
|
}
|
|
80
80
|
const foreignKeyPath = [...path, foreignKeyName];
|
|
81
|
-
return (_jsx(BelongsToRelationshipField, { relationship: node, className: props.className, value: getValueAtPath(props.values, foreignKeyPath), error: props.errors?.[pathKey(foreignKeyPath)], disabled: props.disabled, readOnly: props.readOnly, onValueChange: (value) => props.onFieldChange?.(foreignKeyPath, value), onBlur: () => props.onFieldBlur?.(foreignKeyPath) }));
|
|
81
|
+
return (_jsx(BelongsToRelationshipField, { relationship: node, resourceName: props.resourceName, className: props.className, value: getValueAtPath(props.values, foreignKeyPath), error: props.errors?.[pathKey(foreignKeyPath)], disabled: props.disabled, readOnly: props.readOnly, onValueChange: (value) => props.onFieldChange?.(foreignKeyPath, value), onBlur: () => props.onFieldBlur?.(foreignKeyPath) }));
|
|
82
82
|
}
|
|
83
83
|
function renderSectionNode(node, props, path) {
|
|
84
84
|
return (_jsxs("section", { className: cn("grid gap-4", props.className), children: [_jsx("h3", { className: "text-sm font-medium text-foreground", children: node.title }), _jsx(RenderSchemaTree, { ...schemaRenderProps(props), nodes: node.children, path: path })] }));
|
|
85
85
|
}
|
|
86
86
|
function renderGridNode(node, props, path) {
|
|
87
|
-
return (_jsx("div", { className: cn("grid gap-4", props.className), style: {
|
|
87
|
+
return (_jsx("div", { className: cn("grid grid-cols-1 gap-4 sm:grid-cols-[repeat(var(--vk-grid-columns),minmax(0,1fr))]", props.className), style: { "--vk-grid-columns": node.columns }, children: _jsx(RenderSchemaTree, { ...schemaRenderProps(props), nodes: node.children, path: path }) }));
|
|
88
88
|
}
|
|
89
89
|
function renderTabsNode(node, props, path) {
|
|
90
90
|
const activeTab = clampIndex(props.activeTab ?? 0, node.tabs.length);
|
package/dist/layout/types.d.ts
CHANGED
|
@@ -16,6 +16,11 @@ export type SchemaActionRegistry = Partial<Record<string, SchemaActionSource>>;
|
|
|
16
16
|
export interface SchemaRenderProps {
|
|
17
17
|
/** Current form values. */
|
|
18
18
|
values: Record<string, unknown>;
|
|
19
|
+
/**
|
|
20
|
+
* Name of the resource this tree belongs to. `belongsTo` pickers load
|
|
21
|
+
* their options from that resource's `/relationships/:name` route.
|
|
22
|
+
*/
|
|
23
|
+
resourceName?: string;
|
|
19
24
|
/** Path prefix for nested schema nodes. */
|
|
20
25
|
path?: SchemaPath;
|
|
21
26
|
/** Error content keyed by schema path. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/layout/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC1B,YAAY,GACZ;IACE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,IAAI,YAAY,CAAC;CAC1B,CAAC;AAEN,iDAAiD;AACjD,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;AAE/E,8DAA8D;AAC9D,MAAM,WAAW,iBAAiB;IAChC,2BAA2B;IAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,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AkB,CAAC,EAAE,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,UAAU,KAAK,SAAS,CAAC;CAC9E;AAED,gDAAgD;AAChD,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,6BAA6B;IAC7B,IAAI,EAAE,UAAU,CAAC;IACjB,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,kDAAkD;AAClD,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,uCAAuC;IACvC,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;CAC9B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type RowData, type Table } from "@tanstack/react-table";
|
|
2
|
-
import type { ListActionAvailability, ListParams } from "@verikit/client";
|
|
2
|
+
import type { ListActionAvailability, ListParams, RelationshipLabels } from "@verikit/client";
|
|
3
3
|
import type { FieldSchema, Resource, ResourceSchema } from "@verikit/core";
|
|
4
4
|
declare const resourceTableFeatures: {
|
|
5
5
|
rowSortingFeature: import("@tanstack/react-table").TableFeature;
|
|
@@ -42,10 +42,15 @@ export interface UseResourceTableResult<TRecord extends RowData = Record<string,
|
|
|
42
42
|
setFilters: (filters: ResourceTableFilters) => void;
|
|
43
43
|
/** The actions the actor can't run on the current page, when requested with `includeActions`. */
|
|
44
44
|
actions: ListActionAvailability | undefined;
|
|
45
|
+
/** Display labels for the current page's `belongsTo` relationships, when the resource has any to show. */
|
|
46
|
+
relationships: RelationshipLabels | undefined;
|
|
45
47
|
}
|
|
46
48
|
/**
|
|
47
49
|
* Creates a TanStack Table from a resource's schema, with automatic columns
|
|
48
|
-
* and server-side pagination, sorting, and search.
|
|
50
|
+
* and server-side pagination, sorting, and search. A `belongsTo`
|
|
51
|
+
* relationship gets a column in place of its foreign-key field, showing the
|
|
52
|
+
* related record's `displayField` (fetched with the page, one query per
|
|
53
|
+
* relationship on the server), or the raw key when there's no label.
|
|
49
54
|
*/
|
|
50
55
|
export declare function useResourceTable<TRecord extends RowData = Record<string, unknown>>(resource: UseResourceTableSource, { pageSize, includeActions }?: UseResourceTableOptions): UseResourceTableResult<TRecord>;
|
|
51
56
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-resource-table.d.ts","sourceRoot":"","sources":["../../src/query/use-resource-table.ts"],"names":[],"mappings":"AACA,OAAO,EAYL,KAAK,OAAO,EAGZ,KAAK,KAAK,EACX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"use-resource-table.d.ts","sourceRoot":"","sources":["../../src/query/use-resource-table.ts"],"names":[],"mappings":"AACA,OAAO,EAYL,KAAK,OAAO,EAGZ,KAAK,KAAK,EACX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EACV,sBAAsB,EACtB,UAAU,EACV,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAY3E,QAAA,MAAM,qBAAqB;;;;;;CAMzB,CAAC;AAEH,KAAK,qBAAqB,GAAG,OAAO,qBAAqB,CAAC;AAE1D,+EAA+E;AAC/E,MAAM,MAAM,sBAAsB,GAAG,QAAQ,GAAG,cAAc,CAAC;AAE/D,8GAA8G;AAC9G,MAAM,MAAM,oBAAoB,GAAG,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;AAEtE,oDAAoD;AACpD,MAAM,WAAW,uBAAuB;IACtC,iFAAiF;IACjF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,8DAA8D;AAC9D,MAAM,WAAW,sBAAsB,CACrC,OAAO,SAAS,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAEjD,6EAA6E;IAC7E,KAAK,EAAE,KAAK,CAAC,qBAAqB,EAAE,OAAO,CAAC,CAAC;IAC7C,mEAAmE;IACnE,SAAS,EAAE,OAAO,CAAC;IACnB,sEAAsE;IACtE,UAAU,EAAE,OAAO,CAAC;IACpB,sDAAsD;IACtD,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACpC,2DAA2D;IAC3D,OAAO,EAAE,oBAAoB,CAAC;IAC9B,uDAAuD;IACvD,UAAU,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAC;IACpD,iGAAiG;IACjG,OAAO,EAAE,sBAAsB,GAAG,SAAS,CAAC;IAC5C,0GAA0G;IAC1G,aAAa,EAAE,kBAAkB,GAAG,SAAS,CAAC;CAC/C;AAED;;;;;;GAMG;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,CAsGjC"}
|
|
@@ -2,6 +2,7 @@ import { useMemo, useState } from "react";
|
|
|
2
2
|
import { columnFilteringFeature, functionalUpdate, globalFilteringFeature, rowPaginationFeature, rowSelectionFeature, rowSortingFeature, tableFeatures, useTable, } from "@tanstack/react-table";
|
|
3
3
|
import { recordId } from "@verikit/ui-core/query/optimistic";
|
|
4
4
|
import { resolveVerikitFields } from "@verikit/ui-core/form/resolve-fields";
|
|
5
|
+
import { needsRelationshipLabels, relationshipCellText, resourceColumnSpecs, } from "@verikit/ui-core/layout/table-columns";
|
|
5
6
|
import { useListResource } from "./use-resource-queries.js";
|
|
6
7
|
// `columnFilteringFeature` is required by TanStack's global filtering feature.
|
|
7
8
|
// VeriKit manages field filters separately to support range operators.
|
|
@@ -14,17 +15,15 @@ const resourceTableFeatures = tableFeatures({
|
|
|
14
15
|
});
|
|
15
16
|
/**
|
|
16
17
|
* Creates a TanStack Table from a resource's schema, with automatic columns
|
|
17
|
-
* and server-side pagination, sorting, and search.
|
|
18
|
+
* and server-side pagination, sorting, and search. A `belongsTo`
|
|
19
|
+
* relationship gets a column in place of its foreign-key field, showing the
|
|
20
|
+
* related record's `displayField` (fetched with the page, one query per
|
|
21
|
+
* relationship on the server), or the raw key when there's no label.
|
|
18
22
|
*/
|
|
19
23
|
export function useResourceTable(resource, { pageSize = 25, includeActions = false } = {}) {
|
|
20
24
|
const fields = resolveVerikitFields(resource);
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
.map((field) => ({
|
|
24
|
-
accessorKey: field.name,
|
|
25
|
-
header: field.label ?? field.name,
|
|
26
|
-
enableSorting: field.sortable ?? false,
|
|
27
|
-
})), [fields]);
|
|
25
|
+
const columnSpecs = useMemo(() => resourceColumnSpecs(resource), [resource]);
|
|
26
|
+
const includeRelationships = useMemo(() => needsRelationshipLabels(resource), [resource]);
|
|
28
27
|
const [sorting, setSorting] = useState([]);
|
|
29
28
|
const [pagination, setPagination] = useState({
|
|
30
29
|
pageIndex: 0,
|
|
@@ -54,7 +53,23 @@ export function useResourceTable(resource, { pageSize = 25, includeActions = fal
|
|
|
54
53
|
: undefined,
|
|
55
54
|
...(hasFilters ? { filters } : {}),
|
|
56
55
|
...(includeActions ? { includeActions } : {}),
|
|
56
|
+
...(includeRelationships ? { includeRelationships } : {}),
|
|
57
57
|
});
|
|
58
|
+
const relationships = list.data?.relationships;
|
|
59
|
+
const columns = useMemo(() => columnSpecs.map((spec) => spec.kind === "field"
|
|
60
|
+
? {
|
|
61
|
+
accessorKey: spec.field.name,
|
|
62
|
+
header: spec.field.label ?? spec.field.name,
|
|
63
|
+
enableSorting: spec.field.sortable ?? false,
|
|
64
|
+
}
|
|
65
|
+
: {
|
|
66
|
+
id: spec.name,
|
|
67
|
+
// Records are plain field maps at runtime (see `ResourceTable`).
|
|
68
|
+
accessorFn: (record) => relationshipCellText(relationships, spec, record),
|
|
69
|
+
header: spec.label,
|
|
70
|
+
// Sorting by a foreign key wouldn't follow the labels shown.
|
|
71
|
+
enableSorting: false,
|
|
72
|
+
}), [columnSpecs, relationships]);
|
|
58
73
|
const table = useTable({
|
|
59
74
|
features: resourceTableFeatures,
|
|
60
75
|
columns,
|
|
@@ -79,5 +94,6 @@ export function useResourceTable(resource, { pageSize = 25, includeActions = fal
|
|
|
79
94
|
filters,
|
|
80
95
|
setFilters: handleFiltersChange,
|
|
81
96
|
actions: list.data?.actions,
|
|
97
|
+
relationships,
|
|
82
98
|
};
|
|
83
99
|
}
|
|
@@ -1,29 +1,39 @@
|
|
|
1
1
|
import type { BelongsToRelationshipSchema } from "@verikit/core";
|
|
2
|
-
import type
|
|
2
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
3
3
|
/** Props for {@link BelongsToRelationshipField}. */
|
|
4
4
|
export interface BelongsToRelationshipFieldProps {
|
|
5
5
|
/** Finalized `belongsTo` relationship node being rendered. */
|
|
6
6
|
relationship: BelongsToRelationshipSchema;
|
|
7
|
+
/**
|
|
8
|
+
* Name of the resource that owns the relationship (the one being edited).
|
|
9
|
+
* Options come from its `/relationships/:name` route. Defaults to the
|
|
10
|
+
* target resource, which only matches for a self-referencing relationship.
|
|
11
|
+
*/
|
|
12
|
+
resourceName?: string;
|
|
7
13
|
/** Explicit input id. Defaults to a stable id derived from the relationship. */
|
|
8
14
|
id?: string;
|
|
9
15
|
/** Current foreign-key value (the selected record's id), if any. */
|
|
10
16
|
value?: unknown;
|
|
11
|
-
/** Error content shown below the
|
|
17
|
+
/** Error content shown below the picker and linked with ARIA. */
|
|
12
18
|
error?: ReactNode;
|
|
13
|
-
/** Disables the
|
|
19
|
+
/** Disables the picker. */
|
|
14
20
|
disabled?: boolean;
|
|
15
|
-
/** Marks the
|
|
21
|
+
/** Marks the picker as read-only. */
|
|
16
22
|
readOnly?: boolean;
|
|
17
23
|
/** Class name applied to the outer wrapper. */
|
|
18
24
|
className?: string;
|
|
19
25
|
/** Called with the next foreign-key value (or `null` when cleared). */
|
|
20
26
|
onValueChange?: (value: string | null) => void;
|
|
21
|
-
/** Called when the
|
|
27
|
+
/** Called when the picker's input loses focus. */
|
|
22
28
|
onBlur?: () => void;
|
|
23
29
|
}
|
|
24
30
|
/**
|
|
25
|
-
* Renders a `belongsTo` relationship as a permission-aware
|
|
26
|
-
* reading and writing the related record's ID through its `.via()`
|
|
31
|
+
* Renders a `belongsTo` relationship as a permission-aware, searchable
|
|
32
|
+
* combobox, reading and writing the related record's ID through its `.via()`
|
|
33
|
+
* field. Typing searches the server (the target's `displayField` and
|
|
34
|
+
* `.searchable()` fields), options load 25 at a time with "Load more", and the
|
|
35
|
+
* selected record's label is shown even when it isn't among the loaded
|
|
36
|
+
* options.
|
|
27
37
|
*/
|
|
28
|
-
export declare function BelongsToRelationshipField({ relationship, id, value, error, disabled, readOnly, className, onValueChange, onBlur, }: BelongsToRelationshipFieldProps): ReactElement;
|
|
38
|
+
export declare function BelongsToRelationshipField({ relationship, resourceName, id, value, error, disabled, readOnly, className, onValueChange, onBlur, }: BelongsToRelationshipFieldProps): ReactElement;
|
|
29
39
|
//# sourceMappingURL=belongs-to-field.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"belongs-to-field.d.ts","sourceRoot":"","sources":["../../src/relationships/belongs-to-field.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"belongs-to-field.d.ts","sourceRoot":"","sources":["../../src/relationships/belongs-to-field.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAY,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAapE,oDAAoD;AACpD,MAAM,WAAW,+BAA+B;IAC9C,8DAA8D;IAC9D,YAAY,EAAE,2BAA2B,CAAC;IAC1C;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gFAAgF;IAChF,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,oEAAoE;IACpE,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,iEAAiE;IACjE,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qCAAqC;IACrC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAC/C,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,YAAY,EACZ,YAAY,EACZ,EAAE,EACF,KAAK,EACL,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,aAAa,EACb,MAAM,GACP,EAAE,+BAA+B,GAAG,YAAY,CA6FhD"}
|
|
@@ -1,28 +1,44 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList, } from "#components/combobox";
|
|
2
4
|
import { Label } from "#components/label";
|
|
3
|
-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "#components/select";
|
|
4
5
|
import { cn } from "#lib/utils";
|
|
5
|
-
import {
|
|
6
|
-
// Matches the server's maximum list page size, so a picker is not silently
|
|
7
|
-
// limited to its ordinary table-page default (currently 25 records).
|
|
8
|
-
const RELATIONSHIP_PICKER_PAGE_SIZE = 100;
|
|
9
|
-
function recordId(record) {
|
|
10
|
-
return String(record.id);
|
|
11
|
-
}
|
|
12
|
-
function recordLabel(record, displayField) {
|
|
13
|
-
const raw = displayField ? record[displayField] : undefined;
|
|
14
|
-
return raw === null || raw === undefined ? recordId(record) : String(raw);
|
|
15
|
-
}
|
|
6
|
+
import { useRelationshipPicker } from "./use-relationship-picker.js";
|
|
16
7
|
/**
|
|
17
|
-
* Renders a `belongsTo` relationship as a permission-aware
|
|
18
|
-
* reading and writing the related record's ID through its `.via()`
|
|
8
|
+
* Renders a `belongsTo` relationship as a permission-aware, searchable
|
|
9
|
+
* combobox, reading and writing the related record's ID through its `.via()`
|
|
10
|
+
* field. Typing searches the server (the target's `displayField` and
|
|
11
|
+
* `.searchable()` fields), options load 25 at a time with "Load more", and the
|
|
12
|
+
* selected record's label is shown even when it isn't among the loaded
|
|
13
|
+
* options.
|
|
19
14
|
*/
|
|
20
|
-
export function BelongsToRelationshipField({ relationship, id, value, error, disabled, readOnly, className, onValueChange, onBlur, }) {
|
|
21
|
-
const
|
|
22
|
-
|
|
15
|
+
export function BelongsToRelationshipField({ relationship, resourceName, id, value, error, disabled, readOnly, className, onValueChange, onBlur, }) {
|
|
16
|
+
const inputId = id ??
|
|
17
|
+
`verikit-relationship-${relationship.resource}-${relationship.name ?? ""}`;
|
|
23
18
|
const errorId = error ? `${inputId}-error` : undefined;
|
|
24
|
-
const { data, isLoading, error: fetchError, } = useResourceRelationship(relationship.resource, relationshipName, { pageSize: RELATIONSHIP_PICKER_PAGE_SIZE }, { enabled: relationshipName.length > 0 });
|
|
25
|
-
const records = data?.records ?? [];
|
|
26
19
|
const currentValue = value === null || value === undefined ? "" : String(value);
|
|
27
|
-
|
|
20
|
+
// While the popup is open the input holds what's typed (the selected
|
|
21
|
+
// record's label stays visible as the placeholder); closed, it shows that
|
|
22
|
+
// label.
|
|
23
|
+
const [open, setOpen] = useState(false);
|
|
24
|
+
const [search, setSearch] = useState("");
|
|
25
|
+
const picker = useRelationshipPicker({
|
|
26
|
+
resourceName: resourceName ?? relationship.resource,
|
|
27
|
+
relationship,
|
|
28
|
+
value: currentValue,
|
|
29
|
+
search,
|
|
30
|
+
});
|
|
31
|
+
const selectedLabel = currentValue ? picker.labelFor(currentValue) : "";
|
|
32
|
+
const editable = disabled !== true && readOnly !== true;
|
|
33
|
+
return (_jsxs("div", { className: cn("grid gap-2", className), children: [relationship.label ? (_jsx(Label, { htmlFor: inputId, children: relationship.label })) : null, _jsxs(Combobox, { items: picker.ids,
|
|
34
|
+
// Options are already searched on the server.
|
|
35
|
+
filter: null, value: currentValue === "" ? null : currentValue, itemToStringLabel: picker.labelFor, inputValue: open ? search : selectedLabel, open: open, onOpenChange: (next) => {
|
|
36
|
+
setOpen(next);
|
|
37
|
+
if (!next)
|
|
38
|
+
setSearch("");
|
|
39
|
+
}, onInputValueChange: (text, details) => {
|
|
40
|
+
if (details.reason === "input-change") {
|
|
41
|
+
setSearch(text);
|
|
42
|
+
}
|
|
43
|
+
}, onValueChange: (next) => onValueChange?.(next), name: relationship.name, disabled: disabled === true, readOnly: readOnly === true, children: [_jsx(ComboboxInput, { id: inputId, placeholder: picker.isLoading ? "Loading…" : selectedLabel || "Search…", showClear: editable && currentValue !== "", onBlur: onBlur, "aria-describedby": errorId, "aria-invalid": error ? true : undefined }), _jsxs(ComboboxContent, { children: [_jsx(ComboboxEmpty, { children: picker.isLoading ? "Loading…" : "No matches." }), _jsx(ComboboxList, { children: (optionId) => (_jsx(ComboboxItem, { value: optionId, children: picker.labelFor(optionId) }, optionId)) }), picker.hasMore ? (_jsx("button", { type: "button", className: "w-full rounded-md px-1.5 py-1 text-left text-sm text-muted-foreground hover:bg-accent disabled:opacity-50", disabled: picker.isLoadingMore, onClick: picker.loadMore, children: picker.isLoadingMore ? "Loading…" : "Load more" })) : null] })] }), error ? (_jsx("p", { id: errorId, className: "text-sm text-destructive", children: error })) : null, picker.error ? (_jsx("p", { role: "alert", className: "text-sm text-destructive", children: picker.error.message })) : null] }));
|
|
28
44
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { BelongsToRelationshipSchema } from "@verikit/core";
|
|
2
|
+
/** Records fetched per page as the picker's list is scrolled through. */
|
|
3
|
+
export declare const RELATIONSHIP_PICKER_PAGE_SIZE = 25;
|
|
4
|
+
/** How long the picker waits after the last keystroke before searching. */
|
|
5
|
+
export declare const RELATIONSHIP_SEARCH_DEBOUNCE_MS = 250;
|
|
6
|
+
type PickerRecord = Record<string, unknown>;
|
|
7
|
+
/** A record's label: its `displayField` value, or its id when that's empty. */
|
|
8
|
+
export declare function relationshipRecordLabel(record: PickerRecord, displayField: string | undefined): string;
|
|
9
|
+
/** Options for {@link useRelationshipPicker}. */
|
|
10
|
+
export interface UseRelationshipPickerOptions {
|
|
11
|
+
/** Resource that owns the relationship; options come from its picker route. */
|
|
12
|
+
resourceName: string;
|
|
13
|
+
relationship: BelongsToRelationshipSchema;
|
|
14
|
+
/** The selected record's id, or `""` for none. */
|
|
15
|
+
value: string;
|
|
16
|
+
/** The text typed into the picker, searched after a short pause. */
|
|
17
|
+
search: string;
|
|
18
|
+
}
|
|
19
|
+
/** State returned by {@link useRelationshipPicker}. */
|
|
20
|
+
export interface UseRelationshipPickerResult {
|
|
21
|
+
/** Ids of the loaded options, in server order. */
|
|
22
|
+
ids: string[];
|
|
23
|
+
/** Label for an id: loaded, or looked up for the selected value. */
|
|
24
|
+
labelFor: (id: string) => string;
|
|
25
|
+
isLoading: boolean;
|
|
26
|
+
error: Error | null;
|
|
27
|
+
/** True when the server has more matching records than are loaded. */
|
|
28
|
+
hasMore: boolean;
|
|
29
|
+
isLoadingMore: boolean;
|
|
30
|
+
loadMore: () => void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Loads a `belongsTo` picker's options from the server: searched by what's
|
|
34
|
+
* typed (the server searches the target's `displayField` and `.searchable()`
|
|
35
|
+
* fields), a page at a time. When the selected record isn't among the loaded
|
|
36
|
+
* options, it is fetched by id so its label can still be shown.
|
|
37
|
+
*/
|
|
38
|
+
export declare function useRelationshipPicker({ resourceName, relationship, value, search, }: UseRelationshipPickerOptions): UseRelationshipPickerResult;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=use-relationship-picker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-relationship-picker.d.ts","sourceRoot":"","sources":["../../src/relationships/use-relationship-picker.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAKjE,yEAAyE;AACzE,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAEhD,2EAA2E;AAC3E,eAAO,MAAM,+BAA+B,MAAM,CAAC;AAEnD,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAiB5C,+EAA+E;AAC/E,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,YAAY,EACpB,YAAY,EAAE,MAAM,GAAG,SAAS,GAC/B,MAAM,CAIR;AAED,iDAAiD;AACjD,MAAM,WAAW,4BAA4B;IAC3C,+EAA+E;IAC/E,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,2BAA2B,CAAC;IAC1C,kDAAkD;IAClD,KAAK,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,uDAAuD;AACvD,MAAM,WAAW,2BAA2B;IAC1C,kDAAkD;IAClD,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,oEAAoE;IACpE,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,CAAC;IACjC,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,sEAAsE;IACtE,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,YAAY,EACZ,YAAY,EACZ,KAAK,EACL,MAAM,GACP,EAAE,4BAA4B,GAAG,2BAA2B,CAqE5D"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from "react";
|
|
2
|
+
import { useInfiniteQuery } from "@tanstack/react-query";
|
|
3
|
+
import { resourceQueryKeys } from "@verikit/ui-core/query/query-keys";
|
|
4
|
+
import { useVerikitClient } from "../client/use-verikit-client.js";
|
|
5
|
+
import { useResourceRelationship } from "../query/use-resource-queries.js";
|
|
6
|
+
/** Records fetched per page as the picker's list is scrolled through. */
|
|
7
|
+
export const RELATIONSHIP_PICKER_PAGE_SIZE = 25;
|
|
8
|
+
/** How long the picker waits after the last keystroke before searching. */
|
|
9
|
+
export const RELATIONSHIP_SEARCH_DEBOUNCE_MS = 250;
|
|
10
|
+
function useDebouncedValue(value, delay) {
|
|
11
|
+
const [debounced, setDebounced] = useState(value);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const timer = setTimeout(() => setDebounced(value), delay);
|
|
14
|
+
return () => clearTimeout(timer);
|
|
15
|
+
}, [value, delay]);
|
|
16
|
+
return debounced;
|
|
17
|
+
}
|
|
18
|
+
function recordId(record) {
|
|
19
|
+
return String(record.id);
|
|
20
|
+
}
|
|
21
|
+
/** A record's label: its `displayField` value, or its id when that's empty. */
|
|
22
|
+
export function relationshipRecordLabel(record, displayField) {
|
|
23
|
+
const raw = displayField ? record[displayField] : undefined;
|
|
24
|
+
return raw === null || raw === undefined ? recordId(record) : String(raw);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Loads a `belongsTo` picker's options from the server: searched by what's
|
|
28
|
+
* typed (the server searches the target's `displayField` and `.searchable()`
|
|
29
|
+
* fields), a page at a time. When the selected record isn't among the loaded
|
|
30
|
+
* options, it is fetched by id so its label can still be shown.
|
|
31
|
+
*/
|
|
32
|
+
export function useRelationshipPicker({ resourceName, relationship, value, search, }) {
|
|
33
|
+
const client = useVerikitClient();
|
|
34
|
+
const relationshipName = relationship.name ?? "";
|
|
35
|
+
const enabled = relationshipName.length > 0;
|
|
36
|
+
const term = useDebouncedValue(search.trim(), RELATIONSHIP_SEARCH_DEBOUNCE_MS);
|
|
37
|
+
const params = {
|
|
38
|
+
pageSize: RELATIONSHIP_PICKER_PAGE_SIZE,
|
|
39
|
+
...(term && { search: term }),
|
|
40
|
+
};
|
|
41
|
+
const pages = useInfiniteQuery({
|
|
42
|
+
queryKey: resourceQueryKeys(resourceName, client).relationshipPages(relationshipName, params),
|
|
43
|
+
queryFn: ({ pageParam, signal }) => client
|
|
44
|
+
.resource(resourceName)
|
|
45
|
+
.relationship(relationshipName, { ...params, page: pageParam }, { signal }),
|
|
46
|
+
initialPageParam: 1,
|
|
47
|
+
getNextPageParam: (last, all) => all.reduce((count, page) => count + page.records.length, 0) <
|
|
48
|
+
last.total && last.records.length > 0
|
|
49
|
+
? last.page + 1
|
|
50
|
+
: undefined,
|
|
51
|
+
enabled,
|
|
52
|
+
});
|
|
53
|
+
const records = useMemo(() => pages.data?.pages.flatMap((page) => page.records) ?? [], [pages.data]);
|
|
54
|
+
const loaded = records.some((record) => recordId(record) === value);
|
|
55
|
+
const selected = useResourceRelationship(resourceName, relationshipName, { ids: [value], pageSize: 1 }, { enabled: enabled && value !== "" && !loaded && pages.isSuccess });
|
|
56
|
+
const labels = useMemo(() => {
|
|
57
|
+
const map = new Map();
|
|
58
|
+
for (const record of [...(selected.data?.records ?? []), ...records]) {
|
|
59
|
+
map.set(recordId(record), relationshipRecordLabel(record, relationship.displayField));
|
|
60
|
+
}
|
|
61
|
+
return map;
|
|
62
|
+
}, [records, selected.data, relationship.displayField]);
|
|
63
|
+
return {
|
|
64
|
+
ids: [...new Set(records.map(recordId))],
|
|
65
|
+
labelFor: (id) => labels.get(id) ?? id,
|
|
66
|
+
isLoading: pages.isLoading,
|
|
67
|
+
error: pages.error,
|
|
68
|
+
hasMore: pages.hasNextPage,
|
|
69
|
+
isLoadingMore: pages.isFetchingNextPage,
|
|
70
|
+
loadMore: () => void pages.fetchNextPage(),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -14,6 +14,10 @@ export interface ResourceDetailProps<TRecord extends Record<string, unknown> = R
|
|
|
14
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
15
|
*/
|
|
16
16
|
editAction?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Replaces the built-in edit dialog: the Edit action calls this with the record instead (for example, to navigate to an edit page). It's still hidden when the actor can't update the record. Only used with `editAction`.
|
|
19
|
+
*/
|
|
20
|
+
onEdit?: (record: TRecord) => void;
|
|
17
21
|
/**
|
|
18
22
|
* 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
23
|
*/
|
|
@@ -32,7 +36,7 @@ export interface ResourceDetailProps<TRecord extends Record<string, unknown> = R
|
|
|
32
36
|
className?: string;
|
|
33
37
|
}
|
|
34
38
|
/**
|
|
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.
|
|
39
|
+
* 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 `belongsTo` relationship is shown in place of its foreign-key field, as the related record's `displayField` (or the raw key when the actor can't read that). A record the actor can't read shows as not found, as the server doesn't reveal whether it exists.
|
|
36
40
|
*/
|
|
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;
|
|
41
|
+
export declare function ResourceDetail<TRecord extends Record<string, unknown> = Record<string, unknown>>({ resource, id, actions, editAction, onEdit, deleteAction, resourceActions, renderActions, onDeleted, className, }: ResourceDetailProps<TRecord>): ReactElement;
|
|
38
42
|
//# 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;AAqBhF,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,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC;;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,MAAM,EACN,YAAsB,EACtB,eAAyB,EACzB,aAAa,EACb,SAAS,EACT,SAAS,GACV,EAAE,mBAAmB,CAAC,OAAO,CAAC,GAAG,YAAY,CA0Q7C"}
|
|
@@ -5,22 +5,22 @@ import { Button } from "#components/button";
|
|
|
5
5
|
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "#components/dialog";
|
|
6
6
|
import { cn } from "#lib/utils";
|
|
7
7
|
import { actionNeedsDialog, resourceActionSchemas, } from "@verikit/ui-core/actions/resource-actions";
|
|
8
|
-
import { resolveVerikitFields } from "@verikit/ui-core/form/resolve-fields";
|
|
9
8
|
import { formatFieldValue } from "@verikit/ui-core/layout/format-value";
|
|
9
|
+
import { relationshipCellText, resourceColumnSpecs, } from "@verikit/ui-core/layout/table-columns";
|
|
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
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. 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.
|
|
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 `belongsTo` relationship is shown in place of its foreign-key field, as the related record's `displayField` (or the raw key when the actor can't read that). 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, editAction = actions, deleteAction = actions, resourceActions = actions, renderActions, onDeleted, className, }) {
|
|
18
|
+
export function ResourceDetail({ resource, id, actions = false, editAction = actions, onEdit, 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,
|
|
22
22
|
});
|
|
23
|
-
const
|
|
23
|
+
const rows = resourceColumnSpecs(resource, { view: "detail" });
|
|
24
24
|
const recordActions = resourceActions
|
|
25
25
|
? resourceActionSchemas(resource, "record")
|
|
26
26
|
: [];
|
|
@@ -79,18 +79,37 @@ export function ResourceDetail({ resource, id, actions = false, editAction = act
|
|
|
79
79
|
if (query.isError) {
|
|
80
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 }));
|
|
81
81
|
}
|
|
82
|
-
const { record, actions: unavailable, operations } = query.data;
|
|
82
|
+
const { record, actions: unavailable, operations, relationships, } = query.data;
|
|
83
83
|
const showEdit = editAction && !denied.update && !operations.update;
|
|
84
84
|
const showDelete = deleteAction && !denied.delete && !operations.delete;
|
|
85
|
-
|
|
85
|
+
// The server leaves out fields the actor can't read.
|
|
86
|
+
const visibleRows = rows.flatMap((row) => row.kind === "field"
|
|
87
|
+
? Object.hasOwn(record, row.field.name)
|
|
88
|
+
? [
|
|
89
|
+
{
|
|
90
|
+
key: row.field.name,
|
|
91
|
+
label: row.field.label ?? row.field.name,
|
|
92
|
+
value: formatFieldValue(record[row.field.name]),
|
|
93
|
+
},
|
|
94
|
+
]
|
|
95
|
+
: []
|
|
96
|
+
: Object.hasOwn(record, row.foreignKey)
|
|
97
|
+
? [
|
|
98
|
+
{
|
|
99
|
+
key: row.name,
|
|
100
|
+
label: row.label,
|
|
101
|
+
value: relationshipCellText(relationships, row, record),
|
|
102
|
+
},
|
|
103
|
+
]
|
|
104
|
+
: []);
|
|
86
105
|
const hasActions = showEdit ||
|
|
87
106
|
showDelete ||
|
|
88
107
|
recordActions.length > 0 ||
|
|
89
108
|
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: () => {
|
|
109
|
+
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: () => (onEdit ? onEdit(record) : setEditOpen(true)), children: [_jsx(PencilIcon, {}), "Edit"] })) : null, showDelete ? (_jsxs(Button, { type: "button", variant: "outline", size: "sm", onClick: () => {
|
|
91
110
|
deleteMutation.reset();
|
|
92
111
|
setDeleteOpen(true);
|
|
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:
|
|
112
|
+
}, 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: visibleRows.map((row) => (_jsxs("div", { className: "contents", children: [_jsx("dt", { className: "text-sm font-medium text-muted-foreground", children: row.label }), _jsx("dd", { className: "text-sm wrap-break-word", children: row.value })] }, row.key))) }), recordActions.length > 0 ? (_jsx(ResourceActionDialog, { resourceName: resource.name, action: activeAction, recordId: id, onClose: () => setActiveAction(null), onDenied: denyAction })) : null, editAction && !onEdit ? (_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
113
|
if (isActionDenied(mutationError, id)) {
|
|
95
114
|
setDenied((current) => ({ ...current, update: true }));
|
|
96
115
|
setEditOpen(false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-form.d.ts","sourceRoot":"","sources":["../../src/resource/resource-form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAa,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGhE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAEL,KAAK,gCAAgC,EACtC,MAAM,2CAA2C,CAAC;AACnD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAEvF,sCAAsC;AACtC,MAAM,WAAW,iBAAiB,CAChC,OAAO,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAChD,SAAQ,gCAAgC,CAAC,OAAO,CAAC;IACjD,8EAA8E;IAC9E,QAAQ,EAAE,uBAAuB,CAAC;IAClC,uDAAuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACzC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,UAAU,KAAK,SAAS,CAAC;IAC7E,yEAAyE;IACzE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAC7E,QAAQ,EACR,EAAE,EACF,OAAO,EACP,aAAa,EACb,SAAS,EACT,OAAO,EACP,QAAQ,EACR,kBAAkB,EAClB,WAAoB,EACpB,SAAS,GACV,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"resource-form.d.ts","sourceRoot":"","sources":["../../src/resource/resource-form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAa,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGhE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAEL,KAAK,gCAAgC,EACtC,MAAM,2CAA2C,CAAC;AACnD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAEvF,sCAAsC;AACtC,MAAM,WAAW,iBAAiB,CAChC,OAAO,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAChD,SAAQ,gCAAgC,CAAC,OAAO,CAAC;IACjD,8EAA8E;IAC9E,QAAQ,EAAE,uBAAuB,CAAC;IAClC,uDAAuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACzC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,UAAU,KAAK,SAAS,CAAC;IAC7E,yEAAyE;IACzE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAC7E,QAAQ,EACR,EAAE,EACF,OAAO,EACP,aAAa,EACb,SAAS,EACT,OAAO,EACP,QAAQ,EACR,kBAAkB,EAClB,WAAoB,EACpB,SAAS,GACV,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAAG,YAAY,CAyC3C"}
|
|
@@ -21,5 +21,5 @@ export function ResourceForm({ resource, id, actions, defaultValues, onSuccess,
|
|
|
21
21
|
// `submitError` already handles mutation failures; suppress the rejection here.
|
|
22
22
|
result.submit().catch(() => { });
|
|
23
23
|
};
|
|
24
|
-
return (_jsxs("form", { className: cn("grid gap-4", className), onSubmit: handleSubmit, noValidate: true, children: [_jsx(RenderSchemaTree, { nodes: result.tree, registry: registry, renderRelationship: renderRelationship, ...result.treeProps }), result.submitError ? (_jsx("p", { role: "alert", className: "text-sm text-destructive", children: result.submitError.message })) : null, _jsx("div", { className: "flex justify-end", children: _jsx(Button, { type: "submit", disabled: result.isSubmitting, children: result.isSubmitting ? "Saving…" : submitLabel }) })] }));
|
|
24
|
+
return (_jsxs("form", { className: cn("grid gap-4", className), onSubmit: handleSubmit, noValidate: true, children: [_jsx(RenderSchemaTree, { nodes: result.tree, resourceName: resource.name, registry: registry, renderRelationship: renderRelationship, ...result.treeProps }), result.submitError ? (_jsx("p", { role: "alert", className: "text-sm text-destructive", children: result.submitError.message })) : null, _jsx("div", { className: "flex justify-end", children: _jsx(Button, { type: "submit", disabled: result.isSubmitting, children: result.isSubmitting ? "Saving…" : submitLabel }) })] }));
|
|
25
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-table-filters.d.ts","sourceRoot":"","sources":["../../src/resource/resource-table-filters.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAWjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAI3E,yDAAyD;AACzD,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAClC,WAAW,EAAE,CAEf;
|
|
1
|
+
{"version":3,"file":"resource-table-filters.d.ts","sourceRoot":"","sources":["../../src/resource/resource-table-filters.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAWjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAI3E,yDAAyD;AACzD,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAClC,WAAW,EAAE,CAEf;AAWD,yFAAyF;AACzF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAKrE;AAED,6EAA6E;AAC7E,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAM7D;AAiPD,kDAAkD;AAClD,MAAM,WAAW,6BAA6B;IAC5C,oGAAoG;IACpG,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACpC,0CAA0C;IAC1C,OAAO,EAAE,oBAAoB,CAAC;IAC9B,8EAA8E;IAC9E,eAAe,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAC;CAC1D;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,EACvC,MAAM,EACN,OAAO,EACP,eAAe,GAChB,EAAE,6BAA6B,GAAG,YAAY,GAAG,IAAI,CA8CrD"}
|
|
@@ -8,6 +8,12 @@ export function filterableFields(fields) {
|
|
|
8
8
|
return Object.values(fields).filter((field) => field.filterable);
|
|
9
9
|
}
|
|
10
10
|
const ALL_VALUE = "__all__";
|
|
11
|
+
/** Labels for the boolean filter's options, so the closed trigger shows "Yes" rather than "true". */
|
|
12
|
+
const BOOLEAN_FILTER_ITEMS = [
|
|
13
|
+
{ value: ALL_VALUE, label: "All" },
|
|
14
|
+
{ value: "true", label: "Yes" },
|
|
15
|
+
{ value: "false", label: "No" },
|
|
16
|
+
];
|
|
11
17
|
/** Converts a browser `datetime-local` value into the UTC ISO format adapters expect. */
|
|
12
18
|
export function dateTimeFilterValue(value) {
|
|
13
19
|
if (value === "")
|
|
@@ -33,7 +39,7 @@ function isOrderedRange(min, max) {
|
|
|
33
39
|
/** A boolean field's tri-state filter: unset, true, or false. */
|
|
34
40
|
function BooleanFilterControl({ field, value, onChange, }) {
|
|
35
41
|
const current = value?.eq === true ? "true" : value?.eq === false ? "false" : ALL_VALUE;
|
|
36
|
-
return (_jsxs(Select, { value: current, onValueChange: (next) => {
|
|
42
|
+
return (_jsxs(Select, { value: current, items: BOOLEAN_FILTER_ITEMS, onValueChange: (next) => {
|
|
37
43
|
if (next === "true") {
|
|
38
44
|
onChange({ eq: true });
|
|
39
45
|
}
|
|
@@ -50,7 +56,13 @@ function SelectFilterControl({ field, value, onChange, }) {
|
|
|
50
56
|
const options = field.options ?? [];
|
|
51
57
|
const valuesByKey = new Map(options.map((option) => [String(option.value), option.value]));
|
|
52
58
|
const current = value?.eq === undefined ? ALL_VALUE : String(value.eq);
|
|
53
|
-
return (_jsxs(Select, { value: current,
|
|
59
|
+
return (_jsxs(Select, { value: current, items: [
|
|
60
|
+
{ value: ALL_VALUE, label: "All" },
|
|
61
|
+
...options.map((option) => ({
|
|
62
|
+
value: String(option.value),
|
|
63
|
+
label: option.label,
|
|
64
|
+
})),
|
|
65
|
+
], onValueChange: (next) => {
|
|
54
66
|
if (next === null || next === ALL_VALUE) {
|
|
55
67
|
onChange(undefined);
|
|
56
68
|
return;
|
|
@@ -18,6 +18,23 @@ export interface ResourceTableProps<TRecord extends RowData = Record<string, unk
|
|
|
18
18
|
* component's lifetime rather than shown as a dead end.
|
|
19
19
|
*/
|
|
20
20
|
actions?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Replaces the built-in create dialog: the New button calls this instead
|
|
23
|
+
* (for example, to navigate to a create page). Only used with `actions`.
|
|
24
|
+
*/
|
|
25
|
+
onCreate?: () => void;
|
|
26
|
+
/**
|
|
27
|
+
* Replaces the built-in edit dialog: each row's Edit button calls this with
|
|
28
|
+
* its record instead (for example, to navigate to an edit page). Only used
|
|
29
|
+
* with `actions`.
|
|
30
|
+
*/
|
|
31
|
+
onEdit?: (record: TRecord) => void;
|
|
32
|
+
/**
|
|
33
|
+
* Opens a record (for example, to navigate to its page): adds a View
|
|
34
|
+
* button to each row, and clicking a row anywhere other than its controls
|
|
35
|
+
* calls this too. Independent of `actions`.
|
|
36
|
+
*/
|
|
37
|
+
onView?: (record: TRecord) => void;
|
|
21
38
|
/**
|
|
22
39
|
* 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`.
|
|
23
40
|
*/
|
|
@@ -45,5 +62,5 @@ export interface ResourceTableProps<TRecord extends RowData = Record<string, unk
|
|
|
45
62
|
* A responsive resource table with search, sorting, pagination, and a
|
|
46
63
|
* mobile card layout. Standard CRUD actions and custom row actions are opt-in.
|
|
47
64
|
*/
|
|
48
|
-
export declare function ResourceTable<TRecord extends RowData = Record<string, unknown>>({ resource, pageSize, actions, resourceActions, renderActions, renderBulkActions, emptyState, className, }: ResourceTableProps<TRecord>): ReactElement;
|
|
65
|
+
export declare function ResourceTable<TRecord extends RowData = Record<string, unknown>>({ resource, pageSize, actions, onCreate, onEdit, onView, resourceActions, renderActions, renderBulkActions, emptyState, className, }: ResourceTableProps<TRecord>): ReactElement;
|
|
49
66
|
//# sourceMappingURL=resource-table.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-table.d.ts","sourceRoot":"","sources":["../../src/resource/resource-table.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"resource-table.d.ts","sourceRoot":"","sources":["../../src/resource/resource-table.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;A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AAG,YAAY,CAisB5C"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
import { ArrowDownIcon, ArrowUpIcon, ChevronLeftIcon, ChevronRightIcon, ChevronsUpDownIcon, PencilIcon, PlusIcon, SlidersHorizontalIcon, Trash2Icon, } from "lucide-react";
|
|
2
|
+
import { useState, } from "react";
|
|
3
|
+
import { ArrowDownIcon, ArrowUpIcon, ChevronLeftIcon, ChevronRightIcon, ChevronsUpDownIcon, EyeIcon, PencilIcon, PlusIcon, SlidersHorizontalIcon, Trash2Icon, } from "lucide-react";
|
|
4
4
|
import { Button } from "#components/button";
|
|
5
5
|
import { Checkbox } from "#components/checkbox";
|
|
6
6
|
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "#components/dialog";
|
|
@@ -34,7 +34,7 @@ function SortIcon({ direction }) {
|
|
|
34
34
|
* A responsive resource table with search, sorting, pagination, and a
|
|
35
35
|
* mobile card layout. Standard CRUD actions and custom row actions are opt-in.
|
|
36
36
|
*/
|
|
37
|
-
export function ResourceTable({ resource, pageSize, actions = false, resourceActions = actions, renderActions, renderBulkActions, emptyState, className, }) {
|
|
37
|
+
export function ResourceTable({ resource, pageSize, actions = false, onCreate, onEdit, onView, resourceActions = actions, renderActions, renderBulkActions, emptyState, className, }) {
|
|
38
38
|
const recordActions = resourceActions
|
|
39
39
|
? resourceActionSchemas(resource, "record")
|
|
40
40
|
: [];
|
|
@@ -155,7 +155,7 @@ export function ResourceTable({ resource, pageSize, actions = false, resourceAct
|
|
|
155
155
|
// `recordId` itself already documents at its other call sites.
|
|
156
156
|
const id = recordId(record);
|
|
157
157
|
const denied = deniedRows[id];
|
|
158
|
-
return (_jsxs(_Fragment, { children: [denied?.update ? null : (_jsx(Button, { type: "button", variant: "ghost", size: "icon-sm", "aria-label": "Edit", onClick: () => setEditRecord(record), children: _jsx(PencilIcon, {}) })), denied?.delete ? null : (_jsx(Button, { type: "button", variant: "ghost", size: "icon-sm", "aria-label": "Delete", onClick: () => openDeleteDialog(record), children: _jsx(Trash2Icon, {}) }))] }));
|
|
158
|
+
return (_jsxs(_Fragment, { children: [denied?.update ? null : (_jsx(Button, { type: "button", variant: "ghost", size: "icon-sm", "aria-label": "Edit", onClick: () => (onEdit ? onEdit(record) : setEditRecord(record)), children: _jsx(PencilIcon, {}) })), denied?.delete ? null : (_jsx(Button, { type: "button", variant: "ghost", size: "icon-sm", "aria-label": "Delete", onClick: () => openDeleteDialog(record), children: _jsx(Trash2Icon, {}) }))] }));
|
|
159
159
|
}
|
|
160
160
|
function declaredRowActions(record) {
|
|
161
161
|
// Same contract-guaranteed id as `builtInRowActions`.
|
|
@@ -166,11 +166,27 @@ export function ResourceTable({ resource, pageSize, actions = false, resourceAct
|
|
|
166
166
|
// Only called from a `hasActionsColumn ? ... : null` branch below, so
|
|
167
167
|
// `actions`/`renderActions`/record actions being all unset here can't happen.
|
|
168
168
|
function rowActions(record) {
|
|
169
|
-
return (_jsxs("div", { className: "flex items-center justify-end gap-1", children: [declaredRowActions(record), actions ? builtInRowActions(record) : null, renderActions ? renderActions(record) : null] }));
|
|
169
|
+
return (_jsxs("div", { className: "flex items-center justify-end gap-1", children: [onView ? (_jsx(Button, { type: "button", variant: "ghost", size: "icon-sm", "aria-label": "View", onClick: () => onView(record), children: _jsx(EyeIcon, {}) })) : null, declaredRowActions(record), actions ? builtInRowActions(record) : null, renderActions ? renderActions(record) : null] }));
|
|
170
170
|
}
|
|
171
171
|
const editId = editRecord ? recordId(editRecord) : undefined;
|
|
172
172
|
const deleteId = deleteRecord ? recordId(deleteRecord) : undefined;
|
|
173
|
-
const hasActionsColumn = actions ||
|
|
173
|
+
const hasActionsColumn = actions ||
|
|
174
|
+
Boolean(renderActions) ||
|
|
175
|
+
Boolean(onView) ||
|
|
176
|
+
recordActions.length > 0;
|
|
177
|
+
// A row click opens the record, unless it landed on one of the row's own
|
|
178
|
+
// controls (its checkbox, action buttons, or links).
|
|
179
|
+
function rowClickHandler(record) {
|
|
180
|
+
return onView
|
|
181
|
+
? (event) => {
|
|
182
|
+
const target = event.target;
|
|
183
|
+
if (!target.closest("button, a, input, label, [role='checkbox'], [role='dialog']")) {
|
|
184
|
+
onView(record);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
: undefined;
|
|
188
|
+
}
|
|
189
|
+
const clickableRowClass = onView ? "cursor-pointer hover:bg-muted/50" : "";
|
|
174
190
|
const hasSelectionColumn = actions || Boolean(renderBulkActions);
|
|
175
191
|
const hasFilterableFields = filterableFields(fields).length > 0;
|
|
176
192
|
const activeFilterCount = Object.keys(filters).length;
|
|
@@ -186,10 +202,10 @@ export function ResourceTable({ resource, pageSize, actions = false, resourceAct
|
|
|
186
202
|
return (_jsxs("div", { className: cn("w-full", className), children: [_jsxs("div", { className: "flex items-center justify-between gap-2 pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Input, { type: "search", placeholder: "Search...",
|
|
187
203
|
// `useResourceTable` seeds this state via `useState("")`, so
|
|
188
204
|
// it's always a string, never nullish.
|
|
189
|
-
value: table.store.state.globalFilter, onChange: (event) => table.setGlobalFilter(event.currentTarget.value), className: "max-w-xs" }), hasFilterableFields ? (_jsxs(Button, { type: "button", variant: activeFilterCount > 0 ? "secondary" : "outline", size: "sm", onClick: () => setFiltersOpen((open) => !open), "aria-expanded": filtersOpen, children: [_jsx(SlidersHorizontalIcon, {}), "Filters", activeFilterCount > 0 ? ` (${activeFilterCount})` : ""] })) : null, activeFilterCount > 0 ? (_jsx(Button, { type: "button", variant: "ghost", size: "sm", onClick: () => setFilters({}), children: "Clear filters" })) : null] }), _jsxs("div", { className: "flex items-center gap-2", children: [collectionActions.map((action) => deniedCollectionActions[action.name] ? null : (_jsx(DeclaredActionButton, { action: action, unavailable: unavailableAction(actionAvailability, action.name), variant: action.variant === "danger" ? "destructive" : "outline", disabled: directAction.isPending, onClick: () => startAction(action) }, action.name))), actions && !createDenied ? (_jsxs(Button, { type: "button", size: "sm", onClick: () => setCreateOpen(true), children: [_jsx(PlusIcon, {}), "New"] })) : null] })] }), actionError ? (_jsx("p", { role: "alert", className: "pb-3 text-sm text-destructive", children: actionError })) : null, filtersOpen && hasFilterableFields ? (_jsx("div", { className: "pb-3", children: _jsx(ResourceTableFilterPanel, { fields: fields, filters: filters, onFiltersChange: setFilters }) })) : null, selectedCount > 0 ? (_jsxs("div", { className: "mb-3 flex items-center justify-between gap-2 rounded-lg border border-border bg-muted/50 px-3 py-2", children: [_jsxs("span", { className: "text-sm text-muted-foreground", children: [selectedCount, " selected"] }), _jsxs("div", { className: "flex items-center gap-2", children: [renderBulkActions
|
|
205
|
+
value: table.store.state.globalFilter, onChange: (event) => table.setGlobalFilter(event.currentTarget.value), className: "max-w-xs" }), hasFilterableFields ? (_jsxs(Button, { type: "button", variant: activeFilterCount > 0 ? "secondary" : "outline", size: "sm", onClick: () => setFiltersOpen((open) => !open), "aria-expanded": filtersOpen, children: [_jsx(SlidersHorizontalIcon, {}), "Filters", activeFilterCount > 0 ? ` (${activeFilterCount})` : ""] })) : null, activeFilterCount > 0 ? (_jsx(Button, { type: "button", variant: "ghost", size: "sm", onClick: () => setFilters({}), children: "Clear filters" })) : null] }), _jsxs("div", { className: "flex items-center gap-2", children: [collectionActions.map((action) => deniedCollectionActions[action.name] ? null : (_jsx(DeclaredActionButton, { action: action, unavailable: unavailableAction(actionAvailability, action.name), variant: action.variant === "danger" ? "destructive" : "outline", disabled: directAction.isPending, onClick: () => startAction(action) }, action.name))), actions && !createDenied ? (_jsxs(Button, { type: "button", size: "sm", onClick: () => (onCreate ? onCreate() : setCreateOpen(true)), children: [_jsx(PlusIcon, {}), "New"] })) : null] })] }), actionError ? (_jsx("p", { role: "alert", className: "pb-3 text-sm text-destructive", children: actionError })) : null, filtersOpen && hasFilterableFields ? (_jsx("div", { className: "pb-3", children: _jsx(ResourceTableFilterPanel, { fields: fields, filters: filters, onFiltersChange: setFilters }) })) : null, selectedCount > 0 ? (_jsxs("div", { className: "mb-3 flex items-center justify-between gap-2 rounded-lg border border-border bg-muted/50 px-3 py-2", children: [_jsxs("span", { className: "text-sm text-muted-foreground", children: [selectedCount, " selected"] }), _jsxs("div", { className: "flex items-center gap-2", children: [renderBulkActions
|
|
190
206
|
? renderBulkActions(selectedRecords, clearSelection)
|
|
191
207
|
: null, actions ? (_jsxs(Button, { type: "button", variant: "destructive", size: "sm", onClick: openBulkDeleteDialog, children: [_jsx(Trash2Icon, {}), "Delete selected"] })) : null, _jsx(Button, { type: "button", variant: "outline", size: "sm", onClick: clearSelection, children: "Clear" })] })] })) : null, error ? (_jsx("p", { role: "alert", className: "pb-3 text-sm text-destructive", children: error.message })) : null, _jsx("div", { className: "hidden overflow-x-auto rounded-lg border border-border md:block", children: _jsxs("table", { className: "w-full text-left text-sm", children: [_jsx("thead", { className: "bg-muted/50 text-muted-foreground", children: _jsxs("tr", { children: [hasSelectionColumn ? (_jsx("th", { className: "w-8 px-3 py-2", children: _jsx(Checkbox, { "aria-label": "Select all rows", checked: rows.length > 0 && table.getIsAllPageRowsSelected(), indeterminate: !table.getIsAllPageRowsSelected() &&
|
|
192
|
-
table.getIsSomePageRowsSelected(), onCheckedChange: (checked) => table.toggleAllPageRowsSelected(checked === true) }) })) : null, headerGroup.headers.map((header) => (_jsx("th", { className: "px-3 py-2 font-medium", children: header.column.getCanSort() ? (_jsxs("button", { type: "button", className: "inline-flex items-center gap-1 hover:text-foreground", onClick: header.column.getToggleSortingHandler(), children: [headerText(header), _jsx(SortIcon, { direction: header.column.getIsSorted() })] })) : (headerText(header)) }, header.id))), hasActionsColumn ? _jsx("th", { className: "px-3 py-2" }) : null] }) }), _jsx("tbody", { children: isLoading ? (_jsx("tr", { children: _jsx("td", { colSpan: columnCount, className: "px-3 py-6 text-center text-muted-foreground", children: "Loading\u2026" }) })) : rows.length === 0 ? (_jsx("tr", { children: _jsx("td", { colSpan: columnCount, className: "px-3 py-6 text-center text-muted-foreground", children: resolvedEmptyState }) })) : (rows.map((row) => (_jsxs("tr", { className: "border-t border-border", children: [hasSelectionColumn ? (_jsx("td", { className: "px-3 py-2", children: _jsx(Checkbox, { "aria-label": "Select row", checked: row.getIsSelected(), onCheckedChange: (checked) => row.toggleSelected(checked === true) }) })) : null, row.getAllCells().map((cell) => (_jsx("td", { className: "px-3 py-2", children: formatFieldValue(cell.getValue()) }, cell.id))), hasActionsColumn ? (_jsx("td", { className: "px-3 py-2 text-right", children: rowActions(row.original) })) : null] }, row.id)))) })] }) }), _jsx("div", { className: "grid gap-2 md:hidden", children: isLoading ? (_jsx("p", { className: "py-6 text-center text-sm text-muted-foreground", children: "Loading\u2026" })) : rows.length === 0 ? (_jsx("
|
|
208
|
+
table.getIsSomePageRowsSelected(), onCheckedChange: (checked) => table.toggleAllPageRowsSelected(checked === true) }) })) : null, headerGroup.headers.map((header) => (_jsx("th", { className: "px-3 py-2 font-medium", children: header.column.getCanSort() ? (_jsxs("button", { type: "button", className: "inline-flex items-center gap-1 hover:text-foreground", onClick: header.column.getToggleSortingHandler(), children: [headerText(header), _jsx(SortIcon, { direction: header.column.getIsSorted() })] })) : (headerText(header)) }, header.id))), hasActionsColumn ? _jsx("th", { className: "px-3 py-2" }) : null] }) }), _jsx("tbody", { children: isLoading ? (_jsx("tr", { children: _jsx("td", { colSpan: columnCount, className: "px-3 py-6 text-center text-muted-foreground", children: "Loading\u2026" }) })) : rows.length === 0 ? (_jsx("tr", { children: _jsx("td", { colSpan: columnCount, className: "px-3 py-6 text-center text-muted-foreground", children: resolvedEmptyState }) })) : (rows.map((row) => (_jsxs("tr", { className: cn("border-t border-border", clickableRowClass), onClick: rowClickHandler(row.original), children: [hasSelectionColumn ? (_jsx("td", { className: "px-3 py-2", children: _jsx(Checkbox, { "aria-label": "Select row", checked: row.getIsSelected(), onCheckedChange: (checked) => row.toggleSelected(checked === true) }) })) : null, row.getAllCells().map((cell) => (_jsx("td", { className: "px-3 py-2", children: formatFieldValue(cell.getValue()) }, cell.id))), hasActionsColumn ? (_jsx("td", { className: "px-3 py-2 text-right", children: rowActions(row.original) })) : null] }, row.id)))) })] }) }), _jsx("div", { className: "grid gap-2 md:hidden", children: isLoading ? (_jsx("p", { className: "py-6 text-center text-sm text-muted-foreground", children: "Loading\u2026" })) : rows.length === 0 ? (_jsx("div", { className: "py-6 text-center text-sm text-muted-foreground", children: resolvedEmptyState })) : (rows.map((row) => (_jsxs("div", { className: cn("rounded-lg border border-border p-3", clickableRowClass), onClick: rowClickHandler(row.original), children: [hasSelectionColumn ? (_jsx("div", { className: "flex justify-end pb-2", children: _jsx(Checkbox, { "aria-label": "Select row", checked: row.getIsSelected(), onCheckedChange: (checked) => row.toggleSelected(checked === true) }) })) : null, row.getAllCells().map((cell) => (_jsxs("div", { className: "flex items-center justify-between gap-2 py-1 text-sm", children: [_jsx("span", { className: "text-muted-foreground", children: headerText({ column: cell.column }) }), _jsx("span", { className: "text-right", children: formatFieldValue(cell.getValue()) })] }, cell.id))), hasActionsColumn ? (_jsx("div", { className: "flex justify-end gap-2 pt-2", children: rowActions(row.original) })) : null] }, row.id)))) }), _jsxs("div", { className: "flex items-center justify-between pt-3 text-sm text-muted-foreground", children: [_jsxs("span", { children: ["Page ", table.store.state.pagination.pageIndex + 1, " of", " ", Math.max(1, table.getPageCount()), " \u00B7 ", table.getRowCount(), " total"] }), _jsxs("div", { className: "flex gap-1", children: [_jsx(Button, { type: "button", variant: "outline", size: "icon-sm", disabled: !table.getCanPreviousPage(), onClick: () => table.previousPage(), "aria-label": "Previous page", children: _jsx(ChevronLeftIcon, {}) }), _jsx(Button, { type: "button", variant: "outline", size: "icon-sm", disabled: !table.getCanNextPage(), onClick: () => table.nextPage(), "aria-label": "Next page", children: _jsx(ChevronRightIcon, {}) })] })] }), recordActions.length > 0 || collectionActions.length > 0 ? (_jsx(ResourceActionDialog, { resourceName: resource.name, action: activeAction?.action ?? null, recordId: activeAction?.recordId, onClose: () => setActiveAction(null), onDenied: (action) => denyAction(action, activeAction?.recordId) })) : null, actions && !onCreate ? (_jsx(Dialog, { open: createOpen, onOpenChange: setCreateOpen, children: _jsxs(DialogContent, { children: [_jsx(DialogHeader, { children: _jsxs(DialogTitle, { children: ["New ", resource.name] }) }), _jsx(ResourceForm, { resource: resource, onSuccess: () => setCreateOpen(false), onError: handleCreateError, submitLabel: "Create" })] }) })) : null, actions && !onEdit ? (_jsx(Dialog, { open: editRecord !== null, onOpenChange: (open) => {
|
|
193
209
|
if (!open) {
|
|
194
210
|
setEditRecord(null);
|
|
195
211
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verikit/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "React UI bindings for Verikit resource workflows.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
"./lib/*": {
|
|
38
38
|
"types": "./dist/lib/*.d.ts",
|
|
39
39
|
"default": "./dist/lib/*.js"
|
|
40
|
-
}
|
|
40
|
+
},
|
|
41
|
+
"./tailwind-sources.css": "./tailwind-sources.css"
|
|
41
42
|
},
|
|
42
43
|
"imports": {
|
|
43
44
|
"#components/*": {
|
|
@@ -50,18 +51,22 @@
|
|
|
50
51
|
}
|
|
51
52
|
},
|
|
52
53
|
"files": [
|
|
53
|
-
"dist"
|
|
54
|
+
"dist",
|
|
55
|
+
"tailwind-sources.css"
|
|
54
56
|
],
|
|
55
57
|
"dependencies": {
|
|
58
|
+
"@base-ui/react": "^1.6.0",
|
|
59
|
+
"@tanstack/react-form": "^1.33.2",
|
|
60
|
+
"@tanstack/react-table": "^9.0.0",
|
|
56
61
|
"class-variance-authority": "^0.7.1",
|
|
57
62
|
"clsx": "^2.1.1",
|
|
58
63
|
"lucide-react": "^1.26.0",
|
|
59
64
|
"tailwind-merge": "^3.6.0",
|
|
60
|
-
"@verikit/
|
|
61
|
-
"@verikit/
|
|
62
|
-
"@verikit/
|
|
63
|
-
"@verikit/theme": "0.
|
|
64
|
-
"@verikit/
|
|
65
|
+
"@verikit/core": "0.25.0",
|
|
66
|
+
"@verikit/client": "0.25.0",
|
|
67
|
+
"@verikit/ui-core": "0.25.0",
|
|
68
|
+
"@verikit/theme": "0.25.0",
|
|
69
|
+
"@verikit/runtime": "0.25.0"
|
|
65
70
|
},
|
|
66
71
|
"devDependencies": {
|
|
67
72
|
"@base-ui/react": "^1.6.0",
|
|
@@ -78,13 +83,24 @@
|
|
|
78
83
|
"typescript": "^6.0.3"
|
|
79
84
|
},
|
|
80
85
|
"peerDependencies": {
|
|
81
|
-
"@base-ui/react": "^1.6.0",
|
|
82
|
-
"@tanstack/react-form": "^1.33.2",
|
|
83
86
|
"@tanstack/react-query": "^5.101.4",
|
|
84
|
-
"@tanstack/react-table": "^9.0.0",
|
|
85
87
|
"react": "^19.0.0",
|
|
86
88
|
"react-dom": "^19.0.0"
|
|
87
89
|
},
|
|
90
|
+
"peerDependenciesMeta": {
|
|
91
|
+
"@tanstack/react-query": {
|
|
92
|
+
"optional": true
|
|
93
|
+
},
|
|
94
|
+
"react": {
|
|
95
|
+
"optional": true
|
|
96
|
+
},
|
|
97
|
+
"react-dom": {
|
|
98
|
+
"optional": true
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"sideEffects": [
|
|
102
|
+
"*.css"
|
|
103
|
+
],
|
|
88
104
|
"scripts": {
|
|
89
105
|
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
90
106
|
"build": "pnpm clean && tsc -b",
|