@devtable/settings-form 2.1.0 → 2.2.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/dist/settings-form/src/datasource/add-data-source.d.ts +3 -1
- package/dist/settings-form/src/datasource/data-source-list.d.ts +6 -1
- package/dist/settings-form/src/datasource/delete-data-source.d.ts +6 -2
- package/dist/settings-form/src/datasource/styles.d.ts +6 -0
- package/dist/settings-form.es.js +39 -21
- package/dist/settings-form.umd.js +2 -2
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { IStyles } from "./styles";
|
|
2
3
|
interface IAddDataSource {
|
|
4
|
+
styles?: IStyles;
|
|
3
5
|
onSuccess: () => void;
|
|
4
6
|
}
|
|
5
|
-
export declare function AddDataSource({ onSuccess }: IAddDataSource): JSX.Element;
|
|
7
|
+
export declare function AddDataSource({ onSuccess, styles }: IAddDataSource): JSX.Element;
|
|
6
8
|
export {};
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
|
|
2
|
+
import { IStyles } from "./styles";
|
|
3
|
+
interface IDataSourceList {
|
|
4
|
+
styles?: IStyles;
|
|
5
|
+
}
|
|
6
|
+
export declare function DataSourceList({ styles }: IDataSourceList): JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
|
|
2
|
+
import { IStyles } from "./styles";
|
|
3
|
+
interface IDeleteDataSource {
|
|
3
4
|
id: string;
|
|
4
5
|
name: string;
|
|
5
6
|
onSuccess: () => void;
|
|
6
|
-
|
|
7
|
+
styles?: IStyles;
|
|
8
|
+
}
|
|
9
|
+
export declare function DeleteDataSource({ id, name, onSuccess, styles }: IDeleteDataSource): JSX.Element;
|
|
10
|
+
export {};
|
package/dist/settings-form.es.js
CHANGED
|
@@ -62,6 +62,10 @@ const datasource = {
|
|
|
62
62
|
const APICaller = {
|
|
63
63
|
datasource
|
|
64
64
|
};
|
|
65
|
+
const defaultStyles = {
|
|
66
|
+
size: "sm",
|
|
67
|
+
spacing: "md"
|
|
68
|
+
};
|
|
65
69
|
var jsxRuntime = { exports: {} };
|
|
66
70
|
var reactJsxRuntime_production_min = {};
|
|
67
71
|
/**
|
|
@@ -96,7 +100,8 @@ const jsx = jsxRuntime.exports.jsx;
|
|
|
96
100
|
const jsxs = jsxRuntime.exports.jsxs;
|
|
97
101
|
const Fragment = jsxRuntime.exports.Fragment;
|
|
98
102
|
function AddDataSourceForm({
|
|
99
|
-
postSubmit
|
|
103
|
+
postSubmit,
|
|
104
|
+
styles = defaultStyles
|
|
100
105
|
}) {
|
|
101
106
|
const {
|
|
102
107
|
control,
|
|
@@ -159,7 +164,8 @@ function AddDataSourceForm({
|
|
|
159
164
|
field
|
|
160
165
|
}) => /* @__PURE__ */ jsx(SegmentedControl, {
|
|
161
166
|
fullWidth: true,
|
|
162
|
-
mb:
|
|
167
|
+
mb: styles.spacing,
|
|
168
|
+
size: styles.size,
|
|
163
169
|
data: [{
|
|
164
170
|
label: "PostgreSQL",
|
|
165
171
|
value: "postgresql"
|
|
@@ -179,7 +185,8 @@ function AddDataSourceForm({
|
|
|
179
185
|
render: ({
|
|
180
186
|
field
|
|
181
187
|
}) => /* @__PURE__ */ jsx(TextInput, {
|
|
182
|
-
mb:
|
|
188
|
+
mb: styles.spacing,
|
|
189
|
+
size: styles.size,
|
|
183
190
|
required: true,
|
|
184
191
|
label: "Name",
|
|
185
192
|
placeholder: "A unique name",
|
|
@@ -196,7 +203,8 @@ function AddDataSourceForm({
|
|
|
196
203
|
render: ({
|
|
197
204
|
field
|
|
198
205
|
}) => /* @__PURE__ */ jsx(TextInput, {
|
|
199
|
-
mb:
|
|
206
|
+
mb: styles.spacing,
|
|
207
|
+
size: styles.size,
|
|
200
208
|
required: true,
|
|
201
209
|
label: "Host",
|
|
202
210
|
sx: {
|
|
@@ -210,7 +218,8 @@ function AddDataSourceForm({
|
|
|
210
218
|
render: ({
|
|
211
219
|
field
|
|
212
220
|
}) => /* @__PURE__ */ jsx(NumberInput, {
|
|
213
|
-
mb:
|
|
221
|
+
mb: styles.spacing,
|
|
222
|
+
size: styles.size,
|
|
214
223
|
required: true,
|
|
215
224
|
label: "Port",
|
|
216
225
|
hideControls: true,
|
|
@@ -226,7 +235,8 @@ function AddDataSourceForm({
|
|
|
226
235
|
render: ({
|
|
227
236
|
field
|
|
228
237
|
}) => /* @__PURE__ */ jsx(TextInput, {
|
|
229
|
-
mb:
|
|
238
|
+
mb: styles.spacing,
|
|
239
|
+
size: styles.size,
|
|
230
240
|
required: true,
|
|
231
241
|
label: "Username",
|
|
232
242
|
...field
|
|
@@ -237,7 +247,8 @@ function AddDataSourceForm({
|
|
|
237
247
|
render: ({
|
|
238
248
|
field
|
|
239
249
|
}) => /* @__PURE__ */ jsx(PasswordInput, {
|
|
240
|
-
mb:
|
|
250
|
+
mb: styles.spacing,
|
|
251
|
+
size: styles.size,
|
|
241
252
|
required: true,
|
|
242
253
|
label: "Password",
|
|
243
254
|
...field
|
|
@@ -248,16 +259,18 @@ function AddDataSourceForm({
|
|
|
248
259
|
render: ({
|
|
249
260
|
field
|
|
250
261
|
}) => /* @__PURE__ */ jsx(TextInput, {
|
|
251
|
-
mb:
|
|
262
|
+
mb: styles.spacing,
|
|
263
|
+
size: styles.size,
|
|
252
264
|
required: true,
|
|
253
265
|
label: "Database",
|
|
254
266
|
...field
|
|
255
267
|
})
|
|
256
268
|
}), /* @__PURE__ */ jsx(Group, {
|
|
257
269
|
position: "right",
|
|
258
|
-
mt:
|
|
270
|
+
mt: styles.spacing,
|
|
259
271
|
children: /* @__PURE__ */ jsx(Button, {
|
|
260
272
|
type: "submit",
|
|
273
|
+
size: styles.size,
|
|
261
274
|
children: "Save"
|
|
262
275
|
})
|
|
263
276
|
})]
|
|
@@ -265,7 +278,8 @@ function AddDataSourceForm({
|
|
|
265
278
|
});
|
|
266
279
|
}
|
|
267
280
|
function AddDataSource({
|
|
268
|
-
onSuccess
|
|
281
|
+
onSuccess,
|
|
282
|
+
styles = defaultStyles
|
|
269
283
|
}) {
|
|
270
284
|
const [opened, setOpened] = require$$0.useState(false);
|
|
271
285
|
const open = () => setOpened(true);
|
|
@@ -285,10 +299,11 @@ function AddDataSource({
|
|
|
285
299
|
e.stopPropagation();
|
|
286
300
|
},
|
|
287
301
|
children: /* @__PURE__ */ jsx(AddDataSourceForm, {
|
|
288
|
-
postSubmit
|
|
302
|
+
postSubmit,
|
|
303
|
+
styles
|
|
289
304
|
})
|
|
290
305
|
}), /* @__PURE__ */ jsx(Button, {
|
|
291
|
-
size:
|
|
306
|
+
size: styles.size,
|
|
292
307
|
onClick: open,
|
|
293
308
|
leftIcon: /* @__PURE__ */ jsx(PlaylistAdd, {
|
|
294
309
|
size: 20
|
|
@@ -300,7 +315,8 @@ function AddDataSource({
|
|
|
300
315
|
function DeleteDataSource({
|
|
301
316
|
id,
|
|
302
317
|
name,
|
|
303
|
-
onSuccess
|
|
318
|
+
onSuccess,
|
|
319
|
+
styles = defaultStyles
|
|
304
320
|
}) {
|
|
305
321
|
const modals = useModals();
|
|
306
322
|
const doDelete = async () => {
|
|
@@ -325,7 +341,7 @@ function DeleteDataSource({
|
|
|
325
341
|
const confirmAndDelete = () => modals.openConfirmModal({
|
|
326
342
|
title: "Delete this data source?",
|
|
327
343
|
children: /* @__PURE__ */ jsx(Text, {
|
|
328
|
-
size:
|
|
344
|
+
size: styles.size,
|
|
329
345
|
children: "This action won't affect your database."
|
|
330
346
|
}),
|
|
331
347
|
labels: {
|
|
@@ -336,7 +352,7 @@ function DeleteDataSource({
|
|
|
336
352
|
onConfirm: doDelete
|
|
337
353
|
});
|
|
338
354
|
return /* @__PURE__ */ jsx(Button, {
|
|
339
|
-
size:
|
|
355
|
+
size: styles.size,
|
|
340
356
|
color: "red",
|
|
341
357
|
onClick: confirmAndDelete,
|
|
342
358
|
leftIcon: /* @__PURE__ */ jsx(Trash, {
|
|
@@ -345,7 +361,9 @@ function DeleteDataSource({
|
|
|
345
361
|
children: "Delete"
|
|
346
362
|
});
|
|
347
363
|
}
|
|
348
|
-
function DataSourceList(
|
|
364
|
+
function DataSourceList({
|
|
365
|
+
styles = defaultStyles
|
|
366
|
+
}) {
|
|
349
367
|
const {
|
|
350
368
|
data = [],
|
|
351
369
|
loading,
|
|
@@ -360,22 +378,22 @@ function DataSourceList() {
|
|
|
360
378
|
});
|
|
361
379
|
return /* @__PURE__ */ jsxs(Fragment, {
|
|
362
380
|
children: [/* @__PURE__ */ jsx(Group, {
|
|
363
|
-
pt:
|
|
381
|
+
pt: styles.spacing,
|
|
364
382
|
position: "right",
|
|
365
383
|
children: /* @__PURE__ */ jsx(AddDataSource, {
|
|
366
384
|
onSuccess: refresh
|
|
367
385
|
})
|
|
368
386
|
}), /* @__PURE__ */ jsxs(Box, {
|
|
369
|
-
mt:
|
|
387
|
+
mt: styles.spacing,
|
|
370
388
|
sx: {
|
|
371
389
|
position: "relative"
|
|
372
390
|
},
|
|
373
391
|
children: [/* @__PURE__ */ jsx(LoadingOverlay, {
|
|
374
392
|
visible: loading
|
|
375
393
|
}), /* @__PURE__ */ jsxs(Table, {
|
|
376
|
-
horizontalSpacing:
|
|
377
|
-
verticalSpacing:
|
|
378
|
-
fontSize:
|
|
394
|
+
horizontalSpacing: styles.spacing,
|
|
395
|
+
verticalSpacing: styles.spacing,
|
|
396
|
+
fontSize: styles.size,
|
|
379
397
|
highlightOnHover: true,
|
|
380
398
|
children: [/* @__PURE__ */ jsx("thead", {
|
|
381
399
|
children: /* @__PURE__ */ jsxs("tr", {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(o,
|
|
1
|
+
(function(o,i){typeof exports=="object"&&typeof module!="undefined"?i(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"],i):(o=typeof globalThis!="undefined"?globalThis:o||self,i(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,i,u,p,T,z,P,y,O){"use strict";function w(r){return r&&typeof r=="object"&&"default"in r?r:{default:r}}var _=w(T),j=w(P);const S=(r=>(t,a,n={})=>{const s={"X-Requested-With":"XMLHttpRequest","Content-Type":n.string?"application/x-www-form-urlencoded":"application/json",...n.headers},d={baseURL:"http://localhost:31200",method:r,url:t,params:r==="GET"?a:n.params,headers:s};return["POST","PUT"].includes(r)&&(d.data=n.string?JSON.stringify(a):a),j.default(d).then(l=>l.data).catch(l=>Promise.reject(l))})("POST"),b={datasource:{list:async()=>await S("/datasource/list",{filter:{},sort:{field:"create_time",order:"ASC"},pagination:{page:1,pagesize:100}}),create:async(r,t,a)=>{try{return await S("/datasource/create",{type:r,key:t,config:a})}catch(n){return console.error(n),!1}},delete:async r=>{await S("/datasource/delete",{id:r})}}},m={size:"sm",spacing:"md"};var h={exports:{}},g={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var A=_.default,R=Symbol.for("react.element"),I=Symbol.for("react.fragment"),N=Object.prototype.hasOwnProperty,L=A.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,E={key:!0,ref:!0,__self:!0,__source:!0};function q(r,t,a){var n,s={},d=null,l=null;a!==void 0&&(d=""+a),t.key!==void 0&&(d=""+t.key),t.ref!==void 0&&(l=t.ref);for(n in t)N.call(t,n)&&!E.hasOwnProperty(n)&&(s[n]=t[n]);if(r&&r.defaultProps)for(n in t=r.defaultProps,t)s[n]===void 0&&(s[n]=t[n]);return{$$typeof:R,type:r,key:d,ref:l,props:s,_owner:L.current}}g.Fragment=I,g.jsx=q,g.jsxs=q,h.exports=g;const e=h.exports.jsx,f=h.exports.jsxs,D=h.exports.Fragment;function M({postSubmit:r,styles:t=m}){const{control:a,handleSubmit:n,formState:{errors:s,isValidating:d,isValid:l}}=u.useForm({defaultValues:{type:"postgresql",key:"",config:{host:"",port:5432,username:"",password:"",database:""}}}),x=async({type:c,key:B,config:G})=>{if(p.showNotification({id:"for-creating",title:"Pending",message:"Adding data source...",loading:!0}),!await b.datasource.create(c,B,G)){p.updateNotification({id:"for-creating",title:"Failed",message:"Test connection failed with given info",color:"red"});return}p.updateNotification({id:"for-creating",title:"Successful",message:"Data source is added",color:"green"}),r()};return e(i.Box,{mx:"auto",children:f("form",{onSubmit:n(x),children:[e(u.Controller,{name:"type",control:a,render:({field:c})=>e(i.SegmentedControl,{fullWidth:!0,mb:t.spacing,size:t.size,data:[{label:"PostgreSQL",value:"postgresql"},{label:"MySQL",value:"mysql"},{label:"HTTP",value:"http",disabled:!0}],...c})}),e(u.Controller,{name:"key",control:a,render:({field:c})=>e(i.TextInput,{mb:t.spacing,size:t.size,required:!0,label:"Name",placeholder:"A unique name",...c})}),e(i.Divider,{label:"Connection Info",labelPosition:"center"}),f(i.Group,{grow:!0,children:[e(u.Controller,{name:"config.host",control:a,render:({field:c})=>e(i.TextInput,{mb:t.spacing,size:t.size,required:!0,label:"Host",sx:{flexGrow:1},...c})}),e(u.Controller,{name:"config.port",control:a,render:({field:c})=>e(i.NumberInput,{mb:t.spacing,size:t.size,required:!0,label:"Port",hideControls:!0,sx:{width:"8em"},...c})})]}),e(u.Controller,{name:"config.username",control:a,render:({field:c})=>e(i.TextInput,{mb:t.spacing,size:t.size,required:!0,label:"Username",...c})}),e(u.Controller,{name:"config.password",control:a,render:({field:c})=>e(i.PasswordInput,{mb:t.spacing,size:t.size,required:!0,label:"Password",...c})}),e(u.Controller,{name:"config.database",control:a,render:({field:c})=>e(i.TextInput,{mb:t.spacing,size:t.size,required:!0,label:"Database",...c})}),e(i.Group,{position:"right",mt:t.spacing,children:e(i.Button,{type:"submit",size:t.size,children:"Save"})})]})})}function v({onSuccess:r,styles:t=m}){const[a,n]=_.default.useState(!1),s=()=>n(!0),d=()=>n(!1),l=()=>{r(),d()};return f(D,{children:[e(i.Modal,{overflow:"inside",opened:a,onClose:()=>n(!1),title:"Add a data source",trapFocus:!0,onDragStart:x=>{x.stopPropagation()},children:e(M,{postSubmit:l,styles:t})}),e(i.Button,{size:t.size,onClick:s,leftIcon:e(z.PlaylistAdd,{size:20}),children:"Add a Data Source"})]})}function C({id:r,name:t,onSuccess:a,styles:n=m}){const s=O.useModals(),d=async()=>{!r||(p.showNotification({id:"for-deleting",title:"Pending",message:"Deleting data source...",loading:!0}),await b.datasource.delete(r),p.updateNotification({id:"for-deleting",title:"Successful",message:`Data source [${t}] is deleted`,color:"green"}),a())},l=()=>s.openConfirmModal({title:"Delete this data source?",children:e(i.Text,{size:n.size,children:"This action won't affect your database."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:d});return e(i.Button,{size:n.size,color:"red",onClick:l,leftIcon:e(z.Trash,{size:20}),children:"Delete"})}function k({styles:r=m}){const{data:t=[],loading:a,refresh:n}=y.useRequest(async()=>{const{data:s}=await b.datasource.list();return s},{refreshDeps:[]});return f(D,{children:[e(i.Group,{pt:r.spacing,position:"right",children:e(v,{onSuccess:n})}),f(i.Box,{mt:r.spacing,sx:{position:"relative"},children:[e(i.LoadingOverlay,{visible:a}),f(i.Table,{horizontalSpacing:r.spacing,verticalSpacing:r.spacing,fontSize:r.size,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:s,key:d,type:l})=>f("tr",{children:[e("td",{width:200,children:l}),e("td",{children:d}),e("td",{width:200,children:e(i.Group,{position:"left",children:e(C,{id:s,name:d,onSuccess:n})})})]},d))})]})]})]})}o.AddDataSource=v,o.DataSourceList=k,o.DeleteDataSource=C,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|