@devtable/settings-form 14.58.10 → 14.58.11

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,4 +1,4 @@
1
- const o = "14.58.10";
1
+ const o = "14.58.11";
2
2
  export {
3
3
  o as version
4
4
  };
@@ -2964,7 +2964,7 @@ const Ea = ze("DataSourceList", ({
2964
2964
  ] })
2965
2965
  ] })
2966
2966
  ] });
2967
- }), Pa = () => import("./package-99a58e1b.mjs").then(({
2967
+ }), Pa = () => import("./package-451a0ae9.mjs").then(({
2968
2968
  version: a
2969
2969
  }) => (console.log(`[@devtable/settings-form] version: ${a}`), a));
2970
2970
  export {
@@ -33,4 +33,4 @@ React keys must be passed directly to JSX without using spread:
33
33
  `),post:["function post_process(res, utils) {"," // your code goes here"," return data","}"].join(`
34
34
  `)};function En({submit:r,styles:t=V}){const{t:s}=y.useTranslation(),{control:n,setValue:i,handleSubmit:l}=j.useForm({defaultValues:{type:"http",key:"",config:{host:"",processing:{pre:Ce.pre,post:Ce.post}}}});return e.jsx(o.Box,{mx:"auto",children:e.jsxs("form",{onSubmit:l(r),children:[e.jsx(j.Controller,{name:"key",control:n,render:({field:c})=>e.jsx(o.TextInput,{mb:t.spacing,size:t.size,required:!0,label:s("common.name"),placeholder:s("common.name_placeholder"),...c})}),e.jsx(o.Divider,{label:s("datasource.connection_info"),labelPosition:"center"}),e.jsx(j.Controller,{name:"config.host",control:n,render:({field:c})=>e.jsx(o.TextInput,{mb:t.spacing,size:t.size,required:!0,label:s("datasource.http.host"),sx:{flexGrow:1},...c})}),e.jsxs(o.Group,{grow:!0,children:[e.jsx(j.Controller,{name:"config.processing.pre",control:n,render:({field:c})=>e.jsx(we,{label:s("datasource.http.processing.pre.label"),modalTitle:s("datasource.http.processing.pre.description"),defaultValue:Ce.pre,...c,styles:t})}),e.jsx(j.Controller,{name:"config.processing.post",control:n,render:({field:c})=>e.jsx(we,{label:s("datasource.http.processing.post.label"),modalTitle:s("datasource.http.processing.post.description"),defaultValue:Ce.post,...c,styles:t})})]}),e.jsx(o.Group,{justify:"flex-end",mt:t.spacing,children:e.jsx(W,{size:t.button.size})})]})})}function An({postSubmit:r,styles:t=V}){const{t:s}=y.useTranslation(),[n,i]=P.useState("postgresql"),l=async({type:p,key:h,config:b})=>{T.showNotification({id:"for-creating",title:s("common.state.pending"),message:s("datasource.state.adding"),loading:!0,autoClose:!1});try{console.log({type:p,key:h,config:b}),await R.datasource.create(p,h,b),T.updateNotification({id:"for-creating",title:s("common.state.successful"),message:s("datasource.state.added"),color:"green",autoClose:!0}),r()}catch(v){console.error(v),T.updateNotification({id:"for-creating",title:s("common.state.failed"),message:v.message,color:"red",autoClose:!0})}},c=p=>{i(p)},u=n==="postgresql"||n==="mysql",d=n==="http";return e.jsxs(o.Box,{mx:"auto",children:[e.jsx(o.SegmentedControl,{fullWidth:!0,mb:t.spacing,size:t.size,data:[{label:"PostgreSQL",value:"postgresql"},{label:"MySQL",value:"mysql"},{label:"HTTP",value:"http"}],value:n,onChange:c}),u&&e.jsx(_n,{styles:t}),u&&e.jsx(Dn,{submit:l,styles:t,type:n}),d&&e.jsx(En,{submit:l,styles:t})]})}function ct({onSuccess:r,styles:t=V}){const{t:s}=y.useTranslation(),[n,i]=P.useState(!1),l=()=>i(!0),c=()=>i(!1),u=()=>{r(),c()};return e.jsxs(e.Fragment,{children:[e.jsx(o.Modal,{opened:n,onClose:()=>i(!1),title:s("datasource.add"),trapFocus:!0,onDragStart:d=>{d.stopPropagation()},children:e.jsx(An,{postSubmit:u,styles:t})}),e.jsx(o.Button,{size:t.button.size,onClick:l,leftSection:e.jsx(A.IconPlaylistAdd,{size:20}),children:s("datasource.add")})]})}const Pn={http:"HTTP",mysql:"MySQL",postgresql:"PostgreSQL",merico_metric_system:"Merico Metric System"},On={http:e.jsx(A.IconNetwork,{}),mysql:e.jsx(A.IconBrandMysql,{}),postgresql:e.jsx(A.IconDatabase,{}),merico_metric_system:e.jsx(A.IconTopologyRing3,{})};function $n({type:r}){return e.jsxs(o.Group,{children:[e.jsx(o.ActionIcon,{variant:"subtle",size:"xs",sx:{transform:"none !important"},children:On[r]}),e.jsx(o.Text,{sx:{cusor:"default",userSelect:"none"},children:Pn[r]})]})}function dt({id:r,name:t,isProtected:s,onSuccess:n,styles:i=V}){const{t:l}=y.useTranslation(),c=ae.useModals(),u=async()=>{r&&(T.showNotification({id:"for-deleting",title:l("common.state.pending"),message:l("datasource.state.deleting"),loading:!0,autoClose:!1}),await R.datasource.delete(r),T.updateNotification({id:"for-deleting",title:l("common.state.successful"),message:l("datasource.state.deleted",{name:t}),color:"green",autoClose:!0}),n())},d=()=>c.openConfirmModal({title:l("datasource.delete.title"),children:e.jsx(o.Text,{size:i.size,children:l("datasource.delete.hint")}),labels:{confirm:l("common.actions.confirm"),cancel:l("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:u,cancelProps:{size:i.button.size},confirmProps:{color:"red",size:i.button.size}});return s?e.jsx(o.Tooltip,{withArrow:!0,events:{hover:!0,touch:!1,focus:!1},label:l("datasource.delete.cant_delete_preset"),children:e.jsx(o.Button,{size:i.button.size,color:"gray",variant:"light",leftSection:e.jsx(A.IconLock,{size:16}),sx:{transform:"none !important"},children:l("common.actions.delete")})}):e.jsx(o.Button,{size:i.button.size,color:"red",onClick:d,leftSection:e.jsx(A.IconTrash,{size:16}),children:l("common.actions.delete")})}const ft={pre:["function pre_process({ method, url, params, headers, data }, utils) {"," // your code goes here"," return { method, url, params, headers, data }","}"].join(`
35
35
  `),post:["function post_process(resp, utils) {"," return resp.data","}"].join(`
36
- `)};function Mn({name:r,config:t,submit:s,styles:n=V}){const{t:i}=y.useTranslation(),{control:l,handleSubmit:c}=j.useForm({defaultValues:{config:t}});return e.jsx(o.Box,{mx:"auto",children:e.jsxs("form",{onSubmit:c(s),children:[e.jsx(o.TextInput,{mb:n.spacing,size:n.size,required:!0,label:i("common.name"),value:r,readOnly:!0}),e.jsx(o.Divider,{label:i("datasource.connection_info"),labelPosition:"center"}),e.jsx(j.Controller,{name:"config.host",control:l,render:({field:u})=>e.jsx(o.TextInput,{mb:n.spacing,size:n.size,required:!0,label:i("datasource.http.host"),sx:{flexGrow:1},...u})}),e.jsxs(o.Group,{grow:!0,children:[e.jsx(j.Controller,{name:"config.processing.pre",control:l,render:({field:u})=>e.jsx(we,{label:i("datasource.http.processing.pre.label"),modalTitle:i("datasource.http.processing.pre.description"),defaultValue:ft.pre,...u,styles:n})}),e.jsx(j.Controller,{name:"config.processing.post",control:l,render:({field:u})=>e.jsx(we,{label:i("datasource.http.processing.post.label"),modalTitle:i("datasource.http.processing.post.description"),defaultValue:ft.post,...u,styles:n})})]}),e.jsx(o.Group,{justify:"flex-end",mt:n.spacing,children:e.jsx(W,{size:n.button.size})})]})})}function In({dataSource:r,postSubmit:t,styles:s=V}){const{t:n}=y.useTranslation(),i=async({config:l})=>{T.showNotification({id:"for-updating",title:n("common.state.pending"),message:n("datasource.state.updating"),loading:!0,autoClose:!1});try{console.log({config:l}),await R.datasource.update(r.id,l),T.updateNotification({id:"for-updating",title:n("common.state.successful"),message:n("datasource.state.updated"),color:"green",loading:!1,autoClose:!0}),t()}catch(c){T.updateNotification({id:"for-updating",title:n("common.state.failed"),message:c.message,color:"red",loading:!1,autoClose:!0})}};return r.config?e.jsx(o.Box,{mx:"auto",children:e.jsx(Mn,{name:r.key,config:r.config,submit:i,styles:s})}):(console.error(new Error("unexpected empty config of a http datasource")),null)}function Rn({dataSource:r,onSuccess:t,styles:s=V}){const{t:n}=y.useTranslation(),[i,l]=P.useState(!1),c=()=>l(!0),u=()=>l(!1),d=()=>{t(),u()};return r.is_preset?e.jsx(o.Tooltip,{withArrow:!0,events:{hover:!0,touch:!1,focus:!1},label:n("datasource.cant_edit.preset"),children:e.jsx(o.Button,{size:s.button.size,color:"gray",variant:"light",leftSection:e.jsx(A.IconLock,{size:16}),sx:{transform:"none !important"},children:n("common.actions.edit")})}):r.type!=="http"&&r.type!=="merico_metric_system"?e.jsx(o.Tooltip,{withArrow:!0,events:{hover:!0,touch:!1,focus:!1},label:n("datasource.cant_edit.db"),children:e.jsx(o.Button,{size:s.button.size,color:"gray",variant:"light",leftSection:e.jsx(A.IconEdit,{size:16}),sx:{transform:"none !important"},children:n("common.actions.edit")})}):e.jsxs(e.Fragment,{children:[e.jsx(o.Modal,{opened:i,onClose:()=>l(!1),title:n("datasource.edit"),trapFocus:!0,onDragStart:p=>{p.stopPropagation()},children:e.jsx(In,{dataSource:r,postSubmit:d,styles:s})}),e.jsx(o.Button,{size:s.button.size,color:"blue",onClick:c,leftSection:e.jsx(A.IconEdit,{size:16}),children:n("common.actions.edit")})]})}const qn=be("DataSourceList",({styles:r=V})=>{const{t}=y.useTranslation(),{data:s=[],loading:n,refresh:i}=K.useRequest(async()=>{const{data:l}=await R.datasource.list();return l},{refreshDeps:[]});return e.jsxs(e.Fragment,{children:[e.jsx(o.Group,{pt:r.spacing,justify:"flex-end",children:e.jsx(ct,{onSuccess:i})}),e.jsxs(o.Box,{mt:r.spacing,sx:{position:"relative"},children:[e.jsx(o.LoadingOverlay,{visible:n}),e.jsxs(o.Table,{horizontalSpacing:r.spacing,verticalSpacing:r.spacing,fz:r.size,highlightOnHover:!0,children:[e.jsx(o.Table.Thead,{children:e.jsxs(o.Table.Tr,{children:[e.jsx(o.Table.Th,{children:t("common.type")}),e.jsx(o.Table.Th,{children:t("common.name")}),e.jsx(o.Table.Th,{children:t("common.action")})]})}),e.jsx(o.Table.Tbody,{children:s.map(l=>{const{id:c,key:u,type:d,is_preset:p}=l,h=d==="merico_metric_system";return e.jsxs(o.Table.Tr,{children:[e.jsx(o.Table.Td,{width:230,children:e.jsx($n,{type:d})}),e.jsx(o.Table.Td,{children:u}),e.jsx(o.Table.Td,{width:400,children:e.jsxs(o.Group,{justify:"flex-start",children:[e.jsx(Rn,{dataSource:l,onSuccess:i,styles:r}),e.jsx(dt,{isProtected:p||h,id:c,name:u,onSuccess:i,styles:r})]})})]},u)})})]})]})]})}),Ln=({option:r,...t})=>{const{label:s,value:n,description:i}=r;return e.jsxs(o.Stack,{gap:2,...t,children:[e.jsx(o.Text,{size:"sm",children:s}),e.jsx(o.Text,{size:"xs",c:"dimmed",className:"role-description",children:i})]})},Le=P.forwardRef(({styles:r,value:t,onChange:s},n)=>{const{t:i}=y.useTranslation(),{data:l=[],loading:c}=K.useRequest(async()=>(await R.role.list()).map(d=>({label:d.id,value:d.id,description:d.description,disabled:d.id==="SUPERADMIN"})),{refreshDeps:[]});return e.jsx(o.Select,{ref:n,mb:r.spacing,size:r.size,required:!0,label:i("role.label"),renderOption:Ln,data:l,disabled:c,styles:()=>({item:{"&[data-selected]":{"&, &:hover":{".role-description":{color:"rgba(255,255,255,.8)"}}}}}),value:t,onChange:u=>u!==null&&s(u),comboboxProps:{withinPortal:!0},maxDropdownHeight:500})}),H={size:"sm",spacing:"md",button:{size:"xs"}};function kn({postSubmit:r,styles:t=H,initialRoleID:s}){const{t:n}=y.useTranslation(),{control:i,handleSubmit:l}=j.useForm({defaultValues:{name:"",email:"",role_id:s,password:""}}),c=async({name:u,email:d,password:p,role_id:h})=>{try{T.showNotification({id:"for-creating",title:n("common.state.pending"),message:n("account.state.adding"),loading:!0,autoClose:!1}),await R.account.create(u,d,p,h),T.updateNotification({id:"for-creating",title:n("common.state.successful"),message:n("account.state.added"),color:"green",autoClose:!0,loading:!1}),r()}catch(b){T.updateNotification({id:"for-creating",title:n("common.state.failed"),message:b.message,color:"red",autoClose:!0,loading:!1})}};return e.jsx(o.Box,{mx:"auto",mb:10,children:e.jsxs("form",{onSubmit:l(c),children:[e.jsx(j.Controller,{name:"name",control:i,render:({field:u})=>e.jsx(o.TextInput,{mb:t.spacing,size:t.size,required:!0,label:n("account.username"),...u})}),e.jsx(j.Controller,{name:"email",control:i,render:({field:u})=>e.jsx(o.TextInput,{mb:t.spacing,size:t.size,required:!0,label:n("account.email"),...u})}),e.jsx(j.Controller,{name:"password",control:i,render:({field:u})=>e.jsx(o.PasswordInput,{mb:t.spacing,size:t.size,required:!0,label:n("account.password"),description:n("account.password_hint"),...u})}),e.jsx(j.Controller,{name:"role_id",control:i,render:({field:u})=>e.jsx(Le,{styles:t,...u})}),e.jsx(o.Group,{justify:"flex-end",mt:t.spacing,children:e.jsx(W,{size:t.button.size})})]})})}function pt({onSuccess:r,styles:t=H,initialRoleID:s}){const{t:n}=y.useTranslation(),[i,l]=P.useState(!1),c=()=>l(!0),u=()=>l(!1),d=()=>{r(),u()};return e.jsxs(e.Fragment,{children:[e.jsx(o.Modal,{opened:i,onClose:()=>l(!1),title:n("account.add"),trapFocus:!0,onDragStart:p=>{p.stopPropagation()},children:e.jsx(kn,{postSubmit:d,styles:t,initialRoleID:s})}),e.jsx(o.Button,{size:t.button.size,onClick:c,leftSection:e.jsx(A.IconPlaylistAdd,{size:20}),children:n("account.add")})]})}function mt({id:r,name:t,onSuccess:s,styles:n=H}){const{t:i}=y.useTranslation(),l=ae.useModals(),c=async()=>{if(r){T.showNotification({id:"for-deleting",title:i("common.state.pending"),message:i("account.state.deleting"),loading:!0,autoClose:!1});try{await R.account.delete(r),T.updateNotification({id:"for-deleting",title:i("common.state.successful"),message:i("account.state.deleted",{name:t}),color:"green",autoClose:!0,loading:!1}),s()}catch(d){T.updateNotification({id:"for-deleting",title:i("common.state.failed"),message:d.message,color:"red",autoClose:!0,loading:!1})}}},u=()=>l.openConfirmModal({title:i("account.delete"),labels:{confirm:i("common.actions.confirm"),cancel:i("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:c,cancelProps:{size:n.button.size},confirmProps:{color:"red",size:n.button.size}});return e.jsx(o.Button,{size:n.button.size,color:"red",onClick:u,leftSection:e.jsx(A.IconTrash,{size:20}),children:i("common.actions.delete")})}function Nn({id:r,name:t,email:s,role_id:n,postSubmit:i,styles:l=H}){const{t:c}=y.useTranslation(),{control:u,handleSubmit:d,watch:p}=j.useForm({defaultValues:{name:t,email:s,role_id:n,reset_password:!1,new_password:""}}),h=async({name:C,email:L,role_id:Y,reset_password:X,new_password:k})=>{try{T.showNotification({id:"for-updating",title:c("common.state.pending"),message:c("account.state.updating"),loading:!0,autoClose:!1}),await R.account.edit({id:r,name:C.trim(),email:L.trim(),role_id:Y,reset_password:X,new_password:k.trim()}),T.updateNotification({id:"for-updating",title:c("common.state.successful"),message:c("account.state.updated"),color:"green",autoClose:!0,loading:!1}),i()}catch(D){T.updateNotification({id:"for-updating",title:c("common.state.failed"),message:D.message,color:"red",autoClose:!0,loading:!1})}},[b,v]=p(["reset_password","new_password"]);return e.jsx(o.Box,{mx:"auto",mb:10,children:e.jsxs("form",{onSubmit:d(h),children:[e.jsx(j.Controller,{name:"name",control:u,render:({field:C})=>e.jsx(o.TextInput,{mb:l.spacing,size:l.size,required:!0,label:c("account.username"),...C})}),e.jsx(j.Controller,{name:"email",control:u,render:({field:C})=>e.jsx(o.TextInput,{mb:l.spacing,size:l.size,required:!0,label:c("account.email"),...C})}),e.jsx(j.Controller,{name:"role_id",control:u,render:({field:C})=>e.jsx(Le,{styles:l,...C})}),e.jsx(o.Divider,{my:20,variant:"dashed",label:"",labelPosition:"center"}),e.jsx(j.Controller,{name:"reset_password",control:u,render:({field:C})=>e.jsx(o.Switch,{mb:l.spacing,size:l.size,label:c("account.reset_password"),checked:C.value,onChange:L=>C.onChange(L.currentTarget.checked),styles:{label:{verticalAlign:"middle"}}})}),b&&e.jsx(j.Controller,{name:"new_password",control:u,render:({field:C})=>e.jsx(o.PasswordInput,{autoComplete:"off",mb:l.spacing,size:l.size,required:!0,description:c("account.password_hint"),label:c("account.new_password"),...C})}),e.jsx(o.Group,{justify:"flex-end",mt:l.spacing,children:e.jsx(W,{size:l.button.size})})]})})}function Fn({account:r,onSuccess:t,styles:s=H}){const{t:n}=y.useTranslation(),[i,l]=P.useState(!1),c=()=>l(!0),u=()=>l(!1),d=()=>{t(),u()};return e.jsxs(e.Fragment,{children:[e.jsx(o.Modal,{opened:i,onClose:()=>l(!1),title:n("account.editing_xx",{name:r.name}),trapFocus:!0,onDragStart:p=>{p.stopPropagation()},children:e.jsx(Nn,{...r,postSubmit:d,styles:s})}),e.jsx(o.Button,{size:s.button.size,onClick:c,leftSection:e.jsx(A.IconEdit,{size:20}),children:n("common.actions.edit")})]})}const Bn=be("AccountList",({styles:r=H})=>{var u;const{t}=y.useTranslation(),{data:s=[],loading:n,refresh:i}=K.useRequest(async()=>{const{data:d}=await R.account.list();return d},{refreshDeps:[]}),{data:l=[],loading:c}=K.useRequest(async()=>(await R.role.list()).map(p=>({label:p.id,value:p.id,description:p.description,disabled:p.id==="SUPERADMIN"})),{refreshDeps:[]});return e.jsxs(e.Fragment,{children:[e.jsx(o.Group,{pt:r.spacing,justify:"flex-end",children:e.jsx(pt,{onSuccess:i,initialRoleID:((u=l==null?void 0:l[0])==null?void 0:u.value)??"INACTIVE"})}),e.jsxs(o.Box,{mt:r.spacing,sx:{position:"relative"},children:[e.jsx(o.LoadingOverlay,{visible:n||c}),e.jsxs(o.Table,{horizontalSpacing:r.spacing,verticalSpacing:r.spacing,fz:r.size,highlightOnHover:!0,children:[e.jsx(o.Table.Thead,{children:e.jsxs(o.Table.Tr,{children:[e.jsx(o.Table.Th,{children:t("account.username")}),e.jsx(o.Table.Th,{children:t("account.email")}),e.jsx(o.Table.Th,{children:t("role.label")}),e.jsx(o.Table.Th,{children:t("common.action")})]})}),e.jsx(o.Table.Tbody,{children:s.map(d=>{const{id:p,name:h,email:b,role_id:v}=d;return e.jsxs(o.Table.Tr,{children:[e.jsx(o.Table.Td,{width:200,children:h}),e.jsx(o.Table.Td,{width:200,children:b}),e.jsx(o.Table.Td,{width:200,children:v}),e.jsx(o.Table.Td,{width:200,children:e.jsxs(o.Group,{justify:"flex-start",children:[e.jsx(Fn,{account:d,onSuccess:i}),e.jsx(mt,{id:p,name:h,onSuccess:i})]})})]},p)})})]})]})]})});function Un({postSubmit:r,styles:t=H}){const{t:s}=y.useTranslation(),{control:n,handleSubmit:i}=j.useForm({defaultValues:{name:"",password:""}}),l=async({name:c,password:u})=>{try{T.showNotification({id:"for-login",title:s("common.state.pending"),message:s("account.state.logging_in"),loading:!0,autoClose:!1});const d=await R.account.login(c.trim(),u.trim());window.localStorage.setItem("token",d.token),T.updateNotification({id:"for-login",title:s("common.state.successful"),message:s("account.state.logged_in"),color:"green",autoClose:!0,loading:!1}),r(d)}catch(d){T.updateNotification({id:"for-login",title:s("common.state.failed"),message:d.message,color:"red",autoClose:!0,loading:!1})}};return e.jsx(o.Box,{mx:"auto",children:e.jsxs("form",{onSubmit:i(l),children:[e.jsx(j.Controller,{name:"name",control:n,render:({field:c})=>e.jsx(o.TextInput,{mb:t.spacing,size:t.size,required:!0,label:s("account.username"),...c})}),e.jsx(j.Controller,{name:"password",control:n,render:({field:c})=>e.jsx(o.PasswordInput,{mb:t.spacing,size:t.size,required:!0,label:s("account.password"),...c})}),e.jsx(o.Group,{justify:"flex-end",mt:t.spacing,children:e.jsx(W,{size:t.button.size})})]})})}const Yn=be("Login",({styles:r=H,onSuccess:t})=>e.jsx(e.Fragment,{children:e.jsx(o.Box,{mt:r.spacing,sx:{position:"relative"},children:e.jsx(Un,{styles:r,postSubmit:t})})})),De={size:"sm",spacing:"md",button:{size:"xs"}};function Vn({postSubmit:r,styles:t=De,initialRoleID:s}){const{t:n}=y.useTranslation(),{control:i,handleSubmit:l}=j.useForm({defaultValues:{name:"",role_id:s}}),c=async({name:u,role_id:d})=>{try{T.showNotification({id:"for-creating",title:n("common.state.pending"),message:n("api_key.state.adding"),loading:!0,autoClose:!1});const{app_id:p,app_secret:h}=await R.api_key.create(u,d);T.updateNotification({id:"for-creating",title:n("common.state.successful"),message:n("api_key.state.added"),color:"green",autoClose:!0,loading:!1}),r(p,h)}catch(p){T.updateNotification({id:"for-creating",title:n("common.state.failed"),message:p.message,color:"red",autoClose:!0,loading:!1})}};return e.jsx(o.Box,{mx:"auto",mb:10,children:e.jsxs("form",{onSubmit:l(c),children:[e.jsx(j.Controller,{name:"name",control:i,render:({field:u})=>e.jsx(o.TextInput,{mb:t.spacing,size:t.size,required:!0,label:n("common.name"),...u})}),e.jsx(j.Controller,{name:"role_id",control:i,render:({field:u})=>e.jsx(Le,{styles:t,...u})}),e.jsx(o.Group,{justify:"flex-end",mt:t.spacing,children:e.jsx(W,{size:t.button.size})})]})})}function ht({onSuccess:r,styles:t=De,initialRoleID:s}){const{t:n}=y.useTranslation(),i=ae.useModals(),[l,c]=P.useState(!1),u=()=>c(!0),d=()=>c(!1),p=(h,b)=>{d(),i.openModal({title:n("api_key.save.title"),children:e.jsxs(o.Stack,{children:[e.jsx(o.Text,{size:"sm",c:"dimmed",children:n("api_key.save.warn")}),e.jsx(o.TextInput,{defaultValue:h,disabled:!0,label:n("api_key.app_id"),styles:{input:{cursor:"text !important"}}}),e.jsx(o.TextInput,{defaultValue:b,disabled:!0,label:n("api_key.app_secret"),styles:{input:{cursor:"text !important"}}}),e.jsx(o.Button,{size:"sm",onClick:()=>{ae.closeAllModals()},children:n("api_key.save.saved")})]}),onClose:()=>{r()}})};return e.jsxs(e.Fragment,{children:[e.jsx(o.Modal,{opened:l,onClose:()=>c(!1),title:n("api_key.add"),trapFocus:!0,onDragStart:h=>{h.stopPropagation()},children:e.jsx(Vn,{postSubmit:p,styles:t,initialRoleID:s})}),e.jsx(o.Button,{size:t.button.size,onClick:u,leftSection:e.jsx(A.IconPlaylistAdd,{size:20}),children:n("api_key.add")})]})}function gt({id:r,name:t,onSuccess:s,styles:n=De}){const{t:i}=y.useTranslation(),l=ae.useModals(),c=async()=>{if(r){T.showNotification({id:"for-deleting",title:i("common.state.pending"),message:i("global_sql_snippet.state.deleting"),loading:!0,autoClose:!1});try{await R.api_key.delete(r),T.updateNotification({id:"for-deleting",title:i("common.state.successful"),message:i("global_sql_snippet.state.deleted",{name:t}),color:"green",autoClose:!0,loading:!1}),s()}catch(d){T.updateNotification({id:"for-deleting",title:i("common.state.failed"),message:d.message,color:"red",autoClose:!0,loading:!1})}}},u=()=>l.openConfirmModal({title:i("api_key.delete"),labels:{confirm:i("common.actions.confirm"),cancel:i("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:c,cancelProps:{size:n.button.size},confirmProps:{color:"red",size:n.button.size}});return e.jsx(o.Button,{size:n.button.size,color:"red",onClick:u,leftSection:e.jsx(A.IconTrash,{size:20}),children:i("common.actions.delete")})}const Gn=be("APIKeyList",({styles:r=De})=>{var u;const{t}=y.useTranslation(),{data:s=[],loading:n,refresh:i}=K.useRequest(async()=>{const{data:d}=await R.api_key.list();return d},{refreshDeps:[]}),{data:l=[],loading:c}=K.useRequest(async()=>(await R.role.list()).map(p=>({label:p.id,value:p.id,description:p.description,disabled:p.id==="SUPERADMIN"})),{refreshDeps:[]});return e.jsxs(e.Fragment,{children:[e.jsx(o.Group,{pt:r.spacing,justify:"flex-end",children:e.jsx(ht,{onSuccess:i,initialRoleID:((u=l==null?void 0:l[0])==null?void 0:u.value)??"INACTIVE"})}),e.jsxs(o.Box,{mt:r.spacing,sx:{position:"relative"},children:[e.jsx(o.LoadingOverlay,{visible:n||c}),e.jsxs(o.Table,{horizontalSpacing:r.spacing,verticalSpacing:r.spacing,fz:r.size,highlightOnHover:!0,children:[e.jsx(o.Table.Thead,{children:e.jsxs(o.Table.Tr,{children:[e.jsx(o.Table.Th,{children:t("common.name")}),e.jsx(o.Table.Th,{children:t("api_key.app_id")}),e.jsx(o.Table.Th,{children:t("role.label")}),e.jsx(o.Table.Th,{children:t("common.action")})]})}),e.jsx(o.Table.Tbody,{children:s.map(d=>{const{id:p,name:h,app_id:b,role_id:v}=d;return e.jsxs(o.Table.Tr,{children:[e.jsx(o.Table.Td,{width:200,children:h}),e.jsx(o.Table.Td,{width:200,children:b}),e.jsx(o.Table.Td,{width:200,children:v}),e.jsx(o.Table.Td,{width:200,children:e.jsx(o.Group,{justify:"flex-start",children:e.jsx(gt,{id:p,name:h,onSuccess:i})})})]},p)})})]})]})]})}),ue={size:"sm",spacing:"md",button:{size:"xs"}};function Wn({postSubmit:r,styles:t=ue}){const{t:s}=y.useTranslation(),{control:n,handleSubmit:i}=j.useForm({defaultValues:{id:"",content:""}}),l=async c=>{try{T.showNotification({id:"for-creating",title:s("common.state.pending"),message:s("global_sql_snippet.state.adding"),loading:!0,autoClose:!1}),await R.sql_snippet.create(c),T.updateNotification({id:"for-creating",title:s("common.state.successful"),message:s("global_sql_snippet.state.added"),color:"green",autoClose:!0}),r()}catch(u){T.updateNotification({id:"for-creating",title:s("common.state.failed"),message:u.message,color:"red",autoClose:!0})}};return e.jsx(o.Box,{mx:"auto",children:e.jsxs("form",{onSubmit:i(l),children:[e.jsx(j.Controller,{name:"id",control:n,render:({field:c})=>e.jsx(o.TextInput,{mb:t.spacing,size:t.size,required:!0,label:s("common.name"),placeholder:s("common.name_placeholder"),...c})}),e.jsx(j.Controller,{name:"content",control:n,render:({field:c})=>e.jsxs(o.Stack,{gap:4,children:[e.jsx(o.Text,{size:"14px",fw:500,c:"#212529",sx:{cursor:"default"},children:s("global_sql_snippet.content")}),e.jsx(ut,{height:"600px",...c})]})}),e.jsx(o.Group,{justify:"flex-end",mt:t.spacing,children:e.jsx(W,{size:t.button.size})})]})})}function xt({onSuccess:r,styles:t=ue}){const{t:s}=y.useTranslation(),[n,i]=P.useState(!1),l=()=>i(!0),c=()=>i(!1),u=()=>{c(),r()};return e.jsxs(e.Fragment,{children:[e.jsx(o.Modal,{opened:n,onClose:()=>i(!1),title:s("global_sql_snippet.add"),trapFocus:!0,onDragStart:d=>{d.stopPropagation()},size:"80vw",children:e.jsx(Wn,{postSubmit:u,styles:t})}),e.jsx(o.Button,{size:t.button.size,onClick:l,leftSection:e.jsx(A.IconPlaylistAdd,{size:18}),children:s("global_sql_snippet.add")})]})}function Kn({postSubmit:r,styles:t=ue,id:s,content:n}){const{t:i}=y.useTranslation(),{control:l,handleSubmit:c}=j.useForm({defaultValues:{id:s,content:n}}),u=async d=>{try{T.showNotification({id:"for-updating",title:i("common.state.pending"),message:i("global_sql_snippet.state.updating"),loading:!0,autoClose:!1}),await R.sql_snippet.update(d),T.updateNotification({id:"for-updating",title:i("common.state.successful"),message:i("global_sql_snippet.state.updated"),color:"green",autoClose:!0}),r()}catch(p){T.updateNotification({id:"for-updating",title:i("common.state.failed"),message:p.message,color:"red",autoClose:!0})}};return e.jsx(o.Box,{mx:"auto",children:e.jsxs("form",{onSubmit:c(u),children:[e.jsx(j.Controller,{name:"id",control:l,render:({field:d})=>e.jsx(o.TextInput,{mb:t.spacing,size:t.size,required:!0,label:i("common.name"),placeholder:i("common.name_placeholder"),...d})}),e.jsx(j.Controller,{name:"content",control:l,render:({field:d})=>e.jsxs(o.Stack,{gap:4,children:[e.jsx(o.Text,{size:"14px",fw:500,c:"#212529",sx:{cursor:"default"},children:i("global_sql_snippet.content")}),e.jsx(ut,{height:"600px",...d})]})}),e.jsx(o.Group,{justify:"flex-end",mt:t.spacing,children:e.jsx(W,{size:t.button.size})})]})})}function bt({onSuccess:r,styles:t=ue,...s}){const{t:n}=y.useTranslation(),[i,l]=P.useState(!1),c=()=>l(!0),u=()=>l(!1),d=()=>{u(),r()};return e.jsxs(e.Fragment,{children:[e.jsx(o.Modal,{opened:i,onClose:()=>l(!1),title:n("global_sql_snippet.edit"),trapFocus:!0,onDragStart:p=>{p.stopPropagation()},size:"80vw",children:e.jsx(Kn,{postSubmit:d,styles:t,...s})}),e.jsx(o.Button,{size:t.button.size,onClick:c,leftSection:e.jsx(A.IconEdit,{size:18}),children:n("common.actions.edit")})]})}function vt({id:r,onSuccess:t,styles:s=ue}){const{t:n}=y.useTranslation(),i=ae.useModals(),l=async()=>{if(r){T.showNotification({id:"for-deleting",title:n("common.state.pending"),message:n("global_sql_snippet.state.deleting"),loading:!0,autoClose:!1});try{await R.sql_snippet.delete(r),T.updateNotification({id:"for-deleting",title:n("common.state.successful"),message:n("global_sql_snippet.state.deleted",{name:r}),color:"green",autoClose:!0}),t()}catch(u){T.updateNotification({id:"for-deleting",title:n("common.state.failed"),message:u.message,color:"red",autoClose:!0})}}},c=()=>i.openConfirmModal({title:n("global_sql_snippet.delete"),labels:{confirm:n("common.actions.confirm"),cancel:n("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:l,cancelProps:{size:s.button.size},confirmProps:{color:"red",size:s.button.size}});return e.jsx(o.Button,{size:s.button.size,color:"red",onClick:c,leftSection:e.jsx(A.IconTrash,{size:20}),children:n("common.actions.edit")})}function Qn({content:r}){return e.jsxs(o.HoverCard,{width:"60vw",shadow:"md",children:[e.jsx(o.HoverCard.Target,{children:e.jsx(o.ActionIcon,{variant:"subtle",size:16,children:e.jsx(A.IconEye,{})})}),e.jsx(o.HoverCard.Dropdown,{children:e.jsx(Kt.CodeHighlight,{code:r,language:"sql",withCopyButton:!1})})]})}const Jn=be("DataSourceList",({styles:r=ue})=>{const{t}=y.useTranslation(),{data:s=[],loading:n,refresh:i}=K.useRequest(async()=>{const{data:l}=await R.sql_snippet.list({pagination:{page:1,pagesize:10}});return l},{refreshDeps:[]});return e.jsxs(e.Fragment,{children:[e.jsxs(o.Group,{pt:r.spacing,justify:"space-between",children:[e.jsx(o.Alert,{children:t("global_sql_snippet.description")}),e.jsx(xt,{onSuccess:i})]}),e.jsxs(o.Box,{mt:r.spacing,sx:{position:"relative"},children:[e.jsx(o.LoadingOverlay,{visible:n}),e.jsxs(o.Table,{horizontalSpacing:r.spacing,verticalSpacing:r.spacing,fz:r.size,highlightOnHover:!0,children:[e.jsx(o.Table.Thead,{children:e.jsxs(o.Table.Tr,{children:[e.jsx(o.Table.Th,{children:t("common.name")}),e.jsx(o.Table.Th,{}),e.jsx(o.Table.Th,{children:t("common.created_at")}),e.jsx(o.Table.Th,{children:t("common.updated_at")}),e.jsx(o.Table.Th,{children:t("common.action")})]})}),e.jsx(o.Table.Tbody,{children:s.map(l=>{const{id:c,content:u,create_time:d,update_time:p}=l;return e.jsxs(o.Table.Tr,{children:[e.jsx(o.Table.Td,{children:c}),e.jsx(o.Table.Td,{width:50,children:e.jsx(Qn,{content:u})}),e.jsx(o.Table.Td,{width:200,children:d}),e.jsx(o.Table.Td,{width:200,children:p}),e.jsx(o.Table.Td,{width:400,children:e.jsxs(o.Group,{justify:"flex-start",children:[e.jsx(bt,{...l,onSuccess:i}),e.jsx(vt,{id:c,onSuccess:i})]})})]},c)})})]})]})]})}),Hn=()=>Promise.resolve().then(()=>Xn).then(({version:r})=>(console.log(`[@devtable/settings-form] version: ${r}`),r)),Xn=Object.freeze(Object.defineProperty({__proto__:null,version:"14.58.10"},Symbol.toStringTag,{value:"Module"}));x.APIClient=O,x.APIKeyList=Gn,x.AccountList=Bn,x.AddAPIKey=ht,x.AddAccount=pt,x.AddDataSource=ct,x.AddSQLSnippet=xt,x.DataSourceList=qn,x.DefaultApiClient=Xe,x.DeleteAPIKey=gt,x.DeleteAccount=mt,x.DeleteDataSource=dt,x.DeleteSQLSnippet=vt,x.FacadeApiClient=Ze,x.Login=Yn,x.SQLSnippetList=Jn,x.UpdateSQLSnippet=bt,x.configureAPIClient=tt,x.facadeApiClient=et,x.getVersion=Hn,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
36
+ `)};function Mn({name:r,config:t,submit:s,styles:n=V}){const{t:i}=y.useTranslation(),{control:l,handleSubmit:c}=j.useForm({defaultValues:{config:t}});return e.jsx(o.Box,{mx:"auto",children:e.jsxs("form",{onSubmit:c(s),children:[e.jsx(o.TextInput,{mb:n.spacing,size:n.size,required:!0,label:i("common.name"),value:r,readOnly:!0}),e.jsx(o.Divider,{label:i("datasource.connection_info"),labelPosition:"center"}),e.jsx(j.Controller,{name:"config.host",control:l,render:({field:u})=>e.jsx(o.TextInput,{mb:n.spacing,size:n.size,required:!0,label:i("datasource.http.host"),sx:{flexGrow:1},...u})}),e.jsxs(o.Group,{grow:!0,children:[e.jsx(j.Controller,{name:"config.processing.pre",control:l,render:({field:u})=>e.jsx(we,{label:i("datasource.http.processing.pre.label"),modalTitle:i("datasource.http.processing.pre.description"),defaultValue:ft.pre,...u,styles:n})}),e.jsx(j.Controller,{name:"config.processing.post",control:l,render:({field:u})=>e.jsx(we,{label:i("datasource.http.processing.post.label"),modalTitle:i("datasource.http.processing.post.description"),defaultValue:ft.post,...u,styles:n})})]}),e.jsx(o.Group,{justify:"flex-end",mt:n.spacing,children:e.jsx(W,{size:n.button.size})})]})})}function In({dataSource:r,postSubmit:t,styles:s=V}){const{t:n}=y.useTranslation(),i=async({config:l})=>{T.showNotification({id:"for-updating",title:n("common.state.pending"),message:n("datasource.state.updating"),loading:!0,autoClose:!1});try{console.log({config:l}),await R.datasource.update(r.id,l),T.updateNotification({id:"for-updating",title:n("common.state.successful"),message:n("datasource.state.updated"),color:"green",loading:!1,autoClose:!0}),t()}catch(c){T.updateNotification({id:"for-updating",title:n("common.state.failed"),message:c.message,color:"red",loading:!1,autoClose:!0})}};return r.config?e.jsx(o.Box,{mx:"auto",children:e.jsx(Mn,{name:r.key,config:r.config,submit:i,styles:s})}):(console.error(new Error("unexpected empty config of a http datasource")),null)}function Rn({dataSource:r,onSuccess:t,styles:s=V}){const{t:n}=y.useTranslation(),[i,l]=P.useState(!1),c=()=>l(!0),u=()=>l(!1),d=()=>{t(),u()};return r.is_preset?e.jsx(o.Tooltip,{withArrow:!0,events:{hover:!0,touch:!1,focus:!1},label:n("datasource.cant_edit.preset"),children:e.jsx(o.Button,{size:s.button.size,color:"gray",variant:"light",leftSection:e.jsx(A.IconLock,{size:16}),sx:{transform:"none !important"},children:n("common.actions.edit")})}):r.type!=="http"&&r.type!=="merico_metric_system"?e.jsx(o.Tooltip,{withArrow:!0,events:{hover:!0,touch:!1,focus:!1},label:n("datasource.cant_edit.db"),children:e.jsx(o.Button,{size:s.button.size,color:"gray",variant:"light",leftSection:e.jsx(A.IconEdit,{size:16}),sx:{transform:"none !important"},children:n("common.actions.edit")})}):e.jsxs(e.Fragment,{children:[e.jsx(o.Modal,{opened:i,onClose:()=>l(!1),title:n("datasource.edit"),trapFocus:!0,onDragStart:p=>{p.stopPropagation()},children:e.jsx(In,{dataSource:r,postSubmit:d,styles:s})}),e.jsx(o.Button,{size:s.button.size,color:"blue",onClick:c,leftSection:e.jsx(A.IconEdit,{size:16}),children:n("common.actions.edit")})]})}const qn=be("DataSourceList",({styles:r=V})=>{const{t}=y.useTranslation(),{data:s=[],loading:n,refresh:i}=K.useRequest(async()=>{const{data:l}=await R.datasource.list();return l},{refreshDeps:[]});return e.jsxs(e.Fragment,{children:[e.jsx(o.Group,{pt:r.spacing,justify:"flex-end",children:e.jsx(ct,{onSuccess:i})}),e.jsxs(o.Box,{mt:r.spacing,sx:{position:"relative"},children:[e.jsx(o.LoadingOverlay,{visible:n}),e.jsxs(o.Table,{horizontalSpacing:r.spacing,verticalSpacing:r.spacing,fz:r.size,highlightOnHover:!0,children:[e.jsx(o.Table.Thead,{children:e.jsxs(o.Table.Tr,{children:[e.jsx(o.Table.Th,{children:t("common.type")}),e.jsx(o.Table.Th,{children:t("common.name")}),e.jsx(o.Table.Th,{children:t("common.action")})]})}),e.jsx(o.Table.Tbody,{children:s.map(l=>{const{id:c,key:u,type:d,is_preset:p}=l,h=d==="merico_metric_system";return e.jsxs(o.Table.Tr,{children:[e.jsx(o.Table.Td,{width:230,children:e.jsx($n,{type:d})}),e.jsx(o.Table.Td,{children:u}),e.jsx(o.Table.Td,{width:400,children:e.jsxs(o.Group,{justify:"flex-start",children:[e.jsx(Rn,{dataSource:l,onSuccess:i,styles:r}),e.jsx(dt,{isProtected:p||h,id:c,name:u,onSuccess:i,styles:r})]})})]},u)})})]})]})]})}),Ln=({option:r,...t})=>{const{label:s,value:n,description:i}=r;return e.jsxs(o.Stack,{gap:2,...t,children:[e.jsx(o.Text,{size:"sm",children:s}),e.jsx(o.Text,{size:"xs",c:"dimmed",className:"role-description",children:i})]})},Le=P.forwardRef(({styles:r,value:t,onChange:s},n)=>{const{t:i}=y.useTranslation(),{data:l=[],loading:c}=K.useRequest(async()=>(await R.role.list()).map(d=>({label:d.id,value:d.id,description:d.description,disabled:d.id==="SUPERADMIN"})),{refreshDeps:[]});return e.jsx(o.Select,{ref:n,mb:r.spacing,size:r.size,required:!0,label:i("role.label"),renderOption:Ln,data:l,disabled:c,styles:()=>({item:{"&[data-selected]":{"&, &:hover":{".role-description":{color:"rgba(255,255,255,.8)"}}}}}),value:t,onChange:u=>u!==null&&s(u),comboboxProps:{withinPortal:!0},maxDropdownHeight:500})}),H={size:"sm",spacing:"md",button:{size:"xs"}};function kn({postSubmit:r,styles:t=H,initialRoleID:s}){const{t:n}=y.useTranslation(),{control:i,handleSubmit:l}=j.useForm({defaultValues:{name:"",email:"",role_id:s,password:""}}),c=async({name:u,email:d,password:p,role_id:h})=>{try{T.showNotification({id:"for-creating",title:n("common.state.pending"),message:n("account.state.adding"),loading:!0,autoClose:!1}),await R.account.create(u,d,p,h),T.updateNotification({id:"for-creating",title:n("common.state.successful"),message:n("account.state.added"),color:"green",autoClose:!0,loading:!1}),r()}catch(b){T.updateNotification({id:"for-creating",title:n("common.state.failed"),message:b.message,color:"red",autoClose:!0,loading:!1})}};return e.jsx(o.Box,{mx:"auto",mb:10,children:e.jsxs("form",{onSubmit:l(c),children:[e.jsx(j.Controller,{name:"name",control:i,render:({field:u})=>e.jsx(o.TextInput,{mb:t.spacing,size:t.size,required:!0,label:n("account.username"),...u})}),e.jsx(j.Controller,{name:"email",control:i,render:({field:u})=>e.jsx(o.TextInput,{mb:t.spacing,size:t.size,required:!0,label:n("account.email"),...u})}),e.jsx(j.Controller,{name:"password",control:i,render:({field:u})=>e.jsx(o.PasswordInput,{mb:t.spacing,size:t.size,required:!0,label:n("account.password"),description:n("account.password_hint"),...u})}),e.jsx(j.Controller,{name:"role_id",control:i,render:({field:u})=>e.jsx(Le,{styles:t,...u})}),e.jsx(o.Group,{justify:"flex-end",mt:t.spacing,children:e.jsx(W,{size:t.button.size})})]})})}function pt({onSuccess:r,styles:t=H,initialRoleID:s}){const{t:n}=y.useTranslation(),[i,l]=P.useState(!1),c=()=>l(!0),u=()=>l(!1),d=()=>{r(),u()};return e.jsxs(e.Fragment,{children:[e.jsx(o.Modal,{opened:i,onClose:()=>l(!1),title:n("account.add"),trapFocus:!0,onDragStart:p=>{p.stopPropagation()},children:e.jsx(kn,{postSubmit:d,styles:t,initialRoleID:s})}),e.jsx(o.Button,{size:t.button.size,onClick:c,leftSection:e.jsx(A.IconPlaylistAdd,{size:20}),children:n("account.add")})]})}function mt({id:r,name:t,onSuccess:s,styles:n=H}){const{t:i}=y.useTranslation(),l=ae.useModals(),c=async()=>{if(r){T.showNotification({id:"for-deleting",title:i("common.state.pending"),message:i("account.state.deleting"),loading:!0,autoClose:!1});try{await R.account.delete(r),T.updateNotification({id:"for-deleting",title:i("common.state.successful"),message:i("account.state.deleted",{name:t}),color:"green",autoClose:!0,loading:!1}),s()}catch(d){T.updateNotification({id:"for-deleting",title:i("common.state.failed"),message:d.message,color:"red",autoClose:!0,loading:!1})}}},u=()=>l.openConfirmModal({title:i("account.delete"),labels:{confirm:i("common.actions.confirm"),cancel:i("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:c,cancelProps:{size:n.button.size},confirmProps:{color:"red",size:n.button.size}});return e.jsx(o.Button,{size:n.button.size,color:"red",onClick:u,leftSection:e.jsx(A.IconTrash,{size:20}),children:i("common.actions.delete")})}function Nn({id:r,name:t,email:s,role_id:n,postSubmit:i,styles:l=H}){const{t:c}=y.useTranslation(),{control:u,handleSubmit:d,watch:p}=j.useForm({defaultValues:{name:t,email:s,role_id:n,reset_password:!1,new_password:""}}),h=async({name:C,email:L,role_id:Y,reset_password:X,new_password:k})=>{try{T.showNotification({id:"for-updating",title:c("common.state.pending"),message:c("account.state.updating"),loading:!0,autoClose:!1}),await R.account.edit({id:r,name:C.trim(),email:L.trim(),role_id:Y,reset_password:X,new_password:k.trim()}),T.updateNotification({id:"for-updating",title:c("common.state.successful"),message:c("account.state.updated"),color:"green",autoClose:!0,loading:!1}),i()}catch(D){T.updateNotification({id:"for-updating",title:c("common.state.failed"),message:D.message,color:"red",autoClose:!0,loading:!1})}},[b,v]=p(["reset_password","new_password"]);return e.jsx(o.Box,{mx:"auto",mb:10,children:e.jsxs("form",{onSubmit:d(h),children:[e.jsx(j.Controller,{name:"name",control:u,render:({field:C})=>e.jsx(o.TextInput,{mb:l.spacing,size:l.size,required:!0,label:c("account.username"),...C})}),e.jsx(j.Controller,{name:"email",control:u,render:({field:C})=>e.jsx(o.TextInput,{mb:l.spacing,size:l.size,required:!0,label:c("account.email"),...C})}),e.jsx(j.Controller,{name:"role_id",control:u,render:({field:C})=>e.jsx(Le,{styles:l,...C})}),e.jsx(o.Divider,{my:20,variant:"dashed",label:"",labelPosition:"center"}),e.jsx(j.Controller,{name:"reset_password",control:u,render:({field:C})=>e.jsx(o.Switch,{mb:l.spacing,size:l.size,label:c("account.reset_password"),checked:C.value,onChange:L=>C.onChange(L.currentTarget.checked),styles:{label:{verticalAlign:"middle"}}})}),b&&e.jsx(j.Controller,{name:"new_password",control:u,render:({field:C})=>e.jsx(o.PasswordInput,{autoComplete:"off",mb:l.spacing,size:l.size,required:!0,description:c("account.password_hint"),label:c("account.new_password"),...C})}),e.jsx(o.Group,{justify:"flex-end",mt:l.spacing,children:e.jsx(W,{size:l.button.size})})]})})}function Fn({account:r,onSuccess:t,styles:s=H}){const{t:n}=y.useTranslation(),[i,l]=P.useState(!1),c=()=>l(!0),u=()=>l(!1),d=()=>{t(),u()};return e.jsxs(e.Fragment,{children:[e.jsx(o.Modal,{opened:i,onClose:()=>l(!1),title:n("account.editing_xx",{name:r.name}),trapFocus:!0,onDragStart:p=>{p.stopPropagation()},children:e.jsx(Nn,{...r,postSubmit:d,styles:s})}),e.jsx(o.Button,{size:s.button.size,onClick:c,leftSection:e.jsx(A.IconEdit,{size:20}),children:n("common.actions.edit")})]})}const Bn=be("AccountList",({styles:r=H})=>{var u;const{t}=y.useTranslation(),{data:s=[],loading:n,refresh:i}=K.useRequest(async()=>{const{data:d}=await R.account.list();return d},{refreshDeps:[]}),{data:l=[],loading:c}=K.useRequest(async()=>(await R.role.list()).map(p=>({label:p.id,value:p.id,description:p.description,disabled:p.id==="SUPERADMIN"})),{refreshDeps:[]});return e.jsxs(e.Fragment,{children:[e.jsx(o.Group,{pt:r.spacing,justify:"flex-end",children:e.jsx(pt,{onSuccess:i,initialRoleID:((u=l==null?void 0:l[0])==null?void 0:u.value)??"INACTIVE"})}),e.jsxs(o.Box,{mt:r.spacing,sx:{position:"relative"},children:[e.jsx(o.LoadingOverlay,{visible:n||c}),e.jsxs(o.Table,{horizontalSpacing:r.spacing,verticalSpacing:r.spacing,fz:r.size,highlightOnHover:!0,children:[e.jsx(o.Table.Thead,{children:e.jsxs(o.Table.Tr,{children:[e.jsx(o.Table.Th,{children:t("account.username")}),e.jsx(o.Table.Th,{children:t("account.email")}),e.jsx(o.Table.Th,{children:t("role.label")}),e.jsx(o.Table.Th,{children:t("common.action")})]})}),e.jsx(o.Table.Tbody,{children:s.map(d=>{const{id:p,name:h,email:b,role_id:v}=d;return e.jsxs(o.Table.Tr,{children:[e.jsx(o.Table.Td,{width:200,children:h}),e.jsx(o.Table.Td,{width:200,children:b}),e.jsx(o.Table.Td,{width:200,children:v}),e.jsx(o.Table.Td,{width:200,children:e.jsxs(o.Group,{justify:"flex-start",children:[e.jsx(Fn,{account:d,onSuccess:i}),e.jsx(mt,{id:p,name:h,onSuccess:i})]})})]},p)})})]})]})]})});function Un({postSubmit:r,styles:t=H}){const{t:s}=y.useTranslation(),{control:n,handleSubmit:i}=j.useForm({defaultValues:{name:"",password:""}}),l=async({name:c,password:u})=>{try{T.showNotification({id:"for-login",title:s("common.state.pending"),message:s("account.state.logging_in"),loading:!0,autoClose:!1});const d=await R.account.login(c.trim(),u.trim());window.localStorage.setItem("token",d.token),T.updateNotification({id:"for-login",title:s("common.state.successful"),message:s("account.state.logged_in"),color:"green",autoClose:!0,loading:!1}),r(d)}catch(d){T.updateNotification({id:"for-login",title:s("common.state.failed"),message:d.message,color:"red",autoClose:!0,loading:!1})}};return e.jsx(o.Box,{mx:"auto",children:e.jsxs("form",{onSubmit:i(l),children:[e.jsx(j.Controller,{name:"name",control:n,render:({field:c})=>e.jsx(o.TextInput,{mb:t.spacing,size:t.size,required:!0,label:s("account.username"),...c})}),e.jsx(j.Controller,{name:"password",control:n,render:({field:c})=>e.jsx(o.PasswordInput,{mb:t.spacing,size:t.size,required:!0,label:s("account.password"),...c})}),e.jsx(o.Group,{justify:"flex-end",mt:t.spacing,children:e.jsx(W,{size:t.button.size})})]})})}const Yn=be("Login",({styles:r=H,onSuccess:t})=>e.jsx(e.Fragment,{children:e.jsx(o.Box,{mt:r.spacing,sx:{position:"relative"},children:e.jsx(Un,{styles:r,postSubmit:t})})})),De={size:"sm",spacing:"md",button:{size:"xs"}};function Vn({postSubmit:r,styles:t=De,initialRoleID:s}){const{t:n}=y.useTranslation(),{control:i,handleSubmit:l}=j.useForm({defaultValues:{name:"",role_id:s}}),c=async({name:u,role_id:d})=>{try{T.showNotification({id:"for-creating",title:n("common.state.pending"),message:n("api_key.state.adding"),loading:!0,autoClose:!1});const{app_id:p,app_secret:h}=await R.api_key.create(u,d);T.updateNotification({id:"for-creating",title:n("common.state.successful"),message:n("api_key.state.added"),color:"green",autoClose:!0,loading:!1}),r(p,h)}catch(p){T.updateNotification({id:"for-creating",title:n("common.state.failed"),message:p.message,color:"red",autoClose:!0,loading:!1})}};return e.jsx(o.Box,{mx:"auto",mb:10,children:e.jsxs("form",{onSubmit:l(c),children:[e.jsx(j.Controller,{name:"name",control:i,render:({field:u})=>e.jsx(o.TextInput,{mb:t.spacing,size:t.size,required:!0,label:n("common.name"),...u})}),e.jsx(j.Controller,{name:"role_id",control:i,render:({field:u})=>e.jsx(Le,{styles:t,...u})}),e.jsx(o.Group,{justify:"flex-end",mt:t.spacing,children:e.jsx(W,{size:t.button.size})})]})})}function ht({onSuccess:r,styles:t=De,initialRoleID:s}){const{t:n}=y.useTranslation(),i=ae.useModals(),[l,c]=P.useState(!1),u=()=>c(!0),d=()=>c(!1),p=(h,b)=>{d(),i.openModal({title:n("api_key.save.title"),children:e.jsxs(o.Stack,{children:[e.jsx(o.Text,{size:"sm",c:"dimmed",children:n("api_key.save.warn")}),e.jsx(o.TextInput,{defaultValue:h,disabled:!0,label:n("api_key.app_id"),styles:{input:{cursor:"text !important"}}}),e.jsx(o.TextInput,{defaultValue:b,disabled:!0,label:n("api_key.app_secret"),styles:{input:{cursor:"text !important"}}}),e.jsx(o.Button,{size:"sm",onClick:()=>{ae.closeAllModals()},children:n("api_key.save.saved")})]}),onClose:()=>{r()}})};return e.jsxs(e.Fragment,{children:[e.jsx(o.Modal,{opened:l,onClose:()=>c(!1),title:n("api_key.add"),trapFocus:!0,onDragStart:h=>{h.stopPropagation()},children:e.jsx(Vn,{postSubmit:p,styles:t,initialRoleID:s})}),e.jsx(o.Button,{size:t.button.size,onClick:u,leftSection:e.jsx(A.IconPlaylistAdd,{size:20}),children:n("api_key.add")})]})}function gt({id:r,name:t,onSuccess:s,styles:n=De}){const{t:i}=y.useTranslation(),l=ae.useModals(),c=async()=>{if(r){T.showNotification({id:"for-deleting",title:i("common.state.pending"),message:i("global_sql_snippet.state.deleting"),loading:!0,autoClose:!1});try{await R.api_key.delete(r),T.updateNotification({id:"for-deleting",title:i("common.state.successful"),message:i("global_sql_snippet.state.deleted",{name:t}),color:"green",autoClose:!0,loading:!1}),s()}catch(d){T.updateNotification({id:"for-deleting",title:i("common.state.failed"),message:d.message,color:"red",autoClose:!0,loading:!1})}}},u=()=>l.openConfirmModal({title:i("api_key.delete"),labels:{confirm:i("common.actions.confirm"),cancel:i("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:c,cancelProps:{size:n.button.size},confirmProps:{color:"red",size:n.button.size}});return e.jsx(o.Button,{size:n.button.size,color:"red",onClick:u,leftSection:e.jsx(A.IconTrash,{size:20}),children:i("common.actions.delete")})}const Gn=be("APIKeyList",({styles:r=De})=>{var u;const{t}=y.useTranslation(),{data:s=[],loading:n,refresh:i}=K.useRequest(async()=>{const{data:d}=await R.api_key.list();return d},{refreshDeps:[]}),{data:l=[],loading:c}=K.useRequest(async()=>(await R.role.list()).map(p=>({label:p.id,value:p.id,description:p.description,disabled:p.id==="SUPERADMIN"})),{refreshDeps:[]});return e.jsxs(e.Fragment,{children:[e.jsx(o.Group,{pt:r.spacing,justify:"flex-end",children:e.jsx(ht,{onSuccess:i,initialRoleID:((u=l==null?void 0:l[0])==null?void 0:u.value)??"INACTIVE"})}),e.jsxs(o.Box,{mt:r.spacing,sx:{position:"relative"},children:[e.jsx(o.LoadingOverlay,{visible:n||c}),e.jsxs(o.Table,{horizontalSpacing:r.spacing,verticalSpacing:r.spacing,fz:r.size,highlightOnHover:!0,children:[e.jsx(o.Table.Thead,{children:e.jsxs(o.Table.Tr,{children:[e.jsx(o.Table.Th,{children:t("common.name")}),e.jsx(o.Table.Th,{children:t("api_key.app_id")}),e.jsx(o.Table.Th,{children:t("role.label")}),e.jsx(o.Table.Th,{children:t("common.action")})]})}),e.jsx(o.Table.Tbody,{children:s.map(d=>{const{id:p,name:h,app_id:b,role_id:v}=d;return e.jsxs(o.Table.Tr,{children:[e.jsx(o.Table.Td,{width:200,children:h}),e.jsx(o.Table.Td,{width:200,children:b}),e.jsx(o.Table.Td,{width:200,children:v}),e.jsx(o.Table.Td,{width:200,children:e.jsx(o.Group,{justify:"flex-start",children:e.jsx(gt,{id:p,name:h,onSuccess:i})})})]},p)})})]})]})]})}),ue={size:"sm",spacing:"md",button:{size:"xs"}};function Wn({postSubmit:r,styles:t=ue}){const{t:s}=y.useTranslation(),{control:n,handleSubmit:i}=j.useForm({defaultValues:{id:"",content:""}}),l=async c=>{try{T.showNotification({id:"for-creating",title:s("common.state.pending"),message:s("global_sql_snippet.state.adding"),loading:!0,autoClose:!1}),await R.sql_snippet.create(c),T.updateNotification({id:"for-creating",title:s("common.state.successful"),message:s("global_sql_snippet.state.added"),color:"green",autoClose:!0}),r()}catch(u){T.updateNotification({id:"for-creating",title:s("common.state.failed"),message:u.message,color:"red",autoClose:!0})}};return e.jsx(o.Box,{mx:"auto",children:e.jsxs("form",{onSubmit:i(l),children:[e.jsx(j.Controller,{name:"id",control:n,render:({field:c})=>e.jsx(o.TextInput,{mb:t.spacing,size:t.size,required:!0,label:s("common.name"),placeholder:s("common.name_placeholder"),...c})}),e.jsx(j.Controller,{name:"content",control:n,render:({field:c})=>e.jsxs(o.Stack,{gap:4,children:[e.jsx(o.Text,{size:"14px",fw:500,c:"#212529",sx:{cursor:"default"},children:s("global_sql_snippet.content")}),e.jsx(ut,{height:"600px",...c})]})}),e.jsx(o.Group,{justify:"flex-end",mt:t.spacing,children:e.jsx(W,{size:t.button.size})})]})})}function xt({onSuccess:r,styles:t=ue}){const{t:s}=y.useTranslation(),[n,i]=P.useState(!1),l=()=>i(!0),c=()=>i(!1),u=()=>{c(),r()};return e.jsxs(e.Fragment,{children:[e.jsx(o.Modal,{opened:n,onClose:()=>i(!1),title:s("global_sql_snippet.add"),trapFocus:!0,onDragStart:d=>{d.stopPropagation()},size:"80vw",children:e.jsx(Wn,{postSubmit:u,styles:t})}),e.jsx(o.Button,{size:t.button.size,onClick:l,leftSection:e.jsx(A.IconPlaylistAdd,{size:18}),children:s("global_sql_snippet.add")})]})}function Kn({postSubmit:r,styles:t=ue,id:s,content:n}){const{t:i}=y.useTranslation(),{control:l,handleSubmit:c}=j.useForm({defaultValues:{id:s,content:n}}),u=async d=>{try{T.showNotification({id:"for-updating",title:i("common.state.pending"),message:i("global_sql_snippet.state.updating"),loading:!0,autoClose:!1}),await R.sql_snippet.update(d),T.updateNotification({id:"for-updating",title:i("common.state.successful"),message:i("global_sql_snippet.state.updated"),color:"green",autoClose:!0}),r()}catch(p){T.updateNotification({id:"for-updating",title:i("common.state.failed"),message:p.message,color:"red",autoClose:!0})}};return e.jsx(o.Box,{mx:"auto",children:e.jsxs("form",{onSubmit:c(u),children:[e.jsx(j.Controller,{name:"id",control:l,render:({field:d})=>e.jsx(o.TextInput,{mb:t.spacing,size:t.size,required:!0,label:i("common.name"),placeholder:i("common.name_placeholder"),...d})}),e.jsx(j.Controller,{name:"content",control:l,render:({field:d})=>e.jsxs(o.Stack,{gap:4,children:[e.jsx(o.Text,{size:"14px",fw:500,c:"#212529",sx:{cursor:"default"},children:i("global_sql_snippet.content")}),e.jsx(ut,{height:"600px",...d})]})}),e.jsx(o.Group,{justify:"flex-end",mt:t.spacing,children:e.jsx(W,{size:t.button.size})})]})})}function bt({onSuccess:r,styles:t=ue,...s}){const{t:n}=y.useTranslation(),[i,l]=P.useState(!1),c=()=>l(!0),u=()=>l(!1),d=()=>{u(),r()};return e.jsxs(e.Fragment,{children:[e.jsx(o.Modal,{opened:i,onClose:()=>l(!1),title:n("global_sql_snippet.edit"),trapFocus:!0,onDragStart:p=>{p.stopPropagation()},size:"80vw",children:e.jsx(Kn,{postSubmit:d,styles:t,...s})}),e.jsx(o.Button,{size:t.button.size,onClick:c,leftSection:e.jsx(A.IconEdit,{size:18}),children:n("common.actions.edit")})]})}function vt({id:r,onSuccess:t,styles:s=ue}){const{t:n}=y.useTranslation(),i=ae.useModals(),l=async()=>{if(r){T.showNotification({id:"for-deleting",title:n("common.state.pending"),message:n("global_sql_snippet.state.deleting"),loading:!0,autoClose:!1});try{await R.sql_snippet.delete(r),T.updateNotification({id:"for-deleting",title:n("common.state.successful"),message:n("global_sql_snippet.state.deleted",{name:r}),color:"green",autoClose:!0}),t()}catch(u){T.updateNotification({id:"for-deleting",title:n("common.state.failed"),message:u.message,color:"red",autoClose:!0})}}},c=()=>i.openConfirmModal({title:n("global_sql_snippet.delete"),labels:{confirm:n("common.actions.confirm"),cancel:n("common.actions.cancel")},onCancel:()=>console.log("Cancel"),onConfirm:l,cancelProps:{size:s.button.size},confirmProps:{color:"red",size:s.button.size}});return e.jsx(o.Button,{size:s.button.size,color:"red",onClick:c,leftSection:e.jsx(A.IconTrash,{size:20}),children:n("common.actions.edit")})}function Qn({content:r}){return e.jsxs(o.HoverCard,{width:"60vw",shadow:"md",children:[e.jsx(o.HoverCard.Target,{children:e.jsx(o.ActionIcon,{variant:"subtle",size:16,children:e.jsx(A.IconEye,{})})}),e.jsx(o.HoverCard.Dropdown,{children:e.jsx(Kt.CodeHighlight,{code:r,language:"sql",withCopyButton:!1})})]})}const Jn=be("DataSourceList",({styles:r=ue})=>{const{t}=y.useTranslation(),{data:s=[],loading:n,refresh:i}=K.useRequest(async()=>{const{data:l}=await R.sql_snippet.list({pagination:{page:1,pagesize:10}});return l},{refreshDeps:[]});return e.jsxs(e.Fragment,{children:[e.jsxs(o.Group,{pt:r.spacing,justify:"space-between",children:[e.jsx(o.Alert,{children:t("global_sql_snippet.description")}),e.jsx(xt,{onSuccess:i})]}),e.jsxs(o.Box,{mt:r.spacing,sx:{position:"relative"},children:[e.jsx(o.LoadingOverlay,{visible:n}),e.jsxs(o.Table,{horizontalSpacing:r.spacing,verticalSpacing:r.spacing,fz:r.size,highlightOnHover:!0,children:[e.jsx(o.Table.Thead,{children:e.jsxs(o.Table.Tr,{children:[e.jsx(o.Table.Th,{children:t("common.name")}),e.jsx(o.Table.Th,{}),e.jsx(o.Table.Th,{children:t("common.created_at")}),e.jsx(o.Table.Th,{children:t("common.updated_at")}),e.jsx(o.Table.Th,{children:t("common.action")})]})}),e.jsx(o.Table.Tbody,{children:s.map(l=>{const{id:c,content:u,create_time:d,update_time:p}=l;return e.jsxs(o.Table.Tr,{children:[e.jsx(o.Table.Td,{children:c}),e.jsx(o.Table.Td,{width:50,children:e.jsx(Qn,{content:u})}),e.jsx(o.Table.Td,{width:200,children:d}),e.jsx(o.Table.Td,{width:200,children:p}),e.jsx(o.Table.Td,{width:400,children:e.jsxs(o.Group,{justify:"flex-start",children:[e.jsx(bt,{...l,onSuccess:i}),e.jsx(vt,{id:c,onSuccess:i})]})})]},c)})})]})]})]})}),Hn=()=>Promise.resolve().then(()=>Xn).then(({version:r})=>(console.log(`[@devtable/settings-form] version: ${r}`),r)),Xn=Object.freeze(Object.defineProperty({__proto__:null,version:"14.58.11"},Symbol.toStringTag,{value:"Module"}));x.APIClient=O,x.APIKeyList=Gn,x.AccountList=Bn,x.AddAPIKey=ht,x.AddAccount=pt,x.AddDataSource=ct,x.AddSQLSnippet=xt,x.DataSourceList=qn,x.DefaultApiClient=Xe,x.DeleteAPIKey=gt,x.DeleteAccount=mt,x.DeleteDataSource=dt,x.DeleteSQLSnippet=vt,x.FacadeApiClient=Ze,x.Login=Yn,x.SQLSnippetList=Jn,x.UpdateSQLSnippet=bt,x.configureAPIClient=tt,x.facadeApiClient=et,x.getVersion=Hn,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
package/dist/version.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
- "semver": "14.58.10",
3
- "version": "96091b0f758eaf156ae4d35e2a9fab551fbd3fb6"
2
+ "semver": "14.58.11",
3
+ "version": "1a5cf9c856b3c1a08dc786668f3e7e606e6f5e95"
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtable/settings-form",
3
- "version": "14.58.10",
3
+ "version": "14.58.11",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "url": "https://github.com/merico-dev/table"