@constructive-io/schema-builder 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +12 -4
- package/dist/card-widths-CmIxkRfh.cjs +28 -0
- package/dist/card-widths-CmIxkRfh.cjs.map +1 -0
- package/dist/card-widths-pI4Kw4Xz.js +22 -0
- package/dist/card-widths-pI4Kw4Xz.js.map +1 -0
- package/dist/core-CVxnNLs7.cjs +66 -0
- package/dist/core-CVxnNLs7.cjs.map +1 -0
- package/dist/core-DJ5kA4r-.js +49 -0
- package/dist/core-DJ5kA4r-.js.map +1 -0
- package/dist/core.cjs +14 -212
- package/dist/core.d.cts +3 -54
- package/dist/core.d.ts +3 -54
- package/dist/core.js +3 -200
- package/dist/create-table-card-B6SMrt_g.js +7691 -0
- package/dist/create-table-card-B6SMrt_g.js.map +1 -0
- package/dist/create-table-card-BrQ7pB_U.cjs +7732 -0
- package/dist/create-table-card-BrQ7pB_U.cjs.map +1 -0
- package/dist/delete-confirm-dialog-Ch4tWj6B.cjs +42 -0
- package/dist/delete-confirm-dialog-Ch4tWj6B.cjs.map +1 -0
- package/dist/delete-confirm-dialog-K0AWE643.js +37 -0
- package/dist/delete-confirm-dialog-K0AWE643.js.map +1 -0
- package/dist/empty-state-card-5t7LygTB.cjs +62 -0
- package/dist/empty-state-card-5t7LygTB.cjs.map +1 -0
- package/dist/empty-state-card-C-Nylatg.js +57 -0
- package/dist/empty-state-card-C-Nylatg.js.map +1 -0
- package/dist/fields.cjs +8 -7763
- package/dist/fields.d.cts +38 -39
- package/dist/fields.d.ts +38 -39
- package/dist/fields.js +2 -7735
- package/dist/generated-types-DZMUyNBH.d.cts +27 -0
- package/dist/generated-types-DZMUyNBH.d.ts +27 -0
- package/dist/index--9KTz1LB.d.cts +56 -0
- package/dist/index-10idAfdb.d.cts +7 -0
- package/dist/index-BcdFaKFS.d.ts +7 -0
- package/dist/index-euaSKMQK.d.ts +56 -0
- package/dist/index.cjs +392 -13730
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -10
- package/dist/index.d.ts +4 -10
- package/dist/index.js +381 -13698
- package/dist/index.js.map +1 -1
- package/dist/indexes-view-CBzYpKcd.js +736 -0
- package/dist/indexes-view-CBzYpKcd.js.map +1 -0
- package/dist/indexes-view-D1K24ts1.cjs +759 -0
- package/dist/indexes-view-D1K24ts1.cjs.map +1 -0
- package/dist/indexes.cjs +6 -1041
- package/dist/indexes.d.cts +27 -27
- package/dist/indexes.d.ts +27 -27
- package/dist/indexes.js +2 -1016
- package/dist/invalidate-database-entities-BFCWf5Zf.js +2561 -0
- package/dist/invalidate-database-entities-BFCWf5Zf.js.map +1 -0
- package/dist/invalidate-database-entities-Gs5k8A-M.cjs +2864 -0
- package/dist/invalidate-database-entities-Gs5k8A-M.cjs.map +1 -0
- package/dist/keyboard-activation-BQiV0scm.js +13 -0
- package/dist/keyboard-activation-BQiV0scm.js.map +1 -0
- package/dist/keyboard-activation-D-L0IU6Y.cjs +19 -0
- package/dist/keyboard-activation-D-L0IU6Y.cjs.map +1 -0
- package/dist/policies-view-CkvGpJBo.cjs +1023 -0
- package/dist/policies-view-CkvGpJBo.cjs.map +1 -0
- package/dist/policies-view-DTfAhX7G.js +1018 -0
- package/dist/policies-view-DTfAhX7G.js.map +1 -0
- package/dist/policies.cjs +10 -5939
- package/dist/policies.d.cts +55 -50
- package/dist/policies.d.ts +55 -50
- package/dist/policies.js +4 -5911
- package/dist/policy-config-form-EEcQ9ywL.js +2502 -0
- package/dist/policy-config-form-EEcQ9ywL.js.map +1 -0
- package/dist/policy-config-form-RP9010zj.cjs +2629 -0
- package/dist/policy-config-form-RP9010zj.cjs.map +1 -0
- package/dist/policy-types-D_sYWb-b.d.cts +81 -0
- package/dist/policy-types-D_sYWb-b.d.ts +81 -0
- package/dist/query-BGtzUV7Y.cjs +233 -0
- package/dist/query-BGtzUV7Y.cjs.map +1 -0
- package/dist/query-r6j8IjQB.js +192 -0
- package/dist/query-r6j8IjQB.js.map +1 -0
- package/dist/relationships-view-C884EvGj.js +2417 -0
- package/dist/relationships-view-C884EvGj.js.map +1 -0
- package/dist/relationships-view-DlBs-gCF.cjs +2452 -0
- package/dist/relationships-view-DlBs-gCF.cjs.map +1 -0
- package/dist/relationships.cjs +9 -4328
- package/dist/relationships.d.cts +92 -92
- package/dist/relationships.d.ts +92 -92
- package/dist/relationships.js +2 -4300
- package/dist/rolldown-runtime-D_qnwXdH.cjs +35 -0
- package/dist/schema-builder-sidebar-DAgK7ZTu.js +654 -0
- package/dist/schema-builder-sidebar-DAgK7ZTu.js.map +1 -0
- package/dist/schema-builder-sidebar-L3TcQeQr.cjs +671 -0
- package/dist/schema-builder-sidebar-L3TcQeQr.cjs.map +1 -0
- package/dist/table-editor-B-5i1M79.js +1906 -0
- package/dist/table-editor-B-5i1M79.js.map +1 -0
- package/dist/table-editor-BdLdVZfh.cjs +1935 -0
- package/dist/table-editor-BdLdVZfh.cjs.map +1 -0
- package/dist/tables.cjs +6 -5643
- package/dist/tables.d.cts +22 -21
- package/dist/tables.d.ts +22 -21
- package/dist/tables.js +3 -5618
- package/dist/testing.cjs +63 -62
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +4 -4
- package/dist/testing.d.ts +4 -4
- package/dist/testing.js +62 -61
- package/dist/testing.js.map +1 -1
- package/dist/types-CXNRA22N.d.cts +450 -0
- package/dist/types-CXNRA22N.d.ts +450 -0
- package/dist/use-update-table-DlLX9fdE.js +244 -0
- package/dist/use-update-table-DlLX9fdE.js.map +1 -0
- package/dist/use-update-table-vcoHVolI.cjs +291 -0
- package/dist/use-update-table-vcoHVolI.cjs.map +1 -0
- package/package.json +8 -6
- package/dist/core.cjs.map +0 -1
- package/dist/core.js.map +0 -1
- package/dist/fields.cjs.map +0 -1
- package/dist/fields.js.map +0 -1
- package/dist/generated-types-CnAlqHU_.d.cts +0 -25
- package/dist/generated-types-CnAlqHU_.d.ts +0 -25
- package/dist/indexes.cjs.map +0 -1
- package/dist/indexes.js.map +0 -1
- package/dist/policies.cjs.map +0 -1
- package/dist/policies.js.map +0 -1
- package/dist/policy-types-CEYAR5TN.d.cts +0 -79
- package/dist/policy-types-CEYAR5TN.d.ts +0 -79
- package/dist/relationships.cjs.map +0 -1
- package/dist/relationships.js.map +0 -1
- package/dist/tables.cjs.map +0 -1
- package/dist/tables.js.map +0 -1
- package/dist/types-Du86atZ8.d.cts +0 -199
- package/dist/types-Du86atZ8.d.ts +0 -199
- package/dist/types-bX2dCrdl.d.cts +0 -52
- package/dist/types-bX2dCrdl.d.ts +0 -52
|
@@ -0,0 +1,759 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
const require_invalidate_database_entities = require('./invalidate-database-entities-Gs5k8A-M.cjs');
|
|
3
|
+
const require_card_widths = require('./card-widths-CmIxkRfh.cjs');
|
|
4
|
+
const require_keyboard_activation = require('./keyboard-activation-D-L0IU6Y.cjs');
|
|
5
|
+
const require_empty_state_card = require('./empty-state-card-5t7LygTB.cjs');
|
|
6
|
+
const require_delete_confirm_dialog = require('./delete-confirm-dialog-Ch4tWj6B.cjs');
|
|
7
|
+
let _constructive_io_ui_stack = require("@constructive-io/ui/stack");
|
|
8
|
+
let react = require("react");
|
|
9
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
10
|
+
let _constructive_io_ui_tooltip = require("@constructive-io/ui/tooltip");
|
|
11
|
+
let lucide_react = require("lucide-react");
|
|
12
|
+
let _tanstack_react_query = require("@tanstack/react-query");
|
|
13
|
+
let _constructive_io_ui_button = require("@constructive-io/ui/button");
|
|
14
|
+
let _constructive_io_ui_toast = require("@constructive-io/ui/toast");
|
|
15
|
+
let _constructive_io_ui_input = require("@constructive-io/ui/input");
|
|
16
|
+
let _constructive_io_ui_label = require("@constructive-io/ui/label");
|
|
17
|
+
let _constructive_io_ui_scroll_area = require("@constructive-io/ui/scroll-area");
|
|
18
|
+
let _constructive_io_ui_responsive_diagram = require("@constructive-io/ui/responsive-diagram");
|
|
19
|
+
let _constructive_io_ui_select = require("@constructive-io/ui/select");
|
|
20
|
+
let _constructive_io_ui_switch = require("@constructive-io/ui/switch");
|
|
21
|
+
let _constructive_io_ui_multi_select = require("@constructive-io/ui/multi-select");
|
|
22
|
+
|
|
23
|
+
//#region src/schema/schema-builder-indexes/lib/gql/hooks/schema-builder/use-index-mutations.ts
|
|
24
|
+
/**
|
|
25
|
+
* Hook for managing indexes
|
|
26
|
+
* Tier 4 wrapper: adds cache invalidation and table selection
|
|
27
|
+
*/
|
|
28
|
+
function useCreateIndex() {
|
|
29
|
+
const queryClient = (0, _tanstack_react_query.useQueryClient)();
|
|
30
|
+
const { selectTable, currentDatabase, currentSchema } = require_invalidate_database_entities.useSchemaBuilderSelectors();
|
|
31
|
+
const createIndexMutation = require_invalidate_database_entities.useCreateIndexMutation({ selection: { fields: {
|
|
32
|
+
id: true,
|
|
33
|
+
name: true
|
|
34
|
+
} } });
|
|
35
|
+
return (0, _tanstack_react_query.useMutation)({
|
|
36
|
+
mutationFn: async (input) => {
|
|
37
|
+
const databaseId = currentDatabase?.databaseId ?? currentSchema?.metadata?.databaseId;
|
|
38
|
+
if (!databaseId) throw new Error("Database ID not found");
|
|
39
|
+
const createdIndex = (await createIndexMutation.mutateAsync({
|
|
40
|
+
databaseId,
|
|
41
|
+
tableId: input.tableId,
|
|
42
|
+
name: input.name,
|
|
43
|
+
fieldIds: require_invalidate_database_entities.asFieldIds(input.fieldIds),
|
|
44
|
+
isUnique: input.isUnique ?? false,
|
|
45
|
+
accessMethod: input.accessMethod || "btree"
|
|
46
|
+
})).createIndex?.index;
|
|
47
|
+
if (!createdIndex?.id) throw new Error("Failed to create index");
|
|
48
|
+
return {
|
|
49
|
+
id: createdIndex.id,
|
|
50
|
+
name: createdIndex.name ?? ""
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
onSuccess: async (_createdIndex, variables) => {
|
|
54
|
+
await require_invalidate_database_entities.invalidateDatabaseEntities(queryClient, currentDatabase?.databaseId ?? currentSchema?.metadata?.databaseId);
|
|
55
|
+
selectTable(variables.tableId);
|
|
56
|
+
},
|
|
57
|
+
onError: (error) => {
|
|
58
|
+
console.error("Failed to create index:", error);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function useUpdateIndex() {
|
|
63
|
+
const queryClient = (0, _tanstack_react_query.useQueryClient)();
|
|
64
|
+
const { selectTable, selectedTableId, currentDatabase, currentSchema } = require_invalidate_database_entities.useSchemaBuilderSelectors();
|
|
65
|
+
const updateIndexMutation = require_invalidate_database_entities.useUpdateIndexMutation({ selection: { fields: {
|
|
66
|
+
id: true,
|
|
67
|
+
name: true
|
|
68
|
+
} } });
|
|
69
|
+
return (0, _tanstack_react_query.useMutation)({
|
|
70
|
+
mutationFn: async (input) => {
|
|
71
|
+
const patch = {};
|
|
72
|
+
if (input.name !== void 0) patch.name = input.name;
|
|
73
|
+
if (input.fieldIds !== void 0) patch.fieldIds = input.fieldIds;
|
|
74
|
+
if (input.isUnique !== void 0) patch.isUnique = input.isUnique;
|
|
75
|
+
if (input.accessMethod !== void 0) patch.accessMethod = input.accessMethod;
|
|
76
|
+
const updatedIndex = (await updateIndexMutation.mutateAsync({
|
|
77
|
+
id: input.id,
|
|
78
|
+
indexPatch: patch
|
|
79
|
+
})).updateIndex?.index;
|
|
80
|
+
if (!updatedIndex?.id) throw new Error("Failed to update index");
|
|
81
|
+
return {
|
|
82
|
+
id: updatedIndex.id,
|
|
83
|
+
name: updatedIndex.name ?? ""
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
onSuccess: async () => {
|
|
87
|
+
await require_invalidate_database_entities.invalidateDatabaseEntities(queryClient, currentDatabase?.databaseId ?? currentSchema?.metadata?.databaseId);
|
|
88
|
+
if (selectedTableId) selectTable(selectedTableId);
|
|
89
|
+
},
|
|
90
|
+
onError: (error) => {
|
|
91
|
+
console.error("Failed to update index:", error);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function useDeleteIndex() {
|
|
96
|
+
const queryClient = (0, _tanstack_react_query.useQueryClient)();
|
|
97
|
+
const { selectTable, selectedTableId, currentDatabase, currentSchema } = require_invalidate_database_entities.useSchemaBuilderSelectors();
|
|
98
|
+
const deleteIndexMutation = require_invalidate_database_entities.useDeleteIndexMutation({ selection: { fields: { id: true } } });
|
|
99
|
+
return (0, _tanstack_react_query.useMutation)({
|
|
100
|
+
mutationFn: async (input) => {
|
|
101
|
+
await deleteIndexMutation.mutateAsync({ id: input.id });
|
|
102
|
+
return { id: input.id };
|
|
103
|
+
},
|
|
104
|
+
onSuccess: async () => {
|
|
105
|
+
await require_invalidate_database_entities.invalidateDatabaseEntities(queryClient, currentDatabase?.databaseId ?? currentSchema?.metadata?.databaseId);
|
|
106
|
+
if (selectedTableId) selectTable(selectedTableId);
|
|
107
|
+
},
|
|
108
|
+
onError: (error) => {
|
|
109
|
+
console.error("Failed to delete index:", error);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/schema/schema-builder-indexes/components/table-editor/index-diagram.tsx
|
|
116
|
+
const THEME = {
|
|
117
|
+
primary: "#6366F1",
|
|
118
|
+
light: "#E0E7FF",
|
|
119
|
+
border: "#A5B4FC",
|
|
120
|
+
connector: "#6366F1",
|
|
121
|
+
connectorLight: "#C7D2FE"
|
|
122
|
+
};
|
|
123
|
+
const MAX_NAME_WIDTH = 120;
|
|
124
|
+
function truncateName(name, maxWidth) {
|
|
125
|
+
const maxChars = Math.floor(maxWidth / 7);
|
|
126
|
+
if (name.length <= maxChars) return name;
|
|
127
|
+
return name.slice(0, maxChars - 1) + "…";
|
|
128
|
+
}
|
|
129
|
+
function TableFieldsNode({ tableName, fields, theme }) {
|
|
130
|
+
const fieldsLabel = (fields.length > 0 ? fields : ["field"]).join(", ");
|
|
131
|
+
const sizeClasses = "h-14 w-14";
|
|
132
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
133
|
+
className: "flex flex-col items-center gap-1.5",
|
|
134
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
135
|
+
className: "relative",
|
|
136
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
137
|
+
className: require_invalidate_database_entities.cn("absolute -top-1.5 -left-2 rounded-full border-2 bg-white", sizeClasses),
|
|
138
|
+
style: { borderColor: theme.border }
|
|
139
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
140
|
+
className: require_invalidate_database_entities.cn("absolute -top-0.5 -left-1 rounded-full border-2 bg-white", sizeClasses),
|
|
141
|
+
style: { borderColor: theme.border }
|
|
142
|
+
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
143
|
+
className: require_invalidate_database_entities.cn("relative flex items-center justify-center rounded-full border-2 shadow-sm", sizeClasses),
|
|
144
|
+
style: {
|
|
145
|
+
borderColor: theme.border,
|
|
146
|
+
backgroundColor: theme.light
|
|
147
|
+
},
|
|
148
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Database, {
|
|
149
|
+
className: "size-6",
|
|
150
|
+
style: { color: theme.primary }
|
|
151
|
+
})
|
|
152
|
+
})]
|
|
153
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
154
|
+
className: "flex flex-col items-center gap-0.5",
|
|
155
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
156
|
+
className: "truncate text-sm font-medium text-gray-600 dark:text-gray-300",
|
|
157
|
+
style: { maxWidth: MAX_NAME_WIDTH },
|
|
158
|
+
title: tableName,
|
|
159
|
+
children: truncateName(tableName || "Table", MAX_NAME_WIDTH)
|
|
160
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
161
|
+
className: "truncate text-xs text-gray-600 dark:text-gray-400",
|
|
162
|
+
style: { maxWidth: MAX_NAME_WIDTH },
|
|
163
|
+
title: fieldsLabel,
|
|
164
|
+
children: truncateName(fieldsLabel, MAX_NAME_WIDTH)
|
|
165
|
+
})]
|
|
166
|
+
})]
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
function IndexNode({ indexName, typeLabel, theme, isUnique }) {
|
|
170
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
171
|
+
className: "flex flex-col items-center gap-2",
|
|
172
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
173
|
+
className: "relative",
|
|
174
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
175
|
+
className: "flex flex-col items-center gap-1 rounded-lg border-2 bg-white px-3 py-2",
|
|
176
|
+
style: {
|
|
177
|
+
borderColor: theme.border,
|
|
178
|
+
backgroundColor: theme.light
|
|
179
|
+
},
|
|
180
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.DatabaseZap, {
|
|
181
|
+
className: "size-6",
|
|
182
|
+
style: { color: theme.primary }
|
|
183
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
184
|
+
className: "max-w-[100px] truncate text-center text-xs font-medium",
|
|
185
|
+
style: { color: theme.primary },
|
|
186
|
+
title: typeLabel,
|
|
187
|
+
children: typeLabel
|
|
188
|
+
})]
|
|
189
|
+
}), isUnique && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
190
|
+
className: "absolute -right-2 -bottom-2 flex h-6 w-6 items-center justify-center rounded-full border-2\n border-white shadow-sm",
|
|
191
|
+
style: { backgroundColor: theme.primary },
|
|
192
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
193
|
+
className: "text-[10px] font-bold text-white",
|
|
194
|
+
children: "U"
|
|
195
|
+
})
|
|
196
|
+
})]
|
|
197
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
198
|
+
className: "max-w-[100px] truncate text-center text-sm text-gray-600 dark:text-gray-300",
|
|
199
|
+
title: indexName,
|
|
200
|
+
children: truncateName(indexName || "Index", 100)
|
|
201
|
+
})]
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
function ArrowConnector({ theme, label }) {
|
|
205
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
206
|
+
className: "relative flex flex-col items-center justify-center",
|
|
207
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
208
|
+
className: "absolute -top-2 left-1/2 -translate-x-1/2 rounded border px-1.5 py-px text-[10px] leading-tight\n font-medium whitespace-nowrap",
|
|
209
|
+
style: {
|
|
210
|
+
borderColor: theme.primary,
|
|
211
|
+
backgroundColor: theme.light,
|
|
212
|
+
color: theme.primary
|
|
213
|
+
},
|
|
214
|
+
children: label
|
|
215
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
216
|
+
width: 90,
|
|
217
|
+
height: "40",
|
|
218
|
+
viewBox: "0 0 90 40",
|
|
219
|
+
fill: "none",
|
|
220
|
+
children: [
|
|
221
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
222
|
+
cx: "6",
|
|
223
|
+
cy: "20",
|
|
224
|
+
r: "4",
|
|
225
|
+
fill: theme.connector
|
|
226
|
+
}),
|
|
227
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("line", {
|
|
228
|
+
x1: "10",
|
|
229
|
+
y1: "20",
|
|
230
|
+
x2: "74",
|
|
231
|
+
y2: "20",
|
|
232
|
+
stroke: theme.connectorLight,
|
|
233
|
+
strokeWidth: "2.5",
|
|
234
|
+
strokeLinecap: "round"
|
|
235
|
+
}),
|
|
236
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("polygon", {
|
|
237
|
+
points: "84,20 76,15 76,25",
|
|
238
|
+
fill: theme.connector
|
|
239
|
+
})
|
|
240
|
+
]
|
|
241
|
+
})]
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
function IndexDiagram({ tableName, indexName, fields, indexType, isUnique }) {
|
|
245
|
+
const theme = THEME;
|
|
246
|
+
const typeLabel = require_invalidate_database_entities.INDEX_TYPE_LABELS[indexType && require_invalidate_database_entities.INDEX_TYPE_LABELS[indexType] ? indexType : "btree"];
|
|
247
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
248
|
+
className: "flex items-center justify-center gap-3",
|
|
249
|
+
children: [
|
|
250
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(IndexNode, {
|
|
251
|
+
indexName: indexName || "Index",
|
|
252
|
+
typeLabel,
|
|
253
|
+
theme,
|
|
254
|
+
isUnique
|
|
255
|
+
}),
|
|
256
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ArrowConnector, {
|
|
257
|
+
theme,
|
|
258
|
+
label: "indexes"
|
|
259
|
+
}),
|
|
260
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TableFieldsNode, {
|
|
261
|
+
tableName,
|
|
262
|
+
fields,
|
|
263
|
+
theme
|
|
264
|
+
})
|
|
265
|
+
]
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
//#endregion
|
|
270
|
+
//#region src/schema/schema-builder-indexes/components/table-editor/index-card.tsx
|
|
271
|
+
const FIELD_SUMMARY_LIMIT$1 = 4;
|
|
272
|
+
const indexTypeOptions = Object.keys(require_invalidate_database_entities.INDEX_TYPE_LABELS).map((value) => ({
|
|
273
|
+
value,
|
|
274
|
+
label: value === "btree" ? `${require_invalidate_database_entities.INDEX_TYPE_LABELS[value]} (default)` : require_invalidate_database_entities.INDEX_TYPE_LABELS[value]
|
|
275
|
+
}));
|
|
276
|
+
function normalizeIndexType(type) {
|
|
277
|
+
const raw = type?.toLowerCase();
|
|
278
|
+
return raw && raw in require_invalidate_database_entities.INDEX_TYPE_LABELS ? raw : "btree";
|
|
279
|
+
}
|
|
280
|
+
function generateIndexName(tableName, existingIndexes) {
|
|
281
|
+
let counter = 1;
|
|
282
|
+
let candidateName = `${tableName}_index_${counter}`;
|
|
283
|
+
while (existingIndexes.some((idx) => idx.name === candidateName)) {
|
|
284
|
+
counter++;
|
|
285
|
+
candidateName = `${tableName}_index_${counter}`;
|
|
286
|
+
}
|
|
287
|
+
return candidateName;
|
|
288
|
+
}
|
|
289
|
+
const IndexCard = ({ editingIndex: initialEditingIndex, card }) => {
|
|
290
|
+
const { currentTable } = require_invalidate_database_entities.useSchemaBuilderSelectors();
|
|
291
|
+
const createIndexMutation = useCreateIndex();
|
|
292
|
+
const updateIndexMutation = useUpdateIndex();
|
|
293
|
+
const [isPendingTransition, startTransition] = (0, react.useTransition)();
|
|
294
|
+
const indexes = currentTable?.indexes || [];
|
|
295
|
+
const [editingIndex, setEditingIndex] = (0, react.useState)(() => {
|
|
296
|
+
if (initialEditingIndex) return {
|
|
297
|
+
...initialEditingIndex,
|
|
298
|
+
fields: [...initialEditingIndex.fields],
|
|
299
|
+
type: normalizeIndexType(initialEditingIndex.type)
|
|
300
|
+
};
|
|
301
|
+
return null;
|
|
302
|
+
});
|
|
303
|
+
const [originalIndex, setOriginalIndex] = (0, react.useState)(() => {
|
|
304
|
+
if (initialEditingIndex) return {
|
|
305
|
+
...initialEditingIndex,
|
|
306
|
+
fields: [...initialEditingIndex.fields],
|
|
307
|
+
type: normalizeIndexType(initialEditingIndex.type)
|
|
308
|
+
};
|
|
309
|
+
return null;
|
|
310
|
+
});
|
|
311
|
+
const fieldOptions = (0, react.useMemo)(() => currentTable?.fields.map((field) => ({
|
|
312
|
+
label: field.name,
|
|
313
|
+
value: field.id
|
|
314
|
+
})) || [], [currentTable?.fields]);
|
|
315
|
+
const fieldNameMap = (0, react.useMemo)(() => {
|
|
316
|
+
const map = {};
|
|
317
|
+
currentTable?.fields.forEach((field) => {
|
|
318
|
+
map[field.id] = field.name;
|
|
319
|
+
});
|
|
320
|
+
return map;
|
|
321
|
+
}, [currentTable?.fields]);
|
|
322
|
+
(0, react.useEffect)(() => {
|
|
323
|
+
if (!initialEditingIndex && currentTable && !editingIndex) startTransition(() => {
|
|
324
|
+
const generatedName = generateIndexName(currentTable.name, indexes);
|
|
325
|
+
setEditingIndex({
|
|
326
|
+
id: `idx-${Date.now()}`,
|
|
327
|
+
name: generatedName,
|
|
328
|
+
fields: [],
|
|
329
|
+
unique: false,
|
|
330
|
+
type: "btree"
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
}, [
|
|
334
|
+
initialEditingIndex,
|
|
335
|
+
currentTable,
|
|
336
|
+
indexes,
|
|
337
|
+
editingIndex
|
|
338
|
+
]);
|
|
339
|
+
const handleSaveIndex = (0, react.useCallback)(async () => {
|
|
340
|
+
if (!editingIndex || editingIndex.fields.length === 0 || !currentTable) return;
|
|
341
|
+
const trimmedName = editingIndex.name?.trim() ?? "";
|
|
342
|
+
if (!trimmedName) return;
|
|
343
|
+
const isExisting = indexes.some((index) => index.id === editingIndex.id);
|
|
344
|
+
try {
|
|
345
|
+
if (isExisting) {
|
|
346
|
+
await updateIndexMutation.mutateAsync({
|
|
347
|
+
id: editingIndex.id,
|
|
348
|
+
name: trimmedName,
|
|
349
|
+
fieldIds: editingIndex.fields,
|
|
350
|
+
isUnique: editingIndex.type === "btree" ? editingIndex.unique : false,
|
|
351
|
+
accessMethod: editingIndex.type
|
|
352
|
+
});
|
|
353
|
+
_constructive_io_ui_toast.toast.success({
|
|
354
|
+
message: "Index updated",
|
|
355
|
+
description: `Index "${trimmedName}" has been updated`
|
|
356
|
+
});
|
|
357
|
+
} else {
|
|
358
|
+
await createIndexMutation.mutateAsync({
|
|
359
|
+
tableId: currentTable.id,
|
|
360
|
+
name: trimmedName,
|
|
361
|
+
fieldIds: editingIndex.fields,
|
|
362
|
+
isUnique: editingIndex.type === "btree" ? editingIndex.unique : false,
|
|
363
|
+
accessMethod: editingIndex.type
|
|
364
|
+
});
|
|
365
|
+
_constructive_io_ui_toast.toast.success({
|
|
366
|
+
message: "Index created",
|
|
367
|
+
description: `Index "${trimmedName}" has been created`
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
card.close();
|
|
371
|
+
} catch (error) {
|
|
372
|
+
_constructive_io_ui_toast.toast.error({
|
|
373
|
+
message: isExisting ? "Failed to update index" : "Failed to create index",
|
|
374
|
+
description: error instanceof Error ? error.message : "An error occurred"
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
}, [
|
|
378
|
+
editingIndex,
|
|
379
|
+
currentTable,
|
|
380
|
+
indexes,
|
|
381
|
+
updateIndexMutation,
|
|
382
|
+
createIndexMutation,
|
|
383
|
+
card
|
|
384
|
+
]);
|
|
385
|
+
const handleNameChange = (0, react.useCallback)((event) => {
|
|
386
|
+
setEditingIndex((prev) => prev ? {
|
|
387
|
+
...prev,
|
|
388
|
+
name: event.target.value
|
|
389
|
+
} : null);
|
|
390
|
+
}, []);
|
|
391
|
+
const handleFieldsChange = (0, react.useCallback)((values) => {
|
|
392
|
+
setEditingIndex((prev) => prev ? {
|
|
393
|
+
...prev,
|
|
394
|
+
fields: values
|
|
395
|
+
} : null);
|
|
396
|
+
}, []);
|
|
397
|
+
const handleTypeChange = (0, react.useCallback)((value) => {
|
|
398
|
+
setEditingIndex((prev) => prev ? {
|
|
399
|
+
...prev,
|
|
400
|
+
type: value,
|
|
401
|
+
unique: value === "btree" ? prev.unique : false
|
|
402
|
+
} : null);
|
|
403
|
+
}, []);
|
|
404
|
+
const handleUniqueChange = (0, react.useCallback)((checked) => {
|
|
405
|
+
setEditingIndex((prev) => prev ? {
|
|
406
|
+
...prev,
|
|
407
|
+
unique: checked
|
|
408
|
+
} : null);
|
|
409
|
+
}, []);
|
|
410
|
+
const handleClose = (0, react.useCallback)(() => {
|
|
411
|
+
card.close();
|
|
412
|
+
}, [card]);
|
|
413
|
+
const hasChanges = (0, react.useMemo)(() => {
|
|
414
|
+
if (originalIndex === null) return true;
|
|
415
|
+
if (!editingIndex) return false;
|
|
416
|
+
return editingIndex.name !== originalIndex.name || editingIndex.type !== originalIndex.type || editingIndex.unique !== originalIndex.unique || editingIndex.fields.length !== originalIndex.fields.length || editingIndex.fields.some((f, i) => f !== originalIndex.fields[i]);
|
|
417
|
+
}, [editingIndex, originalIndex]);
|
|
418
|
+
if (!currentTable) return null;
|
|
419
|
+
const isEditMode = initialEditingIndex !== null;
|
|
420
|
+
const selectedIndexType = editingIndex?.type ?? "btree";
|
|
421
|
+
const selectedFieldNames = editingIndex?.fields.map((id) => fieldNameMap[id] || id) || [];
|
|
422
|
+
const canSave = editingIndex && editingIndex.fields.length > 0 && (editingIndex.name?.trim().length ?? 0) > 0 && hasChanges;
|
|
423
|
+
const isPending = createIndexMutation.isPending || updateIndexMutation.isPending;
|
|
424
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
425
|
+
className: "flex h-full flex-col",
|
|
426
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_scroll_area.ScrollArea, {
|
|
427
|
+
className: "min-h-0 flex-1",
|
|
428
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
429
|
+
className: "space-y-6 p-6",
|
|
430
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_responsive_diagram.ResponsiveDiagram, {
|
|
431
|
+
className: "py-8",
|
|
432
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IndexDiagram, {
|
|
433
|
+
tableName: currentTable.name,
|
|
434
|
+
indexName: editingIndex?.name,
|
|
435
|
+
fields: selectedFieldNames,
|
|
436
|
+
indexType: selectedIndexType,
|
|
437
|
+
isUnique: editingIndex?.unique ?? false
|
|
438
|
+
})
|
|
439
|
+
}), editingIndex && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
440
|
+
className: "space-y-4",
|
|
441
|
+
children: [
|
|
442
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
443
|
+
className: "space-y-2",
|
|
444
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_label.Label, {
|
|
445
|
+
className: "block",
|
|
446
|
+
htmlFor: "index-name",
|
|
447
|
+
children: "Index name"
|
|
448
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_input.Input, {
|
|
449
|
+
id: "index-name",
|
|
450
|
+
value: editingIndex.name,
|
|
451
|
+
onChange: handleNameChange,
|
|
452
|
+
placeholder: "e.g. table_index_1"
|
|
453
|
+
})]
|
|
454
|
+
}),
|
|
455
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
456
|
+
className: "space-y-2",
|
|
457
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_label.Label, {
|
|
458
|
+
className: "block",
|
|
459
|
+
children: "Fields"
|
|
460
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_multi_select.MultiSelect, {
|
|
461
|
+
options: fieldOptions,
|
|
462
|
+
defaultValue: editingIndex.fields,
|
|
463
|
+
onValueChange: handleFieldsChange,
|
|
464
|
+
placeholder: "Select fields",
|
|
465
|
+
dropdownMaxHeight: "300px",
|
|
466
|
+
maxCount: FIELD_SUMMARY_LIMIT$1
|
|
467
|
+
})]
|
|
468
|
+
}),
|
|
469
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
470
|
+
className: "space-y-2",
|
|
471
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_label.Label, {
|
|
472
|
+
className: "block",
|
|
473
|
+
children: "Index type"
|
|
474
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_select.Select, {
|
|
475
|
+
value: selectedIndexType,
|
|
476
|
+
onValueChange: handleTypeChange,
|
|
477
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectTrigger, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectValue, { placeholder: "Select index type" }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectContent, { children: indexTypeOptions.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_select.SelectItem, {
|
|
478
|
+
value: option.value,
|
|
479
|
+
children: option.label
|
|
480
|
+
}, option.value)) })]
|
|
481
|
+
})]
|
|
482
|
+
}),
|
|
483
|
+
selectedIndexType === "btree" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
484
|
+
className: "flex items-center justify-between",
|
|
485
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_label.Label, {
|
|
486
|
+
htmlFor: "index-unique",
|
|
487
|
+
children: "Unique"
|
|
488
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_switch.Switch, {
|
|
489
|
+
id: "index-unique",
|
|
490
|
+
checked: editingIndex.unique ?? false,
|
|
491
|
+
onCheckedChange: handleUniqueChange
|
|
492
|
+
})]
|
|
493
|
+
})
|
|
494
|
+
]
|
|
495
|
+
})]
|
|
496
|
+
})
|
|
497
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
498
|
+
className: "flex justify-end gap-2 border-t p-4",
|
|
499
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_button.Button, {
|
|
500
|
+
variant: "outline",
|
|
501
|
+
disabled: isPending,
|
|
502
|
+
onClick: handleClose,
|
|
503
|
+
children: "Cancel"
|
|
504
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_button.Button, {
|
|
505
|
+
onClick: handleSaveIndex,
|
|
506
|
+
disabled: !canSave || isPending,
|
|
507
|
+
children: [isPending && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Loader2, { className: "h-4 w-4 animate-spin" }), isPending ? "Saving..." : isEditMode ? "Update index" : "Create index"]
|
|
508
|
+
})]
|
|
509
|
+
})]
|
|
510
|
+
});
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
//#endregion
|
|
514
|
+
//#region src/schema/schema-builder-indexes/components/table-editor/indexes/index-empty-state.tsx
|
|
515
|
+
function IndexEmptyState({ onCreateClick, tableName }) {
|
|
516
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_empty_state_card.EmptyStateCard, {
|
|
517
|
+
icon: lucide_react.ListChecks,
|
|
518
|
+
title: tableName ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: ["No indexes for ", tableName] }) : "Create your first index",
|
|
519
|
+
description: tableName ? `Add an index to improve query performance on ${tableName}. Indexes speed up data retrieval by creating efficient lookup structures.` : "Create indexes to optimize query performance. Indexes help the database find and retrieve data faster.",
|
|
520
|
+
actionLabel: "Create Index",
|
|
521
|
+
actionIcon: lucide_react.ListChecks,
|
|
522
|
+
onAction: onCreateClick,
|
|
523
|
+
features: [
|
|
524
|
+
{
|
|
525
|
+
icon: lucide_react.Zap,
|
|
526
|
+
title: "Faster Queries",
|
|
527
|
+
description: "Speed up data retrieval operations"
|
|
528
|
+
},
|
|
529
|
+
{
|
|
530
|
+
icon: lucide_react.Search,
|
|
531
|
+
title: "Efficient Lookups",
|
|
532
|
+
description: "Quick access to specific rows"
|
|
533
|
+
},
|
|
534
|
+
{
|
|
535
|
+
icon: lucide_react.Shield,
|
|
536
|
+
title: "Unique Constraints",
|
|
537
|
+
description: "Enforce data uniqueness rules"
|
|
538
|
+
}
|
|
539
|
+
]
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
//#endregion
|
|
544
|
+
//#region src/schema/schema-builder-indexes/components/table-editor/indexes/indexes-view.tsx
|
|
545
|
+
const FIELD_SUMMARY_LIMIT = 4;
|
|
546
|
+
function buildFieldSummary(fieldIds, tableFields, limit = FIELD_SUMMARY_LIMIT) {
|
|
547
|
+
const fieldNameList = fieldIds.map((fieldId) => tableFields.find((field) => field.id === fieldId)?.name || fieldId).filter(Boolean);
|
|
548
|
+
const visibleFields = fieldNameList.slice(0, limit);
|
|
549
|
+
const remainingCount = Math.max(fieldNameList.length - visibleFields.length, 0);
|
|
550
|
+
const hasFields = fieldNameList.length > 0;
|
|
551
|
+
return {
|
|
552
|
+
fieldSummary: hasFields ? `${visibleFields.join(", ")}${remainingCount > 0 ? `, +${remainingCount} more` : ""}` : "None",
|
|
553
|
+
fieldNameList,
|
|
554
|
+
hasFields
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
function NoTableSelectedState() {
|
|
558
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
559
|
+
className: "flex min-h-0 flex-1 flex-col items-center justify-center p-6",
|
|
560
|
+
children: [
|
|
561
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
562
|
+
className: "bg-muted/50 mb-4 flex h-16 w-16 items-center justify-center rounded-full",
|
|
563
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Table2, { className: "text-muted-foreground h-8 w-8" })
|
|
564
|
+
}),
|
|
565
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
|
|
566
|
+
className: "mb-1 text-balance text-lg font-semibold",
|
|
567
|
+
children: "No table selected"
|
|
568
|
+
}),
|
|
569
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
570
|
+
className: "text-muted-foreground max-w-sm text-center text-sm",
|
|
571
|
+
children: "Select a table from the sidebar to view and manage its indexes."
|
|
572
|
+
})
|
|
573
|
+
]
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
function IndexesView() {
|
|
577
|
+
const [deleteTarget, setDeleteTarget] = (0, react.useState)(null);
|
|
578
|
+
const [isDeleting, setIsDeleting] = (0, react.useState)(false);
|
|
579
|
+
const stack = (0, _constructive_io_ui_stack.useCardStack)();
|
|
580
|
+
const { currentTable } = require_invalidate_database_entities.useSchemaBuilderSelectors();
|
|
581
|
+
const deleteIndexMutation = useDeleteIndex();
|
|
582
|
+
if (!currentTable) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NoTableSelectedState, {});
|
|
583
|
+
const indexes = currentTable.indexes || [];
|
|
584
|
+
const hasIndexes = indexes.length > 0;
|
|
585
|
+
const handleOpenCreate = () => {
|
|
586
|
+
stack.push({
|
|
587
|
+
id: "index-new",
|
|
588
|
+
title: "Create Index",
|
|
589
|
+
Component: IndexCard,
|
|
590
|
+
props: { editingIndex: null },
|
|
591
|
+
width: require_card_widths.CARD_WIDTHS.medium
|
|
592
|
+
});
|
|
593
|
+
};
|
|
594
|
+
const handleOpenEdit = (index) => {
|
|
595
|
+
stack.push({
|
|
596
|
+
id: `index-${index.id}`,
|
|
597
|
+
title: "Edit Index",
|
|
598
|
+
Component: IndexCard,
|
|
599
|
+
props: { editingIndex: index },
|
|
600
|
+
width: require_card_widths.CARD_WIDTHS.medium
|
|
601
|
+
});
|
|
602
|
+
};
|
|
603
|
+
const handleDeleteRequest = (indexId, indexName) => {
|
|
604
|
+
setDeleteTarget({
|
|
605
|
+
id: indexId,
|
|
606
|
+
name: indexName
|
|
607
|
+
});
|
|
608
|
+
};
|
|
609
|
+
const handleDeleteConfirm = async () => {
|
|
610
|
+
if (!deleteTarget) return;
|
|
611
|
+
setIsDeleting(true);
|
|
612
|
+
try {
|
|
613
|
+
await deleteIndexMutation.mutateAsync({ id: deleteTarget.id });
|
|
614
|
+
_constructive_io_ui_toast.toast.success({ message: "Index deleted" });
|
|
615
|
+
setDeleteTarget(null);
|
|
616
|
+
} catch (error) {
|
|
617
|
+
_constructive_io_ui_toast.toast.error({
|
|
618
|
+
message: "Failed to delete index",
|
|
619
|
+
description: error instanceof Error ? error.message : "An error occurred"
|
|
620
|
+
});
|
|
621
|
+
} finally {
|
|
622
|
+
setIsDeleting(false);
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
626
|
+
className: "flex min-h-0 flex-1 flex-col overflow-auto p-6",
|
|
627
|
+
children: !hasIndexes ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(IndexEmptyState, {
|
|
628
|
+
onCreateClick: handleOpenCreate,
|
|
629
|
+
tableName: currentTable.name
|
|
630
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
631
|
+
className: "mx-auto w-full max-w-4xl space-y-6",
|
|
632
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
633
|
+
className: "flex items-center justify-between",
|
|
634
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
|
|
635
|
+
className: "text-balance text-xl font-semibold tracking-tight",
|
|
636
|
+
children: "Indexes"
|
|
637
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
638
|
+
className: "text-muted-foreground mt-1 text-sm",
|
|
639
|
+
children: [
|
|
640
|
+
indexes.length,
|
|
641
|
+
" index",
|
|
642
|
+
indexes.length !== 1 ? "es" : "",
|
|
643
|
+
" on",
|
|
644
|
+
" ",
|
|
645
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
|
|
646
|
+
className: "bg-muted rounded px-1.5 py-0.5 font-mono text-xs",
|
|
647
|
+
children: currentTable.name
|
|
648
|
+
})
|
|
649
|
+
]
|
|
650
|
+
})] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_button.Button, {
|
|
651
|
+
onClick: handleOpenCreate,
|
|
652
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Plus, { className: "mr-2 h-4 w-4" }), "Add Index"]
|
|
653
|
+
})]
|
|
654
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
655
|
+
className: "space-y-3",
|
|
656
|
+
children: indexes.map((index) => {
|
|
657
|
+
const { fieldNameList, hasFields } = buildFieldSummary(index.fields, currentTable.fields);
|
|
658
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
659
|
+
role: "button",
|
|
660
|
+
tabIndex: 0,
|
|
661
|
+
onClick: () => handleOpenEdit(index),
|
|
662
|
+
onKeyDown: (event) => {
|
|
663
|
+
require_keyboard_activation.handleActivationKeyDown(event, () => handleOpenEdit(index));
|
|
664
|
+
},
|
|
665
|
+
className: require_invalidate_database_entities.cn(`group relative cursor-pointer rounded-xl border p-4 transition-[background-color,border-color,box-shadow,scale]
|
|
666
|
+
duration-150 ease-out motion-safe:active:scale-[0.96]`, "border-border/60 hover:border-border/80 hover:bg-muted/30"),
|
|
667
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
668
|
+
className: "flex items-center justify-between",
|
|
669
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
670
|
+
className: "flex items-center gap-2",
|
|
671
|
+
children: [
|
|
672
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ListChecks, { className: "text-muted-foreground h-4 w-4" }),
|
|
673
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
674
|
+
className: "truncate text-sm font-semibold",
|
|
675
|
+
children: index.name || "Unnamed index"
|
|
676
|
+
}),
|
|
677
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
678
|
+
className: require_invalidate_database_entities.cn("rounded-full px-2 py-0.5 text-[10px] font-semibold tracking-wide uppercase", "border border-blue-500/30 bg-blue-500/10 text-blue-600 dark:text-blue-400"),
|
|
679
|
+
children: require_invalidate_database_entities.INDEX_TYPE_LABELS[index.type ?? "btree"] ?? index.type ?? "B-tree"
|
|
680
|
+
}),
|
|
681
|
+
index.unique && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
682
|
+
className: require_invalidate_database_entities.cn("rounded-full px-2 py-0.5 text-[10px] font-semibold tracking-wide uppercase", "border border-emerald-500/30 bg-emerald-500/10 text-emerald-600 dark:text-emerald-400"),
|
|
683
|
+
children: "Unique"
|
|
684
|
+
})
|
|
685
|
+
]
|
|
686
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_button.Button, {
|
|
687
|
+
variant: "ghost",
|
|
688
|
+
size: "sm",
|
|
689
|
+
"aria-label": "Delete index",
|
|
690
|
+
className: "text-muted-foreground hover:text-destructive hover:bg-destructive/10 h-8 w-8 shrink-0 p-0",
|
|
691
|
+
onClick: (e) => {
|
|
692
|
+
e.stopPropagation();
|
|
693
|
+
handleDeleteRequest(index.id, index.name || "this index");
|
|
694
|
+
},
|
|
695
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Trash2, { className: "h-4 w-4" })
|
|
696
|
+
})]
|
|
697
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
698
|
+
className: "mt-2.5 flex flex-wrap items-center gap-1.5",
|
|
699
|
+
children: hasFields ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [fieldNameList.slice(0, FIELD_SUMMARY_LIMIT).map((name) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
700
|
+
className: "bg-muted/60 text-foreground/80 rounded-md px-2 py-0.5 font-mono text-xs",
|
|
701
|
+
children: name
|
|
702
|
+
}, name)), fieldNameList.length > FIELD_SUMMARY_LIMIT && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_constructive_io_ui_tooltip.Tooltip, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_tooltip.TooltipTrigger, {
|
|
703
|
+
asChild: true,
|
|
704
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
705
|
+
className: "text-muted-foreground rounded-md px-1.5 py-0.5 text-xs",
|
|
706
|
+
children: [
|
|
707
|
+
"+",
|
|
708
|
+
fieldNameList.length - FIELD_SUMMARY_LIMIT,
|
|
709
|
+
" more"
|
|
710
|
+
]
|
|
711
|
+
})
|
|
712
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_constructive_io_ui_tooltip.TooltipContent, {
|
|
713
|
+
className: "max-w-xs",
|
|
714
|
+
children: fieldNameList.join(", ")
|
|
715
|
+
})] })] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
716
|
+
className: "text-muted-foreground text-xs",
|
|
717
|
+
children: "No fields"
|
|
718
|
+
})
|
|
719
|
+
})]
|
|
720
|
+
}, index.id);
|
|
721
|
+
})
|
|
722
|
+
})]
|
|
723
|
+
})
|
|
724
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_delete_confirm_dialog.DeleteConfirmDialog, {
|
|
725
|
+
entityType: "Index",
|
|
726
|
+
entityName: deleteTarget?.name ?? null,
|
|
727
|
+
open: !!deleteTarget,
|
|
728
|
+
onOpenChange: () => setDeleteTarget(null),
|
|
729
|
+
onConfirm: handleDeleteConfirm,
|
|
730
|
+
isPending: isDeleting
|
|
731
|
+
})] });
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
//#endregion
|
|
735
|
+
Object.defineProperty(exports, 'IndexesView', {
|
|
736
|
+
enumerable: true,
|
|
737
|
+
get: function () {
|
|
738
|
+
return IndexesView;
|
|
739
|
+
}
|
|
740
|
+
});
|
|
741
|
+
Object.defineProperty(exports, 'useCreateIndex', {
|
|
742
|
+
enumerable: true,
|
|
743
|
+
get: function () {
|
|
744
|
+
return useCreateIndex;
|
|
745
|
+
}
|
|
746
|
+
});
|
|
747
|
+
Object.defineProperty(exports, 'useDeleteIndex', {
|
|
748
|
+
enumerable: true,
|
|
749
|
+
get: function () {
|
|
750
|
+
return useDeleteIndex;
|
|
751
|
+
}
|
|
752
|
+
});
|
|
753
|
+
Object.defineProperty(exports, 'useUpdateIndex', {
|
|
754
|
+
enumerable: true,
|
|
755
|
+
get: function () {
|
|
756
|
+
return useUpdateIndex;
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
//# sourceMappingURL=indexes-view-D1K24ts1.cjs.map
|