@devtable/settings-form 2.2.0 → 2.5.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/api-caller → api-caller}/datasource.d.ts +2 -2
- package/dist/{settings-form/src/api-caller → api-caller}/datasource.typed.d.ts +0 -0
- package/dist/api-caller/index.d.ts +7 -0
- package/dist/api-caller/request.d.ts +5 -0
- package/dist/api-caller/types.d.ts +5 -0
- package/dist/{settings-form/src/datasource → datasource}/add-data-source.d.ts +1 -1
- package/dist/datasource/data-source-list.d.ts +9 -0
- package/dist/{settings-form/src/datasource → datasource}/delete-data-source.d.ts +1 -1
- package/dist/{settings-form/src/datasource → datasource}/index.d.ts +0 -0
- package/dist/{settings-form/src/datasource → datasource}/styles.d.ts +1 -1
- package/dist/datasource/types.d.ts +3 -0
- package/dist/index.d.ts +1 -1
- package/dist/settings-form.es.js +33 -27
- package/dist/settings-form.umd.js +2 -2
- package/dist/{settings-form/src/vite-env.d.ts → vite-env.d.ts} +0 -0
- package/package.json +2 -2
- package/dist/settings-form/src/api-caller/index.d.ts +0 -7
- package/dist/settings-form/src/datasource/data-source-list.d.ts +0 -7
- package/dist/settings-form/src/index.d.ts +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DataSourceType, IDataSource, IDataSourceConfig } from
|
|
2
|
-
import { PaginationResponse } from
|
|
1
|
+
import { DataSourceType, IDataSource, IDataSourceConfig } from './datasource.typed';
|
|
2
|
+
import { PaginationResponse } from './types';
|
|
3
3
|
export declare const datasource: {
|
|
4
4
|
list: () => Promise<PaginationResponse<IDataSource>>;
|
|
5
5
|
create: (type: DataSourceType, key: string, config: IDataSourceConfig) => Promise<PaginationResponse<IDataSource> | false>;
|
|
File without changes
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const APICaller: {
|
|
2
|
+
datasource: {
|
|
3
|
+
list: () => Promise<import("./types").PaginationResponse<import("./datasource.typed").IDataSource>>;
|
|
4
|
+
create: (type: import("./datasource.typed").DataSourceType, key: string, config: import("./datasource.typed").IDataSourceConfig) => Promise<false | import("./types").PaginationResponse<import("./datasource.typed").IDataSource>>;
|
|
5
|
+
delete: (id: string) => Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { IStyles } from './styles';
|
|
3
|
+
import { ISettingsFormConfig } from './types';
|
|
4
|
+
interface IDataSourceList {
|
|
5
|
+
styles?: IStyles;
|
|
6
|
+
config: ISettingsFormConfig;
|
|
7
|
+
}
|
|
8
|
+
export declare function DataSourceList({ styles, config }: IDataSourceList): JSX.Element;
|
|
9
|
+
export {};
|
|
File without changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './datasource';
|
package/dist/settings-form.es.js
CHANGED
|
@@ -6,34 +6,36 @@ import { PlaylistAdd, Trash } from "tabler-icons-react";
|
|
|
6
6
|
import axios from "axios";
|
|
7
7
|
import { useRequest } from "ahooks";
|
|
8
8
|
import { useModals } from "@mantine/modals";
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
const APIClient = {
|
|
10
|
+
baseURL: "http://localhost:31200",
|
|
11
|
+
getRequest(method) {
|
|
12
|
+
return (url, data, options = {}) => {
|
|
13
|
+
const headers = {
|
|
14
|
+
"X-Requested-With": "XMLHttpRequest",
|
|
15
|
+
"Content-Type": options.string ? "application/x-www-form-urlencoded" : "application/json",
|
|
16
|
+
...options.headers
|
|
17
|
+
};
|
|
18
|
+
const conf = {
|
|
19
|
+
baseURL: this.baseURL,
|
|
20
|
+
method,
|
|
21
|
+
url,
|
|
22
|
+
params: method === "GET" ? data : options.params,
|
|
23
|
+
headers
|
|
24
|
+
};
|
|
25
|
+
if (method === "POST") {
|
|
26
|
+
conf.data = options.string ? JSON.stringify(data) : data;
|
|
27
|
+
}
|
|
28
|
+
return axios(conf).then((res) => {
|
|
29
|
+
return res.data;
|
|
30
|
+
}).catch((err) => {
|
|
31
|
+
return Promise.reject(err);
|
|
32
|
+
});
|
|
22
33
|
};
|
|
23
|
-
|
|
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
|
-
};
|
|
34
|
+
}
|
|
32
35
|
};
|
|
33
|
-
const post = getRequest("POST");
|
|
34
36
|
const datasource = {
|
|
35
37
|
list: async () => {
|
|
36
|
-
const res = await
|
|
38
|
+
const res = await APIClient.getRequest("POST")("/datasource/list", {
|
|
37
39
|
filter: {},
|
|
38
40
|
sort: {
|
|
39
41
|
field: "create_time",
|
|
@@ -48,7 +50,7 @@ const datasource = {
|
|
|
48
50
|
},
|
|
49
51
|
create: async (type, key, config) => {
|
|
50
52
|
try {
|
|
51
|
-
const res = await
|
|
53
|
+
const res = await APIClient.getRequest("POST")("/datasource/create", { type, key, config });
|
|
52
54
|
return res;
|
|
53
55
|
} catch (error) {
|
|
54
56
|
console.error(error);
|
|
@@ -56,7 +58,7 @@ const datasource = {
|
|
|
56
58
|
}
|
|
57
59
|
},
|
|
58
60
|
delete: async (id) => {
|
|
59
|
-
await
|
|
61
|
+
await APIClient.getRequest("POST")("/datasource/delete", { id });
|
|
60
62
|
}
|
|
61
63
|
};
|
|
62
64
|
const APICaller = {
|
|
@@ -362,7 +364,8 @@ function DeleteDataSource({
|
|
|
362
364
|
});
|
|
363
365
|
}
|
|
364
366
|
function DataSourceList({
|
|
365
|
-
styles = defaultStyles
|
|
367
|
+
styles = defaultStyles,
|
|
368
|
+
config
|
|
366
369
|
}) {
|
|
367
370
|
const {
|
|
368
371
|
data = [],
|
|
@@ -376,6 +379,9 @@ function DataSourceList({
|
|
|
376
379
|
}, {
|
|
377
380
|
refreshDeps: []
|
|
378
381
|
});
|
|
382
|
+
if (APIClient.baseURL !== config.apiBaseURL) {
|
|
383
|
+
APIClient.baseURL = config.apiBaseURL;
|
|
384
|
+
}
|
|
379
385
|
return /* @__PURE__ */ jsxs(Fragment, {
|
|
380
386
|
children: [/* @__PURE__ */ jsx(Group, {
|
|
381
387
|
pt: styles.spacing,
|
|
@@ -1,4 +1,4 @@
|
|
|
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,
|
|
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,R,L){"use strict";function q(r){return r&&typeof r=="object"&&"default"in r?r:{default:r}}var w=q(T),O=q(P);const m={baseURL:"http://localhost:31200",getRequest(r){return(e,a,n={})=>{const l={"X-Requested-With":"XMLHttpRequest","Content-Type":n.string?"application/x-www-form-urlencoded":"application/json",...n.headers},s={baseURL:this.baseURL,method:r,url:e,params:r==="GET"?a:n.params,headers:l};return r==="POST"&&(s.data=n.string?JSON.stringify(a):a),O.default(s).then(d=>d.data).catch(d=>Promise.reject(d))}}},x={datasource:{list:async()=>await m.getRequest("POST")("/datasource/list",{filter:{},sort:{field:"create_time",order:"ASC"},pagination:{page:1,pagesize:100}}),create:async(r,e,a)=>{try{return await m.getRequest("POST")("/datasource/create",{type:r,key:e,config:a})}catch(n){return console.error(n),!1}},delete:async r=>{await m.getRequest("POST")("/datasource/delete",{id:r})}}},g={size:"sm",spacing:"md"};var S={exports:{}},b={};/**
|
|
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 y=w.default,A=Symbol.for("react.element"),j=Symbol.for("react.fragment"),I=Object.prototype.hasOwnProperty,N=y.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,U={key:!0,ref:!0,__self:!0,__source:!0};function _(r,e,a){var n,l={},s=null,d=null;a!==void 0&&(s=""+a),e.key!==void 0&&(s=""+e.key),e.ref!==void 0&&(d=e.ref);for(n in e)I.call(e,n)&&!U.hasOwnProperty(n)&&(l[n]=e[n]);if(r&&r.defaultProps)for(n in e=r.defaultProps,e)l[n]===void 0&&(l[n]=e[n]);return{$$typeof:A,type:r,key:s,ref:d,props:l,_owner:N.current}}b.Fragment=j,b.jsx=_,b.jsxs=_,S.exports=b;const t=S.exports.jsx,f=S.exports.jsxs,C=S.exports.Fragment;function B({postSubmit:r,styles:e=g}){const{control:a,handleSubmit:n,formState:{errors:l,isValidating:s,isValid:d}}=u.useForm({defaultValues:{type:"postgresql",key:"",config:{host:"",port:5432,username:"",password:"",database:""}}}),h=async({type:c,key:M,config:k})=>{if(p.showNotification({id:"for-creating",title:"Pending",message:"Adding data source...",loading:!0}),!await x.datasource.create(c,M,k)){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 t(i.Box,{mx:"auto",children:f("form",{onSubmit:n(h),children:[t(u.Controller,{name:"type",control:a,render:({field:c})=>t(i.SegmentedControl,{fullWidth:!0,mb:e.spacing,size:e.size,data:[{label:"PostgreSQL",value:"postgresql"},{label:"MySQL",value:"mysql"},{label:"HTTP",value:"http",disabled:!0}],...c})}),t(u.Controller,{name:"key",control:a,render:({field:c})=>t(i.TextInput,{mb:e.spacing,size:e.size,required:!0,label:"Name",placeholder:"A unique name",...c})}),t(i.Divider,{label:"Connection Info",labelPosition:"center"}),f(i.Group,{grow:!0,children:[t(u.Controller,{name:"config.host",control:a,render:({field:c})=>t(i.TextInput,{mb:e.spacing,size:e.size,required:!0,label:"Host",sx:{flexGrow:1},...c})}),t(u.Controller,{name:"config.port",control:a,render:({field:c})=>t(i.NumberInput,{mb:e.spacing,size:e.size,required:!0,label:"Port",hideControls:!0,sx:{width:"8em"},...c})})]}),t(u.Controller,{name:"config.username",control:a,render:({field:c})=>t(i.TextInput,{mb:e.spacing,size:e.size,required:!0,label:"Username",...c})}),t(u.Controller,{name:"config.password",control:a,render:({field:c})=>t(i.PasswordInput,{mb:e.spacing,size:e.size,required:!0,label:"Password",...c})}),t(u.Controller,{name:"config.database",control:a,render:({field:c})=>t(i.TextInput,{mb:e.spacing,size:e.size,required:!0,label:"Database",...c})}),t(i.Group,{position:"right",mt:e.spacing,children:t(i.Button,{type:"submit",size:e.size,children:"Save"})})]})})}function D({onSuccess:r,styles:e=g}){const[a,n]=w.default.useState(!1),l=()=>n(!0),s=()=>n(!1),d=()=>{r(),s()};return f(C,{children:[t(i.Modal,{overflow:"inside",opened:a,onClose:()=>n(!1),title:"Add a data source",trapFocus:!0,onDragStart:h=>{h.stopPropagation()},children:t(B,{postSubmit:d,styles:e})}),t(i.Button,{size:e.size,onClick:l,leftIcon:t(z.PlaylistAdd,{size:20}),children:"Add a Data Source"})]})}function v({id:r,name:e,onSuccess:a,styles:n=g}){const l=L.useModals(),s=async()=>{!r||(p.showNotification({id:"for-deleting",title:"Pending",message:"Deleting data source...",loading:!0}),await x.datasource.delete(r),p.updateNotification({id:"for-deleting",title:"Successful",message:`Data source [${e}] is deleted`,color:"green"}),a())},d=()=>l.openConfirmModal({title:"Delete this data source?",children:t(i.Text,{size:n.size,children:"This action won't affect your database."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:s});return t(i.Button,{size:n.size,color:"red",onClick:d,leftIcon:t(z.Trash,{size:20}),children:"Delete"})}function E({styles:r=g,config:e}){const{data:a=[],loading:n,refresh:l}=R.useRequest(async()=>{const{data:s}=await x.datasource.list();return s},{refreshDeps:[]});return m.baseURL!==e.apiBaseURL&&(m.baseURL=e.apiBaseURL),f(C,{children:[t(i.Group,{pt:r.spacing,position:"right",children:t(D,{onSuccess:l})}),f(i.Box,{mt:r.spacing,sx:{position:"relative"},children:[t(i.LoadingOverlay,{visible:n}),f(i.Table,{horizontalSpacing:r.spacing,verticalSpacing:r.spacing,fontSize:r.size,highlightOnHover:!0,children:[t("thead",{children:f("tr",{children:[t("th",{children:"Type"}),t("th",{children:"Name"}),t("th",{children:"Action"})]})}),t("tbody",{children:a.map(({id:s,key:d,type:h})=>f("tr",{children:[t("td",{width:200,children:h}),t("td",{children:d}),t("td",{width:200,children:t(i.Group,{position:"left",children:t(v,{id:s,name:d,onSuccess:l})})})]},d))})]})]})]})}o.AddDataSource=D,o.DataSourceList=E,o.DeleteDataSource=v,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devtable/settings-form",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -52,4 +52,4 @@
|
|
|
52
52
|
"react-hook-form": "^7.31.2",
|
|
53
53
|
"tabler-icons-react": "^1.48.0"
|
|
54
54
|
}
|
|
55
|
-
}
|
|
55
|
+
}
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './datasource';
|