@rise-x/apps-sdk 0.6.0 → 0.7.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 +192 -10
- package/build/connectors/agents.js +1 -1
- package/build/connectors/assets.d.ts +9 -3
- package/build/connectors/assets.js +32 -1
- package/build/connectors/index.d.ts +3 -2
- package/build/connectors/index.js +4 -1
- package/build/connectors/search.d.ts +34 -0
- package/build/connectors/search.js +63 -0
- package/build/connectors/types.d.ts +51 -0
- package/build/connectors/types.js +71 -0
- package/build/connectors/work.d.ts +7 -1
- package/build/connectors/work.js +13 -0
- package/build/index.d.ts +1 -1
- package/build/mockShell.d.ts +11 -0
- package/build/mockShell.js +159 -2
- package/build/query/assets.d.ts +19 -6
- package/build/query/assets.js +35 -3
- package/build/query/context.d.ts +14 -0
- package/build/query/context.js +16 -0
- package/build/query/index.d.ts +4 -3
- package/build/query/index.js +14 -2
- package/build/query/keys.d.ts +4 -0
- package/build/query/keys.js +7 -0
- package/build/query/layer.d.ts +25 -3
- package/build/query/work.d.ts +14 -1
- package/build/query/work.js +32 -1
- package/build/shellBridge.d.ts +1 -1
- package/build/ui/components/data-table.d.ts +13 -2
- package/build/ui/components/table.d.ts +7 -1
- package/build/ui/reference/components/alert-dialog.tsx +6 -1
- package/build/ui/reference/components/button.tsx +8 -1
- package/build/ui/reference/components/data-table.tsx +199 -29
- package/build/ui/reference/components/dialog.tsx +1 -1
- package/build/ui/reference/components/dropdown-menu.tsx +2 -2
- package/build/ui/reference/components/nav.tsx +3 -0
- package/build/ui/reference/components/popover.tsx +1 -1
- package/build/ui/reference/components/select.tsx +1 -1
- package/build/ui/reference/components/sheet.tsx +5 -2
- package/build/ui/reference/components/table.tsx +15 -2
- package/build/ui/standalone.js +9 -9
- package/build/ui/styles.css +1 -1
- package/package.json +10 -9
- package/template/README.md +6 -0
- package/template/src/App.tsx +10 -1
package/build/query/work.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { type InfiniteData, type UseInfiniteQueryResult, type UseQueryResult } from "@tanstack/react-query";
|
|
2
|
-
import { type ListRelatedWorkArgs, type ListWorkRowsArgs, type StartWorkArgs, type SubmitWorkArgs, type WorkConnector, type WorkDataPatch, type WorkRowPage } from "../connectors/work";
|
|
2
|
+
import { type ListRelatedWorkArgs, type ListWorkRowsArgs, type SearchWorkArgs, type StartWorkArgs, type SubmitWorkArgs, type WorkConnector, type WorkDataPatch, type WorkRowPage, type WorkSearchPage } from "../connectors/work";
|
|
3
3
|
import type { ConnectorError } from "../connectors/errors";
|
|
4
4
|
import type { WorkAuditEvent, WorkDetail, WorkRow } from "../connectors/types";
|
|
5
5
|
import { type QueryEnvId } from "./keys";
|
|
6
6
|
import { type SdkMutationOptions, type SdkQueryOptions } from "./shared";
|
|
7
7
|
export type ListWorkRowsQueryArgs = Omit<ListWorkRowsArgs, "skip" | "signal">;
|
|
8
|
+
export type SearchWorkQueryArgs = Omit<SearchWorkArgs, "page" | "signal">;
|
|
8
9
|
export type ListRelatedWorkQueryArgs = Omit<ListRelatedWorkArgs, "signal">;
|
|
9
10
|
export declare function dedupeRows<T extends {
|
|
10
11
|
id: string;
|
|
@@ -35,6 +36,17 @@ export declare function createWorkQueries(connector: WorkConnector, getEnvId: ()
|
|
|
35
36
|
[x: string]: unknown;
|
|
36
37
|
}], InfiniteData<WorkRowPage, unknown>>;
|
|
37
38
|
};
|
|
39
|
+
search: (args: SearchWorkQueryArgs) => import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseInfiniteQueryOptions<WorkSearchPage, Error, InfiniteData<WorkSearchPage, unknown>, WorkSearchPage, readonly ["rise-apps-sdk", QueryEnvId, "work", "search", {
|
|
40
|
+
[x: string]: unknown;
|
|
41
|
+
}], number>, "queryFn"> & {
|
|
42
|
+
queryFn?: import("@tanstack/react-query").QueryFunction<WorkSearchPage, readonly ["rise-apps-sdk", QueryEnvId, "work", "search", {
|
|
43
|
+
[x: string]: unknown;
|
|
44
|
+
}], number> | undefined;
|
|
45
|
+
} & {
|
|
46
|
+
queryKey: import("@tanstack/react-query").DataTag<readonly ["rise-apps-sdk", QueryEnvId, "work", "search", {
|
|
47
|
+
[x: string]: unknown;
|
|
48
|
+
}], InfiniteData<WorkSearchPage, unknown>>;
|
|
49
|
+
};
|
|
38
50
|
related: (args: ListRelatedWorkQueryArgs) => import("@tanstack/react-query").OmitKeyof<import("@tanstack/react-query").UseQueryOptions<WorkRow[], Error, WorkRow[], readonly ["rise-apps-sdk", QueryEnvId, "work", "related", {
|
|
39
51
|
[x: string]: unknown;
|
|
40
52
|
}]>, "queryFn"> & {
|
|
@@ -59,6 +71,7 @@ export declare function useWorkData(workId: string, opts?: {
|
|
|
59
71
|
path?: string;
|
|
60
72
|
}, options?: SdkQueryOptions): UseQueryResult<unknown, ConnectorError>;
|
|
61
73
|
export declare function useWorkRows(args: ListWorkRowsQueryArgs, options?: SdkQueryOptions): UseInfiniteQueryResult<InfiniteData<WorkRowPage>, ConnectorError>;
|
|
74
|
+
export declare function useWorkSearch(args: SearchWorkQueryArgs, options?: SdkQueryOptions): UseInfiniteQueryResult<InfiniteData<WorkSearchPage>, ConnectorError>;
|
|
62
75
|
export declare function useRelatedWork(args: ListRelatedWorkQueryArgs, options?: SdkQueryOptions): UseQueryResult<WorkRow[], ConnectorError>;
|
|
63
76
|
export declare function useWorkAudit(workId: string, options?: SdkQueryOptions): UseQueryResult<WorkAuditEvent[], ConnectorError>;
|
|
64
77
|
export type StartWorkVariables = Omit<StartWorkArgs, "signal">;
|
package/build/query/work.js
CHANGED
|
@@ -6,6 +6,7 @@ exports.createWorkQueries = createWorkQueries;
|
|
|
6
6
|
exports.useWork = useWork;
|
|
7
7
|
exports.useWorkData = useWorkData;
|
|
8
8
|
exports.useWorkRows = useWorkRows;
|
|
9
|
+
exports.useWorkSearch = useWorkSearch;
|
|
9
10
|
exports.useRelatedWork = useRelatedWork;
|
|
10
11
|
exports.useWorkAudit = useWorkAudit;
|
|
11
12
|
exports.useStartWork = useStartWork;
|
|
@@ -17,6 +18,7 @@ exports.useDeleteWork = useDeleteWork;
|
|
|
17
18
|
// caller's onSuccess — composed, never replaced.
|
|
18
19
|
const react_query_1 = require("@tanstack/react-query");
|
|
19
20
|
const work_1 = require("../connectors/work");
|
|
21
|
+
const search_1 = require("../connectors/search");
|
|
20
22
|
const keys_1 = require("./keys");
|
|
21
23
|
const shared_1 = require("./shared");
|
|
22
24
|
// Flatten an infinite rows result, dropping cross-page duplicates: sort-shifted
|
|
@@ -67,6 +69,19 @@ function createWorkQueries(connector, getEnvId) {
|
|
|
67
69
|
enabled: envId != null && args.flow != null,
|
|
68
70
|
});
|
|
69
71
|
},
|
|
72
|
+
// Infinite page-based search. Unlike rows() the server reports hasMore
|
|
73
|
+
// exactly, so the advance rule is just "next page while hasMore".
|
|
74
|
+
// `args.filter` must pin flowOriginId — see SearchWorkArgs.
|
|
75
|
+
search: (args) => {
|
|
76
|
+
const envId = getEnvId();
|
|
77
|
+
return (0, react_query_1.infiniteQueryOptions)({
|
|
78
|
+
queryKey: keys_1.queryKeys.work.search(envId, (0, search_1.searchCacheShape)(args)),
|
|
79
|
+
queryFn: ({ pageParam, signal }) => connector.search({ ...args, page: pageParam, signal }),
|
|
80
|
+
initialPageParam: 1,
|
|
81
|
+
getNextPageParam: (last) => last.hasMore ? last.page + 1 : undefined,
|
|
82
|
+
enabled: envId != null && args.filter != null,
|
|
83
|
+
});
|
|
84
|
+
},
|
|
70
85
|
related: (args) => {
|
|
71
86
|
const envId = getEnvId();
|
|
72
87
|
return (0, react_query_1.queryOptions)({
|
|
@@ -99,6 +114,10 @@ function useWorkData(workId, opts, options) {
|
|
|
99
114
|
function useWorkRows(args, options) {
|
|
100
115
|
return (0, shared_1.useSdkInfiniteQuery)(exports.workQueries.rows(args), options);
|
|
101
116
|
}
|
|
117
|
+
// Infinite page-based search; flatten pages with dedupeRows(data).
|
|
118
|
+
function useWorkSearch(args, options) {
|
|
119
|
+
return (0, shared_1.useSdkInfiniteQuery)(exports.workQueries.search(args), options);
|
|
120
|
+
}
|
|
102
121
|
function useRelatedWork(args, options) {
|
|
103
122
|
return (0, shared_1.useSdkQuery)(exports.workQueries.related(args), options);
|
|
104
123
|
}
|
|
@@ -111,6 +130,9 @@ function useStartWork(options) {
|
|
|
111
130
|
void client.invalidateQueries({
|
|
112
131
|
queryKey: keys_1.queryKeys.work.allRows(envId),
|
|
113
132
|
});
|
|
133
|
+
void client.invalidateQueries({
|
|
134
|
+
queryKey: keys_1.queryKeys.work.searchAll(envId),
|
|
135
|
+
});
|
|
114
136
|
}, options);
|
|
115
137
|
}
|
|
116
138
|
function usePatchWorkData(options) {
|
|
@@ -122,10 +144,13 @@ function usePatchWorkData(options) {
|
|
|
122
144
|
void client.invalidateQueries({
|
|
123
145
|
queryKey: keys_1.queryKeys.work.detail(envId, vars.workId),
|
|
124
146
|
});
|
|
125
|
-
//
|
|
147
|
+
// Listings project data paths, so a data write can stale them.
|
|
126
148
|
void client.invalidateQueries({
|
|
127
149
|
queryKey: keys_1.queryKeys.work.allRows(envId),
|
|
128
150
|
});
|
|
151
|
+
void client.invalidateQueries({
|
|
152
|
+
queryKey: keys_1.queryKeys.work.searchAll(envId),
|
|
153
|
+
});
|
|
129
154
|
}, options);
|
|
130
155
|
}
|
|
131
156
|
function useSubmitWork(options) {
|
|
@@ -144,6 +169,9 @@ function useSubmitWork(options) {
|
|
|
144
169
|
void client.invalidateQueries({
|
|
145
170
|
queryKey: keys_1.queryKeys.work.allRows(envId),
|
|
146
171
|
});
|
|
172
|
+
void client.invalidateQueries({
|
|
173
|
+
queryKey: keys_1.queryKeys.work.searchAll(envId),
|
|
174
|
+
});
|
|
147
175
|
// CROSS-DOMAIN: asset create/edit drafts materialize via work.submit —
|
|
148
176
|
// the whole assets scope goes stale. Over-broad but correct; only
|
|
149
177
|
// active asset queries actually refetch.
|
|
@@ -165,6 +193,9 @@ function useDeleteWork(options) {
|
|
|
165
193
|
void client.invalidateQueries({
|
|
166
194
|
queryKey: keys_1.queryKeys.work.allRows(envId),
|
|
167
195
|
});
|
|
196
|
+
void client.invalidateQueries({
|
|
197
|
+
queryKey: keys_1.queryKeys.work.searchAll(envId),
|
|
198
|
+
});
|
|
168
199
|
void client.invalidateQueries({
|
|
169
200
|
queryKey: keys_1.queryKeys.work.relatedAll(envId),
|
|
170
201
|
});
|
package/build/shellBridge.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface ShellEnvironment {
|
|
|
12
12
|
}
|
|
13
13
|
export type ShellEventUnsubscribe = () => void;
|
|
14
14
|
export type ShellNavigate = NavigateFunction;
|
|
15
|
-
export type V4ApiKey = "apps" | "work" | "config" | "attachment";
|
|
15
|
+
export type V4ApiKey = "apps" | "work" | "config" | "attachment" | "asset";
|
|
16
16
|
export interface ShellAiApi {
|
|
17
17
|
baseUrl: string;
|
|
18
18
|
getHeaders(): Record<string, string>;
|
|
@@ -21,6 +21,11 @@ export interface FacetedFilterProps {
|
|
|
21
21
|
selected: Iterable<string>;
|
|
22
22
|
onSelect: (value: string, checked: boolean) => void;
|
|
23
23
|
onClear: () => void;
|
|
24
|
+
/** Search box above the list. Defaults to on past SEARCH_THRESHOLD options. */
|
|
25
|
+
searchable?: boolean;
|
|
26
|
+
/** Drop options whose `count` is 0 — inert when counts aren't provided.
|
|
27
|
+
* Applied values stay listed so they can be unticked. */
|
|
28
|
+
hideEmpty?: boolean;
|
|
24
29
|
className?: string;
|
|
25
30
|
}
|
|
26
31
|
export interface DataTableFilter {
|
|
@@ -28,6 +33,10 @@ export interface DataTableFilter {
|
|
|
28
33
|
columnId: string;
|
|
29
34
|
title: string;
|
|
30
35
|
options: DataTableFilterOption[];
|
|
36
|
+
/** Search box above the options. Defaults to on past SEARCH_THRESHOLD. */
|
|
37
|
+
searchable?: boolean;
|
|
38
|
+
/** Drop options no visible row carries. */
|
|
39
|
+
hideEmpty?: boolean;
|
|
31
40
|
}
|
|
32
41
|
export interface DataTableProps<TData, TValue> {
|
|
33
42
|
columns: ColumnDef<TData, TValue>[];
|
|
@@ -54,13 +63,15 @@ export declare function DataTableColumnHeader<TData, TValue>({ column, title, cl
|
|
|
54
63
|
* `selected` in, `onSelect`/`onClear` out. DataTableFacetedFilter is this
|
|
55
64
|
* component wired to a TanStack column.
|
|
56
65
|
*/
|
|
57
|
-
export declare function FacetedFilter({ title, options, selected: selectedValues, onSelect, onClear, className, }: FacetedFilterProps): React.JSX.Element;
|
|
66
|
+
export declare function FacetedFilter({ title, options, selected: selectedValues, onSelect, onClear, searchable, hideEmpty, className, }: FacetedFilterProps): React.JSX.Element;
|
|
58
67
|
/** FacetedFilter bound to a TanStack column: facet counts and the filter value
|
|
59
68
|
* come from the table, so the toolbar only names the column. */
|
|
60
|
-
export declare function DataTableFacetedFilter<TData>({ column, title, options, }: {
|
|
69
|
+
export declare function DataTableFacetedFilter<TData>({ column, title, options, searchable, hideEmpty, }: {
|
|
61
70
|
column: Column<TData, unknown>;
|
|
62
71
|
title: string;
|
|
63
72
|
options: DataTableFilterOption[];
|
|
73
|
+
searchable?: boolean;
|
|
74
|
+
hideEmpty?: boolean;
|
|
64
75
|
}): React.JSX.Element;
|
|
65
76
|
/**
|
|
66
77
|
* Rise-X data table: search, faceted filters and column visibility are built
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
declare function Table({ className, ...props }: React.ComponentProps<'table'>
|
|
2
|
+
declare function Table({ className, containerClassName, ...props }: React.ComponentProps<'table'> & {
|
|
3
|
+
/** Extends the scroll container the table always renders inside. Sticky
|
|
4
|
+
* headers pin to THIS element, so a vertically scrolling table puts its
|
|
5
|
+
* max-height + overflow-y here — an outer scroll div never receives the
|
|
6
|
+
* stick. */
|
|
7
|
+
containerClassName?: string;
|
|
8
|
+
}): React.JSX.Element;
|
|
3
9
|
declare function TableWrap({ className, ...props }: React.ComponentProps<'div'>): React.JSX.Element;
|
|
4
10
|
declare function TableHeader({ className, ...props }: React.ComponentProps<'thead'>): React.JSX.Element;
|
|
5
11
|
declare function TableBody({ className, ...props }: React.ComponentProps<'tbody'>): React.JSX.Element;
|
|
@@ -67,7 +67,12 @@ const AlertDialogContent = React.forwardRef<
|
|
|
67
67
|
data-slot="alert-dialog-content"
|
|
68
68
|
data-size={size}
|
|
69
69
|
className={cn(
|
|
70
|
-
'group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 gap-6 rounded-2xl bg-popover p-6 text-popover-foreground shadow-pop duration-100 outline-none data-
|
|
70
|
+
'group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 gap-6 rounded-2xl bg-popover p-6 text-popover-foreground shadow-pop duration-100 outline-none 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',
|
|
71
|
+
/* min() folds dialog.tsx's viewport-gutter clamp into the size cap —
|
|
72
|
+
* a separate bare max-w-* would lose to these data-variants on
|
|
73
|
+
* specificity, and without it the xs cap sits flush against the
|
|
74
|
+
* screen edge on viewports at or under 320px. */
|
|
75
|
+
'data-[size=default]:max-w-[min(var(--container-xs),calc(100%-(var(--spacing)*8)))] data-[size=sm]:max-w-[min(var(--container-xs),calc(100%-(var(--spacing)*8)))] data-[size=default]:sm:max-w-md',
|
|
71
76
|
className,
|
|
72
77
|
)}
|
|
73
78
|
{...props}
|
|
@@ -43,8 +43,15 @@ const buttonVariants = cva(
|
|
|
43
43
|
/* Filter trigger. Two states that must be told apart at a glance:
|
|
44
44
|
* empty = dashed outline + muted label ("a slot you could fill"),
|
|
45
45
|
* applied = solid fill, no dash, full-strength label. */
|
|
46
|
+
/* The applied state has TWO hooks on purpose. `aria-pressed` fits a
|
|
47
|
+
* filter trigger, which is genuinely a toggle. `data-filled` is for
|
|
48
|
+
* slots that are filled rather than pressed — a file picker opens a
|
|
49
|
+
* dialog, so claiming a pressed state there announces a control that
|
|
50
|
+
* does not exist. One deliberate difference: `data-filled` keeps the
|
|
51
|
+
* leading glyph. A filter's "+" stops making sense once applied; an
|
|
52
|
+
* upload glyph still describes the control after a file is chosen. */
|
|
46
53
|
dashed:
|
|
47
|
-
'border-dashed border-border-strong text-muted-foreground hover:bg-fill-1 hover:text-foreground aria-pressed:border-solid aria-pressed:border-transparent aria-pressed:bg-fill-2 aria-pressed:text-foreground aria-pressed:hover:bg-fill-3 aria-pressed:[&>svg:first-child]:hidden',
|
|
54
|
+
'border-dashed border-border-strong text-muted-foreground hover:bg-fill-1 hover:text-foreground aria-pressed:border-solid aria-pressed:border-transparent aria-pressed:bg-fill-2 aria-pressed:text-foreground aria-pressed:hover:bg-fill-3 aria-pressed:[&>svg:first-child]:hidden data-filled:border-solid data-filled:border-transparent data-filled:bg-fill-2 data-filled:text-foreground data-filled:hover:bg-fill-3',
|
|
48
55
|
/* Rise-X wireframe pill — white surface, soft shadow, fully rounded. */
|
|
49
56
|
pill: 'rounded-full border-border/60 bg-card text-card-foreground shadow-pill hover:shadow-card aria-expanded:shadow-card',
|
|
50
57
|
},
|
|
@@ -17,7 +17,16 @@ import {
|
|
|
17
17
|
type Table as TanstackTable,
|
|
18
18
|
type VisibilityState,
|
|
19
19
|
} from '@tanstack/react-table';
|
|
20
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
ArrowDown,
|
|
22
|
+
ArrowUp,
|
|
23
|
+
CheckIcon,
|
|
24
|
+
ChevronsUpDown,
|
|
25
|
+
Plus,
|
|
26
|
+
Search,
|
|
27
|
+
Settings2,
|
|
28
|
+
X,
|
|
29
|
+
} from 'lucide-react';
|
|
21
30
|
|
|
22
31
|
import { cn } from '@rise-x/ui/lib/utils';
|
|
23
32
|
import { Badge } from '@rise-x/ui/components/badge';
|
|
@@ -28,10 +37,10 @@ import {
|
|
|
28
37
|
DropdownMenuCheckboxItem,
|
|
29
38
|
DropdownMenuContent,
|
|
30
39
|
DropdownMenuLabel,
|
|
31
|
-
DropdownMenuSeparator,
|
|
32
40
|
DropdownMenuTrigger,
|
|
33
41
|
} from '@rise-x/ui/components/dropdown-menu';
|
|
34
42
|
import { Input } from '@rise-x/ui/components/input';
|
|
43
|
+
import { Popover, PopoverContent, PopoverTrigger } from '@rise-x/ui/components/popover';
|
|
35
44
|
import { Separator } from '@rise-x/ui/components/separator';
|
|
36
45
|
import {
|
|
37
46
|
Table,
|
|
@@ -66,14 +75,26 @@ export interface FacetedFilterProps {
|
|
|
66
75
|
selected: Iterable<string>;
|
|
67
76
|
onSelect: (value: string, checked: boolean) => void;
|
|
68
77
|
onClear: () => void;
|
|
78
|
+
/** Search box above the list. Defaults to on past SEARCH_THRESHOLD options. */
|
|
79
|
+
searchable?: boolean;
|
|
80
|
+
/** Drop options whose `count` is 0 — inert when counts aren't provided.
|
|
81
|
+
* Applied values stay listed so they can be unticked. */
|
|
82
|
+
hideEmpty?: boolean;
|
|
69
83
|
className?: string;
|
|
70
84
|
}
|
|
71
85
|
|
|
86
|
+
// Long option lists are unusable without a filter; short ones don't need one.
|
|
87
|
+
const SEARCH_THRESHOLD = 10;
|
|
88
|
+
|
|
72
89
|
export interface DataTableFilter {
|
|
73
90
|
/** Column id (accessorKey) the filter applies to. */
|
|
74
91
|
columnId: string;
|
|
75
92
|
title: string;
|
|
76
93
|
options: DataTableFilterOption[];
|
|
94
|
+
/** Search box above the options. Defaults to on past SEARCH_THRESHOLD. */
|
|
95
|
+
searchable?: boolean;
|
|
96
|
+
/** Drop options no visible row carries. */
|
|
97
|
+
hideEmpty?: boolean;
|
|
77
98
|
}
|
|
78
99
|
|
|
79
100
|
export interface DataTableProps<TData, TValue> {
|
|
@@ -140,8 +161,13 @@ export function FacetedFilter({
|
|
|
140
161
|
selected: selectedValues,
|
|
141
162
|
onSelect,
|
|
142
163
|
onClear,
|
|
164
|
+
searchable,
|
|
165
|
+
hideEmpty,
|
|
143
166
|
className,
|
|
144
167
|
}: FacetedFilterProps) {
|
|
168
|
+
const [open, setOpen] = React.useState(false);
|
|
169
|
+
const [query, setQuery] = React.useState('');
|
|
170
|
+
const listRef = React.useRef<HTMLDivElement>(null);
|
|
145
171
|
const selected = new Set(selectedValues);
|
|
146
172
|
const selectedOptions = options.filter((option) => selected.has(option.value));
|
|
147
173
|
|
|
@@ -152,9 +178,62 @@ export function FacetedFilter({
|
|
|
152
178
|
* an × appears to clear THIS filter without touching the others. */
|
|
153
179
|
const hasSelection = selectedOptions.length > 0;
|
|
154
180
|
|
|
181
|
+
const visible = hideEmpty
|
|
182
|
+
? options.filter((option) => option.count !== 0 || selected.has(option.value))
|
|
183
|
+
: options;
|
|
184
|
+
const showSearch = searchable ?? visible.length > SEARCH_THRESHOLD;
|
|
185
|
+
const matches = query
|
|
186
|
+
? visible.filter((option) => option.label.toLowerCase().includes(query.toLowerCase()))
|
|
187
|
+
: visible;
|
|
188
|
+
|
|
189
|
+
/* Roving focus: one tab stop for the whole list, arrows move within it —
|
|
190
|
+
* matching the DropdownMenu this replaced, where a long list would otherwise
|
|
191
|
+
* be one tab stop per option. `active` carries the tab stop with the focus so
|
|
192
|
+
* tabbing away and back returns to where the user left off. */
|
|
193
|
+
const [active, setActive] = React.useState(0);
|
|
194
|
+
const focusOption = (index: number) => {
|
|
195
|
+
const items = listRef.current?.querySelectorAll<HTMLElement>('[role="option"]');
|
|
196
|
+
if (!items?.length) return;
|
|
197
|
+
const next = Math.min(Math.max(index === -1 ? items.length - 1 : index, 0), items.length - 1);
|
|
198
|
+
setActive(next);
|
|
199
|
+
items[next].focus();
|
|
200
|
+
};
|
|
201
|
+
const onListKeyDown = (event: React.KeyboardEvent) => {
|
|
202
|
+
if (!['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(event.key)) return;
|
|
203
|
+
// Home/End belong to the caret while the search box has focus. This handler
|
|
204
|
+
// sits on the popover container, so without this it would swallow them and
|
|
205
|
+
// jump the list instead of moving through what the user typed.
|
|
206
|
+
if (
|
|
207
|
+
document.activeElement instanceof HTMLInputElement &&
|
|
208
|
+
(event.key === 'Home' || event.key === 'End')
|
|
209
|
+
) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
event.preventDefault();
|
|
213
|
+
if (event.key === 'Home') return focusOption(0);
|
|
214
|
+
if (event.key === 'End') return focusOption(-1);
|
|
215
|
+
// Radix focuses the popover container on open and the search box is not an
|
|
216
|
+
// option either, so the first arrow has to ENTER the list rather than step
|
|
217
|
+
// from a position nothing is sitting on.
|
|
218
|
+
const items = listRef.current?.querySelectorAll<HTMLElement>('[role="option"]');
|
|
219
|
+
const inList =
|
|
220
|
+
!!items?.length && Array.from(items).includes(document.activeElement as HTMLElement);
|
|
221
|
+
if (!inList) return focusOption(event.key === 'ArrowDown' ? 0 : -1);
|
|
222
|
+
focusOption(active + (event.key === 'ArrowDown' ? 1 : -1));
|
|
223
|
+
};
|
|
224
|
+
|
|
155
225
|
return (
|
|
156
|
-
<
|
|
157
|
-
|
|
226
|
+
<Popover
|
|
227
|
+
open={open}
|
|
228
|
+
onOpenChange={(next) => {
|
|
229
|
+
setOpen(next);
|
|
230
|
+
if (!next) {
|
|
231
|
+
setQuery('');
|
|
232
|
+
setActive(0);
|
|
233
|
+
}
|
|
234
|
+
}}
|
|
235
|
+
>
|
|
236
|
+
<PopoverTrigger asChild>
|
|
158
237
|
<Button variant="dashed" size="sm" aria-pressed={hasSelection} className={className}>
|
|
159
238
|
<Plus />
|
|
160
239
|
{title}
|
|
@@ -177,8 +256,14 @@ export function FacetedFilter({
|
|
|
177
256
|
role="button"
|
|
178
257
|
tabIndex={-1}
|
|
179
258
|
aria-label={`Clear ${title} filter`}
|
|
259
|
+
// Both handlers: pointerdown suppresses the focus shift, and
|
|
260
|
+
// PopoverTrigger toggles on click, so the click must be
|
|
261
|
+
// swallowed here or clearing would also open the list.
|
|
180
262
|
onPointerDown={(event) => {
|
|
181
|
-
|
|
263
|
+
event.preventDefault();
|
|
264
|
+
event.stopPropagation();
|
|
265
|
+
}}
|
|
266
|
+
onClick={(event) => {
|
|
182
267
|
event.preventDefault();
|
|
183
268
|
event.stopPropagation();
|
|
184
269
|
onClear();
|
|
@@ -190,33 +275,89 @@ export function FacetedFilter({
|
|
|
190
275
|
</>
|
|
191
276
|
)}
|
|
192
277
|
</Button>
|
|
193
|
-
</
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
278
|
+
</PopoverTrigger>
|
|
279
|
+
{/* Width follows the content (nowrap rows, scroll past the cap) so long
|
|
280
|
+
* values read on one line instead of wrapping. */}
|
|
281
|
+
{/* gap-0 resets PopoverContent's own `flex flex-col gap-4`, which would
|
|
282
|
+
* otherwise put 16px between the title, search box, list and clear row.
|
|
283
|
+
* onKeyDown sits here, not on the listbox: Radix focuses the content
|
|
284
|
+
* container on open, so a handler on a child never sees the first
|
|
285
|
+
* arrow. */}
|
|
286
|
+
<PopoverContent
|
|
287
|
+
align="start"
|
|
288
|
+
onKeyDown={onListKeyDown}
|
|
289
|
+
className="w-auto max-w-96 min-w-48 gap-0 p-1"
|
|
290
|
+
>
|
|
291
|
+
<p className="px-2 py-1.5 text-xs font-medium text-muted-foreground">{title}</p>
|
|
292
|
+
{showSearch && (
|
|
293
|
+
<Input
|
|
294
|
+
value={query}
|
|
295
|
+
onChange={(event) => {
|
|
296
|
+
setQuery(event.target.value);
|
|
297
|
+
setActive(0);
|
|
298
|
+
}}
|
|
299
|
+
placeholder={`Filter ${title.toLowerCase()}…`}
|
|
300
|
+
aria-label={`Filter ${title} options`}
|
|
301
|
+
className="mb-1 h-control-sm"
|
|
302
|
+
/>
|
|
303
|
+
)}
|
|
304
|
+
<div ref={listRef} role="listbox" aria-multiselectable className="max-h-72 overflow-auto">
|
|
305
|
+
{matches.map((option, index) => {
|
|
306
|
+
const checked = selected.has(option.value);
|
|
307
|
+
return (
|
|
308
|
+
<button
|
|
309
|
+
key={option.value}
|
|
310
|
+
type="button"
|
|
311
|
+
role="option"
|
|
312
|
+
aria-selected={checked}
|
|
313
|
+
// Clamped: filtering the list can shrink it past `active`, and
|
|
314
|
+
// an out-of-range index would leave no tab stop at all.
|
|
315
|
+
tabIndex={index === Math.min(active, matches.length - 1) ? 0 : -1}
|
|
316
|
+
onFocus={() => setActive(index)}
|
|
317
|
+
onClick={() => onSelect(option.value, !checked)}
|
|
318
|
+
className="flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-sm whitespace-nowrap outline-none hover:bg-fill-2 focus-visible:bg-fill-2"
|
|
319
|
+
>
|
|
320
|
+
{/* Not the Checkbox component: that renders a <button>, and
|
|
321
|
+
* nesting it in the option button is invalid HTML. */}
|
|
322
|
+
<span
|
|
323
|
+
aria-hidden="true"
|
|
324
|
+
className={cn(
|
|
325
|
+
'grid size-[15px] shrink-0 place-content-center rounded-[4px] border transition-[background-color,border-color] duration-100',
|
|
326
|
+
checked
|
|
327
|
+
? 'border-primary bg-primary text-primary-foreground'
|
|
328
|
+
: 'border-input bg-card',
|
|
329
|
+
)}
|
|
330
|
+
>
|
|
331
|
+
{checked && <CheckIcon className="size-2.5 stroke-[3.5]" />}
|
|
332
|
+
</span>
|
|
333
|
+
{option.icon && <option.icon className="size-4 text-muted-foreground" />}
|
|
334
|
+
{option.label}
|
|
335
|
+
{option.count !== undefined && (
|
|
336
|
+
<span className="ms-auto ps-3 text-xs text-muted-foreground">{option.count}</span>
|
|
337
|
+
)}
|
|
338
|
+
</button>
|
|
339
|
+
);
|
|
340
|
+
})}
|
|
341
|
+
</div>
|
|
342
|
+
{matches.length === 0 && (
|
|
343
|
+
<p className="px-2 py-3 text-sm text-muted-foreground">No matches</p>
|
|
344
|
+
)}
|
|
345
|
+
{/* selected, not hasSelection: a value applied but absent from
|
|
346
|
+
* `options` renders no chip, and this row is then the only way out. */}
|
|
210
347
|
{selected.size > 0 && (
|
|
211
348
|
<>
|
|
212
|
-
<
|
|
213
|
-
<
|
|
349
|
+
<Separator className="my-1" />
|
|
350
|
+
<button
|
|
351
|
+
type="button"
|
|
352
|
+
onClick={() => onClear()}
|
|
353
|
+
className="w-full rounded-sm px-2 py-1.5 text-sm outline-none hover:bg-fill-2 focus-visible:bg-fill-2"
|
|
354
|
+
>
|
|
214
355
|
Clear filter
|
|
215
|
-
</
|
|
356
|
+
</button>
|
|
216
357
|
</>
|
|
217
358
|
)}
|
|
218
|
-
</
|
|
219
|
-
</
|
|
359
|
+
</PopoverContent>
|
|
360
|
+
</Popover>
|
|
220
361
|
);
|
|
221
362
|
}
|
|
222
363
|
|
|
@@ -226,19 +367,44 @@ export function DataTableFacetedFilter<TData>({
|
|
|
226
367
|
column,
|
|
227
368
|
title,
|
|
228
369
|
options,
|
|
370
|
+
searchable,
|
|
371
|
+
hideEmpty,
|
|
229
372
|
}: {
|
|
230
373
|
column: Column<TData, unknown>;
|
|
231
374
|
title: string;
|
|
232
375
|
options: DataTableFilterOption[];
|
|
376
|
+
searchable?: boolean;
|
|
377
|
+
hideEmpty?: boolean;
|
|
233
378
|
}) {
|
|
234
|
-
const facets = column.getFacetedUniqueValues();
|
|
235
379
|
const selected = new Set((column.getFilterValue() as string[] | undefined) ?? []);
|
|
236
380
|
|
|
381
|
+
/* Counted here rather than via getFacetedUniqueValues(): faceted columns hold
|
|
382
|
+
* an array per row so `arrIncludesSome` can match, and that helper keys the
|
|
383
|
+
* facet map on the whole array — ['Piping','Structural'] — so a lookup of a
|
|
384
|
+
* single value never hits and every count renders 0. The faceted row model
|
|
385
|
+
* also excludes this column's own filter, which keeps counts stable while
|
|
386
|
+
* values are being ticked. */
|
|
387
|
+
const facetedRows = column.getFacetedRowModel().flatRows;
|
|
388
|
+
const counts = React.useMemo(() => {
|
|
389
|
+
const tally = new Map<string, number>();
|
|
390
|
+
for (const row of facetedRows) {
|
|
391
|
+
const value = row.getValue(column.id);
|
|
392
|
+
for (const item of Array.isArray(value) ? value : [value]) {
|
|
393
|
+
if (item == null || item === '') continue;
|
|
394
|
+
const key = String(item);
|
|
395
|
+
tally.set(key, (tally.get(key) ?? 0) + 1);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return tally;
|
|
399
|
+
}, [facetedRows, column.id]);
|
|
400
|
+
|
|
237
401
|
return (
|
|
238
402
|
<FacetedFilter
|
|
239
403
|
title={title}
|
|
240
|
-
options={options.map((option) => ({ ...option, count:
|
|
404
|
+
options={options.map((option) => ({ ...option, count: counts.get(option.value) ?? 0 }))}
|
|
241
405
|
selected={selected}
|
|
406
|
+
searchable={searchable}
|
|
407
|
+
hideEmpty={hideEmpty}
|
|
242
408
|
onSelect={(value, checked) => {
|
|
243
409
|
const next = new Set(selected);
|
|
244
410
|
if (checked) {
|
|
@@ -363,6 +529,8 @@ export function DataTable<TData, TValue>({
|
|
|
363
529
|
getFilteredRowModel: getFilteredRowModel(),
|
|
364
530
|
getSortedRowModel: getSortedRowModel(),
|
|
365
531
|
getFacetedRowModel: getFacetedRowModel(),
|
|
532
|
+
// Kept for consumers even though the faceted filter counts from the row
|
|
533
|
+
// model instead (this helper keys array cells on the whole array).
|
|
366
534
|
getFacetedUniqueValues: getFacetedUniqueValues(),
|
|
367
535
|
});
|
|
368
536
|
|
|
@@ -391,6 +559,8 @@ export function DataTable<TData, TValue>({
|
|
|
391
559
|
column={column}
|
|
392
560
|
title={filter.title}
|
|
393
561
|
options={filter.options}
|
|
562
|
+
searchable={filter.searchable}
|
|
563
|
+
hideEmpty={filter.hideEmpty}
|
|
394
564
|
/>
|
|
395
565
|
);
|
|
396
566
|
})}
|
|
@@ -72,7 +72,7 @@ const DialogContent = React.forwardRef<
|
|
|
72
72
|
ref={ref}
|
|
73
73
|
data-slot="dialog-content"
|
|
74
74
|
className={cn(
|
|
75
|
-
'fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-
|
|
75
|
+
'fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-(var(--spacing)*8))] -translate-x-1/2 -translate-y-1/2 gap-6 rounded-2xl bg-popover p-6 text-sm text-popover-foreground shadow-pop duration-100 outline-none sm:max-w-md 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',
|
|
76
76
|
className,
|
|
77
77
|
)}
|
|
78
78
|
{...props}
|
|
@@ -33,7 +33,7 @@ function DropdownMenuContent({
|
|
|
33
33
|
sideOffset={sideOffset}
|
|
34
34
|
align={align}
|
|
35
35
|
className={cn(
|
|
36
|
-
'z-50 max-h-(--radix-dropdown-menu-content-available-height) w-(--radix-dropdown-menu-trigger-width) min-w-48 origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-xl bg-popover p-1.5 text-popover-foreground shadow-pop duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:overflow-hidden
|
|
36
|
+
'z-50 max-h-(--radix-dropdown-menu-content-available-height) w-(--radix-dropdown-menu-trigger-width) min-w-48 origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-xl bg-popover p-1.5 text-popover-foreground shadow-pop duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:overflow-hidden 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',
|
|
37
37
|
className,
|
|
38
38
|
)}
|
|
39
39
|
{...props}
|
|
@@ -218,7 +218,7 @@ function DropdownMenuSubContent({
|
|
|
218
218
|
<DropdownMenuPrimitive.SubContent
|
|
219
219
|
data-slot="dropdown-menu-sub-content"
|
|
220
220
|
className={cn(
|
|
221
|
-
'z-50 min-w-36 origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-xl bg-popover p-1.5 text-popover-foreground shadow-pop duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2
|
|
221
|
+
'z-50 min-w-36 origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-xl bg-popover p-1.5 text-popover-foreground shadow-pop duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 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',
|
|
222
222
|
className,
|
|
223
223
|
)}
|
|
224
224
|
{...props}
|
|
@@ -29,6 +29,9 @@ function NavItem({
|
|
|
29
29
|
className={cn(
|
|
30
30
|
'flex h-[30px] w-full cursor-pointer items-center gap-2 rounded-md border-0 bg-transparent px-2 text-left text-ui text-muted-foreground transition-colors duration-150 ease-decelerate',
|
|
31
31
|
'hover:bg-muted hover:text-foreground',
|
|
32
|
+
// Same focus treatment as every other operable control in the kit
|
|
33
|
+
// (Button, Input, SegmentedItem): the neutral ring, not the brand one.
|
|
34
|
+
'outline-none focus-visible:ring-3 focus-visible:ring-ring-control/35',
|
|
32
35
|
'aria-[current=page]:bg-muted aria-[current=page]:font-medium aria-[current=page]:text-foreground',
|
|
33
36
|
'[&>svg]:size-[15px] [&>svg]:shrink-0 [&>svg]:opacity-85',
|
|
34
37
|
'aria-[current=page]:[&>svg]:text-brand-text aria-[current=page]:[&>svg]:opacity-100',
|
|
@@ -26,7 +26,7 @@ function PopoverContent({
|
|
|
26
26
|
align={align}
|
|
27
27
|
sideOffset={sideOffset}
|
|
28
28
|
className={cn(
|
|
29
|
-
'z-50 flex w-72 origin-(--radix-popover-content-transform-origin) flex-col gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground shadow-pop outline-hidden duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2
|
|
29
|
+
'z-50 flex w-72 origin-(--radix-popover-content-transform-origin) flex-col gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground shadow-pop outline-hidden duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 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',
|
|
30
30
|
className,
|
|
31
31
|
)}
|
|
32
32
|
{...props}
|
|
@@ -63,7 +63,7 @@ function SelectContent({
|
|
|
63
63
|
data-slot="select-content"
|
|
64
64
|
data-align-trigger={position === 'item-aligned'}
|
|
65
65
|
className={cn(
|
|
66
|
-
'relative z-50 max-h-(--radix-select-content-available-height) w-(--radix-select-trigger-width) min-w-36 origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-xl bg-popover text-popover-foreground shadow-pop duration-100 data-[align-trigger=true]:animate-none data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2
|
|
66
|
+
'relative z-50 max-h-(--radix-select-content-available-height) w-(--radix-select-trigger-width) min-w-36 origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-xl bg-popover text-popover-foreground shadow-pop duration-100 data-[align-trigger=true]:animate-none data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 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',
|
|
67
67
|
position === 'popper' &&
|
|
68
68
|
'data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1',
|
|
69
69
|
className,
|
|
@@ -84,8 +84,11 @@ const SheetContent = React.forwardRef<
|
|
|
84
84
|
* reads as a separate object you could close. Radius is 18px — the
|
|
85
85
|
* grouped-surface step — because it is the largest surface on screen. */
|
|
86
86
|
'fixed z-50 flex flex-col overflow-hidden rounded-2xl bg-popover bg-clip-padding text-ui text-popover-foreground shadow-pop transition duration-200 ease-in-out',
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
/* Matches the inset-3 gutter on both sides — derived from --spacing
|
|
88
|
+
* rather than written as 24px, so it tracks inset-3 by construction
|
|
89
|
+
* instead of relying on this comment to stay true. */
|
|
90
|
+
'data-[side=right]:inset-y-3 data-[side=right]:right-3 data-[side=right]:w-[calc(100%-(var(--spacing)*6))] data-[side=right]:sm:max-w-md',
|
|
91
|
+
'data-[side=left]:inset-y-3 data-[side=left]:left-3 data-[side=left]:w-[calc(100%-(var(--spacing)*6))] data-[side=left]:sm:max-w-md',
|
|
89
92
|
'data-[side=bottom]:inset-x-3 data-[side=bottom]:bottom-3 data-[side=bottom]:h-auto',
|
|
90
93
|
'data-[side=top]:inset-x-3 data-[side=top]:top-3 data-[side=top]:h-auto',
|
|
91
94
|
'data-open:animate-in data-open:fade-in-0 data-[side=bottom]:data-open:slide-in-from-bottom-10 data-[side=left]:data-open:slide-in-from-left-10 data-[side=right]:data-open:slide-in-from-right-10 data-[side=top]:data-open:slide-in-from-top-10 data-closed:animate-out data-closed:fade-out-0 data-[side=bottom]:data-closed:slide-out-to-bottom-10 data-[side=left]:data-closed:slide-out-to-left-10 data-[side=right]:data-closed:slide-out-to-right-10 data-[side=top]:data-closed:slide-out-to-top-10',
|