dsql-admin/dsql-app/.local_dist/static/chunks/6460-4b0051e1ff7a0e1a.js

1 line
27 KiB
JavaScript
Raw Normal View History

2024-12-05 07:03:33 +00:00
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6460],{76919:(e,t,l)=>{l.d(t,{A:()=>c});var a=l(74848),s=l(96540),n=l(620),i=l(95896),d=l(23698);function r(e){let{paradigm:t,payload:l,setLoading:a,table:s,database:n}=e;a(!0),(0,d.A)("/api/exportTableData",{method:"POST",body:{paradigm:t,dbName:n.db_slug,tableName:s.tableName,payload:l}},!0).then(e=>{if(e.success){if("export"==t){let t=new Blob([JSON.stringify(e.data||[],null,4)],{type:"application/json"}),l=URL.createObjectURL(t),a=document.createElement("a");a.href=l,a.style.display="none",a.download="".concat(n.db_slug,"-").concat(s.tableName,"-").concat(Date.now(),".json"),document.body.appendChild(a),a.click(),document.body.removeChild(a)}else"import"==t&&(window.alert("Data Imported Successfully"),window.location.reload())}else e.msg&&window.alert(e.msg)}).catch(e=>{console.log(e)}).finally(()=>{a(!1)})}function c(e){let{database:t,table:l}=e,[d,c]=s.useState(!1),[o,u]=s.useState(!0),m=s.useRef(null);return s.useRef(null),(0,a.jsxs)("div",{className:"relative",children:[d&&(0,a.jsx)(n.A,{width:"15px"}),(0,a.jsx)("div",{className:"button outlined gray",onClick:e=>{r({paradigm:"export",database:t,setLoading:c,table:l})},children:"Export"}),(0,a.jsx)("div",{className:"button outlined gray",onClick:e=>{var a,s;null===(a=m.current)||void 0===a||a.addEventListener("change",e=>{var a;c(!0);let s=e.target;if(!(null===(a=s.files)||void 0===a?void 0:a[0])){window.alert("No FIles selected"),c(!1);return}(0,i.A)({inputFile:s.files[0]}).then(e=>{window.confirm("Use this file '".concat(e.fileName,"' as your import file?"))?r({paradigm:"import",payload:e.fileBase64,database:t,setLoading:c,table:l}):c(!1),u(!1),setTimeout(()=>{u(!0)},200)})}),null===(s=m.current)||void 0===s||s.click()},children:"Import"}),o&&(0,a.jsx)("input",{type:"file",name:"json_file_input",id:"json_file_input",accept:".json",className:"hidden",ref:m})]})}},93644:(e,t,l)=>{l.d(t,{A:()=>r});var a=l(74848),s=l(96540),n=l(5143),i=l(23238),d=l(31942);function r(e){let{database:t,table:l,dbSchemaData:r,query:c}=e,[o,u]=s.useState(!1);return(0,a.jsx)(n.Popover,{isOpen:o,onClickOutside:()=>u(!1),positions:["bottom"],align:"end",content:(0,a.jsxs)("div",{className:"stack items-stretch bg-white rounded shadow-md gap-0 min-w-[200px]",children:[(0,a.jsx)(d.A,{database:t,table:l,setOpenPopover:u,dbSchemaData:r,query:c}),(0,a.jsx)("hr",{className:"m-0"})]}),containerClassName:"z-[1000]",children:(0,a.jsx)("button",{onClick:()=>{u(!o)},className:"outlined gray px-2 py-1.5",children:(0,a.jsx)(i.A,{})})})}},31942:(e,t,l)=>{l.d(t,{A:()=>m});var a=l(74848),s=l(60637),n=l(41301),i=l(620),d=l(44500),r=l(23698),c=l(2543),o=l.n(c),u=l(96540);function m(e){let{database:t,table:l,setOpenPopover:s,dbSchemaData:n,query:i}=e,[r,c]=u.useState(!1);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{className:"ghost p-3 justify-start",onClick:()=>{c(!0),setTimeout(()=>{s&&s(!1)},200)},children:"Sync Data"}),(0,a.jsx)(d.A,{open:r,setOpen:c,children:(0,a.jsx)(p,{database:t,table:l,dbSchemaData:n,query:i})})]})}function p(e){let{database:t,table:l,query:d,dbSchemaData:c}=e,[m,p]=u.useState(c),[h,f]=u.useState("Push"),[x,b]=u.useState(null==m?void 0:m[0]),[v,g]=u.useState(null==x?void 0:x.tables),[j,N]=u.useState(null==v?void 0:v[0]),[y,w]=u.useState(!1),[T,S]=u.useState(!1);return u.useEffect(()=>{o().isEqual(null==l?void 0:l.fields,null==j?void 0:j.fields)?S(!0):S(!1)},[j,b]),u.useEffect(()=>{d.delegated&&(0,r.A)("/api/get-authorized-databases").then(e=>{e.success&&e.payload&&p(e.payload)})},[]),(0,a.jsxs)("div",{className:"stack gap-2 relative w-full",children:[y||!m&&(0,a.jsx)(i.A,{width:"20px"}),(0,a.jsx)("h3",{className:"m-0 text-lg",children:"Sync Data with another table"}),T?(0,a.jsxs)("span",{className:"info green inline",children:["The selected table matches ",(0,a.jsx)("b",{children:l.tableFullName})," ","schema"]}):(0,a.jsxs)("span",{className:"info warning inline",children:["The selected table is not compatible with"," ",(0,a.jsx)("b",{children:l.tableFullName})]}),m&&(0,a.jsxs)("form",{onSubmit:e=>{!