@devtable/settings-form 1.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/api-caller/datasource.d.ts +7 -0
- package/dist/api-caller/datasource.typed.d.ts +13 -0
- package/dist/api-caller/index.d.ts +7 -0
- package/dist/datasource/add-data-source.d.ts +6 -0
- package/dist/datasource/data-source-list.d.ts +2 -0
- package/dist/datasource/delete-data-source.d.ts +6 -0
- package/dist/datasource/index.d.ts +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/settings-form.es.js +419 -0
- package/dist/settings-form.umd.js +9 -0
- package/dist/vite-env.d.ts +1 -0
- package/package.json +54 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Settings Form
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DataSourceType, IDataSource, IDataSourceConfig } from "./datasource.typed";
|
|
2
|
+
import { PaginationResponse } from "../../../website/src/api-caller/types";
|
|
3
|
+
export declare const datasource: {
|
|
4
|
+
list: () => Promise<PaginationResponse<IDataSource>>;
|
|
5
|
+
create: (type: DataSourceType, key: string, config: IDataSourceConfig) => Promise<PaginationResponse<IDataSource> | false>;
|
|
6
|
+
delete: (id: string) => Promise<void>;
|
|
7
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare type DataSourceType = 'postgresql' | 'mysql' | 'http';
|
|
2
|
+
export interface IDataSource {
|
|
3
|
+
id: string;
|
|
4
|
+
type: DataSourceType;
|
|
5
|
+
key: string;
|
|
6
|
+
}
|
|
7
|
+
export interface IDataSourceConfig {
|
|
8
|
+
host: string;
|
|
9
|
+
port: number;
|
|
10
|
+
username: string;
|
|
11
|
+
password: string;
|
|
12
|
+
database: string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const APICaller: {
|
|
2
|
+
datasource: {
|
|
3
|
+
list: () => Promise<import("../../../website/src/api-caller/types").PaginationResponse<import("./datasource.typed").IDataSource>>;
|
|
4
|
+
create: (type: import("./datasource.typed").DataSourceType, key: string, config: import("./datasource.typed").IDataSourceConfig) => Promise<false | import("../../../website/src/api-caller/types").PaginationResponse<import("./datasource.typed").IDataSource>>;
|
|
5
|
+
delete: (id: string) => Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './datasource';
|
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import { Modal, Button, Box, SegmentedControl, TextInput, Divider, Group, NumberInput, PasswordInput, Text, LoadingOverlay, Table } from "@mantine/core";
|
|
2
|
+
import { useForm, Controller } from "react-hook-form";
|
|
3
|
+
import { showNotification, updateNotification } from "@mantine/notifications";
|
|
4
|
+
import require$$0 from "react";
|
|
5
|
+
import { PlaylistAdd, Trash } from "tabler-icons-react";
|
|
6
|
+
import axios from "axios";
|
|
7
|
+
import { useRequest } from "ahooks";
|
|
8
|
+
import { useModals } from "@mantine/modals";
|
|
9
|
+
const getRequest = (method) => {
|
|
10
|
+
return (url, data, options = {}) => {
|
|
11
|
+
const headers = {
|
|
12
|
+
"X-Requested-With": "XMLHttpRequest",
|
|
13
|
+
"Content-Type": options.string ? "application/x-www-form-urlencoded" : "application/json",
|
|
14
|
+
...options.headers
|
|
15
|
+
};
|
|
16
|
+
const conf = {
|
|
17
|
+
baseURL: "http://localhost:31200",
|
|
18
|
+
method,
|
|
19
|
+
url,
|
|
20
|
+
params: method === "GET" ? data : options.params,
|
|
21
|
+
headers
|
|
22
|
+
};
|
|
23
|
+
if (["POST", "PUT"].includes(method)) {
|
|
24
|
+
conf.data = options.string ? JSON.stringify(data) : data;
|
|
25
|
+
}
|
|
26
|
+
return axios(conf).then((res) => {
|
|
27
|
+
return res.data;
|
|
28
|
+
}).catch((err) => {
|
|
29
|
+
return Promise.reject(err);
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
const post = getRequest("POST");
|
|
34
|
+
const datasource = {
|
|
35
|
+
list: async () => {
|
|
36
|
+
const res = await post("/datasource/list", {
|
|
37
|
+
filter: {},
|
|
38
|
+
sort: {
|
|
39
|
+
field: "create_time",
|
|
40
|
+
order: "ASC"
|
|
41
|
+
},
|
|
42
|
+
pagination: {
|
|
43
|
+
page: 1,
|
|
44
|
+
pagesize: 100
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return res;
|
|
48
|
+
},
|
|
49
|
+
create: async (type, key, config) => {
|
|
50
|
+
try {
|
|
51
|
+
const res = await post("/datasource/create", { type, key, config });
|
|
52
|
+
return res;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error(error);
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
delete: async (id) => {
|
|
59
|
+
await post("/datasource/delete", { id });
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const APICaller = {
|
|
63
|
+
datasource
|
|
64
|
+
};
|
|
65
|
+
var jsxRuntime = { exports: {} };
|
|
66
|
+
var reactJsxRuntime_production_min = {};
|
|
67
|
+
/**
|
|
68
|
+
* @license React
|
|
69
|
+
* react-jsx-runtime.production.min.js
|
|
70
|
+
*
|
|
71
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
72
|
+
*
|
|
73
|
+
* This source code is licensed under the MIT license found in the
|
|
74
|
+
* LICENSE file in the root directory of this source tree.
|
|
75
|
+
*/
|
|
76
|
+
var f = require$$0, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: true, ref: true, __self: true, __source: true };
|
|
77
|
+
function q(c, a, g) {
|
|
78
|
+
var b, d = {}, e = null, h = null;
|
|
79
|
+
void 0 !== g && (e = "" + g);
|
|
80
|
+
void 0 !== a.key && (e = "" + a.key);
|
|
81
|
+
void 0 !== a.ref && (h = a.ref);
|
|
82
|
+
for (b in a)
|
|
83
|
+
m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
|
|
84
|
+
if (c && c.defaultProps)
|
|
85
|
+
for (b in a = c.defaultProps, a)
|
|
86
|
+
void 0 === d[b] && (d[b] = a[b]);
|
|
87
|
+
return { $$typeof: k, type: c, key: e, ref: h, props: d, _owner: n.current };
|
|
88
|
+
}
|
|
89
|
+
reactJsxRuntime_production_min.Fragment = l;
|
|
90
|
+
reactJsxRuntime_production_min.jsx = q;
|
|
91
|
+
reactJsxRuntime_production_min.jsxs = q;
|
|
92
|
+
{
|
|
93
|
+
jsxRuntime.exports = reactJsxRuntime_production_min;
|
|
94
|
+
}
|
|
95
|
+
const jsx = jsxRuntime.exports.jsx;
|
|
96
|
+
const jsxs = jsxRuntime.exports.jsxs;
|
|
97
|
+
const Fragment = jsxRuntime.exports.Fragment;
|
|
98
|
+
function AddDataSourceForm({
|
|
99
|
+
postSubmit
|
|
100
|
+
}) {
|
|
101
|
+
const {
|
|
102
|
+
control,
|
|
103
|
+
handleSubmit,
|
|
104
|
+
formState: {
|
|
105
|
+
errors,
|
|
106
|
+
isValidating,
|
|
107
|
+
isValid
|
|
108
|
+
}
|
|
109
|
+
} = useForm({
|
|
110
|
+
defaultValues: {
|
|
111
|
+
type: "postgresql",
|
|
112
|
+
key: "",
|
|
113
|
+
config: {
|
|
114
|
+
host: "",
|
|
115
|
+
port: 5432,
|
|
116
|
+
username: "",
|
|
117
|
+
password: "",
|
|
118
|
+
database: ""
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
const addDataSource = async ({
|
|
123
|
+
type,
|
|
124
|
+
key,
|
|
125
|
+
config
|
|
126
|
+
}) => {
|
|
127
|
+
showNotification({
|
|
128
|
+
id: "for-creating",
|
|
129
|
+
title: "Pending",
|
|
130
|
+
message: "Adding data source...",
|
|
131
|
+
loading: true
|
|
132
|
+
});
|
|
133
|
+
const result = await APICaller.datasource.create(type, key, config);
|
|
134
|
+
if (!result) {
|
|
135
|
+
updateNotification({
|
|
136
|
+
id: "for-creating",
|
|
137
|
+
title: "Failed",
|
|
138
|
+
message: "Test connection failed with given info",
|
|
139
|
+
color: "red"
|
|
140
|
+
});
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
updateNotification({
|
|
144
|
+
id: "for-creating",
|
|
145
|
+
title: "Successful",
|
|
146
|
+
message: "Data source is added",
|
|
147
|
+
color: "green"
|
|
148
|
+
});
|
|
149
|
+
postSubmit();
|
|
150
|
+
};
|
|
151
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
152
|
+
mx: "auto",
|
|
153
|
+
children: /* @__PURE__ */ jsxs("form", {
|
|
154
|
+
onSubmit: handleSubmit(addDataSource),
|
|
155
|
+
children: [/* @__PURE__ */ jsx(Controller, {
|
|
156
|
+
name: "type",
|
|
157
|
+
control,
|
|
158
|
+
render: ({
|
|
159
|
+
field
|
|
160
|
+
}) => /* @__PURE__ */ jsx(SegmentedControl, {
|
|
161
|
+
fullWidth: true,
|
|
162
|
+
mb: "md",
|
|
163
|
+
data: [{
|
|
164
|
+
label: "PostgreSQL",
|
|
165
|
+
value: "postgresql"
|
|
166
|
+
}, {
|
|
167
|
+
label: "MySQL",
|
|
168
|
+
value: "mysql"
|
|
169
|
+
}, {
|
|
170
|
+
label: "HTTP",
|
|
171
|
+
value: "http",
|
|
172
|
+
disabled: true
|
|
173
|
+
}],
|
|
174
|
+
...field
|
|
175
|
+
})
|
|
176
|
+
}), /* @__PURE__ */ jsx(Controller, {
|
|
177
|
+
name: "key",
|
|
178
|
+
control,
|
|
179
|
+
render: ({
|
|
180
|
+
field
|
|
181
|
+
}) => /* @__PURE__ */ jsx(TextInput, {
|
|
182
|
+
mb: "md",
|
|
183
|
+
required: true,
|
|
184
|
+
label: "Name",
|
|
185
|
+
placeholder: "A unique name",
|
|
186
|
+
...field
|
|
187
|
+
})
|
|
188
|
+
}), /* @__PURE__ */ jsx(Divider, {
|
|
189
|
+
label: "Connection Info",
|
|
190
|
+
labelPosition: "center"
|
|
191
|
+
}), /* @__PURE__ */ jsxs(Group, {
|
|
192
|
+
direction: "row",
|
|
193
|
+
grow: true,
|
|
194
|
+
children: [/* @__PURE__ */ jsx(Controller, {
|
|
195
|
+
name: "config.host",
|
|
196
|
+
control,
|
|
197
|
+
render: ({
|
|
198
|
+
field
|
|
199
|
+
}) => /* @__PURE__ */ jsx(TextInput, {
|
|
200
|
+
mb: "md",
|
|
201
|
+
required: true,
|
|
202
|
+
label: "Host",
|
|
203
|
+
sx: {
|
|
204
|
+
flexGrow: 1
|
|
205
|
+
},
|
|
206
|
+
...field
|
|
207
|
+
})
|
|
208
|
+
}), /* @__PURE__ */ jsx(Controller, {
|
|
209
|
+
name: "config.port",
|
|
210
|
+
control,
|
|
211
|
+
render: ({
|
|
212
|
+
field
|
|
213
|
+
}) => /* @__PURE__ */ jsx(NumberInput, {
|
|
214
|
+
mb: "md",
|
|
215
|
+
required: true,
|
|
216
|
+
label: "Port",
|
|
217
|
+
hideControls: true,
|
|
218
|
+
sx: {
|
|
219
|
+
width: "8em"
|
|
220
|
+
},
|
|
221
|
+
...field
|
|
222
|
+
})
|
|
223
|
+
})]
|
|
224
|
+
}), /* @__PURE__ */ jsx(Controller, {
|
|
225
|
+
name: "config.username",
|
|
226
|
+
control,
|
|
227
|
+
render: ({
|
|
228
|
+
field
|
|
229
|
+
}) => /* @__PURE__ */ jsx(TextInput, {
|
|
230
|
+
mb: "md",
|
|
231
|
+
required: true,
|
|
232
|
+
label: "Username",
|
|
233
|
+
...field
|
|
234
|
+
})
|
|
235
|
+
}), /* @__PURE__ */ jsx(Controller, {
|
|
236
|
+
name: "config.password",
|
|
237
|
+
control,
|
|
238
|
+
render: ({
|
|
239
|
+
field
|
|
240
|
+
}) => /* @__PURE__ */ jsx(PasswordInput, {
|
|
241
|
+
mb: "md",
|
|
242
|
+
required: true,
|
|
243
|
+
label: "Password",
|
|
244
|
+
...field
|
|
245
|
+
})
|
|
246
|
+
}), /* @__PURE__ */ jsx(Controller, {
|
|
247
|
+
name: "config.database",
|
|
248
|
+
control,
|
|
249
|
+
render: ({
|
|
250
|
+
field
|
|
251
|
+
}) => /* @__PURE__ */ jsx(TextInput, {
|
|
252
|
+
mb: "md",
|
|
253
|
+
required: true,
|
|
254
|
+
label: "Database",
|
|
255
|
+
...field
|
|
256
|
+
})
|
|
257
|
+
}), /* @__PURE__ */ jsx(Group, {
|
|
258
|
+
position: "right",
|
|
259
|
+
mt: "md",
|
|
260
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
261
|
+
type: "submit",
|
|
262
|
+
children: "Save"
|
|
263
|
+
})
|
|
264
|
+
})]
|
|
265
|
+
})
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
function AddDataSource({
|
|
269
|
+
onSuccess
|
|
270
|
+
}) {
|
|
271
|
+
const [opened, setOpened] = require$$0.useState(false);
|
|
272
|
+
const open = () => setOpened(true);
|
|
273
|
+
const close = () => setOpened(false);
|
|
274
|
+
const postSubmit = () => {
|
|
275
|
+
onSuccess();
|
|
276
|
+
close();
|
|
277
|
+
};
|
|
278
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
279
|
+
children: [/* @__PURE__ */ jsx(Modal, {
|
|
280
|
+
overflow: "inside",
|
|
281
|
+
opened,
|
|
282
|
+
onClose: () => setOpened(false),
|
|
283
|
+
title: "Add a data source",
|
|
284
|
+
trapFocus: true,
|
|
285
|
+
onDragStart: (e) => {
|
|
286
|
+
e.stopPropagation();
|
|
287
|
+
},
|
|
288
|
+
children: /* @__PURE__ */ jsx(AddDataSourceForm, {
|
|
289
|
+
postSubmit
|
|
290
|
+
})
|
|
291
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
292
|
+
size: "sm",
|
|
293
|
+
onClick: open,
|
|
294
|
+
leftIcon: /* @__PURE__ */ jsx(PlaylistAdd, {
|
|
295
|
+
size: 20
|
|
296
|
+
}),
|
|
297
|
+
children: "Add a Data Source"
|
|
298
|
+
})]
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
function DeleteDataSource({
|
|
302
|
+
id,
|
|
303
|
+
name,
|
|
304
|
+
onSuccess
|
|
305
|
+
}) {
|
|
306
|
+
const modals = useModals();
|
|
307
|
+
const doDelete = async () => {
|
|
308
|
+
if (!id) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
showNotification({
|
|
312
|
+
id: "for-deleting",
|
|
313
|
+
title: "Pending",
|
|
314
|
+
message: "Deleting data source...",
|
|
315
|
+
loading: true
|
|
316
|
+
});
|
|
317
|
+
await APICaller.datasource.delete(id);
|
|
318
|
+
updateNotification({
|
|
319
|
+
id: "for-deleting",
|
|
320
|
+
title: "Successful",
|
|
321
|
+
message: `Data source [${name}] is deleted`,
|
|
322
|
+
color: "green"
|
|
323
|
+
});
|
|
324
|
+
onSuccess();
|
|
325
|
+
};
|
|
326
|
+
const confirmAndDelete = () => modals.openConfirmModal({
|
|
327
|
+
title: "Delete this data source?",
|
|
328
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
329
|
+
size: "sm",
|
|
330
|
+
children: "This action won't affect your database."
|
|
331
|
+
}),
|
|
332
|
+
labels: {
|
|
333
|
+
confirm: "Confirm",
|
|
334
|
+
cancel: "Cancel"
|
|
335
|
+
},
|
|
336
|
+
onCancel: () => console.log("Cancel"),
|
|
337
|
+
onConfirm: doDelete
|
|
338
|
+
});
|
|
339
|
+
return /* @__PURE__ */ jsx(Button, {
|
|
340
|
+
size: "sm",
|
|
341
|
+
color: "red",
|
|
342
|
+
onClick: confirmAndDelete,
|
|
343
|
+
leftIcon: /* @__PURE__ */ jsx(Trash, {
|
|
344
|
+
size: 20
|
|
345
|
+
}),
|
|
346
|
+
children: "Delete"
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
function DataSourceList() {
|
|
350
|
+
const {
|
|
351
|
+
data = [],
|
|
352
|
+
loading,
|
|
353
|
+
refresh
|
|
354
|
+
} = useRequest(async () => {
|
|
355
|
+
const {
|
|
356
|
+
data: data2
|
|
357
|
+
} = await APICaller.datasource.list();
|
|
358
|
+
return data2;
|
|
359
|
+
}, {
|
|
360
|
+
refreshDeps: []
|
|
361
|
+
});
|
|
362
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
363
|
+
children: [/* @__PURE__ */ jsx(Group, {
|
|
364
|
+
pt: "md",
|
|
365
|
+
position: "right",
|
|
366
|
+
children: /* @__PURE__ */ jsx(AddDataSource, {
|
|
367
|
+
onSuccess: refresh
|
|
368
|
+
})
|
|
369
|
+
}), /* @__PURE__ */ jsxs(Box, {
|
|
370
|
+
mt: "xl",
|
|
371
|
+
sx: {
|
|
372
|
+
position: "relative"
|
|
373
|
+
},
|
|
374
|
+
children: [/* @__PURE__ */ jsx(LoadingOverlay, {
|
|
375
|
+
visible: loading
|
|
376
|
+
}), /* @__PURE__ */ jsxs(Table, {
|
|
377
|
+
horizontalSpacing: "md",
|
|
378
|
+
verticalSpacing: "md",
|
|
379
|
+
fontSize: "md",
|
|
380
|
+
highlightOnHover: true,
|
|
381
|
+
children: [/* @__PURE__ */ jsx("thead", {
|
|
382
|
+
children: /* @__PURE__ */ jsxs("tr", {
|
|
383
|
+
children: [/* @__PURE__ */ jsx("th", {
|
|
384
|
+
children: "Type"
|
|
385
|
+
}), /* @__PURE__ */ jsx("th", {
|
|
386
|
+
children: "Name"
|
|
387
|
+
}), /* @__PURE__ */ jsx("th", {
|
|
388
|
+
children: "Action"
|
|
389
|
+
})]
|
|
390
|
+
})
|
|
391
|
+
}), /* @__PURE__ */ jsx("tbody", {
|
|
392
|
+
children: data.map(({
|
|
393
|
+
id,
|
|
394
|
+
key,
|
|
395
|
+
type
|
|
396
|
+
}) => /* @__PURE__ */ jsxs("tr", {
|
|
397
|
+
children: [/* @__PURE__ */ jsx("td", {
|
|
398
|
+
width: 200,
|
|
399
|
+
children: type
|
|
400
|
+
}), /* @__PURE__ */ jsx("td", {
|
|
401
|
+
children: key
|
|
402
|
+
}), /* @__PURE__ */ jsx("td", {
|
|
403
|
+
width: 200,
|
|
404
|
+
children: /* @__PURE__ */ jsx(Group, {
|
|
405
|
+
position: "left",
|
|
406
|
+
children: /* @__PURE__ */ jsx(DeleteDataSource, {
|
|
407
|
+
id,
|
|
408
|
+
name: key,
|
|
409
|
+
onSuccess: refresh
|
|
410
|
+
})
|
|
411
|
+
})
|
|
412
|
+
})]
|
|
413
|
+
}, key))
|
|
414
|
+
})]
|
|
415
|
+
})]
|
|
416
|
+
})]
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
export { AddDataSource, DataSourceList, DeleteDataSource };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
(function(o,a){typeof exports=="object"&&typeof module!="undefined"?a(exports,require("@mantine/core"),require("react-hook-form"),require("@mantine/notifications"),require("react"),require("tabler-icons-react"),require("axios"),require("ahooks"),require("@mantine/modals")):typeof define=="function"&&define.amd?define(["exports","@mantine/core","react-hook-form","@mantine/notifications","react","tabler-icons-react","axios","ahooks","@mantine/modals"],a):(o=typeof globalThis!="undefined"?globalThis:o||self,a(o["settings-form"]={},o["@mantine/core"],o["react-hook-form"],o["@mantine/notifications"],o.React,o["tabler-icons-react"],o.axios,o.ahooks,o["@mantine/modals"]))})(this,function(o,a,c,m,v,b,C,T,P){"use strict";function y(t){return t&&typeof t=="object"&&"default"in t?t:{default:t}}var x=y(v),O=y(C);const g=(t=>(r,i,n={})=>{const s={"X-Requested-With":"XMLHttpRequest","Content-Type":n.string?"application/x-www-form-urlencoded":"application/json",...n.headers},l={baseURL:"http://localhost:31200",method:t,url:r,params:t==="GET"?i:n.params,headers:s};return["POST","PUT"].includes(t)&&(l.data=n.string?JSON.stringify(i):i),O.default(l).then(u=>u.data).catch(u=>Promise.reject(u))})("POST"),S={datasource:{list:async()=>await g("/datasource/list",{filter:{},sort:{field:"create_time",order:"ASC"},pagination:{page:1,pagesize:100}}),create:async(t,r,i)=>{try{return await g("/datasource/create",{type:t,key:r,config:i})}catch(n){return console.error(n),!1}},delete:async t=>{await g("/datasource/delete",{id:t})}}};var p={exports:{}},h={};/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react-jsx-runtime.production.min.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/var j=x.default,A=Symbol.for("react.element"),R=Symbol.for("react.fragment"),I=Object.prototype.hasOwnProperty,N=j.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,L={key:!0,ref:!0,__self:!0,__source:!0};function w(t,r,i){var n,s={},l=null,u=null;i!==void 0&&(l=""+i),r.key!==void 0&&(l=""+r.key),r.ref!==void 0&&(u=r.ref);for(n in r)I.call(r,n)&&!L.hasOwnProperty(n)&&(s[n]=r[n]);if(t&&t.defaultProps)for(n in r=t.defaultProps,r)s[n]===void 0&&(s[n]=r[n]);return{$$typeof:A,type:t,key:l,ref:u,props:s,_owner:N.current}}h.Fragment=R,h.jsx=w,h.jsxs=w,p.exports=h;const e=p.exports.jsx,f=p.exports.jsxs,_=p.exports.Fragment;function z({postSubmit:t}){const{control:r,handleSubmit:i,formState:{errors:n,isValidating:s,isValid:l}}=c.useForm({defaultValues:{type:"postgresql",key:"",config:{host:"",port:5432,username:"",password:"",database:""}}}),u=async({type:d,key:M,config:k})=>{if(m.showNotification({id:"for-creating",title:"Pending",message:"Adding data source...",loading:!0}),!await S.datasource.create(d,M,k)){m.updateNotification({id:"for-creating",title:"Failed",message:"Test connection failed with given info",color:"red"});return}m.updateNotification({id:"for-creating",title:"Successful",message:"Data source is added",color:"green"}),t()};return e(a.Box,{mx:"auto",children:f("form",{onSubmit:i(u),children:[e(c.Controller,{name:"type",control:r,render:({field:d})=>e(a.SegmentedControl,{fullWidth:!0,mb:"md",data:[{label:"PostgreSQL",value:"postgresql"},{label:"MySQL",value:"mysql"},{label:"HTTP",value:"http",disabled:!0}],...d})}),e(c.Controller,{name:"key",control:r,render:({field:d})=>e(a.TextInput,{mb:"md",required:!0,label:"Name",placeholder:"A unique name",...d})}),e(a.Divider,{label:"Connection Info",labelPosition:"center"}),f(a.Group,{direction:"row",grow:!0,children:[e(c.Controller,{name:"config.host",control:r,render:({field:d})=>e(a.TextInput,{mb:"md",required:!0,label:"Host",sx:{flexGrow:1},...d})}),e(c.Controller,{name:"config.port",control:r,render:({field:d})=>e(a.NumberInput,{mb:"md",required:!0,label:"Port",hideControls:!0,sx:{width:"8em"},...d})})]}),e(c.Controller,{name:"config.username",control:r,render:({field:d})=>e(a.TextInput,{mb:"md",required:!0,label:"Username",...d})}),e(c.Controller,{name:"config.password",control:r,render:({field:d})=>e(a.PasswordInput,{mb:"md",required:!0,label:"Password",...d})}),e(c.Controller,{name:"config.database",control:r,render:({field:d})=>e(a.TextInput,{mb:"md",required:!0,label:"Database",...d})}),e(a.Group,{position:"right",mt:"md",children:e(a.Button,{type:"submit",children:"Save"})})]})})}function q({onSuccess:t}){const[r,i]=x.default.useState(!1),n=()=>i(!0),s=()=>i(!1),l=()=>{t(),s()};return f(_,{children:[e(a.Modal,{overflow:"inside",opened:r,onClose:()=>i(!1),title:"Add a data source",trapFocus:!0,onDragStart:u=>{u.stopPropagation()},children:e(z,{postSubmit:l})}),e(a.Button,{size:"sm",onClick:n,leftIcon:e(b.PlaylistAdd,{size:20}),children:"Add a Data Source"})]})}function D({id:t,name:r,onSuccess:i}){const n=P.useModals(),s=async()=>{!t||(m.showNotification({id:"for-deleting",title:"Pending",message:"Deleting data source...",loading:!0}),await S.datasource.delete(t),m.updateNotification({id:"for-deleting",title:"Successful",message:`Data source [${r}] is deleted`,color:"green"}),i())},l=()=>n.openConfirmModal({title:"Delete this data source?",children:e(a.Text,{size:"sm",children:"This action won't affect your database."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:s});return e(a.Button,{size:"sm",color:"red",onClick:l,leftIcon:e(b.Trash,{size:20}),children:"Delete"})}function E(){const{data:t=[],loading:r,refresh:i}=T.useRequest(async()=>{const{data:n}=await S.datasource.list();return n},{refreshDeps:[]});return f(_,{children:[e(a.Group,{pt:"md",position:"right",children:e(q,{onSuccess:i})}),f(a.Box,{mt:"xl",sx:{position:"relative"},children:[e(a.LoadingOverlay,{visible:r}),f(a.Table,{horizontalSpacing:"md",verticalSpacing:"md",fontSize:"md",highlightOnHover:!0,children:[e("thead",{children:f("tr",{children:[e("th",{children:"Type"}),e("th",{children:"Name"}),e("th",{children:"Action"})]})}),e("tbody",{children:t.map(({id:n,key:s,type:l})=>f("tr",{children:[e("td",{width:200,children:l}),e("td",{children:s}),e("td",{width:200,children:e(a.Group,{position:"left",children:e(D,{id:n,name:s,onSuccess:i})})})]},s))})]})]})]})}o.AddDataSource=q,o.DataSourceList=E,o.DeleteDataSource=D,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@devtable/settings-form",
|
|
3
|
+
"version": "1.32.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public",
|
|
6
|
+
"registry": "https://registry.npmjs.org/"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"main": "./dist/settings-form.umd.js",
|
|
12
|
+
"module": "./dist/settings-form.es.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": "./dist/settings-form.es.js",
|
|
17
|
+
"require": "./dist/settings-form.umd.js"
|
|
18
|
+
},
|
|
19
|
+
"./dist/style.css": {
|
|
20
|
+
"import": "./dist/style.css",
|
|
21
|
+
"require": "./dist/style.css"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"dev": "vite",
|
|
26
|
+
"build": "tsc && vite build",
|
|
27
|
+
"preview": "vite preview"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {},
|
|
30
|
+
"devDependencies": {},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@mantine/core": "^4.2.12",
|
|
33
|
+
"@mantine/dates": "^4.2.12",
|
|
34
|
+
"@mantine/form": "^4.2.12",
|
|
35
|
+
"@mantine/hooks": "^4.2.12",
|
|
36
|
+
"@mantine/modals": "^4.2.12",
|
|
37
|
+
"@mantine/notifications": "^4.2.12",
|
|
38
|
+
"@mantine/prism": "^4.2.12",
|
|
39
|
+
"@mantine/rte": "^4.2.12",
|
|
40
|
+
"ahooks": "^3.3.11",
|
|
41
|
+
"axios": "^0.27.2",
|
|
42
|
+
"echarts": "^5.3.2",
|
|
43
|
+
"echarts-for-react": "^3.0.2",
|
|
44
|
+
"echarts-gl": "^2.0.9",
|
|
45
|
+
"echarts-stat": "1.2.0",
|
|
46
|
+
"lodash": "^4.17.21",
|
|
47
|
+
"numbro": "^2.3.6",
|
|
48
|
+
"react": "^16.8.0 || 17.x || 18.x",
|
|
49
|
+
"react-dom": "^16.8.0 || 17.x || 18.x",
|
|
50
|
+
"react-grid-layout": "^1.3.4",
|
|
51
|
+
"react-hook-form": "^7.31.2",
|
|
52
|
+
"tabler-icons-react": "^1.48.0"
|
|
53
|
+
}
|
|
54
|
+
}
|