1 line
27 KiB
JavaScript
1 line
27 KiB
JavaScript
|
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6460],{6919:(e,t,l)=>{l.d(t,{A:()=>c});var a=l(4848),s=l(6540),n=l(620),i=l(5896),d=l(3698);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})]})}},1627:(e,t,l)=>{l.d(t,{A:()=>x});var a=l(4848),s=l(6540),n=l(5143),i=l(3238),d=l(637),r=l(1301),c=l(620),o=l(4500),u=l(3698),m=l(2543),h=l.n(m);function p(e){let{database:t,table:l,setOpenPopover:n,dbSchemaData:i,query:d}=e,[r,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:r,setOpen:c,children:(0,a.jsx)(f,{database:t,table:l,dbSchemaData:i,query:d})})]})}function f(e){let{database:t,table:l,query:n,dbSchemaData:i}=e,[o,m]=s.useState(i),[p,f]=s.useState("Push"),[x,b]=s.useState(null==o?void 0:o[0]),[v,g]=s.useState(null==x?void 0:x.tables),[j,N]=s.useState(null==v?void 0:v[0]),[y,w]=s.useState(!1),[T,S]=s.useState(!1);return s.useEffect(()=>{h().isEqual(null==l?void 0:l.fields,null==j?void 0:j.fields)?S(!0):S(!1)},[j,b]),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:[y||!o&&(0,a.jsx)(c.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})]}),o&&(0,a.jsxs)("form",{onSubmit:e=>{!function(e){var t,l,a;let{e:s,setLoading:n,database:i,table:d,query:r}=e;s.preventDefault(),n(!0);let c=s.target,o=null===(t=c.paradigm)||void 0===t?void 0:t.value,m=null===(l=c.database)||void 0===l?void 0:l.value,h=null===(a=c.table)||void 0===a?void 0:a.value,p={paradigm:o,src:{db:i.db_slug,table:d.tableName},dst:{db:m,table:h},delegated:r.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:{...p}},!0).
|