@mdxui/do 4.0.1 → 4.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/index.d.ts +32 -186
- package/dist/app/index.js +19 -11
- package/dist/auth/index.d.ts +48 -0
- package/dist/auth/index.js +4 -0
- package/dist/{breadcrumbs-C9Qn3S7d.d.ts → breadcrumbs-DltlCiHt.d.ts} +3 -3
- package/dist/chunk-2FWXT4HH.js +576 -0
- package/dist/chunk-2FWXT4HH.js.map +1 -0
- package/dist/chunk-5PC6U46L.js +604 -0
- package/dist/chunk-5PC6U46L.js.map +1 -0
- package/dist/chunk-63VCRTDQ.js +2505 -0
- package/dist/chunk-63VCRTDQ.js.map +1 -0
- package/dist/chunk-7J3RSIG4.js +178 -0
- package/dist/chunk-7J3RSIG4.js.map +1 -0
- package/dist/chunk-7QCTRNEJ.js +173 -0
- package/dist/chunk-7QCTRNEJ.js.map +1 -0
- package/dist/chunk-7TFHUKS7.js +66 -0
- package/dist/chunk-7TFHUKS7.js.map +1 -0
- package/dist/{chunk-LJIWB7KE.js → chunk-BU5HMHGQ.js} +3 -3
- package/dist/chunk-BU5HMHGQ.js.map +1 -0
- package/dist/{chunk-GGO5GW72.js → chunk-BZURBNFD.js} +305 -51
- package/dist/chunk-BZURBNFD.js.map +1 -0
- package/dist/{chunk-XH3LVW7J.js → chunk-FM2RTAHV.js} +5 -65
- package/dist/chunk-FM2RTAHV.js.map +1 -0
- package/dist/{chunk-OHWWWONS.js → chunk-HC4PBXV4.js} +131 -58
- package/dist/chunk-HC4PBXV4.js.map +1 -0
- package/dist/{chunk-Y52IEYVM.js → chunk-JPZ6RZJE.js} +78 -45
- package/dist/chunk-JPZ6RZJE.js.map +1 -0
- package/dist/{chunk-KAZJ43F6.js → chunk-KLN5OTQH.js} +168 -361
- package/dist/chunk-KLN5OTQH.js.map +1 -0
- package/dist/chunk-LCYBQR35.js +79 -0
- package/dist/chunk-LCYBQR35.js.map +1 -0
- package/dist/chunk-PJYGRD7N.js +216 -0
- package/dist/chunk-PJYGRD7N.js.map +1 -0
- package/dist/chunk-QEXY4FZV.js +292 -0
- package/dist/chunk-QEXY4FZV.js.map +1 -0
- package/dist/chunk-SX4IIE2R.js +53 -0
- package/dist/chunk-SX4IIE2R.js.map +1 -0
- package/dist/chunk-UCWMSKCW.js +901 -0
- package/dist/chunk-UCWMSKCW.js.map +1 -0
- package/dist/{chunk-YMQRC6IC.js → chunk-WC6SFBAF.js} +59 -6
- package/dist/chunk-WC6SFBAF.js.map +1 -0
- package/dist/chunk-WIKU77ZY.js +18 -0
- package/dist/chunk-WIKU77ZY.js.map +1 -0
- package/dist/chunk-X3AWNFBF.js +47 -0
- package/dist/chunk-X3AWNFBF.js.map +1 -0
- package/dist/chunk-ZZTQGMLX.js +23 -0
- package/dist/chunk-ZZTQGMLX.js.map +1 -0
- package/dist/{lib → client}/index.d.ts +97 -345
- package/dist/client/index.js +3 -0
- package/dist/common-DW_JM2dW.d.ts +454 -0
- package/dist/components/index.d.ts +11 -2
- package/dist/components/index.js +8 -3
- package/dist/{config-CxvpD8Y6.d.ts → config-DB14_LhF.d.ts} +1 -1
- package/dist/{do-D27i5bU0.d.ts → do-D37hbmL9.d.ts} +6 -14
- package/dist/dotdo-client-2DkwXHM2.d.ts +344 -0
- package/dist/errors-BOY11CJs.d.ts +373 -0
- package/dist/features/data-browser/index.d.ts +51 -0
- package/dist/features/data-browser/index.js +12 -0
- package/dist/features/data-browser/index.js.map +1 -0
- package/dist/features/data-grid/index.d.ts +22 -0
- package/dist/features/data-grid/index.js +12 -0
- package/dist/features/data-grid/index.js.map +1 -0
- package/dist/features/document-editor/index.d.ts +26 -0
- package/dist/features/document-editor/index.js +12 -0
- package/dist/features/document-editor/index.js.map +1 -0
- package/dist/features/function-editor/index.d.ts +215 -0
- package/dist/features/function-editor/index.js +7 -0
- package/dist/features/function-editor/index.js.map +1 -0
- package/dist/hooks/index.d.ts +64 -7
- package/dist/hooks/index.js +8 -7
- package/dist/hooks/things/index.d.ts +5 -297
- package/dist/hooks/things/index.js +6 -6
- package/dist/index-C0m9UI6W.d.ts +444 -0
- package/dist/index.d.ts +41 -31
- package/dist/index.js +21 -13
- package/dist/providers/index.d.ts +16 -28
- package/dist/providers/index.js +3 -3
- package/dist/schemas/index.d.ts +4551 -109
- package/dist/schemas/index.js +2 -260
- package/dist/schemas/index.js.map +1 -1
- package/dist/shell/index.d.ts +92 -0
- package/dist/shell/index.js +6 -0
- package/dist/shell/index.js.map +1 -0
- package/dist/{thing-BF25aUtJ.d.ts → thing-Dc3AE2XI.d.ts} +22 -22
- package/dist/thing-adapters-aMjF0h9u.d.ts +1214 -0
- package/dist/types/index.d.ts +954 -7521
- package/dist/types/index.js +2 -2
- package/dist/ui-filters-BvrjMP_U.d.ts +108 -0
- package/dist/{errors-DratdVIz.d.ts → utils/index.d.ts} +38 -77
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist-app/assets/index-DWX3479M.js +7 -0
- package/dist-app/assets/index-DWX3479M.js.map +1 -0
- package/dist-app/assets/main-BptePr_C.js +318 -0
- package/dist-app/assets/main-BptePr_C.js.map +1 -0
- package/dist-app/assets/main-CS9jgKzj.css +1 -0
- package/dist-app/index.html +38 -0
- package/package.json +46 -33
- package/dist/agents-2_r9e9i7.d.ts +0 -1043
- package/dist/capnweb-client-Bq78FtEA.d.ts +0 -229
- package/dist/chunk-3XKYQRXY.js +0 -192
- package/dist/chunk-3XKYQRXY.js.map +0 -1
- package/dist/chunk-4KXVN3EQ.js +0 -56
- package/dist/chunk-4KXVN3EQ.js.map +0 -1
- package/dist/chunk-GGO5GW72.js.map +0 -1
- package/dist/chunk-GYIMQZE7.js +0 -1994
- package/dist/chunk-GYIMQZE7.js.map +0 -1
- package/dist/chunk-IQ23B4ME.js +0 -944
- package/dist/chunk-IQ23B4ME.js.map +0 -1
- package/dist/chunk-JJLAES6W.js +0 -76
- package/dist/chunk-JJLAES6W.js.map +0 -1
- package/dist/chunk-KAZJ43F6.js.map +0 -1
- package/dist/chunk-LJIWB7KE.js.map +0 -1
- package/dist/chunk-OHWWWONS.js.map +0 -1
- package/dist/chunk-VRLUXCLD.js +0 -31
- package/dist/chunk-VRLUXCLD.js.map +0 -1
- package/dist/chunk-XH3LVW7J.js.map +0 -1
- package/dist/chunk-Y52IEYVM.js.map +0 -1
- package/dist/chunk-YMQRC6IC.js.map +0 -1
- package/dist/lib/index.js +0 -6
- package/dist/query-keys-CZNFikIi.d.ts +0 -153
- package/dist/views/index.d.ts +0 -131
- package/dist/views/index.js +0 -11
- /package/dist/{lib → auth}/index.js.map +0 -0
- /package/dist/{views → client}/index.js.map +0 -0
package/dist/chunk-GYIMQZE7.js
DELETED
|
@@ -1,1994 +0,0 @@
|
|
|
1
|
-
import { useNamespaces, useTypes } from './chunk-XH3LVW7J.js';
|
|
2
|
-
import { useCreateThing, useThings, useThing, useUpdateThing, useDeleteThing } from './chunk-YMQRC6IC.js';
|
|
3
|
-
import { useDO } from './chunk-OHWWWONS.js';
|
|
4
|
-
import { cn } from './chunk-Y52IEYVM.js';
|
|
5
|
-
import * as React4 from 'react';
|
|
6
|
-
import { parseQuery, applyQueryFilter, DataSidebar, DataSidebarTrigger, QuerySearch, ViewSwitcher, DataFilterPopover, DatabaseListView, DatabaseTableView, DatabaseCardView, DatabaseCodeView, applyFilters, useEditHistory, DatabaseSidebar, TableEditorToolbar, DatabaseGrid, QueryView, FormatView, ColumnEditorPanel, TableCreatorPanel, DocumentSidebar, DocumentViewToolbar, DocumentEditor, FunctionSidebar, FunctionViewToolbar, SDKEditor } from '@mdxui/admin';
|
|
7
|
-
export { DataFilterPopover, DataSidebar, DataSidebarTrigger, FILTER_OPERATOR_OPTIONS } from '@mdxui/admin';
|
|
8
|
-
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, Label, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, Input, Textarea, DialogFooter, Button, Sheet, SheetContent, SheetHeader, SheetTitle, SheetDescription, Badge, ScrollArea, SheetFooter, Tooltip, TooltipTrigger, TooltipContent, TooltipProvider, AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogTitle, AlertDialogDescription, AlertDialogFooter, AlertDialogCancel, AlertDialogAction, DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuCheckboxItem, DropdownMenuItem, Toaster } from '@mdxui/primitives';
|
|
9
|
-
import { Hash, Save, Pencil, Copy, Shapes, X, Trash2, Columns3, Plus, MoreVertical, Download, RefreshCw, Database, ExternalLink, Calendar, Clock } from 'lucide-react';
|
|
10
|
-
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
11
|
-
import { toast } from 'sonner';
|
|
12
|
-
|
|
13
|
-
function CreateDialog({
|
|
14
|
-
open,
|
|
15
|
-
onOpenChange,
|
|
16
|
-
namespace,
|
|
17
|
-
defaultType,
|
|
18
|
-
types,
|
|
19
|
-
onCreated
|
|
20
|
-
}) {
|
|
21
|
-
const [selectedType, setSelectedType] = React4.useState(defaultType ?? "");
|
|
22
|
-
const [name, setName] = React4.useState("");
|
|
23
|
-
const [dataJson, setDataJson] = React4.useState("{}");
|
|
24
|
-
const [jsonError, setJsonError] = React4.useState(null);
|
|
25
|
-
const createMutation = useCreateThing();
|
|
26
|
-
React4.useEffect(() => {
|
|
27
|
-
if (open) {
|
|
28
|
-
setSelectedType(defaultType ?? "");
|
|
29
|
-
setName("");
|
|
30
|
-
setDataJson("{}");
|
|
31
|
-
setJsonError(null);
|
|
32
|
-
}
|
|
33
|
-
}, [open, defaultType]);
|
|
34
|
-
const handleSubmit = async (e) => {
|
|
35
|
-
e.preventDefault();
|
|
36
|
-
setJsonError(null);
|
|
37
|
-
let parsedData;
|
|
38
|
-
try {
|
|
39
|
-
parsedData = JSON.parse(dataJson);
|
|
40
|
-
} catch {
|
|
41
|
-
setJsonError("Invalid JSON format");
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
const result = await createMutation.mutateAsync({
|
|
46
|
-
ns: namespace,
|
|
47
|
-
type: selectedType,
|
|
48
|
-
name: name.trim(),
|
|
49
|
-
data: parsedData
|
|
50
|
-
});
|
|
51
|
-
onCreated?.(result);
|
|
52
|
-
onOpenChange(false);
|
|
53
|
-
} catch (error) {
|
|
54
|
-
console.error("Failed to create thing:", error);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxs(DialogContent, { children: [
|
|
58
|
-
/* @__PURE__ */ jsxs(DialogHeader, { children: [
|
|
59
|
-
/* @__PURE__ */ jsx(DialogTitle, { children: "Create New Thing" }),
|
|
60
|
-
/* @__PURE__ */ jsxs(DialogDescription, { children: [
|
|
61
|
-
'Create a new thing in namespace "',
|
|
62
|
-
namespace,
|
|
63
|
-
'"'
|
|
64
|
-
] })
|
|
65
|
-
] }),
|
|
66
|
-
/* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, className: "space-y-4", children: [
|
|
67
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
68
|
-
/* @__PURE__ */ jsx(Label, { htmlFor: "type", children: "Type" }),
|
|
69
|
-
/* @__PURE__ */ jsxs(Select, { value: selectedType, onValueChange: setSelectedType, children: [
|
|
70
|
-
/* @__PURE__ */ jsx(SelectTrigger, { children: /* @__PURE__ */ jsx(SelectValue, { placeholder: "Select a type" }) }),
|
|
71
|
-
/* @__PURE__ */ jsx(SelectContent, { children: types.map((type) => /* @__PURE__ */ jsx(SelectItem, { value: type.name, children: type.label }, type.id)) })
|
|
72
|
-
] })
|
|
73
|
-
] }),
|
|
74
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
75
|
-
/* @__PURE__ */ jsx(Label, { htmlFor: "name", children: "Name" }),
|
|
76
|
-
/* @__PURE__ */ jsx(
|
|
77
|
-
Input,
|
|
78
|
-
{
|
|
79
|
-
id: "name",
|
|
80
|
-
value: name,
|
|
81
|
-
onChange: (e) => setName(e.target.value),
|
|
82
|
-
placeholder: "Enter a name",
|
|
83
|
-
required: true
|
|
84
|
-
}
|
|
85
|
-
)
|
|
86
|
-
] }),
|
|
87
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
88
|
-
/* @__PURE__ */ jsx(Label, { htmlFor: "data", children: "Data (JSON)" }),
|
|
89
|
-
/* @__PURE__ */ jsx(
|
|
90
|
-
Textarea,
|
|
91
|
-
{
|
|
92
|
-
id: "data",
|
|
93
|
-
value: dataJson,
|
|
94
|
-
onChange: (e) => {
|
|
95
|
-
setDataJson(e.target.value);
|
|
96
|
-
setJsonError(null);
|
|
97
|
-
},
|
|
98
|
-
placeholder: '{"key": "value"}',
|
|
99
|
-
className: "font-mono text-sm min-h-[100px]"
|
|
100
|
-
}
|
|
101
|
-
),
|
|
102
|
-
jsonError && /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: jsonError })
|
|
103
|
-
] }),
|
|
104
|
-
/* @__PURE__ */ jsxs(DialogFooter, { children: [
|
|
105
|
-
/* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", onClick: () => onOpenChange(false), children: "Cancel" }),
|
|
106
|
-
/* @__PURE__ */ jsx(
|
|
107
|
-
Button,
|
|
108
|
-
{
|
|
109
|
-
type: "submit",
|
|
110
|
-
disabled: !selectedType || !name.trim() || createMutation.isLoading,
|
|
111
|
-
children: createMutation.isLoading ? "Creating..." : "Create"
|
|
112
|
-
}
|
|
113
|
-
)
|
|
114
|
-
] })
|
|
115
|
-
] })
|
|
116
|
-
] }) });
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// src/views/utils/date-formatting.ts
|
|
120
|
-
function isISODateString(value) {
|
|
121
|
-
if (typeof value !== "string") return false;
|
|
122
|
-
const date = new Date(value);
|
|
123
|
-
return !isNaN(date.getTime()) && value.includes("T");
|
|
124
|
-
}
|
|
125
|
-
function formatDate(dateValue) {
|
|
126
|
-
const date = typeof dateValue === "string" ? new Date(dateValue) : dateValue;
|
|
127
|
-
const now = /* @__PURE__ */ new Date();
|
|
128
|
-
const diffMs = now.getTime() - date.getTime();
|
|
129
|
-
const diffMins = Math.floor(diffMs / 6e4);
|
|
130
|
-
const diffHours = Math.floor(diffMins / 60);
|
|
131
|
-
const diffDays = Math.floor(diffHours / 24);
|
|
132
|
-
let relative;
|
|
133
|
-
if (diffMins < 1) relative = "Just now";
|
|
134
|
-
else if (diffMins < 60) relative = `${diffMins} minute${diffMins !== 1 ? "s" : ""} ago`;
|
|
135
|
-
else if (diffHours < 24) relative = `${diffHours} hour${diffHours !== 1 ? "s" : ""} ago`;
|
|
136
|
-
else if (diffDays < 7) relative = `${diffDays} day${diffDays !== 1 ? "s" : ""} ago`;
|
|
137
|
-
else
|
|
138
|
-
relative = date.toLocaleDateString("en-US", {
|
|
139
|
-
month: "short",
|
|
140
|
-
day: "numeric",
|
|
141
|
-
year: "numeric"
|
|
142
|
-
});
|
|
143
|
-
return {
|
|
144
|
-
date: date.toLocaleDateString("en-US", {
|
|
145
|
-
weekday: "short",
|
|
146
|
-
month: "short",
|
|
147
|
-
day: "numeric",
|
|
148
|
-
year: "numeric"
|
|
149
|
-
}),
|
|
150
|
-
time: date.toLocaleTimeString("en-US", {
|
|
151
|
-
hour: "2-digit",
|
|
152
|
-
minute: "2-digit"
|
|
153
|
-
}),
|
|
154
|
-
relative
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
function formatFieldName(key) {
|
|
158
|
-
return key.replace(/([A-Z])/g, " $1").replace(/_/g, " ").replace(/^./, (str) => str.toUpperCase()).trim();
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// src/views/utils/export.ts
|
|
162
|
-
function exportToJSON(data, filename) {
|
|
163
|
-
const json = JSON.stringify(data, null, 2);
|
|
164
|
-
const blob = new Blob([json], { type: "application/json" });
|
|
165
|
-
const url = URL.createObjectURL(blob);
|
|
166
|
-
const link = document.createElement("a");
|
|
167
|
-
link.href = url;
|
|
168
|
-
link.download = `${filename}.json`;
|
|
169
|
-
document.body.appendChild(link);
|
|
170
|
-
link.click();
|
|
171
|
-
document.body.removeChild(link);
|
|
172
|
-
URL.revokeObjectURL(url);
|
|
173
|
-
}
|
|
174
|
-
function DetailSheet({ open, onOpenChange, thing, onEdit, onSave }) {
|
|
175
|
-
const [isEditing, setIsEditing] = React4.useState(false);
|
|
176
|
-
const [editedName, setEditedName] = React4.useState("");
|
|
177
|
-
const [editedDataJson, setEditedDataJson] = React4.useState("");
|
|
178
|
-
const [jsonError, setJsonError] = React4.useState(null);
|
|
179
|
-
const [isSaving, setIsSaving] = React4.useState(false);
|
|
180
|
-
React4.useEffect(() => {
|
|
181
|
-
if (thing && open) {
|
|
182
|
-
setEditedName(thing.name);
|
|
183
|
-
setEditedDataJson(JSON.stringify(thing.data ?? {}, null, 2));
|
|
184
|
-
setJsonError(null);
|
|
185
|
-
}
|
|
186
|
-
if (!open) {
|
|
187
|
-
setIsEditing(false);
|
|
188
|
-
}
|
|
189
|
-
}, [thing, open]);
|
|
190
|
-
const handleStartEdit = () => {
|
|
191
|
-
if (thing) {
|
|
192
|
-
setEditedName(thing.name);
|
|
193
|
-
setEditedDataJson(JSON.stringify(thing.data ?? {}, null, 2));
|
|
194
|
-
setJsonError(null);
|
|
195
|
-
setIsEditing(true);
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
const handleCancelEdit = () => {
|
|
199
|
-
if (thing) {
|
|
200
|
-
setEditedName(thing.name);
|
|
201
|
-
setEditedDataJson(JSON.stringify(thing.data ?? {}, null, 2));
|
|
202
|
-
setJsonError(null);
|
|
203
|
-
}
|
|
204
|
-
setIsEditing(false);
|
|
205
|
-
};
|
|
206
|
-
const handleSave = async () => {
|
|
207
|
-
if (!thing || !onSave) return;
|
|
208
|
-
setJsonError(null);
|
|
209
|
-
let parsedData;
|
|
210
|
-
try {
|
|
211
|
-
parsedData = JSON.parse(editedDataJson);
|
|
212
|
-
} catch {
|
|
213
|
-
setJsonError("Invalid JSON format");
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
const updates = {};
|
|
217
|
-
if (editedName !== thing.name) {
|
|
218
|
-
updates.name = editedName;
|
|
219
|
-
}
|
|
220
|
-
if (JSON.stringify(parsedData) !== JSON.stringify(thing.data)) {
|
|
221
|
-
updates.data = parsedData;
|
|
222
|
-
}
|
|
223
|
-
if (Object.keys(updates).length === 0) {
|
|
224
|
-
setIsEditing(false);
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
setIsSaving(true);
|
|
228
|
-
try {
|
|
229
|
-
await onSave(thing, updates);
|
|
230
|
-
setIsEditing(false);
|
|
231
|
-
} catch (error) {
|
|
232
|
-
console.error("Failed to save:", error);
|
|
233
|
-
} finally {
|
|
234
|
-
setIsSaving(false);
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
if (!thing) return null;
|
|
238
|
-
const renderValue = (_key, value) => {
|
|
239
|
-
if (value === null || value === void 0) {
|
|
240
|
-
return /* @__PURE__ */ jsx("span", { className: "text-muted-foreground italic text-sm", children: "null" });
|
|
241
|
-
}
|
|
242
|
-
if (typeof value === "boolean") {
|
|
243
|
-
return /* @__PURE__ */ jsx(Badge, { variant: value ? "default" : "secondary", children: value ? "Yes" : "No" });
|
|
244
|
-
}
|
|
245
|
-
if (Array.isArray(value)) {
|
|
246
|
-
return /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-1.5", children: value.map((v, i) => /* @__PURE__ */ jsx(Badge, { variant: "outline", className: "text-xs font-normal", children: String(v) }, String(i))) });
|
|
247
|
-
}
|
|
248
|
-
if (typeof value === "object") {
|
|
249
|
-
return /* @__PURE__ */ jsx("pre", { className: "text-xs bg-muted/50 p-3 rounded-[var(--radius)] overflow-auto max-h-48 font-mono", children: JSON.stringify(value, null, 2) });
|
|
250
|
-
}
|
|
251
|
-
if (typeof value === "string" && (value.startsWith("http://") || value.startsWith("https://"))) {
|
|
252
|
-
return /* @__PURE__ */ jsxs(
|
|
253
|
-
"a",
|
|
254
|
-
{
|
|
255
|
-
href: value,
|
|
256
|
-
target: "_blank",
|
|
257
|
-
rel: "noopener noreferrer",
|
|
258
|
-
className: "text-primary hover:underline inline-flex items-center gap-1.5 break-all",
|
|
259
|
-
children: [
|
|
260
|
-
value,
|
|
261
|
-
/* @__PURE__ */ jsx(ExternalLink, { className: "h-3 w-3 shrink-0" })
|
|
262
|
-
]
|
|
263
|
-
}
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
if (typeof value === "string" && isISODateString(value)) {
|
|
267
|
-
const formatted = formatDate(value);
|
|
268
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-0.5", children: [
|
|
269
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-sm", children: [
|
|
270
|
-
/* @__PURE__ */ jsx(Calendar, { className: "h-3.5 w-3.5 text-muted-foreground" }),
|
|
271
|
-
/* @__PURE__ */ jsx("span", { children: formatted.date })
|
|
272
|
-
] }),
|
|
273
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-sm text-muted-foreground", children: [
|
|
274
|
-
/* @__PURE__ */ jsx(Clock, { className: "h-3.5 w-3.5" }),
|
|
275
|
-
/* @__PURE__ */ jsx("span", { children: formatted.time }),
|
|
276
|
-
/* @__PURE__ */ jsxs("span", { className: "text-xs", children: [
|
|
277
|
-
"(",
|
|
278
|
-
formatted.relative,
|
|
279
|
-
")"
|
|
280
|
-
] })
|
|
281
|
-
] })
|
|
282
|
-
] });
|
|
283
|
-
}
|
|
284
|
-
if (value instanceof Date) {
|
|
285
|
-
const formatted = formatDate(value);
|
|
286
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-0.5", children: [
|
|
287
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-sm", children: [
|
|
288
|
-
/* @__PURE__ */ jsx(Calendar, { className: "h-3.5 w-3.5 text-muted-foreground" }),
|
|
289
|
-
/* @__PURE__ */ jsx("span", { children: formatted.date })
|
|
290
|
-
] }),
|
|
291
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-sm text-muted-foreground", children: [
|
|
292
|
-
/* @__PURE__ */ jsx(Clock, { className: "h-3.5 w-3.5" }),
|
|
293
|
-
/* @__PURE__ */ jsx("span", { children: formatted.time }),
|
|
294
|
-
/* @__PURE__ */ jsxs("span", { className: "text-xs", children: [
|
|
295
|
-
"(",
|
|
296
|
-
formatted.relative,
|
|
297
|
-
")"
|
|
298
|
-
] })
|
|
299
|
-
] })
|
|
300
|
-
] });
|
|
301
|
-
}
|
|
302
|
-
if (typeof value === "number") {
|
|
303
|
-
return /* @__PURE__ */ jsx("span", { className: "tabular-nums", children: value.toLocaleString() });
|
|
304
|
-
}
|
|
305
|
-
return /* @__PURE__ */ jsx("span", { className: "break-all", children: String(value) });
|
|
306
|
-
};
|
|
307
|
-
return /* @__PURE__ */ jsx(Sheet, { open, onOpenChange, children: /* @__PURE__ */ jsxs(SheetContent, { className: "sm:max-w-lg flex flex-col p-0", children: [
|
|
308
|
-
/* @__PURE__ */ jsx(SheetHeader, { className: "px-6 py-4 border-b bg-muted/30", children: /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-4 pr-8", children: [
|
|
309
|
-
/* @__PURE__ */ jsxs("div", { className: "space-y-1 min-w-0", children: [
|
|
310
|
-
isEditing ? /* @__PURE__ */ jsx(
|
|
311
|
-
Input,
|
|
312
|
-
{
|
|
313
|
-
value: editedName,
|
|
314
|
-
onChange: (e) => setEditedName(e.target.value),
|
|
315
|
-
className: "text-lg font-semibold h-auto py-1"
|
|
316
|
-
}
|
|
317
|
-
) : /* @__PURE__ */ jsx(SheetTitle, { className: "text-lg truncate", children: thing.name }),
|
|
318
|
-
/* @__PURE__ */ jsxs(SheetDescription, { className: "flex items-center gap-2", children: [
|
|
319
|
-
/* @__PURE__ */ jsx(Hash, { className: "h-3.5 w-3.5" }),
|
|
320
|
-
/* @__PURE__ */ jsx("span", { className: "font-mono text-xs", children: thing.id })
|
|
321
|
-
] })
|
|
322
|
-
] }),
|
|
323
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
324
|
-
isEditing && /* @__PURE__ */ jsx(Badge, { variant: "secondary", className: "shrink-0", children: "Editing" }),
|
|
325
|
-
/* @__PURE__ */ jsx(Badge, { variant: "outline", className: "capitalize shrink-0", children: thing.type })
|
|
326
|
-
] })
|
|
327
|
-
] }) }),
|
|
328
|
-
/* @__PURE__ */ jsx(ScrollArea, { className: "flex-1", children: /* @__PURE__ */ jsxs("div", { className: "p-4 space-y-4", children: [
|
|
329
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5 py-2", children: [
|
|
330
|
-
/* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-muted-foreground uppercase tracking-wider", children: "Namespace" }),
|
|
331
|
-
renderValue("ns", thing.ns)
|
|
332
|
-
] }),
|
|
333
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5 py-2", children: [
|
|
334
|
-
/* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-muted-foreground uppercase tracking-wider", children: "Type" }),
|
|
335
|
-
renderValue("type", thing.type)
|
|
336
|
-
] }),
|
|
337
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5 py-2", children: [
|
|
338
|
-
/* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-muted-foreground uppercase tracking-wider", children: "Created" }),
|
|
339
|
-
renderValue("createdAt", thing.createdAt)
|
|
340
|
-
] }),
|
|
341
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5 py-2", children: [
|
|
342
|
-
/* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-muted-foreground uppercase tracking-wider", children: "Updated" }),
|
|
343
|
-
renderValue("updatedAt", thing.updatedAt)
|
|
344
|
-
] }),
|
|
345
|
-
isEditing ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5 py-2", children: [
|
|
346
|
-
/* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-muted-foreground uppercase tracking-wider", children: "Data (JSON)" }),
|
|
347
|
-
/* @__PURE__ */ jsx(
|
|
348
|
-
Textarea,
|
|
349
|
-
{
|
|
350
|
-
value: editedDataJson,
|
|
351
|
-
onChange: (e) => {
|
|
352
|
-
setEditedDataJson(e.target.value);
|
|
353
|
-
setJsonError(null);
|
|
354
|
-
},
|
|
355
|
-
className: "font-mono text-sm min-h-[200px]"
|
|
356
|
-
}
|
|
357
|
-
),
|
|
358
|
-
jsonError && /* @__PURE__ */ jsx("p", { className: "text-sm text-destructive", children: jsonError })
|
|
359
|
-
] }) : thing.data && Object.entries(thing.data).filter(([key]) => !key.startsWith("@")).map(([key, value]) => /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5 py-2", children: [
|
|
360
|
-
/* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-muted-foreground uppercase tracking-wider", children: formatFieldName(key) }),
|
|
361
|
-
renderValue(key, value)
|
|
362
|
-
] }, key))
|
|
363
|
-
] }) }),
|
|
364
|
-
/* @__PURE__ */ jsx(SheetFooter, { className: "border-t px-6 py-4 bg-muted/30", children: /* @__PURE__ */ jsx("div", { className: "flex w-full items-center justify-between gap-3", children: isEditing ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
365
|
-
/* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: handleCancelEdit, disabled: isSaving, children: "Cancel" }),
|
|
366
|
-
/* @__PURE__ */ jsx(
|
|
367
|
-
Button,
|
|
368
|
-
{
|
|
369
|
-
size: "sm",
|
|
370
|
-
onClick: handleSave,
|
|
371
|
-
disabled: isSaving || !editedName.trim(),
|
|
372
|
-
className: "gap-2",
|
|
373
|
-
children: isSaving ? /* @__PURE__ */ jsx(Fragment, { children: "Saving..." }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
374
|
-
/* @__PURE__ */ jsx(Save, { className: "h-4 w-4" }),
|
|
375
|
-
"Save"
|
|
376
|
-
] })
|
|
377
|
-
}
|
|
378
|
-
)
|
|
379
|
-
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
380
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
381
|
-
onSave && /* @__PURE__ */ jsxs(
|
|
382
|
-
Button,
|
|
383
|
-
{
|
|
384
|
-
variant: "outline",
|
|
385
|
-
size: "sm",
|
|
386
|
-
className: "gap-2",
|
|
387
|
-
onClick: handleStartEdit,
|
|
388
|
-
children: [
|
|
389
|
-
/* @__PURE__ */ jsx(Pencil, { className: "h-4 w-4" }),
|
|
390
|
-
"Edit"
|
|
391
|
-
]
|
|
392
|
-
}
|
|
393
|
-
),
|
|
394
|
-
onEdit && !onSave && /* @__PURE__ */ jsxs(
|
|
395
|
-
Button,
|
|
396
|
-
{
|
|
397
|
-
variant: "outline",
|
|
398
|
-
size: "sm",
|
|
399
|
-
className: "gap-2",
|
|
400
|
-
onClick: () => onEdit(thing),
|
|
401
|
-
children: [
|
|
402
|
-
/* @__PURE__ */ jsx(Pencil, { className: "h-4 w-4" }),
|
|
403
|
-
"Edit"
|
|
404
|
-
]
|
|
405
|
-
}
|
|
406
|
-
),
|
|
407
|
-
/* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
408
|
-
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
409
|
-
Button,
|
|
410
|
-
{
|
|
411
|
-
variant: "outline",
|
|
412
|
-
size: "sm",
|
|
413
|
-
onClick: () => {
|
|
414
|
-
navigator.clipboard.writeText(JSON.stringify(thing, null, 2));
|
|
415
|
-
},
|
|
416
|
-
children: /* @__PURE__ */ jsx(Copy, { className: "h-4 w-4" })
|
|
417
|
-
}
|
|
418
|
-
) }),
|
|
419
|
-
/* @__PURE__ */ jsx(TooltipContent, { children: "Copy as JSON" })
|
|
420
|
-
] })
|
|
421
|
-
] }),
|
|
422
|
-
/* @__PURE__ */ jsx(Button, { variant: "secondary", size: "sm", onClick: () => onOpenChange(false), children: "Close" })
|
|
423
|
-
] }) }) })
|
|
424
|
-
] }) });
|
|
425
|
-
}
|
|
426
|
-
function getTableColumns() {
|
|
427
|
-
return [
|
|
428
|
-
{ accessorKey: "name", header: "Name", type: "text" },
|
|
429
|
-
{ accessorKey: "type", header: "Type", type: "text" },
|
|
430
|
-
{ accessorKey: "createdAt", header: "Created", type: "date" },
|
|
431
|
-
{ accessorKey: "updatedAt", header: "Updated", type: "date" }
|
|
432
|
-
];
|
|
433
|
-
}
|
|
434
|
-
function DataBrowserView({
|
|
435
|
-
initialNamespace,
|
|
436
|
-
initialType,
|
|
437
|
-
onSelect,
|
|
438
|
-
onOpen,
|
|
439
|
-
className
|
|
440
|
-
}) {
|
|
441
|
-
const { namespace: contextNamespace, client } = useDO();
|
|
442
|
-
const selectedNamespace = initialNamespace ?? contextNamespace;
|
|
443
|
-
const [selectedType, setSelectedType] = React4.useState(
|
|
444
|
-
initialType
|
|
445
|
-
);
|
|
446
|
-
const [viewType, setViewType] = React4.useState("table");
|
|
447
|
-
const [searchQuery, setSearchQuery] = React4.useState("");
|
|
448
|
-
const [selectedIds, setSelectedIds] = React4.useState([]);
|
|
449
|
-
const [sidebarCollapsed, setSidebarCollapsed] = React4.useState(false);
|
|
450
|
-
const [detailThing, setDetailThing] = React4.useState(null);
|
|
451
|
-
const [detailOpen, setDetailOpen] = React4.useState(false);
|
|
452
|
-
const [recentQueries, setRecentQueries] = React4.useState([]);
|
|
453
|
-
const [createDialogOpen, setCreateDialogOpen] = React4.useState(false);
|
|
454
|
-
const [filterPopoverOpen, setFilterPopoverOpen] = React4.useState(false);
|
|
455
|
-
const [filterConditions, setFilterConditions] = React4.useState([]);
|
|
456
|
-
const [hiddenColumns, setHiddenColumns] = React4.useState(
|
|
457
|
-
/* @__PURE__ */ new Set()
|
|
458
|
-
);
|
|
459
|
-
const { error: namespacesError } = useNamespaces();
|
|
460
|
-
const { data: types, error: typesError } = useTypes({ ns: selectedNamespace });
|
|
461
|
-
const filter = React4.useMemo(() => {
|
|
462
|
-
const f = { ns: selectedNamespace };
|
|
463
|
-
if (selectedType) f.type = selectedType;
|
|
464
|
-
if (searchQuery) f.nameSearch = searchQuery;
|
|
465
|
-
return f;
|
|
466
|
-
}, [selectedNamespace, selectedType, searchQuery]);
|
|
467
|
-
const { data: thingsResult, isLoading, error: thingsError, refetch } = useThings(filter);
|
|
468
|
-
const connectionError = namespacesError || typesError || thingsError;
|
|
469
|
-
const queryConditions = React4.useMemo(() => {
|
|
470
|
-
return parseQuery(searchQuery);
|
|
471
|
-
}, [searchQuery]);
|
|
472
|
-
const data = React4.useMemo(() => {
|
|
473
|
-
if (!thingsResult?.data) return [];
|
|
474
|
-
let filtered = thingsResult.data.map((thing) => ({
|
|
475
|
-
id: thing.id,
|
|
476
|
-
ns: thing.ns,
|
|
477
|
-
type: thing.type,
|
|
478
|
-
name: thing.name,
|
|
479
|
-
createdAt: thing.createdAt,
|
|
480
|
-
updatedAt: thing.updatedAt,
|
|
481
|
-
...thing.data
|
|
482
|
-
}));
|
|
483
|
-
if (queryConditions.length > 0) {
|
|
484
|
-
filtered = applyQueryFilter(filtered, queryConditions);
|
|
485
|
-
}
|
|
486
|
-
if (filterConditions.length > 0) {
|
|
487
|
-
filtered = filtered.filter((item) => {
|
|
488
|
-
return filterConditions.every((condition) => {
|
|
489
|
-
const fieldValue = item[condition.field];
|
|
490
|
-
const strValue = String(fieldValue ?? "").toLowerCase();
|
|
491
|
-
const conditionValue = condition.value.toLowerCase();
|
|
492
|
-
switch (condition.operator) {
|
|
493
|
-
case "equals":
|
|
494
|
-
return strValue === conditionValue;
|
|
495
|
-
case "contains":
|
|
496
|
-
return strValue.includes(conditionValue);
|
|
497
|
-
case "startsWith":
|
|
498
|
-
return strValue.startsWith(conditionValue);
|
|
499
|
-
case "endsWith":
|
|
500
|
-
return strValue.endsWith(conditionValue);
|
|
501
|
-
case "isEmpty":
|
|
502
|
-
return !fieldValue || strValue === "";
|
|
503
|
-
case "isNotEmpty":
|
|
504
|
-
return !!fieldValue && strValue !== "";
|
|
505
|
-
default:
|
|
506
|
-
return true;
|
|
507
|
-
}
|
|
508
|
-
});
|
|
509
|
-
});
|
|
510
|
-
}
|
|
511
|
-
return filtered;
|
|
512
|
-
}, [thingsResult, queryConditions, filterConditions]);
|
|
513
|
-
const allTableColumns = React4.useMemo(() => getTableColumns(), []);
|
|
514
|
-
const tableColumns = React4.useMemo(
|
|
515
|
-
() => allTableColumns.filter((col) => !hiddenColumns.has(col.accessorKey)),
|
|
516
|
-
[allTableColumns, hiddenColumns]
|
|
517
|
-
);
|
|
518
|
-
const queryFields = React4.useMemo(() => {
|
|
519
|
-
return ["name", "type", "ns", "createdAt", "updatedAt"];
|
|
520
|
-
}, []);
|
|
521
|
-
const handleExportSelected = React4.useCallback(() => {
|
|
522
|
-
if (selectedIds.length === 0) return;
|
|
523
|
-
const exportData = data.filter((d) => selectedIds.includes(d.id));
|
|
524
|
-
const filename = `${selectedNamespace}-${selectedType ?? "all"}-selected-${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}`;
|
|
525
|
-
exportToJSON(exportData, filename);
|
|
526
|
-
}, [data, selectedIds, selectedNamespace, selectedType]);
|
|
527
|
-
const handleExportAll = React4.useCallback(() => {
|
|
528
|
-
const filename = `${selectedNamespace}-${selectedType ?? "all"}-${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}`;
|
|
529
|
-
exportToJSON(data, filename);
|
|
530
|
-
}, [data, selectedNamespace, selectedType]);
|
|
531
|
-
const handleSaveThing = React4.useCallback(
|
|
532
|
-
async (thing, updates) => {
|
|
533
|
-
await client.Thing.update({
|
|
534
|
-
ns: thing.ns,
|
|
535
|
-
type: thing.type,
|
|
536
|
-
id: thing.id,
|
|
537
|
-
...updates
|
|
538
|
-
});
|
|
539
|
-
await refetch();
|
|
540
|
-
if (detailThing?.id === thing.id) {
|
|
541
|
-
const updated = thingsResult?.data?.find((t) => t.id === thing.id);
|
|
542
|
-
if (updated) {
|
|
543
|
-
setDetailThing(updated);
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
},
|
|
547
|
-
[client, refetch, detailThing, thingsResult]
|
|
548
|
-
);
|
|
549
|
-
const handleItemClick = React4.useCallback(
|
|
550
|
-
(item) => {
|
|
551
|
-
const thing = thingsResult?.data?.find((t) => t.id === item.id);
|
|
552
|
-
if (thing) {
|
|
553
|
-
setDetailThing(thing);
|
|
554
|
-
setDetailOpen(true);
|
|
555
|
-
onSelect?.(thing);
|
|
556
|
-
}
|
|
557
|
-
},
|
|
558
|
-
[thingsResult, onSelect]
|
|
559
|
-
);
|
|
560
|
-
const handleClearSelection = React4.useCallback(() => {
|
|
561
|
-
setSelectedIds([]);
|
|
562
|
-
}, []);
|
|
563
|
-
const handleSelectRecentQuery = React4.useCallback((query) => {
|
|
564
|
-
setRecentQueries((prev) => {
|
|
565
|
-
const filtered = prev.filter((q) => q !== query);
|
|
566
|
-
return [query, ...filtered].slice(0, 10);
|
|
567
|
-
});
|
|
568
|
-
setSearchQuery(query);
|
|
569
|
-
}, []);
|
|
570
|
-
React4.useEffect(() => {
|
|
571
|
-
const mediaQuery = window.matchMedia("(max-width: 768px)");
|
|
572
|
-
const handleMediaChange = (e) => {
|
|
573
|
-
if (e.matches) {
|
|
574
|
-
setSidebarCollapsed(true);
|
|
575
|
-
}
|
|
576
|
-
};
|
|
577
|
-
handleMediaChange(mediaQuery);
|
|
578
|
-
mediaQuery.addEventListener("change", handleMediaChange);
|
|
579
|
-
return () => mediaQuery.removeEventListener("change", handleMediaChange);
|
|
580
|
-
}, []);
|
|
581
|
-
return /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsxs("div", { className: cn("flex h-full bg-background", className), children: [
|
|
582
|
-
/* @__PURE__ */ jsx(
|
|
583
|
-
DataSidebar,
|
|
584
|
-
{
|
|
585
|
-
title: "Types",
|
|
586
|
-
items: types?.map(
|
|
587
|
-
(t) => ({
|
|
588
|
-
id: t.id,
|
|
589
|
-
name: t.name,
|
|
590
|
-
label: t.label
|
|
591
|
-
})
|
|
592
|
-
),
|
|
593
|
-
selectedItem: selectedType,
|
|
594
|
-
onSelectItem: setSelectedType,
|
|
595
|
-
collapsed: sidebarCollapsed,
|
|
596
|
-
onCollapsedChange: setSidebarCollapsed,
|
|
597
|
-
allItemsLabel: "All Types",
|
|
598
|
-
emptyMessage: "No types found"
|
|
599
|
-
}
|
|
600
|
-
),
|
|
601
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
602
|
-
/* @__PURE__ */ jsxs("header", { className: "flex h-12 shrink-0 items-center gap-3 border-b px-4", children: [
|
|
603
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 shrink-0", children: [
|
|
604
|
-
/* @__PURE__ */ jsx(
|
|
605
|
-
DataSidebarTrigger,
|
|
606
|
-
{
|
|
607
|
-
collapsed: sidebarCollapsed,
|
|
608
|
-
onToggle: () => setSidebarCollapsed(!sidebarCollapsed)
|
|
609
|
-
}
|
|
610
|
-
),
|
|
611
|
-
/* @__PURE__ */ jsx(Shapes, { className: "h-4 w-4 text-muted-foreground hidden sm:block" }),
|
|
612
|
-
/* @__PURE__ */ jsx("span", { className: "text-sm font-semibold hidden sm:inline", children: selectedType ?? "All Things" })
|
|
613
|
-
] }),
|
|
614
|
-
/* @__PURE__ */ jsx("div", { className: "hidden sm:flex flex-1" }),
|
|
615
|
-
/* @__PURE__ */ jsx(
|
|
616
|
-
QuerySearch,
|
|
617
|
-
{
|
|
618
|
-
query: searchQuery,
|
|
619
|
-
onQueryChange: setSearchQuery,
|
|
620
|
-
conditions: queryConditions,
|
|
621
|
-
fields: queryFields,
|
|
622
|
-
recentQueries,
|
|
623
|
-
onSelectRecentQuery: handleSelectRecentQuery,
|
|
624
|
-
placeholder: "Search... (e.g., type: User)",
|
|
625
|
-
className: "flex-1 min-w-0 sm:w-64 sm:flex-none md:w-80 lg:w-[480px]"
|
|
626
|
-
}
|
|
627
|
-
),
|
|
628
|
-
/* @__PURE__ */ jsx("div", { className: "hidden sm:flex flex-1" }),
|
|
629
|
-
selectedIds.length > 0 && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 animate-in fade-in-0 slide-in-from-left-2 duration-200 shrink-0", children: [
|
|
630
|
-
/* @__PURE__ */ jsxs(Badge, { variant: "secondary", className: "gap-1 pl-2 pr-1", children: [
|
|
631
|
-
/* @__PURE__ */ jsx("span", { className: "tabular-nums", children: selectedIds.length }),
|
|
632
|
-
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground", children: "selected" }),
|
|
633
|
-
/* @__PURE__ */ jsx(
|
|
634
|
-
"button",
|
|
635
|
-
{
|
|
636
|
-
type: "button",
|
|
637
|
-
onClick: handleClearSelection,
|
|
638
|
-
className: "ml-0.5 rounded-sm p-0.5 hover:bg-muted-foreground/20 transition-colors",
|
|
639
|
-
children: /* @__PURE__ */ jsx(X, { className: "h-3 w-3" })
|
|
640
|
-
}
|
|
641
|
-
)
|
|
642
|
-
] }),
|
|
643
|
-
/* @__PURE__ */ jsxs(AlertDialog, { children: [
|
|
644
|
-
/* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
645
|
-
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(AlertDialogTrigger, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon", className: "h-7 w-7", children: /* @__PURE__ */ jsx(Trash2, { className: "h-4 w-4 text-destructive" }) }) }) }),
|
|
646
|
-
/* @__PURE__ */ jsx(TooltipContent, { children: "Delete selected" })
|
|
647
|
-
] }),
|
|
648
|
-
/* @__PURE__ */ jsxs(AlertDialogContent, { children: [
|
|
649
|
-
/* @__PURE__ */ jsxs(AlertDialogHeader, { children: [
|
|
650
|
-
/* @__PURE__ */ jsxs(AlertDialogTitle, { children: [
|
|
651
|
-
"Delete ",
|
|
652
|
-
selectedIds.length,
|
|
653
|
-
" item",
|
|
654
|
-
selectedIds.length !== 1 ? "s" : "",
|
|
655
|
-
"?"
|
|
656
|
-
] }),
|
|
657
|
-
/* @__PURE__ */ jsx(AlertDialogDescription, { children: "This action cannot be undone. The selected items will be permanently removed." })
|
|
658
|
-
] }),
|
|
659
|
-
/* @__PURE__ */ jsxs(AlertDialogFooter, { children: [
|
|
660
|
-
/* @__PURE__ */ jsx(AlertDialogCancel, { children: "Cancel" }),
|
|
661
|
-
/* @__PURE__ */ jsx(
|
|
662
|
-
AlertDialogAction,
|
|
663
|
-
{
|
|
664
|
-
className: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
|
|
665
|
-
onClick: async () => {
|
|
666
|
-
try {
|
|
667
|
-
const thingsToDelete = thingsResult?.data?.filter(
|
|
668
|
-
(t) => selectedIds.includes(t.id)
|
|
669
|
-
) ?? [];
|
|
670
|
-
await Promise.all(
|
|
671
|
-
thingsToDelete.map(
|
|
672
|
-
(thing) => client.Thing.delete({
|
|
673
|
-
ns: thing.ns,
|
|
674
|
-
type: thing.type,
|
|
675
|
-
id: thing.id
|
|
676
|
-
})
|
|
677
|
-
)
|
|
678
|
-
);
|
|
679
|
-
setSelectedIds([]);
|
|
680
|
-
await refetch();
|
|
681
|
-
} catch (err) {
|
|
682
|
-
console.error("Failed to delete:", err);
|
|
683
|
-
}
|
|
684
|
-
},
|
|
685
|
-
children: "Delete"
|
|
686
|
-
}
|
|
687
|
-
)
|
|
688
|
-
] })
|
|
689
|
-
] })
|
|
690
|
-
] })
|
|
691
|
-
] }),
|
|
692
|
-
/* @__PURE__ */ jsx(
|
|
693
|
-
ViewSwitcher,
|
|
694
|
-
{
|
|
695
|
-
currentView: viewType,
|
|
696
|
-
onViewChange: setViewType,
|
|
697
|
-
availableViews: ["list", "table", "card", "code"],
|
|
698
|
-
className: "hidden sm:inline-flex"
|
|
699
|
-
}
|
|
700
|
-
),
|
|
701
|
-
/* @__PURE__ */ jsx("div", { className: "hidden sm:block h-4 w-px bg-border" }),
|
|
702
|
-
/* @__PURE__ */ jsx(
|
|
703
|
-
DataFilterPopover,
|
|
704
|
-
{
|
|
705
|
-
open: filterPopoverOpen,
|
|
706
|
-
onOpenChange: setFilterPopoverOpen,
|
|
707
|
-
conditions: filterConditions,
|
|
708
|
-
onConditionsChange: setFilterConditions,
|
|
709
|
-
availableFields: queryFields
|
|
710
|
-
}
|
|
711
|
-
),
|
|
712
|
-
viewType === "table" && /* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
713
|
-
/* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
714
|
-
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
|
|
715
|
-
Button,
|
|
716
|
-
{
|
|
717
|
-
variant: "ghost",
|
|
718
|
-
size: "icon",
|
|
719
|
-
className: "h-7 w-7 relative",
|
|
720
|
-
children: [
|
|
721
|
-
/* @__PURE__ */ jsx(Columns3, { className: "h-4 w-4" }),
|
|
722
|
-
hiddenColumns.size > 0 && /* @__PURE__ */ jsx("span", { className: "absolute -right-1 -top-1 flex h-4 w-4 items-center justify-center rounded-full bg-primary text-[10px] text-primary-foreground", children: hiddenColumns.size })
|
|
723
|
-
]
|
|
724
|
-
}
|
|
725
|
-
) }) }),
|
|
726
|
-
/* @__PURE__ */ jsx(TooltipContent, { children: "Columns" })
|
|
727
|
-
] }),
|
|
728
|
-
/* @__PURE__ */ jsxs(DropdownMenuContent, { align: "end", className: "w-48", children: [
|
|
729
|
-
/* @__PURE__ */ jsx(DropdownMenuLabel, { children: "Toggle columns" }),
|
|
730
|
-
/* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
|
|
731
|
-
allTableColumns.map((column) => /* @__PURE__ */ jsx(
|
|
732
|
-
DropdownMenuCheckboxItem,
|
|
733
|
-
{
|
|
734
|
-
checked: !hiddenColumns.has(column.accessorKey),
|
|
735
|
-
onCheckedChange: (checked) => {
|
|
736
|
-
setHiddenColumns((prev) => {
|
|
737
|
-
const next = new Set(prev);
|
|
738
|
-
if (checked) {
|
|
739
|
-
next.delete(column.accessorKey);
|
|
740
|
-
} else {
|
|
741
|
-
next.add(column.accessorKey);
|
|
742
|
-
}
|
|
743
|
-
return next;
|
|
744
|
-
});
|
|
745
|
-
},
|
|
746
|
-
children: column.header
|
|
747
|
-
},
|
|
748
|
-
column.accessorKey
|
|
749
|
-
))
|
|
750
|
-
] })
|
|
751
|
-
] }),
|
|
752
|
-
/* @__PURE__ */ jsxs(
|
|
753
|
-
Button,
|
|
754
|
-
{
|
|
755
|
-
variant: "default",
|
|
756
|
-
size: "sm",
|
|
757
|
-
className: "gap-1.5 px-3 hidden sm:inline-flex",
|
|
758
|
-
onClick: () => setCreateDialogOpen(true),
|
|
759
|
-
children: [
|
|
760
|
-
/* @__PURE__ */ jsx(Plus, { className: "h-4 w-4" }),
|
|
761
|
-
/* @__PURE__ */ jsx("span", { children: "Add" })
|
|
762
|
-
]
|
|
763
|
-
}
|
|
764
|
-
),
|
|
765
|
-
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
766
|
-
/* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
767
|
-
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon", className: "h-7 w-7", children: /* @__PURE__ */ jsx(MoreVertical, { className: "h-4 w-4" }) }) }) }),
|
|
768
|
-
/* @__PURE__ */ jsx(TooltipContent, { children: "More actions" })
|
|
769
|
-
] }),
|
|
770
|
-
/* @__PURE__ */ jsxs(DropdownMenuContent, { align: "end", children: [
|
|
771
|
-
/* @__PURE__ */ jsxs(
|
|
772
|
-
DropdownMenuItem,
|
|
773
|
-
{
|
|
774
|
-
disabled: selectedIds.length === 0,
|
|
775
|
-
onClick: handleExportSelected,
|
|
776
|
-
children: [
|
|
777
|
-
/* @__PURE__ */ jsx(Download, { className: "h-4 w-4 mr-2" }),
|
|
778
|
-
"Export selected (",
|
|
779
|
-
selectedIds.length,
|
|
780
|
-
")"
|
|
781
|
-
]
|
|
782
|
-
}
|
|
783
|
-
),
|
|
784
|
-
/* @__PURE__ */ jsxs(DropdownMenuItem, { onClick: handleExportAll, children: [
|
|
785
|
-
/* @__PURE__ */ jsx(Download, { className: "h-4 w-4 mr-2" }),
|
|
786
|
-
"Export all (",
|
|
787
|
-
data.length,
|
|
788
|
-
")"
|
|
789
|
-
] }),
|
|
790
|
-
/* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
|
|
791
|
-
/* @__PURE__ */ jsxs(DropdownMenuItem, { onClick: () => refetch(), children: [
|
|
792
|
-
/* @__PURE__ */ jsx(RefreshCw, { className: "h-4 w-4 mr-2" }),
|
|
793
|
-
"Refresh data"
|
|
794
|
-
] })
|
|
795
|
-
] })
|
|
796
|
-
] })
|
|
797
|
-
] }),
|
|
798
|
-
/* @__PURE__ */ jsx("div", { className: "flex min-h-0 flex-1 flex-col overflow-hidden p-2", children: connectionError ? /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsxs("div", { className: "text-center max-w-md p-6", children: [
|
|
799
|
-
/* @__PURE__ */ jsx("div", { className: "mx-auto mb-4 h-12 w-12 rounded-full bg-destructive/10 flex items-center justify-center", children: /* @__PURE__ */ jsx(X, { className: "h-6 w-6 text-destructive" }) }),
|
|
800
|
-
/* @__PURE__ */ jsx("h3", { className: "font-semibold text-lg mb-2", children: "Connection Error" }),
|
|
801
|
-
/* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-sm mb-4", children: connectionError.message }),
|
|
802
|
-
/* @__PURE__ */ jsxs(
|
|
803
|
-
Button,
|
|
804
|
-
{
|
|
805
|
-
variant: "outline",
|
|
806
|
-
size: "sm",
|
|
807
|
-
onClick: () => refetch(),
|
|
808
|
-
className: "gap-2",
|
|
809
|
-
children: [
|
|
810
|
-
/* @__PURE__ */ jsx(RefreshCw, { className: "h-4 w-4" }),
|
|
811
|
-
"Retry"
|
|
812
|
-
]
|
|
813
|
-
}
|
|
814
|
-
)
|
|
815
|
-
] }) }) : isLoading ? /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-2", children: [
|
|
816
|
-
/* @__PURE__ */ jsx("div", { className: "h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" }),
|
|
817
|
-
/* @__PURE__ */ jsx("span", { className: "text-sm text-muted-foreground", children: "Loading..." })
|
|
818
|
-
] }) }) : data.length === 0 ? /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsxs("div", { className: "text-center", children: [
|
|
819
|
-
/* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: "No things found" }),
|
|
820
|
-
searchQuery && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground mt-1", children: "Try adjusting your search query" })
|
|
821
|
-
] }) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
822
|
-
viewType === "list" && /* @__PURE__ */ jsx(
|
|
823
|
-
DatabaseListView,
|
|
824
|
-
{
|
|
825
|
-
data,
|
|
826
|
-
displayFields: ["name", "type", "ns"],
|
|
827
|
-
primaryField: "name",
|
|
828
|
-
secondaryField: "type",
|
|
829
|
-
selectedIds,
|
|
830
|
-
onSelectionChange: setSelectedIds,
|
|
831
|
-
onRecordClick: handleItemClick
|
|
832
|
-
}
|
|
833
|
-
),
|
|
834
|
-
viewType === "table" && /* @__PURE__ */ jsx(
|
|
835
|
-
DatabaseTableView,
|
|
836
|
-
{
|
|
837
|
-
data,
|
|
838
|
-
columns: tableColumns,
|
|
839
|
-
onSelectionChange: setSelectedIds,
|
|
840
|
-
onRowClick: handleItemClick,
|
|
841
|
-
enableRowSelection: true,
|
|
842
|
-
enablePagination: false,
|
|
843
|
-
enableColumnVisibility: false
|
|
844
|
-
}
|
|
845
|
-
),
|
|
846
|
-
viewType === "card" && /* @__PURE__ */ jsx("div", { className: "h-full overflow-auto p-2", children: /* @__PURE__ */ jsx(
|
|
847
|
-
DatabaseCardView,
|
|
848
|
-
{
|
|
849
|
-
data,
|
|
850
|
-
titleField: "name",
|
|
851
|
-
descriptionField: "type",
|
|
852
|
-
badgeFields: ["ns"],
|
|
853
|
-
onItemClick: handleItemClick,
|
|
854
|
-
columns: 3
|
|
855
|
-
}
|
|
856
|
-
) }),
|
|
857
|
-
viewType === "code" && /* @__PURE__ */ jsx(DatabaseCodeView, { data, height: "100%", format: "json" })
|
|
858
|
-
] }) }),
|
|
859
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 py-2 border-t border-border bg-muted/50 text-sm text-muted-foreground", children: [
|
|
860
|
-
/* @__PURE__ */ jsxs("span", { children: [
|
|
861
|
-
thingsResult?.total ?? 0,
|
|
862
|
-
" items",
|
|
863
|
-
selectedType && ` \u2022 Type: ${selectedType}`
|
|
864
|
-
] }),
|
|
865
|
-
/* @__PURE__ */ jsxs("span", { children: [
|
|
866
|
-
"Page ",
|
|
867
|
-
thingsResult?.page ?? 1,
|
|
868
|
-
" of ",
|
|
869
|
-
thingsResult?.totalPages ?? 1
|
|
870
|
-
] })
|
|
871
|
-
] })
|
|
872
|
-
] }),
|
|
873
|
-
/* @__PURE__ */ jsx(
|
|
874
|
-
DetailSheet,
|
|
875
|
-
{
|
|
876
|
-
open: detailOpen,
|
|
877
|
-
onOpenChange: setDetailOpen,
|
|
878
|
-
thing: detailThing,
|
|
879
|
-
onEdit: onOpen,
|
|
880
|
-
onSave: handleSaveThing
|
|
881
|
-
}
|
|
882
|
-
),
|
|
883
|
-
/* @__PURE__ */ jsx(
|
|
884
|
-
CreateDialog,
|
|
885
|
-
{
|
|
886
|
-
open: createDialogOpen,
|
|
887
|
-
onOpenChange: setCreateDialogOpen,
|
|
888
|
-
namespace: selectedNamespace,
|
|
889
|
-
defaultType: selectedType,
|
|
890
|
-
types: types ?? [],
|
|
891
|
-
onCreated: (thing) => {
|
|
892
|
-
refetch();
|
|
893
|
-
setDetailThing(thing);
|
|
894
|
-
setDetailOpen(true);
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
)
|
|
898
|
-
] }) });
|
|
899
|
-
}
|
|
900
|
-
function inferDataType(value) {
|
|
901
|
-
if (value === null || value === void 0) return "text";
|
|
902
|
-
if (typeof value === "boolean") return "boolean";
|
|
903
|
-
if (typeof value === "number") return "number";
|
|
904
|
-
if (value instanceof Date) return "date";
|
|
905
|
-
if (typeof value === "string") {
|
|
906
|
-
if (/^\d{4}-\d{2}-\d{2}/.test(value)) return "date";
|
|
907
|
-
if (value.includes("@")) return "email";
|
|
908
|
-
}
|
|
909
|
-
if (typeof value === "object") return "json";
|
|
910
|
-
return "text";
|
|
911
|
-
}
|
|
912
|
-
function generateColumns(things) {
|
|
913
|
-
const columns = [
|
|
914
|
-
{ accessorKey: "id", header: "ID", dataType: "text", isPrimaryKey: true, editable: false },
|
|
915
|
-
{ accessorKey: "name", header: "Name", dataType: "text" },
|
|
916
|
-
{ accessorKey: "createdAt", header: "Created", dataType: "date", editable: false },
|
|
917
|
-
{ accessorKey: "updatedAt", header: "Updated", dataType: "date", editable: false }
|
|
918
|
-
];
|
|
919
|
-
const dataKeys = /* @__PURE__ */ new Map();
|
|
920
|
-
things.forEach((thing) => {
|
|
921
|
-
if (thing.data && typeof thing.data === "object") {
|
|
922
|
-
Object.entries(thing.data).forEach(([key, value]) => {
|
|
923
|
-
if (!key.startsWith("@") && !dataKeys.has(key)) {
|
|
924
|
-
dataKeys.set(key, inferDataType(value));
|
|
925
|
-
}
|
|
926
|
-
});
|
|
927
|
-
}
|
|
928
|
-
});
|
|
929
|
-
dataKeys.forEach((dataType, key) => {
|
|
930
|
-
columns.push({
|
|
931
|
-
accessorKey: key,
|
|
932
|
-
header: key.charAt(0).toUpperCase() + key.slice(1),
|
|
933
|
-
dataType
|
|
934
|
-
});
|
|
935
|
-
});
|
|
936
|
-
return columns;
|
|
937
|
-
}
|
|
938
|
-
function thingToRow(thing) {
|
|
939
|
-
return {
|
|
940
|
-
id: thing.id,
|
|
941
|
-
_ns: thing.ns,
|
|
942
|
-
_type: thing.type,
|
|
943
|
-
name: thing.name,
|
|
944
|
-
createdAt: thing.createdAt,
|
|
945
|
-
updatedAt: thing.updatedAt,
|
|
946
|
-
...thing.data
|
|
947
|
-
};
|
|
948
|
-
}
|
|
949
|
-
function DataGridView({
|
|
950
|
-
initialNamespace,
|
|
951
|
-
initialType,
|
|
952
|
-
readOnly = false,
|
|
953
|
-
onRowSelect: _onRowSelect,
|
|
954
|
-
className
|
|
955
|
-
}) {
|
|
956
|
-
const { namespace: contextNamespace, client } = useDO();
|
|
957
|
-
const [selectedNamespace, setSelectedNamespace] = React4.useState(
|
|
958
|
-
initialNamespace ?? contextNamespace
|
|
959
|
-
);
|
|
960
|
-
const [selectedType, setSelectedType] = React4.useState(initialType);
|
|
961
|
-
const [selectedTable, setSelectedTable] = React4.useState(
|
|
962
|
-
`${selectedNamespace}.${initialType ?? ""}`
|
|
963
|
-
);
|
|
964
|
-
const [sidebarCollapsed, setSidebarCollapsed] = React4.useState(false);
|
|
965
|
-
const [viewMode, setViewMode] = React4.useState("table");
|
|
966
|
-
const [formatViewFormat, _setFormatViewFormat] = React4.useState("json");
|
|
967
|
-
const [selectedRows, setSelectedRows] = React4.useState([]);
|
|
968
|
-
const [filters, setFilters] = React4.useState([]);
|
|
969
|
-
const [hiddenColumns, setHiddenColumns] = React4.useState(/* @__PURE__ */ new Set());
|
|
970
|
-
const [refreshStatus, setRefreshStatus] = React4.useState("idle");
|
|
971
|
-
const [autoRefreshEnabled, setAutoRefreshEnabled] = React4.useState(false);
|
|
972
|
-
const [autoRefreshInterval, setAutoRefreshInterval] = React4.useState(30);
|
|
973
|
-
const [lastRefreshTime, setLastRefreshTime] = React4.useState(null);
|
|
974
|
-
const [columnEditorOpen, setColumnEditorOpen] = React4.useState(false);
|
|
975
|
-
const [tableCreatorOpen, setTableCreatorOpen] = React4.useState(false);
|
|
976
|
-
const [editingColumn, setEditingColumn] = React4.useState();
|
|
977
|
-
const gridActionsRef = React4.useRef(null);
|
|
978
|
-
const [localData, setLocalData] = React4.useState([]);
|
|
979
|
-
const { data: namespaces } = useNamespaces();
|
|
980
|
-
const { data: types } = useTypes({ ns: selectedNamespace });
|
|
981
|
-
const filter = React4.useMemo(() => {
|
|
982
|
-
const f = { ns: selectedNamespace };
|
|
983
|
-
if (selectedType) f.type = selectedType;
|
|
984
|
-
return f;
|
|
985
|
-
}, [selectedNamespace, selectedType]);
|
|
986
|
-
const { data: thingsResult, isLoading, refetch } = useThings(filter);
|
|
987
|
-
React4.useEffect(() => {
|
|
988
|
-
if (thingsResult?.data) {
|
|
989
|
-
setLocalData(thingsResult.data.map(thingToRow));
|
|
990
|
-
}
|
|
991
|
-
}, [thingsResult]);
|
|
992
|
-
const schemas = React4.useMemo(() => {
|
|
993
|
-
if (!namespaces || !types) return [];
|
|
994
|
-
return namespaces.map((ns) => ({
|
|
995
|
-
name: ns.name,
|
|
996
|
-
tables: types.filter((t) => t.namespace === ns.name).map((t) => ({
|
|
997
|
-
name: t.name,
|
|
998
|
-
schema: ns.name,
|
|
999
|
-
rowCount: 0
|
|
1000
|
-
// We don't have row counts per type from the hook
|
|
1001
|
-
}))
|
|
1002
|
-
}));
|
|
1003
|
-
}, [namespaces, types]);
|
|
1004
|
-
const columns = React4.useMemo(() => {
|
|
1005
|
-
if (!thingsResult?.data || thingsResult.data.length === 0) {
|
|
1006
|
-
return [
|
|
1007
|
-
{ accessorKey: "id", header: "ID", dataType: "text", isPrimaryKey: true, editable: false },
|
|
1008
|
-
{ accessorKey: "name", header: "Name", dataType: "text" },
|
|
1009
|
-
{ accessorKey: "createdAt", header: "Created", dataType: "date" },
|
|
1010
|
-
{ accessorKey: "updatedAt", header: "Updated", dataType: "date" }
|
|
1011
|
-
];
|
|
1012
|
-
}
|
|
1013
|
-
return generateColumns(thingsResult.data);
|
|
1014
|
-
}, [thingsResult]);
|
|
1015
|
-
const visibleColumns = React4.useMemo(
|
|
1016
|
-
() => columns.filter((col) => !hiddenColumns.has(col.accessorKey)),
|
|
1017
|
-
[columns, hiddenColumns]
|
|
1018
|
-
);
|
|
1019
|
-
const filteredData = React4.useMemo(
|
|
1020
|
-
() => applyFilters(localData, filters, columns),
|
|
1021
|
-
[localData, filters, columns]
|
|
1022
|
-
);
|
|
1023
|
-
const {
|
|
1024
|
-
pushOperation,
|
|
1025
|
-
undo,
|
|
1026
|
-
redo,
|
|
1027
|
-
canUndo,
|
|
1028
|
-
canRedo,
|
|
1029
|
-
undoCount,
|
|
1030
|
-
redoCount
|
|
1031
|
-
} = useEditHistory({
|
|
1032
|
-
onRedo: (operation) => {
|
|
1033
|
-
const { rowIndex, columnId, newValue } = operation;
|
|
1034
|
-
setLocalData((prev) => {
|
|
1035
|
-
const newData = [...prev];
|
|
1036
|
-
newData[rowIndex] = { ...newData[rowIndex], [columnId]: newValue };
|
|
1037
|
-
return newData;
|
|
1038
|
-
});
|
|
1039
|
-
},
|
|
1040
|
-
onUndo: (operation) => {
|
|
1041
|
-
const { rowIndex, columnId, oldValue } = operation;
|
|
1042
|
-
setLocalData((prev) => {
|
|
1043
|
-
const newData = [...prev];
|
|
1044
|
-
newData[rowIndex] = { ...newData[rowIndex], [columnId]: oldValue };
|
|
1045
|
-
return newData;
|
|
1046
|
-
});
|
|
1047
|
-
}
|
|
1048
|
-
});
|
|
1049
|
-
const handleSelectTable = React4.useCallback((schema2, table) => {
|
|
1050
|
-
setSelectedNamespace(schema2);
|
|
1051
|
-
setSelectedType(table);
|
|
1052
|
-
setSelectedTable(`${schema2}.${table}`);
|
|
1053
|
-
setSelectedRows([]);
|
|
1054
|
-
setFilters([]);
|
|
1055
|
-
}, []);
|
|
1056
|
-
const handleAddColumn = React4.useCallback(() => {
|
|
1057
|
-
setEditingColumn(void 0);
|
|
1058
|
-
setColumnEditorOpen(true);
|
|
1059
|
-
}, []);
|
|
1060
|
-
const handleSaveColumn = React4.useCallback(
|
|
1061
|
-
async (column) => {
|
|
1062
|
-
if (!selectedType) return;
|
|
1063
|
-
try {
|
|
1064
|
-
const nullable = column.isNullable ? "" : "NOT NULL";
|
|
1065
|
-
const defaultVal = column.defaultValue ? `DEFAULT ${column.isDefaultExpression ? column.defaultValue : `'${column.defaultValue}'`}` : "";
|
|
1066
|
-
const unique = column.isUnique ? "UNIQUE" : "";
|
|
1067
|
-
const sql = editingColumn ? `ALTER TABLE ${selectedType} RENAME COLUMN ${editingColumn.name} TO ${column.name}` : `ALTER TABLE ${selectedType} ADD COLUMN ${column.name} ${column.dataType} ${nullable} ${defaultVal} ${unique}`;
|
|
1068
|
-
await client.SQL.execute({ query: sql.trim() });
|
|
1069
|
-
setColumnEditorOpen(false);
|
|
1070
|
-
toast.success(`Column "${column.name}" ${editingColumn ? "updated" : "created"}`);
|
|
1071
|
-
await refetch();
|
|
1072
|
-
} catch (err) {
|
|
1073
|
-
toast.error(`Failed to save column: ${err instanceof Error ? err.message : "Unknown error"}`);
|
|
1074
|
-
}
|
|
1075
|
-
},
|
|
1076
|
-
[selectedType, editingColumn, client, refetch]
|
|
1077
|
-
);
|
|
1078
|
-
const handleDeleteColumn = React4.useCallback(async () => {
|
|
1079
|
-
if (!selectedType || !editingColumn) return;
|
|
1080
|
-
try {
|
|
1081
|
-
await client.SQL.execute({
|
|
1082
|
-
query: `ALTER TABLE ${selectedType} DROP COLUMN ${editingColumn.name}`
|
|
1083
|
-
});
|
|
1084
|
-
setColumnEditorOpen(false);
|
|
1085
|
-
toast.success(`Column "${editingColumn.name}" deleted`);
|
|
1086
|
-
await refetch();
|
|
1087
|
-
} catch (err) {
|
|
1088
|
-
toast.error(`Failed to delete column: ${err instanceof Error ? err.message : "Unknown error"}`);
|
|
1089
|
-
}
|
|
1090
|
-
}, [selectedType, editingColumn, client, refetch]);
|
|
1091
|
-
const handleCreateTable = React4.useCallback(
|
|
1092
|
-
async (table) => {
|
|
1093
|
-
try {
|
|
1094
|
-
const columnDefs = table.columns.map((col) => {
|
|
1095
|
-
const nullable = col.isNullable ? "" : "NOT NULL";
|
|
1096
|
-
const pk = col.isPrimaryKey ? "PRIMARY KEY" : "";
|
|
1097
|
-
const defaultVal = col.defaultValue ? `DEFAULT '${col.defaultValue}'` : "";
|
|
1098
|
-
return `${col.name} ${col.dataType} ${pk} ${nullable} ${defaultVal}`.trim();
|
|
1099
|
-
}).join(", ");
|
|
1100
|
-
const sql = `CREATE TABLE ${table.name} (${columnDefs})`;
|
|
1101
|
-
await client.SQL.execute({ query: sql });
|
|
1102
|
-
setTableCreatorOpen(false);
|
|
1103
|
-
toast.success(`Table "${table.name}" created`);
|
|
1104
|
-
await refetch();
|
|
1105
|
-
} catch (err) {
|
|
1106
|
-
toast.error(`Failed to create table: ${err instanceof Error ? err.message : "Unknown error"}`);
|
|
1107
|
-
}
|
|
1108
|
-
},
|
|
1109
|
-
[client, refetch]
|
|
1110
|
-
);
|
|
1111
|
-
const handleCellUpdate = React4.useCallback(
|
|
1112
|
-
async (rowIndex, columnId, value) => {
|
|
1113
|
-
if (readOnly || !selectedType) return;
|
|
1114
|
-
const row = localData[rowIndex];
|
|
1115
|
-
const oldValue = row?.[columnId];
|
|
1116
|
-
const rowId = row?.id;
|
|
1117
|
-
pushOperation({ rowIndex, columnId, oldValue, newValue: value, type: "cell_update" });
|
|
1118
|
-
try {
|
|
1119
|
-
await client.Thing.update({
|
|
1120
|
-
ns: selectedNamespace,
|
|
1121
|
-
type: selectedType,
|
|
1122
|
-
id: rowId,
|
|
1123
|
-
data: { [columnId]: value }
|
|
1124
|
-
});
|
|
1125
|
-
toast.success("Cell updated");
|
|
1126
|
-
} catch (err) {
|
|
1127
|
-
undo();
|
|
1128
|
-
toast.error(`Failed to save cell: ${err instanceof Error ? err.message : "Unknown error"}`);
|
|
1129
|
-
}
|
|
1130
|
-
},
|
|
1131
|
-
[readOnly, selectedType, selectedNamespace, localData, pushOperation, undo, client]
|
|
1132
|
-
);
|
|
1133
|
-
const handleInsert = React4.useCallback(
|
|
1134
|
-
async (newRow) => {
|
|
1135
|
-
if (readOnly || !selectedType) return;
|
|
1136
|
-
try {
|
|
1137
|
-
const name = newRow.name || `New ${selectedType}`;
|
|
1138
|
-
const cleanData = {};
|
|
1139
|
-
for (const [key, value] of Object.entries(newRow)) {
|
|
1140
|
-
if (["id", "createdAt", "updatedAt", "_ns", "_type"].includes(key)) continue;
|
|
1141
|
-
if (value === null || value === void 0) continue;
|
|
1142
|
-
cleanData[key] = value;
|
|
1143
|
-
}
|
|
1144
|
-
await client.Thing.create({
|
|
1145
|
-
ns: selectedNamespace,
|
|
1146
|
-
type: selectedType,
|
|
1147
|
-
name,
|
|
1148
|
-
data: cleanData
|
|
1149
|
-
});
|
|
1150
|
-
await refetch();
|
|
1151
|
-
toast.success("Row added successfully");
|
|
1152
|
-
} catch (err) {
|
|
1153
|
-
console.error("[@mdxui/do] Failed to create row:", err);
|
|
1154
|
-
toast.error(`Failed to create row: ${err instanceof Error ? err.message : "Unknown error"}`);
|
|
1155
|
-
}
|
|
1156
|
-
},
|
|
1157
|
-
[readOnly, selectedType, selectedNamespace, client, refetch]
|
|
1158
|
-
);
|
|
1159
|
-
const handleDeleteRows = React4.useCallback(
|
|
1160
|
-
async (rowIds) => {
|
|
1161
|
-
if (readOnly || !selectedType) return;
|
|
1162
|
-
try {
|
|
1163
|
-
await Promise.all(
|
|
1164
|
-
rowIds.map(
|
|
1165
|
-
(id) => (
|
|
1166
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1167
|
-
client.Thing.delete({
|
|
1168
|
-
ns: selectedNamespace,
|
|
1169
|
-
type: selectedType,
|
|
1170
|
-
id
|
|
1171
|
-
})
|
|
1172
|
-
)
|
|
1173
|
-
)
|
|
1174
|
-
);
|
|
1175
|
-
setLocalData((prev) => prev.filter((row) => !rowIds.includes(String(row.id))));
|
|
1176
|
-
setSelectedRows([]);
|
|
1177
|
-
toast.success(`${rowIds.length} row${rowIds.length > 1 ? "s" : ""} deleted`);
|
|
1178
|
-
} catch (err) {
|
|
1179
|
-
toast.error(`Failed to delete rows: ${err instanceof Error ? err.message : "Unknown error"}`);
|
|
1180
|
-
}
|
|
1181
|
-
},
|
|
1182
|
-
[readOnly, selectedType, selectedNamespace, client]
|
|
1183
|
-
);
|
|
1184
|
-
const handleRefresh = React4.useCallback(async () => {
|
|
1185
|
-
setRefreshStatus("refreshing");
|
|
1186
|
-
try {
|
|
1187
|
-
await refetch();
|
|
1188
|
-
setRefreshStatus("success");
|
|
1189
|
-
setLastRefreshTime(/* @__PURE__ */ new Date());
|
|
1190
|
-
setTimeout(() => setRefreshStatus("idle"), 2e3);
|
|
1191
|
-
} catch {
|
|
1192
|
-
setRefreshStatus("error");
|
|
1193
|
-
setTimeout(() => setRefreshStatus("idle"), 3e3);
|
|
1194
|
-
}
|
|
1195
|
-
}, [refetch]);
|
|
1196
|
-
const handleToggleColumnVisibility = React4.useCallback((accessorKey) => {
|
|
1197
|
-
setHiddenColumns((prev) => {
|
|
1198
|
-
const next = new Set(prev);
|
|
1199
|
-
if (next.has(accessorKey)) {
|
|
1200
|
-
next.delete(accessorKey);
|
|
1201
|
-
} else {
|
|
1202
|
-
next.add(accessorKey);
|
|
1203
|
-
}
|
|
1204
|
-
return next;
|
|
1205
|
-
});
|
|
1206
|
-
}, []);
|
|
1207
|
-
const handleExport = React4.useCallback(
|
|
1208
|
-
(scope, format) => {
|
|
1209
|
-
const dataToExport = scope === "all" ? localData : scope === "filtered" ? filteredData : filteredData;
|
|
1210
|
-
let content;
|
|
1211
|
-
let mimeType;
|
|
1212
|
-
let extension;
|
|
1213
|
-
switch (format) {
|
|
1214
|
-
case "json":
|
|
1215
|
-
content = JSON.stringify(dataToExport, null, 2);
|
|
1216
|
-
mimeType = "application/json";
|
|
1217
|
-
extension = "json";
|
|
1218
|
-
break;
|
|
1219
|
-
case "csv": {
|
|
1220
|
-
const headers = visibleColumns.map((c) => c.header).join(",");
|
|
1221
|
-
const rows = dataToExport.map(
|
|
1222
|
-
(row) => visibleColumns.map((c) => JSON.stringify(row[c.accessorKey] ?? "")).join(",")
|
|
1223
|
-
);
|
|
1224
|
-
content = [headers, ...rows].join("\n");
|
|
1225
|
-
mimeType = "text/csv";
|
|
1226
|
-
extension = "csv";
|
|
1227
|
-
break;
|
|
1228
|
-
}
|
|
1229
|
-
default:
|
|
1230
|
-
content = JSON.stringify(dataToExport, null, 2);
|
|
1231
|
-
mimeType = "application/json";
|
|
1232
|
-
extension = "json";
|
|
1233
|
-
}
|
|
1234
|
-
const blob = new Blob([content], { type: mimeType });
|
|
1235
|
-
const url = URL.createObjectURL(blob);
|
|
1236
|
-
const link = document.createElement("a");
|
|
1237
|
-
link.href = url;
|
|
1238
|
-
link.download = `${selectedType ?? "data"}-${scope}.${extension}`;
|
|
1239
|
-
document.body.appendChild(link);
|
|
1240
|
-
link.click();
|
|
1241
|
-
document.body.removeChild(link);
|
|
1242
|
-
URL.revokeObjectURL(url);
|
|
1243
|
-
},
|
|
1244
|
-
[localData, filteredData, visibleColumns, selectedType]
|
|
1245
|
-
);
|
|
1246
|
-
const handleQueryExecute = React4.useCallback(
|
|
1247
|
-
async (query) => {
|
|
1248
|
-
const startTime = Date.now();
|
|
1249
|
-
try {
|
|
1250
|
-
const result = await client.SQL.execute({ query });
|
|
1251
|
-
return {
|
|
1252
|
-
rows: result.rows,
|
|
1253
|
-
columns: result.columns.map((col) => ({
|
|
1254
|
-
name: col.name,
|
|
1255
|
-
type: col.type
|
|
1256
|
-
})),
|
|
1257
|
-
rowsAffected: result.rowsAffected,
|
|
1258
|
-
executionTime: result.executionTimeMs ?? Date.now() - startTime
|
|
1259
|
-
};
|
|
1260
|
-
} catch (err) {
|
|
1261
|
-
throw new Error(err instanceof Error ? err.message : "Query execution failed");
|
|
1262
|
-
}
|
|
1263
|
-
},
|
|
1264
|
-
[client]
|
|
1265
|
-
);
|
|
1266
|
-
React4.useEffect(() => {
|
|
1267
|
-
const mediaQuery = window.matchMedia("(max-width: 768px)");
|
|
1268
|
-
const handleMediaChange = (e) => {
|
|
1269
|
-
if (e.matches) {
|
|
1270
|
-
setSidebarCollapsed(true);
|
|
1271
|
-
}
|
|
1272
|
-
};
|
|
1273
|
-
handleMediaChange(mediaQuery);
|
|
1274
|
-
mediaQuery.addEventListener("change", handleMediaChange);
|
|
1275
|
-
return () => mediaQuery.removeEventListener("change", handleMediaChange);
|
|
1276
|
-
}, []);
|
|
1277
|
-
React4.useEffect(() => {
|
|
1278
|
-
const handleKeyDown = (e) => {
|
|
1279
|
-
if ((e.metaKey || e.ctrlKey) && e.key === "z") {
|
|
1280
|
-
if (e.shiftKey) {
|
|
1281
|
-
e.preventDefault();
|
|
1282
|
-
redo();
|
|
1283
|
-
} else {
|
|
1284
|
-
e.preventDefault();
|
|
1285
|
-
undo();
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
};
|
|
1289
|
-
document.addEventListener("keydown", handleKeyDown);
|
|
1290
|
-
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
1291
|
-
}, [undo, redo]);
|
|
1292
|
-
React4.useEffect(() => {
|
|
1293
|
-
if (!autoRefreshEnabled) return;
|
|
1294
|
-
const intervalMs = autoRefreshInterval * 1e3;
|
|
1295
|
-
const timer = setInterval(handleRefresh, intervalMs);
|
|
1296
|
-
return () => clearInterval(timer);
|
|
1297
|
-
}, [autoRefreshEnabled, autoRefreshInterval, handleRefresh]);
|
|
1298
|
-
const [schema, tableName] = selectedTable.split(".");
|
|
1299
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1300
|
-
/* @__PURE__ */ jsxs("div", { className: cn("flex h-full overflow-x-auto bg-background", className), children: [
|
|
1301
|
-
/* @__PURE__ */ jsx(
|
|
1302
|
-
DatabaseSidebar,
|
|
1303
|
-
{
|
|
1304
|
-
schemas,
|
|
1305
|
-
selectedTable,
|
|
1306
|
-
onSelectTable: handleSelectTable,
|
|
1307
|
-
onViewTable: (schema2, table) => handleSelectTable(schema2, table),
|
|
1308
|
-
onDuplicateTable: async (_schema, table) => {
|
|
1309
|
-
try {
|
|
1310
|
-
const sql = `CREATE TABLE ${table}_copy AS SELECT * FROM ${table}`;
|
|
1311
|
-
await client.SQL.execute({ query: sql });
|
|
1312
|
-
toast.success(`Table "${table}" duplicated as "${table}_copy"`);
|
|
1313
|
-
await refetch();
|
|
1314
|
-
} catch (err) {
|
|
1315
|
-
toast.error(`Failed to duplicate table: ${err instanceof Error ? err.message : "Unknown error"}`);
|
|
1316
|
-
}
|
|
1317
|
-
},
|
|
1318
|
-
onDeleteTable: async (_schema, table) => {
|
|
1319
|
-
try {
|
|
1320
|
-
await client.SQL.execute({ query: `DROP TABLE ${table}` });
|
|
1321
|
-
toast.success(`Table "${table}" deleted`);
|
|
1322
|
-
await refetch();
|
|
1323
|
-
} catch (err) {
|
|
1324
|
-
toast.error(`Failed to delete table: ${err instanceof Error ? err.message : "Unknown error"}`);
|
|
1325
|
-
}
|
|
1326
|
-
},
|
|
1327
|
-
onCreateTable: () => setTableCreatorOpen(true),
|
|
1328
|
-
collapsed: sidebarCollapsed,
|
|
1329
|
-
onCollapsedChange: setSidebarCollapsed,
|
|
1330
|
-
className: "shrink-0"
|
|
1331
|
-
}
|
|
1332
|
-
),
|
|
1333
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden min-w-[320px]", children: [
|
|
1334
|
-
/* @__PURE__ */ jsx(
|
|
1335
|
-
TableEditorToolbar,
|
|
1336
|
-
{
|
|
1337
|
-
schema,
|
|
1338
|
-
tableName: tableName || "Select a type",
|
|
1339
|
-
columns,
|
|
1340
|
-
totalRowCount: localData.length,
|
|
1341
|
-
filteredRowCount: filteredData.length,
|
|
1342
|
-
visibleRowCount: filteredData.length,
|
|
1343
|
-
selectedRowIds: selectedRows,
|
|
1344
|
-
onClearSelection: () => setSelectedRows([]),
|
|
1345
|
-
onDeleteSelectedRows: handleDeleteRows,
|
|
1346
|
-
sidebarCollapsed,
|
|
1347
|
-
onSidebarCollapsedChange: setSidebarCollapsed,
|
|
1348
|
-
viewMode,
|
|
1349
|
-
onViewModeChange: setViewMode,
|
|
1350
|
-
canUndo,
|
|
1351
|
-
canRedo,
|
|
1352
|
-
undoCount,
|
|
1353
|
-
redoCount,
|
|
1354
|
-
onUndo: undo,
|
|
1355
|
-
onRedo: redo,
|
|
1356
|
-
refreshStatus,
|
|
1357
|
-
onRefresh: handleRefresh,
|
|
1358
|
-
autoRefreshEnabled,
|
|
1359
|
-
onAutoRefreshEnabledChange: setAutoRefreshEnabled,
|
|
1360
|
-
autoRefreshInterval,
|
|
1361
|
-
onAutoRefreshIntervalChange: setAutoRefreshInterval,
|
|
1362
|
-
lastRefreshTime,
|
|
1363
|
-
filters,
|
|
1364
|
-
onFiltersChange: setFilters,
|
|
1365
|
-
hiddenColumns,
|
|
1366
|
-
onToggleColumnVisibility: handleToggleColumnVisibility,
|
|
1367
|
-
onInsertRow: () => gridActionsRef.current?.startNewRow(),
|
|
1368
|
-
onAddColumn: handleAddColumn,
|
|
1369
|
-
onExport: handleExport
|
|
1370
|
-
}
|
|
1371
|
-
),
|
|
1372
|
-
viewMode === "table" ? /* @__PURE__ */ jsx("div", { className: "flex min-h-0 flex-1 flex-col p-2", children: isLoading ? /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-2", children: [
|
|
1373
|
-
/* @__PURE__ */ jsx("div", { className: "h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" }),
|
|
1374
|
-
/* @__PURE__ */ jsx("span", { className: "text-sm text-muted-foreground", children: "Loading..." })
|
|
1375
|
-
] }) }) : !selectedType ? /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center h-full text-muted-foreground", children: "Select a type from the sidebar to view data" }) : /* @__PURE__ */ jsx(
|
|
1376
|
-
DatabaseGrid,
|
|
1377
|
-
{
|
|
1378
|
-
data: filteredData,
|
|
1379
|
-
columns: visibleColumns,
|
|
1380
|
-
onCellUpdate: handleCellUpdate,
|
|
1381
|
-
onInsert: handleInsert,
|
|
1382
|
-
onDeleteRows: handleDeleteRows,
|
|
1383
|
-
onViewRow: (rowId) => {
|
|
1384
|
-
toast.info(`Row ID: ${rowId}`);
|
|
1385
|
-
},
|
|
1386
|
-
onDuplicateRow: async (_rowId, row) => {
|
|
1387
|
-
if (!selectedType) return;
|
|
1388
|
-
const { id, _ns, _type, name, ...data } = row;
|
|
1389
|
-
try {
|
|
1390
|
-
await client.Thing.create({
|
|
1391
|
-
ns: selectedNamespace,
|
|
1392
|
-
type: selectedType,
|
|
1393
|
-
name: `${name || selectedType} (copy)`,
|
|
1394
|
-
data
|
|
1395
|
-
});
|
|
1396
|
-
await refetch();
|
|
1397
|
-
toast.success("Row duplicated");
|
|
1398
|
-
} catch (err) {
|
|
1399
|
-
console.error("[@mdxui/do] Failed to duplicate row:", err);
|
|
1400
|
-
toast.error(`Failed to duplicate row: ${err instanceof Error ? err.message : "Unknown error"}`);
|
|
1401
|
-
}
|
|
1402
|
-
},
|
|
1403
|
-
onSelectionChange: setSelectedRows,
|
|
1404
|
-
onColumnReorder: (order) => {
|
|
1405
|
-
if (selectedType) {
|
|
1406
|
-
localStorage.setItem(
|
|
1407
|
-
`do-column-order-${selectedNamespace}-${selectedType}`,
|
|
1408
|
-
JSON.stringify(order)
|
|
1409
|
-
);
|
|
1410
|
-
}
|
|
1411
|
-
},
|
|
1412
|
-
actionsRef: gridActionsRef,
|
|
1413
|
-
emptyMessage: "No data matches the current filters",
|
|
1414
|
-
className: "h-full"
|
|
1415
|
-
}
|
|
1416
|
-
) }) : viewMode === "query" ? /* @__PURE__ */ jsx(
|
|
1417
|
-
QueryView,
|
|
1418
|
-
{
|
|
1419
|
-
currentTable: tableName || "",
|
|
1420
|
-
schema,
|
|
1421
|
-
onExecute: handleQueryExecute,
|
|
1422
|
-
className: "flex-1"
|
|
1423
|
-
}
|
|
1424
|
-
) : /* @__PURE__ */ jsx(
|
|
1425
|
-
FormatView,
|
|
1426
|
-
{
|
|
1427
|
-
data: filteredData,
|
|
1428
|
-
columns,
|
|
1429
|
-
format: formatViewFormat,
|
|
1430
|
-
className: "flex-1"
|
|
1431
|
-
}
|
|
1432
|
-
)
|
|
1433
|
-
] })
|
|
1434
|
-
] }),
|
|
1435
|
-
/* @__PURE__ */ jsx(
|
|
1436
|
-
ColumnEditorPanel,
|
|
1437
|
-
{
|
|
1438
|
-
open: columnEditorOpen,
|
|
1439
|
-
onOpenChange: setColumnEditorOpen,
|
|
1440
|
-
column: editingColumn,
|
|
1441
|
-
referenceTables: types?.map((t) => ({
|
|
1442
|
-
name: t.name,
|
|
1443
|
-
columns: ["id", "name", "createdAt", "updatedAt"]
|
|
1444
|
-
})) ?? [],
|
|
1445
|
-
onSave: handleSaveColumn,
|
|
1446
|
-
onDelete: editingColumn ? handleDeleteColumn : void 0
|
|
1447
|
-
}
|
|
1448
|
-
),
|
|
1449
|
-
/* @__PURE__ */ jsx(
|
|
1450
|
-
TableCreatorPanel,
|
|
1451
|
-
{
|
|
1452
|
-
open: tableCreatorOpen,
|
|
1453
|
-
onOpenChange: setTableCreatorOpen,
|
|
1454
|
-
schemas: namespaces?.map((ns) => ns.name) ?? ["default"],
|
|
1455
|
-
onCreate: handleCreateTable
|
|
1456
|
-
}
|
|
1457
|
-
),
|
|
1458
|
-
/* @__PURE__ */ jsx(Toaster, { closeButton: true, position: "top-right" })
|
|
1459
|
-
] });
|
|
1460
|
-
}
|
|
1461
|
-
DataGridView.displayName = "DataGridView";
|
|
1462
|
-
function toDocumentType(type) {
|
|
1463
|
-
return {
|
|
1464
|
-
id: type.id,
|
|
1465
|
-
name: type.name,
|
|
1466
|
-
label: type.label
|
|
1467
|
-
};
|
|
1468
|
-
}
|
|
1469
|
-
function toDocumentTypeOption(type) {
|
|
1470
|
-
return {
|
|
1471
|
-
id: type.id,
|
|
1472
|
-
name: type.name,
|
|
1473
|
-
label: type.label
|
|
1474
|
-
};
|
|
1475
|
-
}
|
|
1476
|
-
function toDocumentItem(thing) {
|
|
1477
|
-
return {
|
|
1478
|
-
id: thing.id,
|
|
1479
|
-
name: thing.name,
|
|
1480
|
-
type: thing.type
|
|
1481
|
-
};
|
|
1482
|
-
}
|
|
1483
|
-
function DocumentEditorView({
|
|
1484
|
-
initialNamespace,
|
|
1485
|
-
initialType,
|
|
1486
|
-
initialId,
|
|
1487
|
-
onSave,
|
|
1488
|
-
onDelete,
|
|
1489
|
-
onBack: _onBack,
|
|
1490
|
-
className
|
|
1491
|
-
}) {
|
|
1492
|
-
const { namespace: contextNamespace } = useDO();
|
|
1493
|
-
const [selectedNamespace] = React4.useState(initialNamespace ?? contextNamespace);
|
|
1494
|
-
const [selectedType, setSelectedType] = React4.useState(initialType);
|
|
1495
|
-
const [selectedThingId, setSelectedThingId] = React4.useState(initialId);
|
|
1496
|
-
const [sidebarCollapsed, setSidebarCollapsed] = React4.useState(false);
|
|
1497
|
-
const [hasUnsavedChanges, setHasUnsavedChanges] = React4.useState(false);
|
|
1498
|
-
const [isSaving, setIsSaving] = React4.useState(false);
|
|
1499
|
-
const [localDocument, setLocalDocument] = React4.useState(null);
|
|
1500
|
-
const fileInputRef = React4.useRef(null);
|
|
1501
|
-
const { data: types } = useTypes({ ns: selectedNamespace });
|
|
1502
|
-
const { data: thingsResult, refetch: refetchThings } = useThings({
|
|
1503
|
-
ns: selectedNamespace,
|
|
1504
|
-
type: selectedType
|
|
1505
|
-
});
|
|
1506
|
-
const thingParams = selectedType && selectedThingId ? { ns: selectedNamespace, type: selectedType, id: selectedThingId } : { ns: "", type: "", id: "" };
|
|
1507
|
-
const { data: currentThing, isLoading: isLoadingThing } = useThing(thingParams);
|
|
1508
|
-
const updateThing = useUpdateThing(
|
|
1509
|
-
selectedType && selectedThingId ? { ns: selectedNamespace, type: selectedType, id: selectedThingId } : { ns: "temp", type: "temp", id: "temp" }
|
|
1510
|
-
);
|
|
1511
|
-
const deleteThing = useDeleteThing(
|
|
1512
|
-
selectedType && selectedThingId ? { ns: selectedNamespace, type: selectedType, id: selectedThingId } : { ns: "temp", type: "temp", id: "temp" }
|
|
1513
|
-
);
|
|
1514
|
-
const documentTypes = React4.useMemo(
|
|
1515
|
-
() => types?.map(toDocumentType) ?? [],
|
|
1516
|
-
[types]
|
|
1517
|
-
);
|
|
1518
|
-
const documentTypeOptions = React4.useMemo(
|
|
1519
|
-
() => types?.map(toDocumentTypeOption) ?? [],
|
|
1520
|
-
[types]
|
|
1521
|
-
);
|
|
1522
|
-
const documentItems = React4.useMemo(
|
|
1523
|
-
() => thingsResult?.data?.map(toDocumentItem) ?? [],
|
|
1524
|
-
[thingsResult]
|
|
1525
|
-
);
|
|
1526
|
-
React4.useEffect(() => {
|
|
1527
|
-
if (currentThing) {
|
|
1528
|
-
setLocalDocument({
|
|
1529
|
-
_id: currentThing.id,
|
|
1530
|
-
_ns: currentThing.ns,
|
|
1531
|
-
_type: currentThing.type,
|
|
1532
|
-
name: currentThing.name,
|
|
1533
|
-
createdAt: currentThing.createdAt instanceof Date ? currentThing.createdAt.toISOString() : currentThing.createdAt,
|
|
1534
|
-
updatedAt: currentThing.updatedAt instanceof Date ? currentThing.updatedAt.toISOString() : currentThing.updatedAt,
|
|
1535
|
-
...currentThing.data
|
|
1536
|
-
});
|
|
1537
|
-
setHasUnsavedChanges(false);
|
|
1538
|
-
} else {
|
|
1539
|
-
setLocalDocument(null);
|
|
1540
|
-
}
|
|
1541
|
-
}, [currentThing]);
|
|
1542
|
-
const handleSelectDocument = React4.useCallback((type, documentId) => {
|
|
1543
|
-
setSelectedType(type);
|
|
1544
|
-
setSelectedThingId(documentId);
|
|
1545
|
-
setHasUnsavedChanges(false);
|
|
1546
|
-
}, []);
|
|
1547
|
-
const handleDocumentChange = React4.useCallback((updatedDoc) => {
|
|
1548
|
-
setLocalDocument(updatedDoc);
|
|
1549
|
-
setHasUnsavedChanges(true);
|
|
1550
|
-
}, []);
|
|
1551
|
-
const handleCreateDocument = React4.useCallback((type) => {
|
|
1552
|
-
const newId = `${Date.now()}`;
|
|
1553
|
-
setSelectedType(type);
|
|
1554
|
-
setSelectedThingId(newId);
|
|
1555
|
-
setLocalDocument({
|
|
1556
|
-
_id: newId,
|
|
1557
|
-
_type: type,
|
|
1558
|
-
_ns: selectedNamespace,
|
|
1559
|
-
name: "New Thing",
|
|
1560
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1561
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1562
|
-
});
|
|
1563
|
-
setHasUnsavedChanges(true);
|
|
1564
|
-
}, [selectedNamespace]);
|
|
1565
|
-
const handleSave = React4.useCallback(async () => {
|
|
1566
|
-
if (!localDocument || !selectedType || !selectedThingId) return;
|
|
1567
|
-
setIsSaving(true);
|
|
1568
|
-
try {
|
|
1569
|
-
const { _id, _ns, _type, createdAt, updatedAt, name, ...data } = localDocument;
|
|
1570
|
-
await updateThing.mutateAsync({
|
|
1571
|
-
name,
|
|
1572
|
-
data
|
|
1573
|
-
});
|
|
1574
|
-
setHasUnsavedChanges(false);
|
|
1575
|
-
await refetchThings();
|
|
1576
|
-
if (onSave && currentThing) {
|
|
1577
|
-
onSave({ ...currentThing, name, data });
|
|
1578
|
-
}
|
|
1579
|
-
} catch (err) {
|
|
1580
|
-
console.error("Failed to save:", err);
|
|
1581
|
-
} finally {
|
|
1582
|
-
setIsSaving(false);
|
|
1583
|
-
}
|
|
1584
|
-
}, [localDocument, selectedType, selectedThingId, updateThing, refetchThings, onSave, currentThing]);
|
|
1585
|
-
const handleDelete = React4.useCallback(async () => {
|
|
1586
|
-
if (!selectedType || !selectedThingId) return;
|
|
1587
|
-
try {
|
|
1588
|
-
await deleteThing.mutateAsync();
|
|
1589
|
-
const remainingThings = thingsResult?.data?.filter((t) => t.id !== selectedThingId) ?? [];
|
|
1590
|
-
if (remainingThings.length > 0) {
|
|
1591
|
-
setSelectedThingId(remainingThings[0].id);
|
|
1592
|
-
setSelectedType(remainingThings[0].type);
|
|
1593
|
-
} else {
|
|
1594
|
-
setSelectedThingId(void 0);
|
|
1595
|
-
}
|
|
1596
|
-
setHasUnsavedChanges(false);
|
|
1597
|
-
await refetchThings();
|
|
1598
|
-
onDelete?.();
|
|
1599
|
-
} catch (err) {
|
|
1600
|
-
console.error("Failed to delete:", err);
|
|
1601
|
-
}
|
|
1602
|
-
}, [selectedType, selectedThingId, deleteThing, thingsResult, refetchThings, onDelete]);
|
|
1603
|
-
const handleExport = React4.useCallback(() => {
|
|
1604
|
-
if (!localDocument) return;
|
|
1605
|
-
const json = JSON.stringify(localDocument, null, 2);
|
|
1606
|
-
const blob = new Blob([json], { type: "application/json" });
|
|
1607
|
-
const url = URL.createObjectURL(blob);
|
|
1608
|
-
const link = document.createElement("a");
|
|
1609
|
-
link.href = url;
|
|
1610
|
-
link.download = `${selectedThingId}.json`;
|
|
1611
|
-
document.body.appendChild(link);
|
|
1612
|
-
link.click();
|
|
1613
|
-
document.body.removeChild(link);
|
|
1614
|
-
URL.revokeObjectURL(url);
|
|
1615
|
-
}, [localDocument, selectedThingId]);
|
|
1616
|
-
const handleImport = React4.useCallback(() => {
|
|
1617
|
-
fileInputRef.current?.click();
|
|
1618
|
-
}, []);
|
|
1619
|
-
const handleFileChange = React4.useCallback(
|
|
1620
|
-
(event) => {
|
|
1621
|
-
const file = event.target.files?.[0];
|
|
1622
|
-
if (!file || !selectedType) return;
|
|
1623
|
-
const reader = new FileReader();
|
|
1624
|
-
reader.onload = (e) => {
|
|
1625
|
-
try {
|
|
1626
|
-
const content = e.target?.result;
|
|
1627
|
-
const parsed = JSON.parse(content);
|
|
1628
|
-
if (typeof parsed !== "object" || parsed === null) {
|
|
1629
|
-
throw new Error("Invalid JSON: root must be an object");
|
|
1630
|
-
}
|
|
1631
|
-
const newId = `${Date.now()}`;
|
|
1632
|
-
setSelectedThingId(newId);
|
|
1633
|
-
setLocalDocument({
|
|
1634
|
-
...parsed,
|
|
1635
|
-
_id: newId,
|
|
1636
|
-
_type: selectedType,
|
|
1637
|
-
_ns: selectedNamespace
|
|
1638
|
-
});
|
|
1639
|
-
setHasUnsavedChanges(true);
|
|
1640
|
-
} catch (err) {
|
|
1641
|
-
console.error("Failed to import document:", err);
|
|
1642
|
-
}
|
|
1643
|
-
};
|
|
1644
|
-
reader.readAsText(file);
|
|
1645
|
-
event.target.value = "";
|
|
1646
|
-
},
|
|
1647
|
-
[selectedType, selectedNamespace]
|
|
1648
|
-
);
|
|
1649
|
-
const handleRefresh = React4.useCallback(async () => {
|
|
1650
|
-
await refetchThings();
|
|
1651
|
-
setHasUnsavedChanges(false);
|
|
1652
|
-
}, [refetchThings]);
|
|
1653
|
-
React4.useEffect(() => {
|
|
1654
|
-
const mediaQuery = window.matchMedia("(max-width: 768px)");
|
|
1655
|
-
const handleMediaChange = (e) => {
|
|
1656
|
-
if (e.matches) {
|
|
1657
|
-
setSidebarCollapsed(true);
|
|
1658
|
-
}
|
|
1659
|
-
};
|
|
1660
|
-
handleMediaChange(mediaQuery);
|
|
1661
|
-
mediaQuery.addEventListener("change", handleMediaChange);
|
|
1662
|
-
return () => mediaQuery.removeEventListener("change", handleMediaChange);
|
|
1663
|
-
}, []);
|
|
1664
|
-
return /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsxs("div", { className: cn("flex h-full overflow-x-auto bg-background", className), children: [
|
|
1665
|
-
/* @__PURE__ */ jsx(
|
|
1666
|
-
"input",
|
|
1667
|
-
{
|
|
1668
|
-
ref: fileInputRef,
|
|
1669
|
-
type: "file",
|
|
1670
|
-
accept: ".json,application/json",
|
|
1671
|
-
className: "hidden",
|
|
1672
|
-
onChange: handleFileChange
|
|
1673
|
-
}
|
|
1674
|
-
),
|
|
1675
|
-
/* @__PURE__ */ jsx(
|
|
1676
|
-
DocumentSidebar,
|
|
1677
|
-
{
|
|
1678
|
-
types: documentTypes,
|
|
1679
|
-
documents: documentItems,
|
|
1680
|
-
selectedType,
|
|
1681
|
-
selectedDocumentId: selectedThingId,
|
|
1682
|
-
onSelectDocument: handleSelectDocument,
|
|
1683
|
-
onCreateDocument: handleCreateDocument,
|
|
1684
|
-
collapsed: sidebarCollapsed
|
|
1685
|
-
}
|
|
1686
|
-
),
|
|
1687
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden min-w-[320px]", children: [
|
|
1688
|
-
/* @__PURE__ */ jsx(
|
|
1689
|
-
DocumentViewToolbar,
|
|
1690
|
-
{
|
|
1691
|
-
typeName: selectedType,
|
|
1692
|
-
documentName: localDocument ? localDocument.name : void 0,
|
|
1693
|
-
documentId: selectedThingId,
|
|
1694
|
-
hasUnsavedChanges,
|
|
1695
|
-
isSaving,
|
|
1696
|
-
hasDocument: !!localDocument,
|
|
1697
|
-
types: documentTypeOptions,
|
|
1698
|
-
sidebarCollapsed,
|
|
1699
|
-
onSidebarToggle: () => setSidebarCollapsed(!sidebarCollapsed),
|
|
1700
|
-
onSave: handleSave,
|
|
1701
|
-
onRefresh: handleRefresh,
|
|
1702
|
-
onImport: handleImport,
|
|
1703
|
-
onExport: handleExport,
|
|
1704
|
-
onDelete: handleDelete,
|
|
1705
|
-
onCreateNew: handleCreateDocument
|
|
1706
|
-
}
|
|
1707
|
-
),
|
|
1708
|
-
/* @__PURE__ */ jsx("div", { className: "flex min-h-0 flex-1 flex-col", children: isLoadingThing ? /* @__PURE__ */ jsx("div", { className: "flex h-full items-center justify-center", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-2", children: [
|
|
1709
|
-
/* @__PURE__ */ jsx("div", { className: "h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent" }),
|
|
1710
|
-
/* @__PURE__ */ jsx("span", { className: "text-sm text-muted-foreground", children: "Loading..." })
|
|
1711
|
-
] }) }) : localDocument ? /* @__PURE__ */ jsx(
|
|
1712
|
-
DocumentEditor,
|
|
1713
|
-
{
|
|
1714
|
-
document: localDocument,
|
|
1715
|
-
onChange: handleDocumentChange,
|
|
1716
|
-
className: "h-full"
|
|
1717
|
-
}
|
|
1718
|
-
) : /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col items-center justify-center text-muted-foreground", children: [
|
|
1719
|
-
/* @__PURE__ */ jsx(Database, { className: "mb-4 h-12 w-12 opacity-20" }),
|
|
1720
|
-
/* @__PURE__ */ jsx("p", { className: "text-sm", children: "No document selected" }),
|
|
1721
|
-
/* @__PURE__ */ jsx("p", { className: "mt-1 text-xs", children: "Select a document from the sidebar or create a new one" })
|
|
1722
|
-
] }) }),
|
|
1723
|
-
/* @__PURE__ */ jsxs("footer", { className: "flex h-10 shrink-0 items-center justify-between border-t bg-muted/30 px-2 sm:px-4 gap-4", children: [
|
|
1724
|
-
/* @__PURE__ */ jsx("div", { className: "text-xs text-muted-foreground whitespace-nowrap shrink-0", children: selectedType && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1725
|
-
/* @__PURE__ */ jsx("span", { className: "font-medium text-foreground", children: thingsResult?.data?.filter((t) => t.type === selectedType).length ?? 0 }),
|
|
1726
|
-
" ",
|
|
1727
|
-
"documents in ",
|
|
1728
|
-
selectedType
|
|
1729
|
-
] }) }),
|
|
1730
|
-
/* @__PURE__ */ jsx("div", { className: "text-xs text-muted-foreground truncate", children: localDocument && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1731
|
-
"ID:",
|
|
1732
|
-
" ",
|
|
1733
|
-
/* @__PURE__ */ jsx("span", { className: "font-mono text-foreground", children: selectedThingId })
|
|
1734
|
-
] }) })
|
|
1735
|
-
] })
|
|
1736
|
-
] })
|
|
1737
|
-
] }) });
|
|
1738
|
-
}
|
|
1739
|
-
DocumentEditorView.displayName = "DocumentEditorView";
|
|
1740
|
-
var STARTER_TEMPLATES = [
|
|
1741
|
-
{
|
|
1742
|
-
id: "list-things",
|
|
1743
|
-
name: "List all Things",
|
|
1744
|
-
description: "List all Things in the namespace",
|
|
1745
|
-
code: `// List all Things
|
|
1746
|
-
const things = await client.things.list({
|
|
1747
|
-
limit: 100,
|
|
1748
|
-
})
|
|
1749
|
-
|
|
1750
|
-
return { things, relationships: [] }`
|
|
1751
|
-
},
|
|
1752
|
-
{
|
|
1753
|
-
id: "list-by-type",
|
|
1754
|
-
name: "List Things by type",
|
|
1755
|
-
description: "Filter Things by their semantic type",
|
|
1756
|
-
code: `// List Things by type
|
|
1757
|
-
const type = 'User' // Change this to your type
|
|
1758
|
-
|
|
1759
|
-
const things = await client.things.list({
|
|
1760
|
-
type,
|
|
1761
|
-
limit: 100,
|
|
1762
|
-
})
|
|
1763
|
-
|
|
1764
|
-
return { things, relationships: [] }`
|
|
1765
|
-
},
|
|
1766
|
-
{
|
|
1767
|
-
id: "get-thing",
|
|
1768
|
-
name: "Get single Thing",
|
|
1769
|
-
description: "Fetch a specific Thing by ID",
|
|
1770
|
-
code: `// Get a single Thing by ID
|
|
1771
|
-
const id = 'thing-id' // Replace with actual ID
|
|
1772
|
-
|
|
1773
|
-
const thing = await client.things.get(id)
|
|
1774
|
-
|
|
1775
|
-
return { things: [thing], relationships: [] }`
|
|
1776
|
-
},
|
|
1777
|
-
{
|
|
1778
|
-
id: "create-thing",
|
|
1779
|
-
name: "Create new Thing",
|
|
1780
|
-
description: "Create a new Thing in the namespace",
|
|
1781
|
-
code: `// Create a new Thing
|
|
1782
|
-
const newThing = await client.things.create({
|
|
1783
|
-
type: 'User',
|
|
1784
|
-
name: 'New User',
|
|
1785
|
-
data: {
|
|
1786
|
-
email: 'user@example.com',
|
|
1787
|
-
role: 'member',
|
|
1788
|
-
},
|
|
1789
|
-
})
|
|
1790
|
-
|
|
1791
|
-
return { things: [newThing], relationships: [] }`
|
|
1792
|
-
},
|
|
1793
|
-
{
|
|
1794
|
-
id: "update-thing",
|
|
1795
|
-
name: "Update a Thing",
|
|
1796
|
-
description: "Update an existing Thing",
|
|
1797
|
-
code: `// Update a Thing
|
|
1798
|
-
const id = 'thing-id' // Replace with actual ID
|
|
1799
|
-
|
|
1800
|
-
const updatedThing = await client.things.update(id, {
|
|
1801
|
-
name: 'Updated Name',
|
|
1802
|
-
data: {
|
|
1803
|
-
email: 'updated@example.com',
|
|
1804
|
-
},
|
|
1805
|
-
})
|
|
1806
|
-
|
|
1807
|
-
return { things: [updatedThing], relationships: [] }`
|
|
1808
|
-
},
|
|
1809
|
-
{
|
|
1810
|
-
id: "query-things",
|
|
1811
|
-
name: "Query with filters",
|
|
1812
|
-
description: "Complex query with multiple filters",
|
|
1813
|
-
code: `// Query Things with filters
|
|
1814
|
-
const things = await client.things.list({
|
|
1815
|
-
type: 'User',
|
|
1816
|
-
filter: {
|
|
1817
|
-
'data.role': 'admin',
|
|
1818
|
-
},
|
|
1819
|
-
sort: '-createdAt',
|
|
1820
|
-
limit: 50,
|
|
1821
|
-
})
|
|
1822
|
-
|
|
1823
|
-
return { things, relationships: [] }`
|
|
1824
|
-
}
|
|
1825
|
-
];
|
|
1826
|
-
function FunctionEditorView({
|
|
1827
|
-
initialCode,
|
|
1828
|
-
onCodeChange,
|
|
1829
|
-
className
|
|
1830
|
-
}) {
|
|
1831
|
-
const { client, namespace } = useDO();
|
|
1832
|
-
const editorControlsRef = React4.useRef(null);
|
|
1833
|
-
const [, forceUpdate] = React4.useReducer((x) => x + 1, 0);
|
|
1834
|
-
const [sidebarCollapsed, setSidebarCollapsed] = React4.useState(false);
|
|
1835
|
-
const [currentCode, setCurrentCode] = React4.useState(initialCode ?? STARTER_TEMPLATES[0].code);
|
|
1836
|
-
const [history, setHistory] = React4.useState([]);
|
|
1837
|
-
const [savedQueries, setSavedQueries] = React4.useState([]);
|
|
1838
|
-
const [saveDialogOpen, setSaveDialogOpen] = React4.useState(false);
|
|
1839
|
-
const [queryName, setQueryName] = React4.useState("");
|
|
1840
|
-
React4.useEffect(() => {
|
|
1841
|
-
const interval = setInterval(() => {
|
|
1842
|
-
if (editorControlsRef.current) {
|
|
1843
|
-
forceUpdate();
|
|
1844
|
-
}
|
|
1845
|
-
}, 100);
|
|
1846
|
-
return () => clearInterval(interval);
|
|
1847
|
-
}, []);
|
|
1848
|
-
const handleExecute = React4.useCallback(
|
|
1849
|
-
async (code) => {
|
|
1850
|
-
const startTime = performance.now();
|
|
1851
|
-
try {
|
|
1852
|
-
const AsyncFunction = Object.getPrototypeOf(async function() {
|
|
1853
|
-
}).constructor;
|
|
1854
|
-
const fn = new AsyncFunction("client", "namespace", code);
|
|
1855
|
-
const result = await fn(client, namespace);
|
|
1856
|
-
const executionTime = Math.round(performance.now() - startTime);
|
|
1857
|
-
const historyItem = {
|
|
1858
|
-
id: `hist_${Date.now()}`,
|
|
1859
|
-
code,
|
|
1860
|
-
timestamp: /* @__PURE__ */ new Date(),
|
|
1861
|
-
executionTime,
|
|
1862
|
-
resultCount: (result?.things?.length ?? 0) + (result?.relationships?.length ?? 0)
|
|
1863
|
-
};
|
|
1864
|
-
setHistory((prev) => [historyItem, ...prev].slice(0, 20));
|
|
1865
|
-
onCodeChange?.(code);
|
|
1866
|
-
return {
|
|
1867
|
-
things: result?.things ?? [],
|
|
1868
|
-
relationships: result?.relationships ?? [],
|
|
1869
|
-
executionTime
|
|
1870
|
-
};
|
|
1871
|
-
} catch (err) {
|
|
1872
|
-
const executionTime = Math.round(performance.now() - startTime);
|
|
1873
|
-
const historyItem = {
|
|
1874
|
-
id: `hist_${Date.now()}`,
|
|
1875
|
-
code,
|
|
1876
|
-
timestamp: /* @__PURE__ */ new Date(),
|
|
1877
|
-
executionTime,
|
|
1878
|
-
resultCount: 0
|
|
1879
|
-
};
|
|
1880
|
-
setHistory((prev) => [historyItem, ...prev].slice(0, 20));
|
|
1881
|
-
throw err;
|
|
1882
|
-
}
|
|
1883
|
-
},
|
|
1884
|
-
[client, namespace, onCodeChange]
|
|
1885
|
-
);
|
|
1886
|
-
const handleSelectHistory = React4.useCallback((code) => {
|
|
1887
|
-
setCurrentCode(code);
|
|
1888
|
-
}, []);
|
|
1889
|
-
const handleClearHistory = React4.useCallback(() => {
|
|
1890
|
-
setHistory([]);
|
|
1891
|
-
}, []);
|
|
1892
|
-
const handleSelectSavedQuery = React4.useCallback((query) => {
|
|
1893
|
-
setCurrentCode(query.code);
|
|
1894
|
-
}, []);
|
|
1895
|
-
const handleDeleteSavedQuery = React4.useCallback((id) => {
|
|
1896
|
-
setSavedQueries((prev) => prev.filter((q) => q.id !== id));
|
|
1897
|
-
}, []);
|
|
1898
|
-
const handleSelectTemplate = React4.useCallback((template) => {
|
|
1899
|
-
setCurrentCode(template.code);
|
|
1900
|
-
}, []);
|
|
1901
|
-
const handleSaveQuery = React4.useCallback(() => {
|
|
1902
|
-
if (!queryName.trim()) return;
|
|
1903
|
-
const newQuery = {
|
|
1904
|
-
id: `saved_${Date.now()}`,
|
|
1905
|
-
name: queryName.trim(),
|
|
1906
|
-
code: currentCode,
|
|
1907
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
1908
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
1909
|
-
};
|
|
1910
|
-
setSavedQueries((prev) => [newQuery, ...prev]);
|
|
1911
|
-
setSaveDialogOpen(false);
|
|
1912
|
-
setQueryName("");
|
|
1913
|
-
}, [queryName, currentCode]);
|
|
1914
|
-
const toolbarHistory = editorControlsRef.current?.history?.map((item) => ({
|
|
1915
|
-
code: item.code,
|
|
1916
|
-
timestamp: item.timestamp
|
|
1917
|
-
})) ?? [];
|
|
1918
|
-
return /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsxs("div", { className: cn("flex h-full bg-background", className), children: [
|
|
1919
|
-
/* @__PURE__ */ jsx(
|
|
1920
|
-
FunctionSidebar,
|
|
1921
|
-
{
|
|
1922
|
-
title: "Function Editor",
|
|
1923
|
-
templates: STARTER_TEMPLATES,
|
|
1924
|
-
savedQueries,
|
|
1925
|
-
history,
|
|
1926
|
-
collapsed: sidebarCollapsed,
|
|
1927
|
-
onCollapsedChange: setSidebarCollapsed,
|
|
1928
|
-
onSelectTemplate: handleSelectTemplate,
|
|
1929
|
-
onSelectSavedQuery: handleSelectSavedQuery,
|
|
1930
|
-
onDeleteSavedQuery: handleDeleteSavedQuery,
|
|
1931
|
-
onSelectHistory: handleSelectHistory,
|
|
1932
|
-
onClearHistory: handleClearHistory
|
|
1933
|
-
}
|
|
1934
|
-
),
|
|
1935
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden min-w-[320px]", children: [
|
|
1936
|
-
/* @__PURE__ */ jsx(
|
|
1937
|
-
FunctionViewToolbar,
|
|
1938
|
-
{
|
|
1939
|
-
sidebarCollapsed,
|
|
1940
|
-
onSidebarToggle: () => setSidebarCollapsed(!sidebarCollapsed),
|
|
1941
|
-
isExecuting: editorControlsRef.current?.isExecuting,
|
|
1942
|
-
disabled: editorControlsRef.current?.disabled,
|
|
1943
|
-
onRun: () => editorControlsRef.current?.execute(),
|
|
1944
|
-
onClear: () => editorControlsRef.current?.clear(),
|
|
1945
|
-
history: toolbarHistory,
|
|
1946
|
-
onSelectHistory: (code) => editorControlsRef.current?.selectHistory(code),
|
|
1947
|
-
canSave: !!currentCode.trim(),
|
|
1948
|
-
onSave: () => setSaveDialogOpen(true)
|
|
1949
|
-
}
|
|
1950
|
-
),
|
|
1951
|
-
/* @__PURE__ */ jsx("div", { className: "flex-1 h-0 overflow-hidden", children: /* @__PURE__ */ jsx(
|
|
1952
|
-
SDKEditor,
|
|
1953
|
-
{
|
|
1954
|
-
initialCode: currentCode,
|
|
1955
|
-
onExecute: handleExecute,
|
|
1956
|
-
defaultResultTab: "table",
|
|
1957
|
-
showToolbar: false,
|
|
1958
|
-
controlsRef: editorControlsRef,
|
|
1959
|
-
className: "h-full"
|
|
1960
|
-
}
|
|
1961
|
-
) })
|
|
1962
|
-
] }),
|
|
1963
|
-
/* @__PURE__ */ jsx(Dialog, { open: saveDialogOpen, onOpenChange: setSaveDialogOpen, children: /* @__PURE__ */ jsxs(DialogContent, { children: [
|
|
1964
|
-
/* @__PURE__ */ jsxs(DialogHeader, { children: [
|
|
1965
|
-
/* @__PURE__ */ jsx(DialogTitle, { children: "Save Query" }),
|
|
1966
|
-
/* @__PURE__ */ jsx(DialogDescription, { children: "Give your query a name to save it for later use." })
|
|
1967
|
-
] }),
|
|
1968
|
-
/* @__PURE__ */ jsx("div", { className: "py-4", children: /* @__PURE__ */ jsx(
|
|
1969
|
-
Input,
|
|
1970
|
-
{
|
|
1971
|
-
placeholder: "Query name...",
|
|
1972
|
-
value: queryName,
|
|
1973
|
-
onChange: (e) => setQueryName(e.target.value),
|
|
1974
|
-
onKeyDown: (e) => {
|
|
1975
|
-
if (e.key === "Enter") {
|
|
1976
|
-
handleSaveQuery();
|
|
1977
|
-
}
|
|
1978
|
-
},
|
|
1979
|
-
autoFocus: true
|
|
1980
|
-
}
|
|
1981
|
-
) }),
|
|
1982
|
-
/* @__PURE__ */ jsxs(DialogFooter, { children: [
|
|
1983
|
-
/* @__PURE__ */ jsx(Button, { variant: "outline", onClick: () => setSaveDialogOpen(false), children: "Cancel" }),
|
|
1984
|
-
/* @__PURE__ */ jsx(Button, { onClick: handleSaveQuery, disabled: !queryName.trim(), children: "Save" })
|
|
1985
|
-
] })
|
|
1986
|
-
] }) }),
|
|
1987
|
-
/* @__PURE__ */ jsx(Toaster, { closeButton: true, position: "top-right" })
|
|
1988
|
-
] }) });
|
|
1989
|
-
}
|
|
1990
|
-
FunctionEditorView.displayName = "FunctionEditorView";
|
|
1991
|
-
|
|
1992
|
-
export { CreateDialog, DataBrowserView, DataGridView, DetailSheet, DocumentEditorView, FunctionEditorView, exportToJSON, formatDate, formatFieldName, isISODateString };
|
|
1993
|
-
//# sourceMappingURL=chunk-GYIMQZE7.js.map
|
|
1994
|
-
//# sourceMappingURL=chunk-GYIMQZE7.js.map
|