@rise-x/apps-sdk 0.6.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/LICENSE +1 -0
- package/README.md +553 -0
- package/build/_internal.d.ts +2 -0
- package/build/_internal.js +23 -0
- package/build/accessors.d.ts +8 -0
- package/build/accessors.js +40 -0
- package/build/cli/index.d.ts +13 -0
- package/build/cli/index.js +54 -0
- package/build/cli/init.d.ts +6 -0
- package/build/cli/init.js +179 -0
- package/build/cli/templating.d.ts +2 -0
- package/build/cli/templating.js +84 -0
- package/build/connectors/agents.d.ts +85 -0
- package/build/connectors/agents.js +404 -0
- package/build/connectors/assets.d.ts +76 -0
- package/build/connectors/assets.js +204 -0
- package/build/connectors/deps.d.ts +4 -0
- package/build/connectors/deps.js +2 -0
- package/build/connectors/errors.d.ts +11 -0
- package/build/connectors/errors.js +67 -0
- package/build/connectors/flows.d.ts +37 -0
- package/build/connectors/flows.js +191 -0
- package/build/connectors/index.d.ts +8 -0
- package/build/connectors/index.js +50 -0
- package/build/connectors/sse.d.ts +12 -0
- package/build/connectors/sse.js +157 -0
- package/build/connectors/types.d.ts +285 -0
- package/build/connectors/types.js +419 -0
- package/build/connectors/work.d.ts +84 -0
- package/build/connectors/work.js +224 -0
- package/build/hooks.d.ts +4 -0
- package/build/hooks.js +28 -0
- package/build/index.d.ts +6 -0
- package/build/index.js +34 -0
- package/build/lifecycle.d.ts +23 -0
- package/build/lifecycle.js +6 -0
- package/build/mockShell.d.ts +10 -0
- package/build/mockShell.js +55 -0
- package/build/query/agents.d.ts +80 -0
- package/build/query/agents.js +143 -0
- package/build/query/assets.d.ts +73 -0
- package/build/query/assets.js +152 -0
- package/build/query/client.d.ts +5 -0
- package/build/query/client.js +68 -0
- package/build/query/context.d.ts +2 -0
- package/build/query/context.js +34 -0
- package/build/query/flows.d.ts +54 -0
- package/build/query/flows.js +81 -0
- package/build/query/index.d.ts +10 -0
- package/build/query/index.js +85 -0
- package/build/query/keys.d.ts +51 -0
- package/build/query/keys.js +79 -0
- package/build/query/layer.d.ts +175 -0
- package/build/query/layer.js +35 -0
- package/build/query/shared.d.ts +43 -0
- package/build/query/shared.js +116 -0
- package/build/query/work.d.ts +75 -0
- package/build/query/work.js +172 -0
- package/build/shell/index.d.ts +1 -0
- package/build/shell/index.js +6 -0
- package/build/shell/installShellBridge.d.ts +11 -0
- package/build/shell/installShellBridge.js +104 -0
- package/build/shellBridge.d.ts +36 -0
- package/build/shellBridge.js +10 -0
- package/build/topBar.d.ts +25 -0
- package/build/topBar.js +17 -0
- package/build/ui/components/ai.d.ts +49 -0
- package/build/ui/components/alert-dialog.d.ts +27 -0
- package/build/ui/components/alert.d.ts +14 -0
- package/build/ui/components/avatar.d.ts +17 -0
- package/build/ui/components/badge.d.ts +19 -0
- package/build/ui/components/button.d.ts +13 -0
- package/build/ui/components/calendar.d.ts +21 -0
- package/build/ui/components/card.d.ts +16 -0
- package/build/ui/components/chart.d.ts +124 -0
- package/build/ui/components/checkbox.d.ts +4 -0
- package/build/ui/components/data-table.d.ts +70 -0
- package/build/ui/components/dialog.d.ts +17 -0
- package/build/ui/components/dropdown-menu.d.ts +29 -0
- package/build/ui/components/empty-state.d.ts +7 -0
- package/build/ui/components/file-upload.d.ts +17 -0
- package/build/ui/components/input.d.ts +8 -0
- package/build/ui/components/label.d.ts +4 -0
- package/build/ui/components/list.d.ts +24 -0
- package/build/ui/components/map.d.ts +26 -0
- package/build/ui/components/message.d.ts +24 -0
- package/build/ui/components/nav.d.ts +12 -0
- package/build/ui/components/page-header.d.ts +27 -0
- package/build/ui/components/popover.d.ts +10 -0
- package/build/ui/components/progress.d.ts +4 -0
- package/build/ui/components/radio.d.ts +6 -0
- package/build/ui/components/resizable.d.ts +7 -0
- package/build/ui/components/scroll-area.d.ts +5 -0
- package/build/ui/components/segmented.d.ts +6 -0
- package/build/ui/components/select.d.ts +15 -0
- package/build/ui/components/separator.d.ts +4 -0
- package/build/ui/components/sheet.d.ts +14 -0
- package/build/ui/components/skeleton.d.ts +3 -0
- package/build/ui/components/slider.d.ts +15 -0
- package/build/ui/components/snackbar.d.ts +3 -0
- package/build/ui/components/sonner.d.ts +4 -0
- package/build/ui/components/spinner.d.ts +5 -0
- package/build/ui/components/statistic.d.ts +19 -0
- package/build/ui/components/stepper.d.ts +12 -0
- package/build/ui/components/switch.d.ts +6 -0
- package/build/ui/components/table.d.ts +24 -0
- package/build/ui/components/textarea.d.ts +3 -0
- package/build/ui/components/timeline.d.ts +15 -0
- package/build/ui/components/toggle-group.d.ts +10 -0
- package/build/ui/components/toggle.d.ts +9 -0
- package/build/ui/components/tooltip.d.ts +7 -0
- package/build/ui/index.d.ts +46 -0
- package/build/ui/index.js +8 -0
- package/build/ui/lib/utils.d.ts +2 -0
- package/build/ui/reference/README.md +11 -0
- package/build/ui/reference/components/ai.tsx +291 -0
- package/build/ui/reference/components/alert-dialog.tsx +208 -0
- package/build/ui/reference/components/alert.tsx +112 -0
- package/build/ui/reference/components/avatar.tsx +158 -0
- package/build/ui/reference/components/badge.tsx +160 -0
- package/build/ui/reference/components/button.tsx +100 -0
- package/build/ui/reference/components/calendar.tsx +119 -0
- package/build/ui/reference/components/card.tsx +144 -0
- package/build/ui/reference/components/chart.tsx +1394 -0
- package/build/ui/reference/components/checkbox.tsx +44 -0
- package/build/ui/reference/components/data-table.tsx +480 -0
- package/build/ui/reference/components/dialog.tsx +172 -0
- package/build/ui/reference/components/dropdown-menu.tsx +245 -0
- package/build/ui/reference/components/empty-state.tsx +63 -0
- package/build/ui/reference/components/file-upload.tsx +116 -0
- package/build/ui/reference/components/input.tsx +114 -0
- package/build/ui/reference/components/label.tsx +19 -0
- package/build/ui/reference/components/list.tsx +191 -0
- package/build/ui/reference/components/map.css +251 -0
- package/build/ui/reference/components/map.tsx +294 -0
- package/build/ui/reference/components/message.tsx +171 -0
- package/build/ui/reference/components/nav.tsx +113 -0
- package/build/ui/reference/components/page-header.tsx +213 -0
- package/build/ui/reference/components/popover.tsx +76 -0
- package/build/ui/reference/components/progress.tsx +31 -0
- package/build/ui/reference/components/radio.tsx +65 -0
- package/build/ui/reference/components/resizable.tsx +40 -0
- package/build/ui/reference/components/scroll-area.tsx +55 -0
- package/build/ui/reference/components/segmented.tsx +45 -0
- package/build/ui/reference/components/select.tsx +185 -0
- package/build/ui/reference/components/separator.tsx +26 -0
- package/build/ui/reference/components/sheet.tsx +173 -0
- package/build/ui/reference/components/skeleton.tsx +15 -0
- package/build/ui/reference/components/slider.tsx +161 -0
- package/build/ui/reference/components/snackbar.tsx +27 -0
- package/build/ui/reference/components/sonner.tsx +43 -0
- package/build/ui/reference/components/spinner.tsx +27 -0
- package/build/ui/reference/components/statistic.tsx +122 -0
- package/build/ui/reference/components/stepper.tsx +138 -0
- package/build/ui/reference/components/switch.tsx +47 -0
- package/build/ui/reference/components/table.tsx +233 -0
- package/build/ui/reference/components/textarea.tsx +28 -0
- package/build/ui/reference/components/timeline.tsx +94 -0
- package/build/ui/reference/components/toggle-group.tsx +86 -0
- package/build/ui/reference/components/toggle.tsx +46 -0
- package/build/ui/reference/components/tooltip.tsx +53 -0
- package/build/ui/reference/index.ts +49 -0
- package/build/ui/reference/lib/utils.ts +34 -0
- package/build/ui/standalone-stub.js +5 -0
- package/build/ui/standalone.js +135 -0
- package/build/ui/styles.css +3 -0
- package/connectors/package.json +8 -0
- package/package.json +114 -0
- package/query/package.json +8 -0
- package/shell/package.json +8 -0
- package/template/AGENTS.md +70 -0
- package/template/CLAUDE.md +4 -0
- package/template/README.md +102 -0
- package/template/_gitignore +6 -0
- package/template/commitlint.config.js +12 -0
- package/template/package.json +31 -0
- package/template/public/index.html +13 -0
- package/template/src/App.tsx +171 -0
- package/template/src/bootstrap.tsx +13 -0
- package/template/src/index.tsx +1 -0
- package/template/src/lifecycle.ts +20 -0
- package/template/tsconfig.json +31 -0
- package/template/webpack.config.js +112 -0
- package/template/webpack.local.config.js +68 -0
- package/ui/package.json +8 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { Checkbox as CheckboxPrimitive } from 'radix-ui';
|
|
5
|
+
import { CheckIcon, MinusIcon } from 'lucide-react';
|
|
6
|
+
|
|
7
|
+
import { cn } from '@rise-x/ui/lib/utils';
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* 15px box, 4px radius. Checked fills with `primary` — near-black, not brand.
|
|
11
|
+
* In a table, twenty checked rows in brand green swamp everything else on
|
|
12
|
+
* screen, and "selected" is a neutral fact about the row rather than an
|
|
13
|
+
* affirmative one about the data. Focus uses the neutral control ring.
|
|
14
|
+
*/
|
|
15
|
+
function Checkbox({ className, ...props }: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
|
|
16
|
+
return (
|
|
17
|
+
<CheckboxPrimitive.Root
|
|
18
|
+
data-slot="checkbox"
|
|
19
|
+
className={cn(
|
|
20
|
+
'peer size-[15px] shrink-0 rounded-[4px] border border-input bg-card transition-[background-color,border-color] duration-100 outline-none',
|
|
21
|
+
'focus-visible:ring-3 focus-visible:ring-ring-control/35',
|
|
22
|
+
'disabled:cursor-not-allowed disabled:opacity-45',
|
|
23
|
+
'aria-invalid:border-error aria-invalid:ring-3 aria-invalid:ring-error/20',
|
|
24
|
+
'data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground',
|
|
25
|
+
'data-[state=indeterminate]:border-primary data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-foreground',
|
|
26
|
+
className,
|
|
27
|
+
)}
|
|
28
|
+
{...props}
|
|
29
|
+
>
|
|
30
|
+
<CheckboxPrimitive.Indicator
|
|
31
|
+
data-slot="checkbox-indicator"
|
|
32
|
+
className="grid place-content-center text-current"
|
|
33
|
+
>
|
|
34
|
+
{props.checked === 'indeterminate' ? (
|
|
35
|
+
<MinusIcon className="size-2.5 stroke-[3.5]" />
|
|
36
|
+
) : (
|
|
37
|
+
<CheckIcon className="size-2.5 stroke-[3.5]" />
|
|
38
|
+
)}
|
|
39
|
+
</CheckboxPrimitive.Indicator>
|
|
40
|
+
</CheckboxPrimitive.Root>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { Checkbox };
|
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import {
|
|
5
|
+
flexRender,
|
|
6
|
+
getCoreRowModel,
|
|
7
|
+
getFacetedRowModel,
|
|
8
|
+
getFacetedUniqueValues,
|
|
9
|
+
getFilteredRowModel,
|
|
10
|
+
getSortedRowModel,
|
|
11
|
+
useReactTable,
|
|
12
|
+
type Column,
|
|
13
|
+
type ColumnDef,
|
|
14
|
+
type ColumnFiltersState,
|
|
15
|
+
type RowSelectionState,
|
|
16
|
+
type SortingState,
|
|
17
|
+
type Table as TanstackTable,
|
|
18
|
+
type VisibilityState,
|
|
19
|
+
} from '@tanstack/react-table';
|
|
20
|
+
import { ArrowDown, ArrowUp, ChevronsUpDown, Plus, Search, Settings2, X } from 'lucide-react';
|
|
21
|
+
|
|
22
|
+
import { cn } from '@rise-x/ui/lib/utils';
|
|
23
|
+
import { Badge } from '@rise-x/ui/components/badge';
|
|
24
|
+
import { Button } from '@rise-x/ui/components/button';
|
|
25
|
+
import { Checkbox } from '@rise-x/ui/components/checkbox';
|
|
26
|
+
import {
|
|
27
|
+
DropdownMenu,
|
|
28
|
+
DropdownMenuCheckboxItem,
|
|
29
|
+
DropdownMenuContent,
|
|
30
|
+
DropdownMenuLabel,
|
|
31
|
+
DropdownMenuSeparator,
|
|
32
|
+
DropdownMenuTrigger,
|
|
33
|
+
} from '@rise-x/ui/components/dropdown-menu';
|
|
34
|
+
import { Input } from '@rise-x/ui/components/input';
|
|
35
|
+
import { Separator } from '@rise-x/ui/components/separator';
|
|
36
|
+
import {
|
|
37
|
+
Table,
|
|
38
|
+
TableBody,
|
|
39
|
+
TableCell,
|
|
40
|
+
TableHead,
|
|
41
|
+
TableHeader,
|
|
42
|
+
TableRow,
|
|
43
|
+
} from '@rise-x/ui/components/table';
|
|
44
|
+
|
|
45
|
+
// Re-exported so consumers can type their columns without depending on
|
|
46
|
+
// @tanstack/react-table directly.
|
|
47
|
+
export type { ColumnDef } from '@tanstack/react-table';
|
|
48
|
+
|
|
49
|
+
export interface DataTableFilterOption {
|
|
50
|
+
label: string;
|
|
51
|
+
value: string;
|
|
52
|
+
icon?: React.ComponentType<{ className?: string }>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface FacetedFilterOption extends DataTableFilterOption {
|
|
56
|
+
/** Right-aligned tally in the menu — usually how many rows carry this value.
|
|
57
|
+
* Omitted means "not counted", and the tally is left off entirely rather
|
|
58
|
+
* than printed as 0. */
|
|
59
|
+
count?: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface FacetedFilterProps {
|
|
63
|
+
title: string;
|
|
64
|
+
options: FacetedFilterOption[];
|
|
65
|
+
/** Applied values — a Set or an array, whichever the caller already holds. */
|
|
66
|
+
selected: Iterable<string>;
|
|
67
|
+
onSelect: (value: string, checked: boolean) => void;
|
|
68
|
+
onClear: () => void;
|
|
69
|
+
className?: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface DataTableFilter {
|
|
73
|
+
/** Column id (accessorKey) the filter applies to. */
|
|
74
|
+
columnId: string;
|
|
75
|
+
title: string;
|
|
76
|
+
options: DataTableFilterOption[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface DataTableProps<TData, TValue> {
|
|
80
|
+
columns: ColumnDef<TData, TValue>[];
|
|
81
|
+
data: TData[];
|
|
82
|
+
searchPlaceholder?: string;
|
|
83
|
+
/** Faceted multi-select filters shown in the toolbar. */
|
|
84
|
+
filters?: DataTableFilter[];
|
|
85
|
+
/** Prepends a checkbox column and shows the selection count. */
|
|
86
|
+
enableRowSelection?: boolean;
|
|
87
|
+
onRowClick?: (row: TData) => void;
|
|
88
|
+
/** Extra toolbar content (e.g. a "New item" button), right-aligned. */
|
|
89
|
+
toolbarEnd?: React.ReactNode;
|
|
90
|
+
className?: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Column label for the view-options menu: `meta.label` or the column id. */
|
|
94
|
+
function getColumnLabel<TData>(column: Column<TData, unknown>): string {
|
|
95
|
+
const meta = column.columnDef.meta as { label?: string } | undefined;
|
|
96
|
+
return meta?.label ?? column.id;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Sortable column header — pass via `header: ({ column }) => <DataTableColumnHeader …/>`. */
|
|
100
|
+
export function DataTableColumnHeader<TData, TValue>({
|
|
101
|
+
column,
|
|
102
|
+
title,
|
|
103
|
+
className,
|
|
104
|
+
}: {
|
|
105
|
+
column: Column<TData, TValue>;
|
|
106
|
+
title: string;
|
|
107
|
+
className?: string;
|
|
108
|
+
}) {
|
|
109
|
+
if (!column.getCanSort()) {
|
|
110
|
+
return <div className={className}>{title}</div>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const sorted = column.getIsSorted();
|
|
114
|
+
const Icon = sorted === 'asc' ? ArrowUp : sorted === 'desc' ? ArrowDown : ChevronsUpDown;
|
|
115
|
+
return (
|
|
116
|
+
<button
|
|
117
|
+
type="button"
|
|
118
|
+
onClick={() => column.toggleSorting(sorted === 'asc')}
|
|
119
|
+
className={cn(
|
|
120
|
+
'inline-flex items-center gap-1 font-medium outline-none hover:text-foreground focus-visible:underline',
|
|
121
|
+
sorted && 'text-foreground',
|
|
122
|
+
className,
|
|
123
|
+
)}
|
|
124
|
+
>
|
|
125
|
+
{title}
|
|
126
|
+
<Icon className={cn('size-3.5', !sorted && 'text-muted-foreground')} />
|
|
127
|
+
</button>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Multi-select filter trigger + menu, with no table attached — for toolbars
|
|
133
|
+
* that filter something other than a DataTable. State is the caller's:
|
|
134
|
+
* `selected` in, `onSelect`/`onClear` out. DataTableFacetedFilter is this
|
|
135
|
+
* component wired to a TanStack column.
|
|
136
|
+
*/
|
|
137
|
+
export function FacetedFilter({
|
|
138
|
+
title,
|
|
139
|
+
options,
|
|
140
|
+
selected: selectedValues,
|
|
141
|
+
onSelect,
|
|
142
|
+
onClear,
|
|
143
|
+
className,
|
|
144
|
+
}: FacetedFilterProps) {
|
|
145
|
+
const selected = new Set(selectedValues);
|
|
146
|
+
const selectedOptions = options.filter((option) => selected.has(option.value));
|
|
147
|
+
|
|
148
|
+
/* Two states that must be told apart at a glance:
|
|
149
|
+
* empty → dashed outline + "+" + muted label ("a slot you could fill")
|
|
150
|
+
* applied → solid fill, no dash, full-strength label, white value chips
|
|
151
|
+
* The "+" disappears once something is applied (handled by the variant), and
|
|
152
|
+
* an × appears to clear THIS filter without touching the others. */
|
|
153
|
+
const hasSelection = selectedOptions.length > 0;
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<DropdownMenu>
|
|
157
|
+
<DropdownMenuTrigger asChild>
|
|
158
|
+
<Button variant="dashed" size="sm" aria-pressed={hasSelection} className={className}>
|
|
159
|
+
<Plus />
|
|
160
|
+
{title}
|
|
161
|
+
{hasSelection && (
|
|
162
|
+
<>
|
|
163
|
+
<Separator orientation="vertical" className="mx-0.5 h-3.5" />
|
|
164
|
+
{selectedOptions.length > 2 ? (
|
|
165
|
+
// 3+ collapses to a count so the trigger keeps a stable width
|
|
166
|
+
<Badge className="bg-card px-1.5 font-normal text-foreground">
|
|
167
|
+
{selectedOptions.length} selected
|
|
168
|
+
</Badge>
|
|
169
|
+
) : (
|
|
170
|
+
selectedOptions.map((option) => (
|
|
171
|
+
<Badge key={option.value} className="bg-card px-1.5 font-normal text-foreground">
|
|
172
|
+
{option.label}
|
|
173
|
+
</Badge>
|
|
174
|
+
))
|
|
175
|
+
)}
|
|
176
|
+
<span
|
|
177
|
+
role="button"
|
|
178
|
+
tabIndex={-1}
|
|
179
|
+
aria-label={`Clear ${title} filter`}
|
|
180
|
+
onPointerDown={(event) => {
|
|
181
|
+
// pointerdown, not click: the trigger would open the menu first
|
|
182
|
+
event.preventDefault();
|
|
183
|
+
event.stopPropagation();
|
|
184
|
+
onClear();
|
|
185
|
+
}}
|
|
186
|
+
className="-mr-1 ml-0.5 grid size-[17px] shrink-0 place-items-center rounded-full text-subtle transition-colors hover:bg-fill-3 hover:text-foreground"
|
|
187
|
+
>
|
|
188
|
+
<X className="size-2.5" />
|
|
189
|
+
</span>
|
|
190
|
+
</>
|
|
191
|
+
)}
|
|
192
|
+
</Button>
|
|
193
|
+
</DropdownMenuTrigger>
|
|
194
|
+
<DropdownMenuContent align="start">
|
|
195
|
+
<DropdownMenuLabel>{title}</DropdownMenuLabel>
|
|
196
|
+
{options.map((option) => (
|
|
197
|
+
<DropdownMenuCheckboxItem
|
|
198
|
+
key={option.value}
|
|
199
|
+
checked={selected.has(option.value)}
|
|
200
|
+
onCheckedChange={(checked) => onSelect(option.value, checked === true)}
|
|
201
|
+
onSelect={(event) => event.preventDefault()}
|
|
202
|
+
>
|
|
203
|
+
{option.icon && <option.icon className="size-4 text-muted-foreground" />}
|
|
204
|
+
{option.label}
|
|
205
|
+
{option.count !== undefined && (
|
|
206
|
+
<span className="ms-auto ps-3 text-xs text-muted-foreground">{option.count}</span>
|
|
207
|
+
)}
|
|
208
|
+
</DropdownMenuCheckboxItem>
|
|
209
|
+
))}
|
|
210
|
+
{selected.size > 0 && (
|
|
211
|
+
<>
|
|
212
|
+
<DropdownMenuSeparator />
|
|
213
|
+
<DropdownMenuCheckboxItem checked={false} onCheckedChange={() => onClear()}>
|
|
214
|
+
Clear filter
|
|
215
|
+
</DropdownMenuCheckboxItem>
|
|
216
|
+
</>
|
|
217
|
+
)}
|
|
218
|
+
</DropdownMenuContent>
|
|
219
|
+
</DropdownMenu>
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** FacetedFilter bound to a TanStack column: facet counts and the filter value
|
|
224
|
+
* come from the table, so the toolbar only names the column. */
|
|
225
|
+
export function DataTableFacetedFilter<TData>({
|
|
226
|
+
column,
|
|
227
|
+
title,
|
|
228
|
+
options,
|
|
229
|
+
}: {
|
|
230
|
+
column: Column<TData, unknown>;
|
|
231
|
+
title: string;
|
|
232
|
+
options: DataTableFilterOption[];
|
|
233
|
+
}) {
|
|
234
|
+
const facets = column.getFacetedUniqueValues();
|
|
235
|
+
const selected = new Set((column.getFilterValue() as string[] | undefined) ?? []);
|
|
236
|
+
|
|
237
|
+
return (
|
|
238
|
+
<FacetedFilter
|
|
239
|
+
title={title}
|
|
240
|
+
options={options.map((option) => ({ ...option, count: facets.get(option.value) ?? 0 }))}
|
|
241
|
+
selected={selected}
|
|
242
|
+
onSelect={(value, checked) => {
|
|
243
|
+
const next = new Set(selected);
|
|
244
|
+
if (checked) {
|
|
245
|
+
next.add(value);
|
|
246
|
+
} else {
|
|
247
|
+
next.delete(value);
|
|
248
|
+
}
|
|
249
|
+
column.setFilterValue(next.size ? Array.from(next) : undefined);
|
|
250
|
+
}}
|
|
251
|
+
onClear={() => column.setFilterValue(undefined)}
|
|
252
|
+
/>
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function DataTableViewOptions<TData>({ table }: { table: TanstackTable<TData> }) {
|
|
257
|
+
const columns = table
|
|
258
|
+
.getAllColumns()
|
|
259
|
+
.filter((column) => typeof column.accessorFn !== 'undefined' && column.getCanHide());
|
|
260
|
+
|
|
261
|
+
return (
|
|
262
|
+
<DropdownMenu>
|
|
263
|
+
<DropdownMenuTrigger asChild>
|
|
264
|
+
<Button variant="outline" size="sm" aria-label="Toggle columns">
|
|
265
|
+
<Settings2 />
|
|
266
|
+
View
|
|
267
|
+
</Button>
|
|
268
|
+
</DropdownMenuTrigger>
|
|
269
|
+
<DropdownMenuContent align="end">
|
|
270
|
+
<DropdownMenuLabel>Toggle columns</DropdownMenuLabel>
|
|
271
|
+
{columns.map((column) => (
|
|
272
|
+
<DropdownMenuCheckboxItem
|
|
273
|
+
key={column.id}
|
|
274
|
+
checked={column.getIsVisible()}
|
|
275
|
+
onCheckedChange={(checked) => column.toggleVisibility(checked === true)}
|
|
276
|
+
onSelect={(event) => event.preventDefault()}
|
|
277
|
+
className="capitalize"
|
|
278
|
+
>
|
|
279
|
+
{getColumnLabel(column)}
|
|
280
|
+
</DropdownMenuCheckboxItem>
|
|
281
|
+
))}
|
|
282
|
+
</DropdownMenuContent>
|
|
283
|
+
</DropdownMenu>
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Rise-X data table: search, faceted filters and column visibility are built
|
|
289
|
+
* in — every table ships with the full toolbar. Sorting via
|
|
290
|
+
* DataTableColumnHeader, optional row selection and row-click handling.
|
|
291
|
+
*/
|
|
292
|
+
export function DataTable<TData, TValue>({
|
|
293
|
+
columns,
|
|
294
|
+
data,
|
|
295
|
+
searchPlaceholder = 'Search…',
|
|
296
|
+
filters,
|
|
297
|
+
enableRowSelection = false,
|
|
298
|
+
onRowClick,
|
|
299
|
+
toolbarEnd,
|
|
300
|
+
className,
|
|
301
|
+
}: DataTableProps<TData, TValue>) {
|
|
302
|
+
const [sorting, setSorting] = React.useState<SortingState>([]);
|
|
303
|
+
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>([]);
|
|
304
|
+
const [columnVisibility, setColumnVisibility] = React.useState<VisibilityState>({});
|
|
305
|
+
const [rowSelection, setRowSelection] = React.useState<RowSelectionState>({});
|
|
306
|
+
const [globalFilter, setGlobalFilter] = React.useState('');
|
|
307
|
+
|
|
308
|
+
const allColumns = React.useMemo(() => {
|
|
309
|
+
// Faceted filters store arrays — give their columns the matching filterFn.
|
|
310
|
+
const facetedIds = new Set(filters?.map((filter) => filter.columnId));
|
|
311
|
+
const withFilterFn = columns.map((column) => {
|
|
312
|
+
const id = column.id ?? (column as { accessorKey?: string }).accessorKey;
|
|
313
|
+
return id && facetedIds.has(id)
|
|
314
|
+
? { ...column, filterFn: 'arrIncludesSome' as const }
|
|
315
|
+
: column;
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
if (!enableRowSelection) return withFilterFn;
|
|
319
|
+
const selectColumn: ColumnDef<TData, TValue> = {
|
|
320
|
+
id: 'select',
|
|
321
|
+
/* PAGE rows, not ALL rows. With filters on, `getIsAllRowsSelected` /
|
|
322
|
+
* `toggleAllRowsSelected` reach rows the user cannot see: select-all would
|
|
323
|
+
* check hidden rows, the footer (which counts the FILTERED selection)
|
|
324
|
+
* would disagree with the box, and clearing the filter would reveal rows
|
|
325
|
+
* silently selected. There is no pagination here, so "page" is exactly the
|
|
326
|
+
* filtered set — i.e. what is on screen. */
|
|
327
|
+
header: ({ table }) => (
|
|
328
|
+
<Checkbox
|
|
329
|
+
checked={
|
|
330
|
+
table.getIsAllPageRowsSelected() ||
|
|
331
|
+
(table.getIsSomePageRowsSelected() && 'indeterminate')
|
|
332
|
+
}
|
|
333
|
+
onCheckedChange={(checked) => table.toggleAllPageRowsSelected(checked === true)}
|
|
334
|
+
aria-label="Select all rows"
|
|
335
|
+
/>
|
|
336
|
+
),
|
|
337
|
+
cell: ({ row }) => (
|
|
338
|
+
<Checkbox
|
|
339
|
+
checked={row.getIsSelected()}
|
|
340
|
+
onCheckedChange={(checked) => row.toggleSelected(checked === true)}
|
|
341
|
+
onClick={(event) => event.stopPropagation()}
|
|
342
|
+
aria-label="Select row"
|
|
343
|
+
/>
|
|
344
|
+
),
|
|
345
|
+
enableSorting: false,
|
|
346
|
+
enableHiding: false,
|
|
347
|
+
};
|
|
348
|
+
return [selectColumn, ...withFilterFn];
|
|
349
|
+
}, [columns, filters, enableRowSelection]);
|
|
350
|
+
|
|
351
|
+
const table = useReactTable({
|
|
352
|
+
data,
|
|
353
|
+
columns: allColumns,
|
|
354
|
+
state: { sorting, columnFilters, columnVisibility, rowSelection, globalFilter },
|
|
355
|
+
enableRowSelection,
|
|
356
|
+
onSortingChange: setSorting,
|
|
357
|
+
onColumnFiltersChange: setColumnFilters,
|
|
358
|
+
onColumnVisibilityChange: setColumnVisibility,
|
|
359
|
+
onRowSelectionChange: setRowSelection,
|
|
360
|
+
onGlobalFilterChange: setGlobalFilter,
|
|
361
|
+
globalFilterFn: 'includesString',
|
|
362
|
+
getCoreRowModel: getCoreRowModel(),
|
|
363
|
+
getFilteredRowModel: getFilteredRowModel(),
|
|
364
|
+
getSortedRowModel: getSortedRowModel(),
|
|
365
|
+
getFacetedRowModel: getFacetedRowModel(),
|
|
366
|
+
getFacetedUniqueValues: getFacetedUniqueValues(),
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
const isFiltered = globalFilter !== '' || columnFilters.length > 0;
|
|
370
|
+
const rows = table.getRowModel().rows;
|
|
371
|
+
|
|
372
|
+
return (
|
|
373
|
+
<div className={cn('flex flex-col gap-3', className)}>
|
|
374
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
375
|
+
<div className="relative">
|
|
376
|
+
<Search className="pointer-events-none absolute top-1/2 left-2.5 size-3.5 -translate-y-1/2 text-subtle" />
|
|
377
|
+
<Input
|
|
378
|
+
value={globalFilter}
|
|
379
|
+
onChange={(event) => setGlobalFilter(event.target.value)}
|
|
380
|
+
placeholder={searchPlaceholder}
|
|
381
|
+
className="h-control-sm w-52 pl-7"
|
|
382
|
+
aria-label={searchPlaceholder}
|
|
383
|
+
/>
|
|
384
|
+
</div>
|
|
385
|
+
{filters?.map((filter) => {
|
|
386
|
+
const column = table.getColumn(filter.columnId);
|
|
387
|
+
if (!column) return null;
|
|
388
|
+
return (
|
|
389
|
+
<DataTableFacetedFilter
|
|
390
|
+
key={filter.columnId}
|
|
391
|
+
column={column}
|
|
392
|
+
title={filter.title}
|
|
393
|
+
options={filter.options}
|
|
394
|
+
/>
|
|
395
|
+
);
|
|
396
|
+
})}
|
|
397
|
+
{isFiltered && (
|
|
398
|
+
<Button
|
|
399
|
+
variant="ghost"
|
|
400
|
+
size="sm"
|
|
401
|
+
className="text-muted-foreground"
|
|
402
|
+
onClick={() => {
|
|
403
|
+
setGlobalFilter('');
|
|
404
|
+
table.resetColumnFilters();
|
|
405
|
+
}}
|
|
406
|
+
>
|
|
407
|
+
<X />
|
|
408
|
+
{/* Reset only appears when something is on, and says how much it
|
|
409
|
+
* will undo — "Reset" alone on a bar of four filters is a guess. */}
|
|
410
|
+
Reset{columnFilters.length > 1 ? ` all (${columnFilters.length})` : ''}
|
|
411
|
+
</Button>
|
|
412
|
+
)}
|
|
413
|
+
<div className="ms-auto flex items-center gap-2">
|
|
414
|
+
{toolbarEnd}
|
|
415
|
+
<DataTableViewOptions table={table} />
|
|
416
|
+
</div>
|
|
417
|
+
</div>
|
|
418
|
+
|
|
419
|
+
<div className="overflow-x-auto rounded-2xl border border-border bg-card text-card-foreground">
|
|
420
|
+
<Table>
|
|
421
|
+
<TableHeader>
|
|
422
|
+
{table.getHeaderGroups().map((headerGroup) => (
|
|
423
|
+
<TableRow key={headerGroup.id} className="hover:bg-transparent">
|
|
424
|
+
{headerGroup.headers.map((header) => (
|
|
425
|
+
<TableHead key={header.id}>
|
|
426
|
+
{header.isPlaceholder
|
|
427
|
+
? null
|
|
428
|
+
: flexRender(header.column.columnDef.header, header.getContext())}
|
|
429
|
+
</TableHead>
|
|
430
|
+
))}
|
|
431
|
+
</TableRow>
|
|
432
|
+
))}
|
|
433
|
+
</TableHeader>
|
|
434
|
+
<TableBody>
|
|
435
|
+
{rows.length ? (
|
|
436
|
+
rows.map((row) => (
|
|
437
|
+
<TableRow
|
|
438
|
+
key={row.id}
|
|
439
|
+
data-state={row.getIsSelected() && 'selected'}
|
|
440
|
+
onClick={onRowClick ? () => onRowClick(row.original) : undefined}
|
|
441
|
+
className={cn(onRowClick && 'cursor-pointer')}
|
|
442
|
+
>
|
|
443
|
+
{row.getVisibleCells().map((cell) => (
|
|
444
|
+
<TableCell key={cell.id}>
|
|
445
|
+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
446
|
+
</TableCell>
|
|
447
|
+
))}
|
|
448
|
+
</TableRow>
|
|
449
|
+
))
|
|
450
|
+
) : (
|
|
451
|
+
<TableRow className="hover:bg-transparent">
|
|
452
|
+
<TableCell
|
|
453
|
+
colSpan={table.getVisibleLeafColumns().length}
|
|
454
|
+
className="h-24 text-center text-muted-foreground"
|
|
455
|
+
>
|
|
456
|
+
No results.
|
|
457
|
+
</TableCell>
|
|
458
|
+
</TableRow>
|
|
459
|
+
)}
|
|
460
|
+
</TableBody>
|
|
461
|
+
</Table>
|
|
462
|
+
</div>
|
|
463
|
+
|
|
464
|
+
{/* Lazy loading, not pagination — so the footer reports scope rather than
|
|
465
|
+
* offering page controls. */}
|
|
466
|
+
<div className="flex items-center justify-between text-xs text-muted-foreground">
|
|
467
|
+
<span>
|
|
468
|
+
{enableRowSelection
|
|
469
|
+
? `${table.getFilteredSelectedRowModel().rows.length} of ${
|
|
470
|
+
table.getFilteredRowModel().rows.length
|
|
471
|
+
} row(s) selected`
|
|
472
|
+
: `${table.getFilteredRowModel().rows.length} row(s)`}
|
|
473
|
+
</span>
|
|
474
|
+
<span>
|
|
475
|
+
Showing <b className="font-medium text-foreground">{rows.length}</b> of {data.length}
|
|
476
|
+
</span>
|
|
477
|
+
</div>
|
|
478
|
+
</div>
|
|
479
|
+
);
|
|
480
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Dialog as DialogPrimitive } from 'radix-ui';
|
|
3
|
+
|
|
4
|
+
import { cn } from '@rise-x/ui/lib/utils';
|
|
5
|
+
import { Button } from '@rise-x/ui/components/button';
|
|
6
|
+
import { XIcon } from 'lucide-react';
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* forwardRef throughout, for the same reason button.tsx and alert-dialog.tsx use
|
|
10
|
+
* it: the classic React 18 host renders these components too, and React 18
|
|
11
|
+
* strips `ref` from a plain function component instead of passing it as a prop.
|
|
12
|
+
*
|
|
13
|
+
* This is not only about refs a caller passes. Radix refs the overlay ITSELF:
|
|
14
|
+
* DialogContent puts <DialogOverlay /> inside the portal, and radix's Portal
|
|
15
|
+
* wraps each child in Presence + `Primitive.div asChild`, whose Slot hands the
|
|
16
|
+
* child a composed ref. Under React 18 a plain-function overlay drops it, so
|
|
17
|
+
* Presence never sees the overlay node and closes it without its exit
|
|
18
|
+
* animation — plus a "Function components cannot be given refs" warning on
|
|
19
|
+
* every open. Only Dialog (Root) and DialogPortal are left as plain functions:
|
|
20
|
+
* neither renders a DOM node, and radix's own are plain too.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
function Dialog({ ...props }: React.ComponentProps<typeof DialogPrimitive.Root>) {
|
|
24
|
+
return <DialogPrimitive.Root data-slot="dialog" {...props} />;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const DialogTrigger = React.forwardRef<
|
|
28
|
+
HTMLButtonElement,
|
|
29
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Trigger>
|
|
30
|
+
>(function DialogTrigger({ ...props }, ref) {
|
|
31
|
+
return <DialogPrimitive.Trigger ref={ref} data-slot="dialog-trigger" {...props} />;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
function DialogPortal({ ...props }: React.ComponentProps<typeof DialogPrimitive.Portal>) {
|
|
35
|
+
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const DialogClose = React.forwardRef<
|
|
39
|
+
HTMLButtonElement,
|
|
40
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Close>
|
|
41
|
+
>(function DialogClose({ ...props }, ref) {
|
|
42
|
+
return <DialogPrimitive.Close ref={ref} data-slot="dialog-close" {...props} />;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const DialogOverlay = React.forwardRef<
|
|
46
|
+
HTMLDivElement,
|
|
47
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
|
|
48
|
+
>(function DialogOverlay({ className, ...props }, ref) {
|
|
49
|
+
return (
|
|
50
|
+
<DialogPrimitive.Overlay
|
|
51
|
+
ref={ref}
|
|
52
|
+
data-slot="dialog-overlay"
|
|
53
|
+
className={cn(
|
|
54
|
+
'fixed inset-0 isolate z-50 bg-black/30 duration-100 supports-backdrop-filter:backdrop-blur-sm data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0',
|
|
55
|
+
className,
|
|
56
|
+
)}
|
|
57
|
+
{...props}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const DialogContent = React.forwardRef<
|
|
63
|
+
HTMLDivElement,
|
|
64
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & {
|
|
65
|
+
showCloseButton?: boolean;
|
|
66
|
+
}
|
|
67
|
+
>(function DialogContent({ className, children, showCloseButton = true, ...props }, ref) {
|
|
68
|
+
return (
|
|
69
|
+
<DialogPortal>
|
|
70
|
+
<DialogOverlay />
|
|
71
|
+
<DialogPrimitive.Content
|
|
72
|
+
ref={ref}
|
|
73
|
+
data-slot="dialog-content"
|
|
74
|
+
className={cn(
|
|
75
|
+
'fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -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 dark:ring-foreground/10 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
|
+
className,
|
|
77
|
+
)}
|
|
78
|
+
{...props}
|
|
79
|
+
>
|
|
80
|
+
{children}
|
|
81
|
+
{showCloseButton && (
|
|
82
|
+
<DialogPrimitive.Close data-slot="dialog-close" asChild>
|
|
83
|
+
<Button variant="ghost" className="absolute top-4 right-4 bg-secondary" size="icon-sm">
|
|
84
|
+
<XIcon />
|
|
85
|
+
<span className="sr-only">Close</span>
|
|
86
|
+
</Button>
|
|
87
|
+
</DialogPrimitive.Close>
|
|
88
|
+
)}
|
|
89
|
+
</DialogPrimitive.Content>
|
|
90
|
+
</DialogPortal>
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const DialogHeader = React.forwardRef<HTMLDivElement, React.ComponentPropsWithoutRef<'div'>>(
|
|
95
|
+
function DialogHeader({ className, ...props }, ref) {
|
|
96
|
+
return (
|
|
97
|
+
<div
|
|
98
|
+
ref={ref}
|
|
99
|
+
data-slot="dialog-header"
|
|
100
|
+
className={cn('flex flex-col gap-1.5', className)}
|
|
101
|
+
{...props}
|
|
102
|
+
/>
|
|
103
|
+
);
|
|
104
|
+
},
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const DialogFooter = React.forwardRef<
|
|
108
|
+
HTMLDivElement,
|
|
109
|
+
React.ComponentPropsWithoutRef<'div'> & {
|
|
110
|
+
showCloseButton?: boolean;
|
|
111
|
+
}
|
|
112
|
+
>(function DialogFooter({ className, showCloseButton = false, children, ...props }, ref) {
|
|
113
|
+
return (
|
|
114
|
+
<div
|
|
115
|
+
ref={ref}
|
|
116
|
+
data-slot="dialog-footer"
|
|
117
|
+
className={cn('flex flex-col-reverse gap-2 sm:flex-row sm:justify-end', className)}
|
|
118
|
+
{...props}
|
|
119
|
+
>
|
|
120
|
+
{children}
|
|
121
|
+
{showCloseButton && (
|
|
122
|
+
<DialogPrimitive.Close asChild>
|
|
123
|
+
<Button variant="outline">Close</Button>
|
|
124
|
+
</DialogPrimitive.Close>
|
|
125
|
+
)}
|
|
126
|
+
</div>
|
|
127
|
+
);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const DialogTitle = React.forwardRef<
|
|
131
|
+
HTMLHeadingElement,
|
|
132
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
|
|
133
|
+
>(function DialogTitle({ className, ...props }, ref) {
|
|
134
|
+
return (
|
|
135
|
+
<DialogPrimitive.Title
|
|
136
|
+
ref={ref}
|
|
137
|
+
data-slot="dialog-title"
|
|
138
|
+
className={cn('text-ui font-medium leading-none', className)}
|
|
139
|
+
{...props}
|
|
140
|
+
/>
|
|
141
|
+
);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const DialogDescription = React.forwardRef<
|
|
145
|
+
HTMLParagraphElement,
|
|
146
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
|
|
147
|
+
>(function DialogDescription({ className, ...props }, ref) {
|
|
148
|
+
return (
|
|
149
|
+
<DialogPrimitive.Description
|
|
150
|
+
ref={ref}
|
|
151
|
+
data-slot="dialog-description"
|
|
152
|
+
className={cn(
|
|
153
|
+
'text-sm text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground',
|
|
154
|
+
className,
|
|
155
|
+
)}
|
|
156
|
+
{...props}
|
|
157
|
+
/>
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
export {
|
|
162
|
+
Dialog,
|
|
163
|
+
DialogClose,
|
|
164
|
+
DialogContent,
|
|
165
|
+
DialogDescription,
|
|
166
|
+
DialogFooter,
|
|
167
|
+
DialogHeader,
|
|
168
|
+
DialogOverlay,
|
|
169
|
+
DialogPortal,
|
|
170
|
+
DialogTitle,
|
|
171
|
+
DialogTrigger,
|
|
172
|
+
};
|