1 line
21 KiB
JavaScript
1 line
21 KiB
JavaScript
|
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4403],{6206:(e,l,t)=>{t.d(l,{A:()=>c});var a=t(4848),s=t(6540),n=t(1710),i=t(3078),r=t(9020);function d(e){let{paradigm:l,payload:t,setLoading:a,table:s,database:n}=e;a(!0),(0,r.A)("/api/exportTableData",{method:"POST",body:{paradigm:l,dbName:n.db_slug,tableName:s.tableName,payload:t}},!0).then(e=>{if(e.success){if("export"==l){let l=new Blob([JSON.stringify(e.data||[],null,4)],{type:"application/json"}),t=URL.createObjectURL(l),a=document.createElement("a");a.href=t,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"==l&&(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:l,table:t}=e,[r,c]=s.useState(!1),[o,u]=s.useState(!0),m=s.useRef(null);return s.useRef(null),(0,a.jsxs)("div",{className:"relative",children:[r&&(0,a.jsx)(n.A,{width:"15px"}),(0,a.jsx)("div",{className:"button outlined gray",onClick:e=>{d({paradigm:"export",database:l,setLoading:c,table:t})},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?"))?d({paradigm:"import",payload:e.fileBase64,database:l,setLoading:c,table:t}):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})]})}},3425:(e,l,t)=>{t.d(l,{A:()=>b});var a=t(4848),s=t(6540),n=t(5143),i=t(3238),r=t(1671),d=t(6959),c=t(1710),o=t(9878),u=t(9020),m=t(2543),h=t.n(m);function x(e){let{database:l,table:t,setOpenPopover:n,dbSchemaData:i,query:r}=e,[d,c]=s.useState(!1);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("button",{className:"ghost p-3 justify-start",onClick:()=>{c(!0),setTimeout(()=>{n&&n(!1)},200)},children:"Sync Data"}),(0,a.jsx)(o.A,{open:d,setOpen:c,children:(0,a.jsx)(p,{database:l,table:t,dbSchemaData:i,query:r})})]})}function p(e){let{database:l,table:t,query:n,dbSchemaData:i}=e,[o,m]=s.useState(i),[x,p]=s.useState("Push"),[b,v]=s.useState(null==o?void 0:o[0]),[f,y]=s.useState(null==b?void 0:b.tables),[g,j]=s.useState(null==f?void 0:f[0]),[N,w]=s.useState(!1),[k,A]=s.useState(!1);return s.useEffect(()=>{h().isEqual(null==t?void 0:t.fields,null==g?void 0:g.fields)?A(!0):A(!1)},[g,v]),s.useEffect(()=>{n.delegated&&(0,u.A)("/api/get-authorized-databases").then(e=>{e.success&&e.payload&&m(e.payload)})},[]),(0,a.jsxs)("div",{className:"stack gap-2 relative w-full",children:[N||!o&&(0,a.jsx)(c.A,{width:"20px"}),(0,a.jsx)("h3",{className:"m-0 text-lg",children:"Sync Data with another table"}),k?(0,a.jsxs)("span",{className:"info green inline",children:["The selected table matches ",(0,a.jsx)("b",{children:t.tableFullName})," ","schema"]}):(0,a.jsxs)("span",{className:"info warning inline",children:["The selected table is not compatible with"," ",(0,a.jsx)("b",{children:t.tableFullName})]}),o&&(0,a.jsxs)("form",{onSubmit:e=>{!function(e){var l,t,a;let{e:s,setLoading:n,database:i,table:r,query:d}=e;s.preventDefault(),n(!0);let c=s.target,o=null===(l=c.paradigm)||void 0===l?void 0:l.value,m=null===(t=c.database)||void 0===t?void 0:t.value,h=null===(a=c.table)||void 0===a?void 0:a.value,x={paradigm:o,src:{db:i.db_slug,table:r.tableName},dst:{db:m,table:h},delegated:d.delegated};if(!window.confirm("Pull"==o?"NOTE: This operation will override the current database entries. Continue?":"NOTE: This operation will override the selected database entries. Continue?")){setTimeout(()=>{n(!1)},1e3);return}(0,u.A)("/api/sync-table-data",{method:"POST",body:{...x}},!
|