@devtable/settings-form 5.3.0 → 5.5.0-alpha
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/account/account-list.d.ts +0 -1
- package/dist/account/login/index.d.ts +1 -2
- package/dist/api-caller/api-key.d.ts +7 -0
- package/dist/api-caller/api-key.typed.d.ts +6 -0
- package/dist/api-caller/index.d.ts +5 -0
- package/dist/api-caller/request.d.ts +2 -0
- package/dist/api-key/add-api-key.d.ts +9 -0
- package/dist/api-key/api-key-list.d.ts +8 -0
- package/dist/api-key/delete-api-key.d.ts +10 -0
- package/dist/api-key/index.d.ts +3 -0
- package/dist/api-key/styles.d.ts +9 -0
- package/dist/datasource/data-source-list.d.ts +0 -1
- package/dist/global.d.ts +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/settings-form.es.js +1103 -768
- package/dist/settings-form.umd.js +10 -10
- package/package.json +1 -1
- package/dist/account/types.d.ts +0 -3
- package/dist/datasource/types.d.ts +0 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(P,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@mantine/core"),require("@mantine/notifications"),require("react"),require("react-hook-form"),require("tabler-icons-react"),require("axios"),require("ahooks"),require("@mantine/modals")):typeof define=="function"&&define.amd?define(["exports","@mantine/core","@mantine/notifications","react","react-hook-form","tabler-icons-react","axios","ahooks","@mantine/modals"],o):(P=typeof globalThis<"u"?globalThis:P||self,o(P["settings-form"]={},P["@mantine/core"],P["@mantine/notifications"],P.React,P["react-hook-form"],P["tabler-icons-react"],P.axios,P.ahooks,P["@mantine/modals"]))})(this,function(P,o,C,Y,_,$,Ze,K,J){"use strict";const we=r=>r&&typeof r=="object"&&"default"in r?r:{default:r},W=we(Y),He=we(Ze),z={baseURL:"http://localhost:31200",apiKey:"",getRequest(r){return(a,l,u={})=>{const d=window.localStorage.getItem("token"),i={"X-Requested-With":"XMLHttpRequest","Content-Type":u.string?"application/x-www-form-urlencoded":"application/json",authorization:d?`bearer ${d}`:"","x-api-key":this.apiKey,...u.headers},c={baseURL:this.baseURL,method:r,url:a,params:r==="GET"?l:u.params,headers:i};return["POST","PUT"].includes(r)&&(c.data=u.string?JSON.stringify(l):l),He.default(c).then(p=>p.data).catch(p=>Promise.reject(p))}}};function ee(r){z.baseURL!==r.apiBaseURL&&(z.baseURL=r.apiBaseURL),r.apiKey&&(z.apiKey=r.apiKey)}const D={datasource:{list:async()=>await z.getRequest("POST")("/datasource/list",{filter:{},sort:{field:"create_time",order:"ASC"},pagination:{page:1,pagesize:100}}),create:async(r,a,l)=>{try{return await z.getRequest("POST")("/datasource/create",{type:r,key:a,config:l})}catch(u){return console.error(u),!1}},delete:async r=>{await z.getRequest("POST")("/datasource/delete",{id:r})}},account:{login:async(r,a)=>{const l={name:r,password:a};return await z.getRequest("POST")("/account/login",l)},list:async()=>await z.getRequest("POST")("/account/list",{filter:{search:""},sort:{field:"name",order:"ASC"},pagination:{page:1,pagesize:100}}),get:async()=>await z.getRequest("GET")("/account/get",{}),update:async(r,a)=>{const l={name:r,email:a};return await z.getRequest("PUT")("/account/update",l)},changepassword:async(r,a)=>{const l={old_password:r,new_password:a};return await z.getRequest("POST")("/account/changepassword",l)},create:async(r,a,l,u)=>await z.getRequest("POST")("/account/create",{name:r,email:a,password:l,role_id:u}),edit:async r=>(r.reset_password||(r.new_password=void 0),await z.getRequest("PUT")("/account/edit",r)),delete:async r=>{if(!!r)return z.getRequest("POST")("/account/delete",{id:r})}},role:{list:async()=>await z.getRequest("GET")("/role/list",{})},api_key:{list:async()=>await z.getRequest("POST")("/api/key/list",{filter:{search:""},sort:{field:"name",order:"ASC"},pagination:{page:1,pagesize:100}}),create:async(r,a,l)=>await z.getRequest("POST")("/api/key/create",{name:r,role_id:a,domain:l}),delete:async r=>{if(!!r)return z.getRequest("POST")("/api/key/delete",{id:r})}}},te={size:"sm",spacing:"md",button:{size:"xs"}};var re={exports:{}},X={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
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 Se;function et(){if(Se)return X;Se=1;var r=W.default,a=Symbol.for("react.element"),l=Symbol.for("react.fragment"),u=Object.prototype.hasOwnProperty,d=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function c(p,b,R){var T,v={},f=null,I=null;R!==void 0&&(f=""+R),b.key!==void 0&&(f=""+b.key),b.ref!==void 0&&(I=b.ref);for(T in b)u.call(b,T)&&!i.hasOwnProperty(T)&&(v[T]=b[T]);if(p&&p.defaultProps)for(T in b=p.defaultProps,b)v[T]===void 0&&(v[T]=b[T]);return{$$typeof:a,type:p,key:f,ref:I,props:v,_owner:d.current}}return X.Fragment=l,X.jsx=c,X.jsxs=c,X}var Q={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
18
|
-
`+
|
|
19
|
-
`),
|
|
20
|
-
`),
|
|
21
|
-
`+
|
|
17
|
+
*/var ye;function tt(){return ye||(ye=1,process.env.NODE_ENV!=="production"&&function(){var r=W.default,a=Symbol.for("react.element"),l=Symbol.for("react.portal"),u=Symbol.for("react.fragment"),d=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),c=Symbol.for("react.provider"),p=Symbol.for("react.context"),b=Symbol.for("react.forward_ref"),R=Symbol.for("react.suspense"),T=Symbol.for("react.suspense_list"),v=Symbol.for("react.memo"),f=Symbol.for("react.lazy"),I=Symbol.for("react.offscreen"),M=Symbol.iterator,B="@@iterator";function ce(e){if(e===null||typeof e!="object")return null;var n=M&&e[M]||e[B];return typeof n=="function"?n:null}var F=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function x(e){{for(var n=arguments.length,s=new Array(n>1?n-1:0),g=1;g<n;g++)s[g-1]=arguments[g];pt("error",e,s)}}function pt(e,n,s){{var g=F.ReactDebugCurrentFrame,w=g.getStackAddendum();w!==""&&(n+="%s",s=s.concat([w]));var y=s.map(function(m){return String(m)});y.unshift("Warning: "+n),Function.prototype.apply.call(console[e],console,y)}}var gt=!1,ht=!1,mt=!1,vt=!1,bt=!1,Ae;Ae=Symbol.for("react.module.reference");function wt(e){return!!(typeof e=="string"||typeof e=="function"||e===u||e===i||bt||e===d||e===R||e===T||vt||e===I||gt||ht||mt||typeof e=="object"&&e!==null&&(e.$$typeof===f||e.$$typeof===v||e.$$typeof===c||e.$$typeof===p||e.$$typeof===b||e.$$typeof===Ae||e.getModuleId!==void 0))}function St(e,n,s){var g=e.displayName;if(g)return g;var w=n.displayName||n.name||"";return w!==""?s+"("+w+")":s}function ze(e){return e.displayName||"Context"}function j(e){if(e==null)return null;if(typeof e.tag=="number"&&x("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case u:return"Fragment";case l:return"Portal";case i:return"Profiler";case d:return"StrictMode";case R:return"Suspense";case T:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case p:var n=e;return ze(n)+".Consumer";case c:var s=e;return ze(s._context)+".Provider";case b:return St(e,e.render,"ForwardRef");case v:var g=e.displayName||null;return g!==null?g:j(e.type)||"Memo";case f:{var w=e,y=w._payload,m=w._init;try{return j(m(y))}catch{return null}}}return null}var U=Object.assign,Z=0,xe,Oe,De,Ie,qe,je,Ne;function ke(){}ke.__reactDisabledLog=!0;function yt(){{if(Z===0){xe=console.log,Oe=console.info,De=console.warn,Ie=console.error,qe=console.group,je=console.groupCollapsed,Ne=console.groupEnd;var e={configurable:!0,enumerable:!0,value:ke,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}Z++}}function _t(){{if(Z--,Z===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:U({},e,{value:xe}),info:U({},e,{value:Oe}),warn:U({},e,{value:De}),error:U({},e,{value:Ie}),group:U({},e,{value:qe}),groupCollapsed:U({},e,{value:je}),groupEnd:U({},e,{value:Ne})})}Z<0&&x("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var de=F.ReactCurrentDispatcher,fe;function ae(e,n,s){{if(fe===void 0)try{throw Error()}catch(w){var g=w.stack.trim().match(/\n( *(at )?)/);fe=g&&g[1]||""}return`
|
|
18
|
+
`+fe+e}}var pe=!1,ie;{var Rt=typeof WeakMap=="function"?WeakMap:Map;ie=new Rt}function Le(e,n){if(!e||pe)return"";{var s=ie.get(e);if(s!==void 0)return s}var g;pe=!0;var w=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var y;y=de.current,de.current=null,yt();try{if(n){var m=function(){throw Error()};if(Object.defineProperty(m.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(m,[])}catch(N){g=N}Reflect.construct(e,[],m)}else{try{m.call()}catch(N){g=N}e.call(m.prototype)}}else{try{throw Error()}catch(N){g=N}e()}}catch(N){if(N&&g&&typeof N.stack=="string"){for(var h=N.stack.split(`
|
|
19
|
+
`),O=g.stack.split(`
|
|
20
|
+
`),E=h.length-1,A=O.length-1;E>=1&&A>=0&&h[E]!==O[A];)A--;for(;E>=1&&A>=0;E--,A--)if(h[E]!==O[A]){if(E!==1||A!==1)do if(E--,A--,A<0||h[E]!==O[A]){var q=`
|
|
21
|
+
`+h[E].replace(" at new "," at ");return e.displayName&&q.includes("<anonymous>")&&(q=q.replace("<anonymous>",e.displayName)),typeof e=="function"&&ie.set(e,q),q}while(E>=1&&A>=0);break}}}finally{pe=!1,de.current=y,_t(),Error.prepareStackTrace=w}var V=e?e.displayName||e.name:"",Qe=V?ae(V):"";return typeof e=="function"&&ie.set(e,Qe),Qe}function Pt(e,n,s){return Le(e,!1)}function Ct(e){var n=e.prototype;return!!(n&&n.isReactComponent)}function oe(e,n,s){if(e==null)return"";if(typeof e=="function")return Le(e,Ct(e));if(typeof e=="string")return ae(e);switch(e){case R:return ae("Suspense");case T:return ae("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case b:return Pt(e.render);case v:return oe(e.type,n,s);case f:{var g=e,w=g._payload,y=g._init;try{return oe(y(w),n,s)}catch{}}}return""}var se=Object.prototype.hasOwnProperty,Me={},Fe=F.ReactDebugCurrentFrame;function le(e){if(e){var n=e._owner,s=oe(e.type,e._source,n?n.type:null);Fe.setExtraStackFrame(s)}else Fe.setExtraStackFrame(null)}function Tt(e,n,s,g,w){{var y=Function.call.bind(se);for(var m in e)if(y(e,m)){var h=void 0;try{if(typeof e[m]!="function"){var O=Error((g||"React class")+": "+s+" type `"+m+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[m]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw O.name="Invariant Violation",O}h=e[m](n,m,g,s,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(E){h=E}h&&!(h instanceof Error)&&(le(w),x("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",g||"React class",s,m,typeof h),le(null)),h instanceof Error&&!(h.message in Me)&&(Me[h.message]=!0,le(w),x("Failed %s type: %s",s,h.message),le(null))}}}var Et=Array.isArray;function ge(e){return Et(e)}function At(e){{var n=typeof Symbol=="function"&&Symbol.toStringTag,s=n&&e[Symbol.toStringTag]||e.constructor.name||"Object";return s}}function zt(e){try{return $e(e),!1}catch{return!0}}function $e(e){return""+e}function Be(e){if(zt(e))return x("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",At(e)),$e(e)}var H=F.ReactCurrentOwner,xt={key:!0,ref:!0,__self:!0,__source:!0},Ue,Ke,he;he={};function Ot(e){if(se.call(e,"ref")){var n=Object.getOwnPropertyDescriptor(e,"ref").get;if(n&&n.isReactWarning)return!1}return e.ref!==void 0}function Dt(e){if(se.call(e,"key")){var n=Object.getOwnPropertyDescriptor(e,"key").get;if(n&&n.isReactWarning)return!1}return e.key!==void 0}function It(e,n){if(typeof e.ref=="string"&&H.current&&n&&H.current.stateNode!==n){var s=j(H.current.type);he[s]||(x('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',j(H.current.type),e.ref),he[s]=!0)}}function qt(e,n){{var s=function(){Ue||(Ue=!0,x("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",n))};s.isReactWarning=!0,Object.defineProperty(e,"key",{get:s,configurable:!0})}}function jt(e,n){{var s=function(){Ke||(Ke=!0,x("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",n))};s.isReactWarning=!0,Object.defineProperty(e,"ref",{get:s,configurable:!0})}}var Nt=function(e,n,s,g,w,y,m){var h={$$typeof:a,type:e,key:n,ref:s,props:m,_owner:y};return h._store={},Object.defineProperty(h._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(h,"_self",{configurable:!1,enumerable:!1,writable:!1,value:g}),Object.defineProperty(h,"_source",{configurable:!1,enumerable:!1,writable:!1,value:w}),Object.freeze&&(Object.freeze(h.props),Object.freeze(h)),h};function kt(e,n,s,g,w){{var y,m={},h=null,O=null;s!==void 0&&(Be(s),h=""+s),Dt(n)&&(Be(n.key),h=""+n.key),Ot(n)&&(O=n.ref,It(n,w));for(y in n)se.call(n,y)&&!xt.hasOwnProperty(y)&&(m[y]=n[y]);if(e&&e.defaultProps){var E=e.defaultProps;for(y in E)m[y]===void 0&&(m[y]=E[y])}if(h||O){var A=typeof e=="function"?e.displayName||e.name||"Unknown":e;h&&qt(m,A),O&&jt(m,A)}return Nt(e,h,O,w,g,H.current,m)}}var me=F.ReactCurrentOwner,We=F.ReactDebugCurrentFrame;function G(e){if(e){var n=e._owner,s=oe(e.type,e._source,n?n.type:null);We.setExtraStackFrame(s)}else We.setExtraStackFrame(null)}var ve;ve=!1;function be(e){return typeof e=="object"&&e!==null&&e.$$typeof===a}function Ge(){{if(me.current){var e=j(me.current.type);if(e)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+e+"`."}return""}}function
|
|
23
|
+
Check the render method of \``+e+"`."}return""}}function Lt(e){{if(e!==void 0){var n=e.fileName.replace(/^.*[\\\/]/,""),s=e.lineNumber;return`
|
|
24
24
|
|
|
25
|
-
Check your code at `+
|
|
25
|
+
Check your code at `+n+":"+s+"."}return""}}var Ve={};function Mt(e){{var n=Ge();if(!n){var s=typeof e=="string"?e:e.displayName||e.name;s&&(n=`
|
|
26
26
|
|
|
27
|
-
Check the top-level render call using <`+i+">.")}return t}}function We(e,t){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var i=jr(t);if($e[i])return;$e[i]=!0;var c="";e&&e._owner&&e._owner!==fe.current&&(c=" It was passed a child from "+L(e._owner.type)+"."),M(e),O('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',i,c),M(null)}}function Ye(e,t){{if(typeof e!="object")return;if(ce(e))for(var i=0;i<e.length;i++){var c=e[i];ge(c)&&We(c,t)}else if(ge(e))e._store&&(e._store.validated=!0);else if(e){var v=oe(e);if(typeof v=="function"&&v!==e.entries)for(var b=v.call(e),h;!(h=b.next()).done;)ge(h.value)&&We(h.value,t)}}}function qr(e){{var t=e.type;if(t==null||typeof t=="string")return;var i;if(typeof t=="function")i=t.propTypes;else if(typeof t=="object"&&(t.$$typeof===w||t.$$typeof===S))i=t.propTypes;else return;if(i){var c=L(t);Rr(i,e.props,"prop",c,e)}else if(t.PropTypes!==void 0&&!pe){pe=!0;var v=L(t);O("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",v||"Unknown")}typeof t.getDefaultProps=="function"&&!t.getDefaultProps.isReactClassApproved&&O("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Lr(e){{for(var t=Object.keys(e.props),i=0;i<t.length;i++){var c=t[i];if(c!=="children"&&c!=="key"){M(e),O("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",c),M(null);break}}e.ref!==null&&(M(e),O("Invalid attribute `ref` supplied to `React.Fragment`."),M(null))}}function Ve(e,t,i,c,v,b){{var h=pr(e);if(!h){var g="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(g+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var z=Ar(v);z?g+=z:g+=Me();var _;e===null?_="null":ce(e)?_="array":e!==void 0&&e.$$typeof===a?(_="<"+(L(e.type)||"Unknown")+" />",g=" Did you accidentally export a JSX literal instead of a component?"):_=typeof e,O("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",_,g)}var y=Dr(e,t,i,v,b);if(y==null)return y;if(h){var A=t.children;if(A!==void 0)if(c)if(ce(A)){for(var $=0;$<A.length;$++)Ye(A[$],e);Object.freeze&&Object.freeze(A)}else O("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Ye(A,e)}return e===l?Lr(y):qr(y),y}}function Ir(e,t,i){return Ve(e,t,i,!0)}function Nr(e,t,i){return Ve(e,t,i,!1)}var Ur=Nr,kr=Ir;G.Fragment=l,G.jsx=Ur,G.jsxs=kr}()),G}(function(n){process.env.NODE_ENV==="production"?n.exports=Ke():n.exports=Qe()})(ee);const F=ee.exports.Fragment,r=ee.exports.jsx,T=ee.exports.jsxs;function Ze({postSubmit:n,styles:a=H}){const{control:u,handleSubmit:l}=R.useForm({defaultValues:{type:"postgresql",key:"",config:{host:"",port:5432,username:"",password:"",database:""}}}),f=async({type:o,key:d,config:p})=>{if(x.showNotification({id:"for-creating",title:"Pending",message:"Adding data source...",loading:!0}),!await q.datasource.create(o,d,p)){x.updateNotification({id:"for-creating",title:"Failed",message:"Test connection failed with given info",color:"red"});return}x.updateNotification({id:"for-creating",title:"Successful",message:"Data source is added",color:"green"}),n()};return r(s.Box,{mx:"auto",children:T("form",{onSubmit:l(f),children:[r(R.Controller,{name:"type",control:u,render:({field:o})=>r(s.SegmentedControl,{fullWidth:!0,mb:a.spacing,size:a.size,data:[{label:"PostgreSQL",value:"postgresql"},{label:"MySQL",value:"mysql"},{label:"HTTP",value:"http",disabled:!0}],...o})}),r(R.Controller,{name:"key",control:u,render:({field:o})=>r(s.TextInput,{mb:a.spacing,size:a.size,required:!0,label:"Name",placeholder:"A unique name",...o})}),r(s.Divider,{label:"Connection Info",labelPosition:"center"}),T(s.Group,{grow:!0,children:[r(R.Controller,{name:"config.host",control:u,render:({field:o})=>r(s.TextInput,{mb:a.spacing,size:a.size,required:!0,label:"Host",sx:{flexGrow:1},...o})}),r(R.Controller,{name:"config.port",control:u,render:({field:o})=>r(s.NumberInput,{mb:a.spacing,size:a.size,required:!0,label:"Port",hideControls:!0,sx:{width:"8em"},...o})})]}),r(R.Controller,{name:"config.username",control:u,render:({field:o})=>r(s.TextInput,{mb:a.spacing,size:a.size,required:!0,label:"Username",...o})}),r(R.Controller,{name:"config.password",control:u,render:({field:o})=>r(s.PasswordInput,{mb:a.spacing,size:a.size,required:!0,label:"Password",...o})}),r(R.Controller,{name:"config.database",control:u,render:({field:o})=>r(s.TextInput,{mb:a.spacing,size:a.size,required:!0,label:"Database",...o})}),r(s.Group,{position:"right",mt:a.spacing,children:r(s.Button,{type:"submit",size:a.button.size,children:"Save"})})]})})}function we({onSuccess:n,styles:a=H}){const[u,l]=Y.default.useState(!1),f=()=>l(!0),o=()=>l(!1),d=()=>{n(),o()};return T(F,{children:[r(s.Modal,{overflow:"inside",opened:u,onClose:()=>l(!1),title:"Add a data source",trapFocus:!0,onDragStart:p=>{p.stopPropagation()},children:r(Ze,{postSubmit:d,styles:a})}),r(s.Button,{size:a.button.size,onClick:f,leftIcon:r(W.PlaylistAdd,{size:20}),children:"Add a Data Source"})]})}function Re({id:n,name:a,onSuccess:u,styles:l=H}){const f=me.useModals(),o=async()=>{!n||(x.showNotification({id:"for-deleting",title:"Pending",message:"Deleting data source...",loading:!0}),await q.datasource.delete(n),x.updateNotification({id:"for-deleting",title:"Successful",message:`Data source [${a}] is deleted`,color:"green"}),u())},d=()=>f.openConfirmModal({title:"Delete this data source?",children:r(s.Text,{size:l.size,children:"This action won't affect your database."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:o});return r(s.Button,{size:l.button.size,color:"red",onClick:d,leftIcon:r(W.Trash,{size:20}),children:"Delete"})}function He({styles:n=H,config:a}){const{data:u=[],loading:l,refresh:f}=Z.useRequest(async()=>{const{data:o}=await q.datasource.list();return o},{refreshDeps:[]});return P.baseURL!==a.apiBaseURL&&(P.baseURL=a.apiBaseURL),T(F,{children:[r(s.Group,{pt:n.spacing,position:"right",children:r(we,{onSuccess:f})}),T(s.Box,{mt:n.spacing,sx:{position:"relative"},children:[r(s.LoadingOverlay,{visible:l}),T(s.Table,{horizontalSpacing:n.spacing,verticalSpacing:n.spacing,fontSize:n.size,highlightOnHover:!0,children:[r("thead",{children:T("tr",{children:[r("th",{children:"Type"}),r("th",{children:"Name"}),r("th",{children:"Action"})]})}),r("tbody",{children:u.map(({id:o,key:d,type:p})=>T("tr",{children:[r("td",{width:200,children:p}),r("td",{children:d}),r("td",{width:200,children:r(s.Group,{position:"left",children:r(Re,{id:o,name:d,onSuccess:f})})})]},d))})]})]})]})}const er=Q.forwardRef(({label:n,value:a,description:u,...l},f)=>T(s.Stack,{spacing:2,ref:f,...l,children:[r(s.Text,{size:"sm",children:n}),r(s.Text,{size:"xs",color:"dimmed",className:"role-description",children:u})]})),Se=Q.forwardRef(({styles:n,value:a,onChange:u},l)=>{const{data:f=[],loading:o}=Z.useRequest(async()=>(await q.role.list()).map(p=>({label:p.name,value:p.id,description:p.description,disabled:p.id===50})),{refreshDeps:[]});return r(s.Select,{ref:l,mb:n.spacing,size:n.size,required:!0,label:"Role",itemComponent:er,data:f,disabled:o,styles:()=>({item:{"&[data-selected]":{"&, &:hover":{".role-description":{color:"rgba(255,255,255,.8)"}}}}}),value:a,onChange:u})}),N={size:"sm",spacing:"md",button:{size:"xs"}};function rr({postSubmit:n,styles:a=N,initialRoleID:u}){const{control:l,handleSubmit:f}=R.useForm({defaultValues:{name:"",email:"",role_id:u,password:""}}),o=async({name:d,email:p,password:w,role_id:D})=>{try{x.showNotification({id:"for-creating",title:"Pending",message:"Adding account...",loading:!0}),await q.account.create(d,p,w,D),x.updateNotification({id:"for-creating",title:"Successful",message:"Account is added",color:"green"}),n()}catch(C){x.updateNotification({id:"for-creating",title:"Failed",message:C.message,color:"red"})}};return r(s.Box,{mx:"auto",children:T("form",{onSubmit:f(o),children:[r(R.Controller,{name:"name",control:l,render:({field:d})=>r(s.TextInput,{mb:a.spacing,size:a.size,required:!0,label:"Username",...d})}),r(R.Controller,{name:"email",control:l,render:({field:d})=>r(s.TextInput,{mb:a.spacing,size:a.size,required:!0,label:"Email",...d})}),r(R.Controller,{name:"password",control:l,render:({field:d})=>r(s.PasswordInput,{mb:a.spacing,size:a.size,required:!0,label:"Password",description:"Password must be at least 8 characters long",...d})}),r(R.Controller,{name:"role_id",control:l,render:({field:d})=>r(Se,{styles:a,...d})}),r(s.Group,{position:"right",mt:a.spacing,children:r(s.Button,{type:"submit",size:a.button.size,children:"Save"})})]})})}function _e({onSuccess:n,styles:a=N,initialRoleID:u}){const[l,f]=Y.default.useState(!1),o=()=>f(!0),d=()=>f(!1),p=()=>{n(),d()};return T(F,{children:[r(s.Modal,{overflow:"inside",opened:l,onClose:()=>f(!1),title:"Add an Account",trapFocus:!0,onDragStart:w=>{w.stopPropagation()},children:r(rr,{postSubmit:p,styles:a,initialRoleID:u})}),r(s.Button,{size:a.button.size,onClick:o,leftIcon:r(W.PlaylistAdd,{size:20}),children:"Add an Account"})]})}function Ee({id:n,name:a,onSuccess:u,styles:l=N}){const f=me.useModals(),o=async()=>{if(!!n){x.showNotification({id:"for-deleting",title:"Pending",message:"Deleting account...",loading:!0});try{await q.account.delete(n),x.updateNotification({id:"for-deleting",title:"Successful",message:`Account [${a}] is deleted`,color:"green"}),u()}catch(p){x.updateNotification({id:"for-deleting",title:"Failed",message:p.message,color:"red"})}}},d=()=>f.openConfirmModal({title:"Delete this account?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:o});return r(s.Button,{size:l.button.size,color:"red",onClick:d,leftIcon:r(W.Trash,{size:20}),children:"Delete"})}function tr({id:n,name:a,email:u,role_id:l,postSubmit:f,styles:o=N}){const{control:d,handleSubmit:p,watch:w}=R.useForm({defaultValues:{name:a,email:u,role_id:l,reset_password:!1,new_password:""}}),D=async({name:m,email:j,role_id:B,reset_password:J,new_password:oe})=>{try{x.showNotification({id:"for-updating",title:"Pending",message:"Updating account...",loading:!0}),await q.account.edit({id:n,name:m,email:j,role_id:B,reset_password:J,new_password:oe}),x.updateNotification({id:"for-updating",title:"Successful",message:"Account is updated",color:"green"}),f()}catch(U){x.updateNotification({id:"for-updating",title:"Failed",message:U.message,color:"red"})}},[C,S]=w(["reset_password","new_password"]);return r(s.Box,{mx:"auto",children:T("form",{onSubmit:p(D),children:[r(R.Controller,{name:"name",control:d,render:({field:m})=>r(s.TextInput,{mb:o.spacing,size:o.size,required:!0,label:"Username",...m})}),r(R.Controller,{name:"email",control:d,render:({field:m})=>r(s.TextInput,{mb:o.spacing,size:o.size,required:!0,label:"Email",...m})}),r(R.Controller,{name:"role_id",control:d,render:({field:m})=>r(Se,{styles:o,...m})}),r(s.Divider,{my:20,variant:"dashed",label:"",labelPosition:"center"}),r(R.Controller,{name:"reset_password",control:d,render:({field:m})=>r(s.Switch,{mb:o.spacing,size:o.size,label:"Reset password",checked:m.value,onChange:j=>m.onChange(j.currentTarget.checked),styles:{label:{verticalAlign:"middle"}}})}),C&&r(R.Controller,{name:"new_password",control:d,render:({field:m})=>r(s.PasswordInput,{autoComplete:"off",mb:o.spacing,size:o.size,required:!0,description:"Password must be at least 8 characters long",label:"New Password",...m})}),r(s.Group,{position:"right",mt:o.spacing,children:r(s.Button,{type:"submit",size:o.button.size,children:"Submit"})})]})})}function nr({account:n,onSuccess:a,styles:u=N}){const[l,f]=Y.default.useState(!1),o=()=>f(!0),d=()=>f(!1),p=()=>{a(),d()};return T(F,{children:[r(s.Modal,{overflow:"inside",opened:l,onClose:()=>f(!1),title:`Editing ${n.name}`,trapFocus:!0,onDragStart:w=>{w.stopPropagation()},children:r(tr,{...n,postSubmit:p,styles:u})}),r(s.Button,{size:u.button.size,onClick:o,leftIcon:r(W.Edit,{size:20}),children:"Edit"})]})}function ar({styles:n=N,config:a}){var D,C;const{data:u=[],loading:l,refresh:f}=Z.useRequest(async()=>{const{data:S}=await q.account.list();return S},{refreshDeps:[]}),{data:o=[],loading:d}=Z.useRequest(async()=>(await q.role.list()).map(m=>({label:m.name,value:m.id,description:m.description,disabled:m.id===50})),{refreshDeps:[]}),p=Q.useMemo(()=>o.reduce((S,m)=>(S.set(m.value,m.label),S),new Map),[o]),w=S=>{var m;return(m=p.get(S))!=null?m:S};return P.baseURL!==a.apiBaseURL&&(P.baseURL=a.apiBaseURL),T(F,{children:[r(s.Group,{pt:n.spacing,position:"right",children:r(_e,{onSuccess:f,initialRoleID:(C=(D=o==null?void 0:o[0])==null?void 0:D.value)!=null?C:0})}),T(s.Box,{mt:n.spacing,sx:{position:"relative"},children:[r(s.LoadingOverlay,{visible:l||d}),T(s.Table,{horizontalSpacing:n.spacing,verticalSpacing:n.spacing,fontSize:n.size,highlightOnHover:!0,children:[r("thead",{children:T("tr",{children:[r("th",{children:"Username"}),r("th",{children:"Email"}),r("th",{children:"Role"}),r("th",{children:"Action"})]})}),r("tbody",{children:u.map(S=>{const{id:m,name:j,email:B,role_id:J}=S;return T("tr",{children:[r("td",{width:200,children:j}),r("td",{width:200,children:B}),r("td",{width:200,children:w(J)}),r("td",{width:200,children:T(s.Group,{position:"left",children:[r(nr,{account:S,onSuccess:f}),r(Ee,{id:m,name:j,onSuccess:f})]})})]},m)})})]})]})]})}function ir({postSubmit:n,styles:a=N}){const{control:u,handleSubmit:l}=R.useForm({defaultValues:{name:"",password:""}}),f=async({name:o,password:d})=>{try{x.showNotification({id:"for-login",title:"Pending",message:"Loggin in...",loading:!0});const p=await q.account.login(o,d);window.localStorage.setItem("token",p.token),x.updateNotification({id:"for-login",title:"Successful",message:"Logged in",color:"green"}),n(p)}catch(p){x.updateNotification({id:"for-login",title:"Login Failed",message:p.message,color:"red"})}};return r(s.Box,{mx:"auto",children:T("form",{onSubmit:l(f),children:[r(R.Controller,{name:"name",control:u,render:({field:o})=>r(s.TextInput,{mb:a.spacing,size:a.size,required:!0,label:"Username",...o})}),r(R.Controller,{name:"password",control:u,render:({field:o})=>r(s.PasswordInput,{mb:a.spacing,size:a.size,required:!0,label:"Password",...o})}),r(s.Group,{position:"right",mt:a.spacing,children:r(s.Button,{type:"submit",size:a.button.size,children:"Submit"})})]})})}function or({styles:n=N,config:a,onSuccess:u}){return P.baseURL!==a.apiBaseURL&&(P.baseURL=a.apiBaseURL),r(F,{children:r(s.Box,{mt:n.spacing,sx:{position:"relative"},children:r(ir,{styles:n,postSubmit:u})})})}E.AccountList=ar,E.AddAccount=_e,E.AddDataSource=we,E.DataSourceList=He,E.DeleteAccount=Ee,E.DeleteDataSource=Re,E.Login=or,Object.defineProperties(E,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
27
|
+
Check the top-level render call using <`+s+">.")}return n}}function Ye(e,n){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var s=Mt(n);if(Ve[s])return;Ve[s]=!0;var g="";e&&e._owner&&e._owner!==me.current&&(g=" It was passed a child from "+j(e._owner.type)+"."),G(e),x('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',s,g),G(null)}}function Je(e,n){{if(typeof e!="object")return;if(ge(e))for(var s=0;s<e.length;s++){var g=e[s];be(g)&&Ye(g,n)}else if(be(e))e._store&&(e._store.validated=!0);else if(e){var w=ce(e);if(typeof w=="function"&&w!==e.entries)for(var y=w.call(e),m;!(m=y.next()).done;)be(m.value)&&Ye(m.value,n)}}}function Ft(e){{var n=e.type;if(n==null||typeof n=="string")return;var s;if(typeof n=="function")s=n.propTypes;else if(typeof n=="object"&&(n.$$typeof===b||n.$$typeof===v))s=n.propTypes;else return;if(s){var g=j(n);Tt(s,e.props,"prop",g,e)}else if(n.PropTypes!==void 0&&!ve){ve=!0;var w=j(n);x("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",w||"Unknown")}typeof n.getDefaultProps=="function"&&!n.getDefaultProps.isReactClassApproved&&x("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function $t(e){{for(var n=Object.keys(e.props),s=0;s<n.length;s++){var g=n[s];if(g!=="children"&&g!=="key"){G(e),x("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",g),G(null);break}}e.ref!==null&&(G(e),x("Invalid attribute `ref` supplied to `React.Fragment`."),G(null))}}function Xe(e,n,s,g,w,y){{var m=wt(e);if(!m){var h="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(h+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var O=Lt(w);O?h+=O:h+=Ge();var E;e===null?E="null":ge(e)?E="array":e!==void 0&&e.$$typeof===a?(E="<"+(j(e.type)||"Unknown")+" />",h=" Did you accidentally export a JSX literal instead of a component?"):E=typeof e,x("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",E,h)}var A=kt(e,n,s,w,y);if(A==null)return A;if(m){var q=n.children;if(q!==void 0)if(g)if(ge(q)){for(var V=0;V<q.length;V++)Je(q[V],e);Object.freeze&&Object.freeze(q)}else x("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Je(q,e)}return e===u?$t(A):Ft(A),A}}function Bt(e,n,s){return Xe(e,n,s,!0)}function Ut(e,n,s){return Xe(e,n,s,!1)}var Kt=Ut,Wt=Bt;Q.Fragment=u,Q.jsx=Kt,Q.jsxs=Wt}()),Q}(function(r){process.env.NODE_ENV==="production"?r.exports=et():r.exports=tt()})(re);const k=re.exports.Fragment,t=re.exports.jsx,S=re.exports.jsxs;function rt({postSubmit:r,styles:a=te}){const{control:l,handleSubmit:u}=_.useForm({defaultValues:{type:"postgresql",key:"",config:{host:"",port:5432,username:"",password:"",database:""}}}),d=async({type:i,key:c,config:p})=>{if(C.showNotification({id:"for-creating",title:"Pending",message:"Adding data source...",loading:!0}),!await D.datasource.create(i,c,p)){C.updateNotification({id:"for-creating",title:"Failed",message:"Test connection failed with given info",color:"red"});return}C.updateNotification({id:"for-creating",title:"Successful",message:"Data source is added",color:"green"}),r()};return t(o.Box,{mx:"auto",children:S("form",{onSubmit:u(d),children:[t(_.Controller,{name:"type",control:l,render:({field:i})=>t(o.SegmentedControl,{fullWidth:!0,mb:a.spacing,size:a.size,data:[{label:"PostgreSQL",value:"postgresql"},{label:"MySQL",value:"mysql"},{label:"HTTP",value:"http",disabled:!0}],...i})}),t(_.Controller,{name:"key",control:l,render:({field:i})=>t(o.TextInput,{mb:a.spacing,size:a.size,required:!0,label:"Name",placeholder:"A unique name",...i})}),t(o.Divider,{label:"Connection Info",labelPosition:"center"}),S(o.Group,{grow:!0,children:[t(_.Controller,{name:"config.host",control:l,render:({field:i})=>t(o.TextInput,{mb:a.spacing,size:a.size,required:!0,label:"Host",sx:{flexGrow:1},...i})}),t(_.Controller,{name:"config.port",control:l,render:({field:i})=>t(o.NumberInput,{mb:a.spacing,size:a.size,required:!0,label:"Port",hideControls:!0,sx:{width:"8em"},...i})})]}),t(_.Controller,{name:"config.username",control:l,render:({field:i})=>t(o.TextInput,{mb:a.spacing,size:a.size,required:!0,label:"Username",...i})}),t(_.Controller,{name:"config.password",control:l,render:({field:i})=>t(o.PasswordInput,{mb:a.spacing,size:a.size,required:!0,label:"Password",...i})}),t(_.Controller,{name:"config.database",control:l,render:({field:i})=>t(o.TextInput,{mb:a.spacing,size:a.size,required:!0,label:"Database",...i})}),t(o.Group,{position:"right",mt:a.spacing,children:t(o.Button,{type:"submit",size:a.button.size,children:"Save"})})]})})}function _e({onSuccess:r,styles:a=te}){const[l,u]=W.default.useState(!1),d=()=>u(!0),i=()=>u(!1),c=()=>{r(),i()};return S(k,{children:[t(o.Modal,{overflow:"inside",opened:l,onClose:()=>u(!1),title:"Add a data source",trapFocus:!0,onDragStart:p=>{p.stopPropagation()},children:t(rt,{postSubmit:c,styles:a})}),t(o.Button,{size:a.button.size,onClick:d,leftIcon:t($.PlaylistAdd,{size:20}),children:"Add a Data Source"})]})}function Re({id:r,name:a,onSuccess:l,styles:u=te}){const d=J.useModals(),i=async()=>{!r||(C.showNotification({id:"for-deleting",title:"Pending",message:"Deleting data source...",loading:!0}),await D.datasource.delete(r),C.updateNotification({id:"for-deleting",title:"Successful",message:`Data source [${a}] is deleted`,color:"green"}),l())},c=()=>d.openConfirmModal({title:"Delete this data source?",children:t(o.Text,{size:u.size,children:"This action won't affect your database."}),labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:i});return t(o.Button,{size:u.button.size,color:"red",onClick:c,leftIcon:t($.Trash,{size:20}),children:"Delete"})}function nt({styles:r=te,config:a}){ee(a);const{data:l=[],loading:u,refresh:d}=K.useRequest(async()=>{const{data:i}=await D.datasource.list();return i},{refreshDeps:[]});return S(k,{children:[t(o.Group,{pt:r.spacing,position:"right",children:t(_e,{onSuccess:d})}),S(o.Box,{mt:r.spacing,sx:{position:"relative"},children:[t(o.LoadingOverlay,{visible:u}),S(o.Table,{horizontalSpacing:r.spacing,verticalSpacing:r.spacing,fontSize:r.size,highlightOnHover:!0,children:[t("thead",{children:S("tr",{children:[t("th",{children:"Type"}),t("th",{children:"Name"}),t("th",{children:"Action"})]})}),t("tbody",{children:l.map(({id:i,key:c,type:p})=>S("tr",{children:[t("td",{width:200,children:p}),t("td",{children:c}),t("td",{width:200,children:t(o.Group,{position:"left",children:t(Re,{id:i,name:c,onSuccess:d})})})]},c))})]})]})]})}const at=Y.forwardRef(({label:r,value:a,description:l,...u},d)=>S(o.Stack,{spacing:2,ref:d,...u,children:[t(o.Text,{size:"sm",children:r}),t(o.Text,{size:"xs",color:"dimmed",className:"role-description",children:l})]})),ue=Y.forwardRef(({styles:r,value:a,onChange:l},u)=>{const{data:d=[],loading:i}=K.useRequest(async()=>(await D.role.list()).map(p=>({label:p.name,value:p.id,description:p.description,disabled:p.id===50})),{refreshDeps:[]});return t(o.Select,{ref:u,mb:r.spacing,size:r.size,required:!0,label:"Role",itemComponent:at,data:d,disabled:i,styles:()=>({item:{"&[data-selected]":{"&, &:hover":{".role-description":{color:"rgba(255,255,255,.8)"}}}}}),value:a,onChange:l})}),L={size:"sm",spacing:"md",button:{size:"xs"}};function it({postSubmit:r,styles:a=L,initialRoleID:l}){const{control:u,handleSubmit:d}=_.useForm({defaultValues:{name:"",email:"",role_id:l,password:""}}),i=async({name:c,email:p,password:b,role_id:R})=>{try{C.showNotification({id:"for-creating",title:"Pending",message:"Adding account...",loading:!0}),await D.account.create(c,p,b,R),C.updateNotification({id:"for-creating",title:"Successful",message:"Account is added",color:"green"}),r()}catch(T){C.updateNotification({id:"for-creating",title:"Failed",message:T.message,color:"red"})}};return t(o.Box,{mx:"auto",children:S("form",{onSubmit:d(i),children:[t(_.Controller,{name:"name",control:u,render:({field:c})=>t(o.TextInput,{mb:a.spacing,size:a.size,required:!0,label:"Username",...c})}),t(_.Controller,{name:"email",control:u,render:({field:c})=>t(o.TextInput,{mb:a.spacing,size:a.size,required:!0,label:"Email",...c})}),t(_.Controller,{name:"password",control:u,render:({field:c})=>t(o.PasswordInput,{mb:a.spacing,size:a.size,required:!0,label:"Password",description:"Password must be at least 8 characters long",...c})}),t(_.Controller,{name:"role_id",control:u,render:({field:c})=>t(ue,{styles:a,...c})}),t(o.Group,{position:"right",mt:a.spacing,children:t(o.Button,{type:"submit",size:a.button.size,children:"Save"})})]})})}function Pe({onSuccess:r,styles:a=L,initialRoleID:l}){const[u,d]=W.default.useState(!1),i=()=>d(!0),c=()=>d(!1),p=()=>{r(),c()};return S(k,{children:[t(o.Modal,{overflow:"inside",opened:u,onClose:()=>d(!1),title:"Add an Account",trapFocus:!0,onDragStart:b=>{b.stopPropagation()},children:t(it,{postSubmit:p,styles:a,initialRoleID:l})}),t(o.Button,{size:a.button.size,onClick:i,leftIcon:t($.PlaylistAdd,{size:20}),children:"Add an Account"})]})}function Ce({id:r,name:a,onSuccess:l,styles:u=L}){const d=J.useModals(),i=async()=>{if(!!r){C.showNotification({id:"for-deleting",title:"Pending",message:"Deleting account...",loading:!0});try{await D.account.delete(r),C.updateNotification({id:"for-deleting",title:"Successful",message:`Account [${a}] is deleted`,color:"green"}),l()}catch(p){C.updateNotification({id:"for-deleting",title:"Failed",message:p.message,color:"red"})}}},c=()=>d.openConfirmModal({title:"Delete this account?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:i});return t(o.Button,{size:u.button.size,color:"red",onClick:c,leftIcon:t($.Trash,{size:20}),children:"Delete"})}function ot({id:r,name:a,email:l,role_id:u,postSubmit:d,styles:i=L}){const{control:c,handleSubmit:p,watch:b}=_.useForm({defaultValues:{name:a,email:l,role_id:u,reset_password:!1,new_password:""}}),R=async({name:f,email:I,role_id:M,reset_password:B,new_password:ce})=>{try{C.showNotification({id:"for-updating",title:"Pending",message:"Updating account...",loading:!0}),await D.account.edit({id:r,name:f,email:I,role_id:M,reset_password:B,new_password:ce}),C.updateNotification({id:"for-updating",title:"Successful",message:"Account is updated",color:"green"}),d()}catch(F){C.updateNotification({id:"for-updating",title:"Failed",message:F.message,color:"red"})}},[T,v]=b(["reset_password","new_password"]);return t(o.Box,{mx:"auto",children:S("form",{onSubmit:p(R),children:[t(_.Controller,{name:"name",control:c,render:({field:f})=>t(o.TextInput,{mb:i.spacing,size:i.size,required:!0,label:"Username",...f})}),t(_.Controller,{name:"email",control:c,render:({field:f})=>t(o.TextInput,{mb:i.spacing,size:i.size,required:!0,label:"Email",...f})}),t(_.Controller,{name:"role_id",control:c,render:({field:f})=>t(ue,{styles:i,...f})}),t(o.Divider,{my:20,variant:"dashed",label:"",labelPosition:"center"}),t(_.Controller,{name:"reset_password",control:c,render:({field:f})=>t(o.Switch,{mb:i.spacing,size:i.size,label:"Reset password",checked:f.value,onChange:I=>f.onChange(I.currentTarget.checked),styles:{label:{verticalAlign:"middle"}}})}),T&&t(_.Controller,{name:"new_password",control:c,render:({field:f})=>t(o.PasswordInput,{autoComplete:"off",mb:i.spacing,size:i.size,required:!0,description:"Password must be at least 8 characters long",label:"New Password",...f})}),t(o.Group,{position:"right",mt:i.spacing,children:t(o.Button,{type:"submit",size:i.button.size,children:"Submit"})})]})})}function st({account:r,onSuccess:a,styles:l=L}){const[u,d]=W.default.useState(!1),i=()=>d(!0),c=()=>d(!1),p=()=>{a(),c()};return S(k,{children:[t(o.Modal,{overflow:"inside",opened:u,onClose:()=>d(!1),title:`Editing ${r.name}`,trapFocus:!0,onDragStart:b=>{b.stopPropagation()},children:t(ot,{...r,postSubmit:p,styles:l})}),t(o.Button,{size:l.button.size,onClick:i,leftIcon:t($.Edit,{size:20}),children:"Edit"})]})}function lt({styles:r=L,config:a}){var R,T;ee(a);const{data:l=[],loading:u,refresh:d}=K.useRequest(async()=>{const{data:v}=await D.account.list();return v},{refreshDeps:[]}),{data:i=[],loading:c}=K.useRequest(async()=>(await D.role.list()).map(f=>({label:f.name,value:f.id,description:f.description,disabled:f.id===50})),{refreshDeps:[]}),p=Y.useMemo(()=>i.reduce((v,f)=>(v.set(f.value,f.label),v),new Map),[i]),b=v=>{var f;return(f=p.get(v))!=null?f:v};return S(k,{children:[t(o.Group,{pt:r.spacing,position:"right",children:t(Pe,{onSuccess:d,initialRoleID:(T=(R=i==null?void 0:i[0])==null?void 0:R.value)!=null?T:0})}),S(o.Box,{mt:r.spacing,sx:{position:"relative"},children:[t(o.LoadingOverlay,{visible:u||c}),S(o.Table,{horizontalSpacing:r.spacing,verticalSpacing:r.spacing,fontSize:r.size,highlightOnHover:!0,children:[t("thead",{children:S("tr",{children:[t("th",{children:"Username"}),t("th",{children:"Email"}),t("th",{children:"Role"}),t("th",{children:"Action"})]})}),t("tbody",{children:l.map(v=>{const{id:f,name:I,email:M,role_id:B}=v;return S("tr",{children:[t("td",{width:200,children:I}),t("td",{width:200,children:M}),t("td",{width:200,children:b(B)}),t("td",{width:200,children:S(o.Group,{position:"left",children:[t(st,{account:v,onSuccess:d}),t(Ce,{id:f,name:I,onSuccess:d})]})})]},f)})})]})]})]})}function ut({postSubmit:r,styles:a=L}){const{control:l,handleSubmit:u}=_.useForm({defaultValues:{name:"",password:""}}),d=async({name:i,password:c})=>{try{C.showNotification({id:"for-login",title:"Pending",message:"Loggin in...",loading:!0});const p=await D.account.login(i,c);window.localStorage.setItem("token",p.token),C.updateNotification({id:"for-login",title:"Successful",message:"Logged in",color:"green"}),r(p)}catch(p){C.updateNotification({id:"for-login",title:"Login Failed",message:p.message,color:"red"})}};return t(o.Box,{mx:"auto",children:S("form",{onSubmit:u(d),children:[t(_.Controller,{name:"name",control:l,render:({field:i})=>t(o.TextInput,{mb:a.spacing,size:a.size,required:!0,label:"Username",...i})}),t(_.Controller,{name:"password",control:l,render:({field:i})=>t(o.PasswordInput,{mb:a.spacing,size:a.size,required:!0,label:"Password",...i})}),t(o.Group,{position:"right",mt:a.spacing,children:t(o.Button,{type:"submit",size:a.button.size,children:"Submit"})})]})})}function ct({styles:r=L,config:a,onSuccess:l}){return ee(a),t(k,{children:t(o.Box,{mt:r.spacing,sx:{position:"relative"},children:t(ut,{styles:r,postSubmit:l})})})}const ne={size:"sm",spacing:"md",button:{size:"xs"}};function dt({postSubmit:r,styles:a=ne,initialRoleID:l}){const{control:u,handleSubmit:d}=_.useForm({defaultValues:{name:"",role_id:l,domain:""}}),i=async({name:c,role_id:p,domain:b})=>{try{C.showNotification({id:"for-creating",title:"Pending",message:"Adding API Key...",loading:!0});const R=await D.api_key.create(c,p,b);C.updateNotification({id:"for-creating",title:"Successful",message:"API Key is added",color:"green"}),r(R)}catch(R){C.updateNotification({id:"for-creating",title:"Failed",message:R.message,color:"red"})}};return t(o.Box,{mx:"auto",children:S("form",{onSubmit:d(i),children:[t(_.Controller,{name:"name",control:u,render:({field:c})=>t(o.TextInput,{mb:a.spacing,size:a.size,required:!0,label:"Name",...c})}),t(_.Controller,{name:"domain",control:u,render:({field:c})=>t(o.TextInput,{mb:a.spacing,size:a.size,required:!0,label:"Domain",...c})}),t(_.Controller,{name:"role_id",control:u,render:({field:c})=>t(ue,{styles:a,...c})}),t(o.Group,{position:"right",mt:a.spacing,children:t(o.Button,{type:"submit",size:a.button.size,children:"Save"})})]})})}function Te({onSuccess:r,styles:a=ne,initialRoleID:l}){const u=J.useModals(),[d,i]=W.default.useState(!1),c=()=>i(!0),p=()=>i(!1),b=R=>{p(),u.openModal({title:"API Key is generated",children:S(o.Stack,{children:[t(o.TextInput,{defaultValue:R,disabled:!0,label:"Generated API Key",description:"Make sure you save it - you won't be able to access it again.",styles:{input:{cursor:"text !important"}}}),t(o.Button,{size:"sm",onClick:()=>{J.closeAllModals(),r()},children:"I've saved this API Key"})]})})};return S(k,{children:[t(o.Modal,{overflow:"inside",opened:d,onClose:()=>i(!1),title:"Add an API Key",trapFocus:!0,onDragStart:R=>{R.stopPropagation()},children:t(dt,{postSubmit:b,styles:a,initialRoleID:l})}),t(o.Button,{size:a.button.size,onClick:c,leftIcon:t($.PlaylistAdd,{size:20}),children:"Add an API Key"})]})}function Ee({id:r,name:a,onSuccess:l,styles:u=ne}){const d=J.useModals(),i=async()=>{if(!!r){C.showNotification({id:"for-deleting",title:"Pending",message:"Deleting API Key...",loading:!0});try{await D.api_key.delete(r),C.updateNotification({id:"for-deleting",title:"Successful",message:`API Key [${a}] is deleted`,color:"green"}),l()}catch(p){C.updateNotification({id:"for-deleting",title:"Failed",message:p.message,color:"red"})}}},c=()=>d.openConfirmModal({title:"Delete this api-key?",labels:{confirm:"Confirm",cancel:"Cancel"},onCancel:()=>console.log("Cancel"),onConfirm:i});return t(o.Button,{size:u.button.size,color:"red",onClick:c,leftIcon:t($.Trash,{size:20}),children:"Delete"})}function ft({styles:r=ne,config:a}){var R,T;ee(a);const{data:l=[],loading:u,refresh:d}=K.useRequest(async()=>{const{data:v}=await D.api_key.list();return v},{refreshDeps:[]}),{data:i=[],loading:c}=K.useRequest(async()=>(await D.role.list()).map(f=>({label:f.name,value:f.id,description:f.description,disabled:f.id===50})),{refreshDeps:[]}),p=Y.useMemo(()=>i.reduce((v,f)=>(v.set(f.value,f.label),v),new Map),[i]),b=v=>{var f;return(f=p.get(v))!=null?f:v};return S(k,{children:[t(o.Group,{pt:r.spacing,position:"right",children:t(Te,{onSuccess:d,initialRoleID:(T=(R=i==null?void 0:i[0])==null?void 0:R.value)!=null?T:0})}),S(o.Box,{mt:r.spacing,sx:{position:"relative"},children:[t(o.LoadingOverlay,{visible:u||c}),S(o.Table,{horizontalSpacing:r.spacing,verticalSpacing:r.spacing,fontSize:r.size,highlightOnHover:!0,children:[t("thead",{children:S("tr",{children:[t("th",{children:"Name"}),t("th",{children:"Domain"}),t("th",{children:"Role"}),t("th",{children:"Action"})]})}),t("tbody",{children:l.map(v=>{const{id:f,name:I,domain:M,role_id:B}=v;return S("tr",{children:[t("td",{width:200,children:I}),t("td",{width:200,children:M}),t("td",{width:200,children:b(B)}),t("td",{width:200,children:t(o.Group,{position:"left",children:t(Ee,{id:f,name:I,onSuccess:d})})})]},f)})})]})]})]})}P.APIKeyList=ft,P.AccountList=lt,P.AddAPIKey=Te,P.AddAccount=Pe,P.AddDataSource=_e,P.DataSourceList=nt,P.DeleteAPIKey=Ee,P.DeleteAccount=Ce,P.DeleteDataSource=Re,P.Login=ct,Object.defineProperties(P,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
package/dist/account/types.d.ts
DELETED