@devtable/settings-form 2.1.0 → 2.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.
@@ -1,5 +1,5 @@
1
- import { DataSourceType, IDataSource, IDataSourceConfig } from "./datasource.typed";
2
- import { PaginationResponse } from "../../../website/src/api-caller/types";
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>;
@@ -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,5 @@
1
+ import { Method } from 'axios';
2
+ export declare const APIClient: {
3
+ baseURL: string;
4
+ getRequest(method: Method): (url: string, data: any, options?: any) => Promise<any>;
5
+ };
@@ -0,0 +1,5 @@
1
+ export declare type PaginationResponse<T> = {
2
+ total: number;
3
+ offset: number;
4
+ data: T[];
5
+ };
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { IStyles } from './styles';
3
+ interface IAddDataSource {
4
+ styles?: IStyles;
5
+ onSuccess: () => void;
6
+ }
7
+ export declare function AddDataSource({ onSuccess, styles }: IAddDataSource): JSX.Element;
8
+ export {};
@@ -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 {};
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import { IStyles } from './styles';
3
+ interface IDeleteDataSource {
4
+ id: string;
5
+ name: string;
6
+ onSuccess: () => void;
7
+ styles?: IStyles;
8
+ }
9
+ export declare function DeleteDataSource({ id, name, onSuccess, styles }: IDeleteDataSource): JSX.Element;
10
+ export {};
@@ -0,0 +1,6 @@
1
+ import { MantineSize } from '@mantine/core';
2
+ export interface IStyles {
3
+ size: MantineSize;
4
+ spacing: MantineSize;
5
+ }
6
+ export declare const defaultStyles: IStyles;
@@ -0,0 +1,3 @@
1
+ export interface ISettingsFormConfig {
2
+ apiBaseURL: string;
3
+ }
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export * from './settings-form/src/index'
1
+ export * from './datasource';
@@ -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 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
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
- 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
- };
34
+ }
32
35
  };
33
- const post = getRequest("POST");
34
36
  const datasource = {
35
37
  list: async () => {
36
- const res = await post("/datasource/list", {
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 post("/datasource/create", { type, key, config });
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,12 +58,16 @@ const datasource = {
56
58
  }
57
59
  },
58
60
  delete: async (id) => {
59
- await post("/datasource/delete", { id });
61
+ await APIClient.getRequest("POST")("/datasource/delete", { id });
60
62
  }
61
63
  };
62
64
  const APICaller = {
63
65
  datasource
64
66
  };
67
+ const defaultStyles = {
68
+ size: "sm",
69
+ spacing: "md"
70
+ };
65
71
  var jsxRuntime = { exports: {} };
66
72
  var reactJsxRuntime_production_min = {};
67
73
  /**
@@ -96,7 +102,8 @@ const jsx = jsxRuntime.exports.jsx;
96
102
  const jsxs = jsxRuntime.exports.jsxs;
97
103
  const Fragment = jsxRuntime.exports.Fragment;
98
104
  function AddDataSourceForm({
99
- postSubmit
105
+ postSubmit,
106
+ styles = defaultStyles
100
107
  }) {
101
108
  const {
102
109
  control,
@@ -159,7 +166,8 @@ function AddDataSourceForm({
159
166
  field
160
167
  }) => /* @__PURE__ */ jsx(SegmentedControl, {
161
168
  fullWidth: true,
162
- mb: "md",
169
+ mb: styles.spacing,
170
+ size: styles.size,
163
171
  data: [{
164
172
  label: "PostgreSQL",
165
173
  value: "postgresql"
@@ -179,7 +187,8 @@ function AddDataSourceForm({
179
187
  render: ({
180
188
  field
181
189
  }) => /* @__PURE__ */ jsx(TextInput, {
182
- mb: "md",
190
+ mb: styles.spacing,
191
+ size: styles.size,
183
192
  required: true,
184
193
  label: "Name",
185
194
  placeholder: "A unique name",
@@ -196,7 +205,8 @@ function AddDataSourceForm({
196
205
  render: ({
197
206
  field
198
207
  }) => /* @__PURE__ */ jsx(TextInput, {
199
- mb: "md",
208
+ mb: styles.spacing,
209
+ size: styles.size,
200
210
  required: true,
201
211
  label: "Host",
202
212
  sx: {
@@ -210,7 +220,8 @@ function AddDataSourceForm({
210
220
  render: ({
211
221
  field
212
222
  }) => /* @__PURE__ */ jsx(NumberInput, {
213
- mb: "md",
223
+ mb: styles.spacing,
224
+ size: styles.size,
214
225
  required: true,
215
226
  label: "Port",
216
227
  hideControls: true,
@@ -226,7 +237,8 @@ function AddDataSourceForm({
226
237
  render: ({
227
238
  field
228
239
  }) => /* @__PURE__ */ jsx(TextInput, {
229
- mb: "md",
240
+ mb: styles.spacing,
241
+ size: styles.size,
230
242
  required: true,
231
243
  label: "Username",
232
244
  ...field
@@ -237,7 +249,8 @@ function AddDataSourceForm({
237
249
  render: ({
238
250
  field
239
251
  }) => /* @__PURE__ */ jsx(PasswordInput, {
240
- mb: "md",
252
+ mb: styles.spacing,
253
+ size: styles.size,
241
254
  required: true,
242
255
  label: "Password",
243
256
  ...field
@@ -248,16 +261,18 @@ function AddDataSourceForm({
248
261
  render: ({
249
262
  field
250
263
  }) => /* @__PURE__ */ jsx(TextInput, {
251
- mb: "md",
264
+ mb: styles.spacing,
265
+ size: styles.size,
252
266
  required: true,
253
267
  label: "Database",
254
268
  ...field
255
269
  })
256
270
  }), /* @__PURE__ */ jsx(Group, {
257
271
  position: "right",
258
- mt: "md",
272
+ mt: styles.spacing,
259
273
  children: /* @__PURE__ */ jsx(Button, {
260
274
  type: "submit",
275
+ size: styles.size,
261
276
  children: "Save"
262
277
  })
263
278
  })]
@@ -265,7 +280,8 @@ function AddDataSourceForm({
265
280
  });
266
281
  }
267
282
  function AddDataSource({
268
- onSuccess
283
+ onSuccess,
284
+ styles = defaultStyles
269
285
  }) {
270
286
  const [opened, setOpened] = require$$0.useState(false);
271
287
  const open = () => setOpened(true);
@@ -285,10 +301,11 @@ function AddDataSource({
285
301
  e.stopPropagation();
286
302
  },
287
303
  children: /* @__PURE__ */ jsx(AddDataSourceForm, {
288
- postSubmit
304
+ postSubmit,
305
+ styles
289
306
  })
290
307
  }), /* @__PURE__ */ jsx(Button, {
291
- size: "sm",
308
+ size: styles.size,
292
309
  onClick: open,
293
310
  leftIcon: /* @__PURE__ */ jsx(PlaylistAdd, {
294
311
  size: 20
@@ -300,7 +317,8 @@ function AddDataSource({
300
317
  function DeleteDataSource({
301
318
  id,
302
319
  name,
303
- onSuccess
320
+ onSuccess,
321
+ styles = defaultStyles
304
322
  }) {
305
323
  const modals = useModals();
306
324
  const doDelete = async () => {
@@ -325,7 +343,7 @@ function DeleteDataSource({
325
343
  const confirmAndDelete = () => modals.openConfirmModal({
326
344
  title: "Delete this data source?",
327
345
  children: /* @__PURE__ */ jsx(Text, {
328
- size: "sm",
346
+ size: styles.size,
329
347
  children: "This action won't affect your database."
330
348
  }),
331
349
  labels: {
@@ -336,7 +354,7 @@ function DeleteDataSource({
336
354
  onConfirm: doDelete
337
355
  });
338
356
  return /* @__PURE__ */ jsx(Button, {
339
- size: "sm",
357
+ size: styles.size,
340
358
  color: "red",
341
359
  onClick: confirmAndDelete,
342
360
  leftIcon: /* @__PURE__ */ jsx(Trash, {
@@ -345,7 +363,10 @@ function DeleteDataSource({
345
363
  children: "Delete"
346
364
  });
347
365
  }
348
- function DataSourceList() {
366
+ function DataSourceList({
367
+ styles = defaultStyles,
368
+ config
369
+ }) {
349
370
  const {
350
371
  data = [],
351
372
  loading,
@@ -358,24 +379,27 @@ function DataSourceList() {
358
379
  }, {
359
380
  refreshDeps: []
360
381
  });
382
+ if (APIClient.baseURL !== config.apiBaseURL) {
383
+ APIClient.baseURL = config.apiBaseURL;
384
+ }
361
385
  return /* @__PURE__ */ jsxs(Fragment, {
362
386
  children: [/* @__PURE__ */ jsx(Group, {
363
- pt: "md",
387
+ pt: styles.spacing,
364
388
  position: "right",
365
389
  children: /* @__PURE__ */ jsx(AddDataSource, {
366
390
  onSuccess: refresh
367
391
  })
368
392
  }), /* @__PURE__ */ jsxs(Box, {
369
- mt: "xl",
393
+ mt: styles.spacing,
370
394
  sx: {
371
395
  position: "relative"
372
396
  },
373
397
  children: [/* @__PURE__ */ jsx(LoadingOverlay, {
374
398
  visible: loading
375
399
  }), /* @__PURE__ */ jsxs(Table, {
376
- horizontalSpacing: "md",
377
- verticalSpacing: "md",
378
- fontSize: "md",
400
+ horizontalSpacing: styles.spacing,
401
+ verticalSpacing: styles.spacing,
402
+ fontSize: styles.size,
379
403
  highlightOnHover: true,
380
404
  children: [/* @__PURE__ */ jsx("thead", {
381
405
  children: /* @__PURE__ */ jsxs("tr", {
@@ -1,4 +1,4 @@
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={};/**
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 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,{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"}})});
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"}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtable/settings-form",
3
- "version": "2.1.0",
3
+ "version": "2.4.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,6 +0,0 @@
1
- /// <reference types="react" />
2
- interface IAddDataSource {
3
- onSuccess: () => void;
4
- }
5
- export declare function AddDataSource({ onSuccess }: IAddDataSource): JSX.Element;
6
- export {};
@@ -1,2 +0,0 @@
1
- /// <reference types="react" />
2
- export declare function DataSourceList(): JSX.Element;
@@ -1,6 +0,0 @@
1
- /// <reference types="react" />
2
- export declare function DeleteDataSource({ id, name, onSuccess }: {
3
- id: string;
4
- name: string;
5
- onSuccess: () => void;
6
- }): JSX.Element;
@@ -1 +0,0 @@
1
- export * from './datasource';