harperdb
Version:
HarperDB is a distributed database, caching service, streaming broker, and application development platform focused on performance and ease of use.
1 lines • 7.8 kB
JavaScript
;(self.webpackChunkharperdb_studio=self.webpackChunkharperdb_studio||[]).push([[417],{8086:(e,s,a)=>{a.r(s),a.d(s,{default:()=>y});var r=a(9950),t=a(4084),c=a(8156),l=a(7176),o=a(6114),i=a(3452),n=a(5077),d=a(5488),u=a(6713),m=a(9163),h=a.n(m),p=a(9435),x=a(5269),b=a(127);const f=async e=>{let{auth:s,url:a,id:r}=e;return(0,b.A)({operation:{operation:"get_job",id:r},auth:s,url:a})};var v=a(2773);var g=a(3628),j=a(3150),A=a(4414);const _=function(){const e=(0,n.Zp)(),{schema:s,table:a,customer_id:t,compute_stack_id:c}=(0,n.g)(),m=(0,u.O$)(x.A,(e=>e.auth)),_=(0,u.O$)(x.A,(e=>e.url)),[k,C]=(0,r.useState)({}),[w,N]=(0,r.useState)({}),[R,y]=(0,r.useState)(!1),T=(0,r.useCallback)((async r=>{try{const[{status:l,message:o}]=await f({auth:m,url:_,id:r});return"ERROR"===l?["Error: CSV Load failed from URL","Error downloading CSV file"].some((e=>-1!==o.indexOf(e)))?N({error:"The URL did not return a valid csv file"}):["unsupported content type"].some((e=>-1!==o.indexOf(e)))?N({error:"File error: ".concat(o.split(",")[1])}):N({error:o.split(":")[1]}):"COMPLETE"!==l&&R?setTimeout((()=>T(r)),2e3):(x.A.update((e=>{e.lastUpdate=Date.now()})),setTimeout((()=>e("/o/".concat(t,"/i/").concat(c,"/browse/").concat(s,"/").concat(a))),1e3))}catch(l){return setTimeout((()=>{x.A.update((e=>{e.lastUpdate=Date.now()})),e("/o/".concat(t,"/i/").concat(c,"/browse/").concat(s,"/").concat(a))}),2e3)}}),[R]);return h()((async()=>{if(w.submitted)if((0,v.A)(k.csv_url)){N({uploading:!0});const e=await(async e=>{let{schema:s,table:a,csv_url:r,auth:t,url:c}=e;return(0,b.A)({operation:{operation:"csv_url_load",action:"insert",transact_to_cluster:!0,schema:s,table:a,csv_url:r},auth:t,url:c})})({schema:s,table:a,csv_url:k.csv_url,auth:m,url:_}),r=e.message.replace("Starting job with id ","");setTimeout((()=>T(r)),1e3)}else N({error:"Please provide a valid URL"}),setTimeout((()=>N({})),2e3)}),[w]),h()((()=>y(!0)),(()=>y(!1)),[]),(0,A.jsx)(p.tH,{onError:(e,s)=>(0,g.A)({error:{message:e.message,componentStack:s}}),FallbackComponent:j.A,children:(0,A.jsxs)(l.A,{children:[(0,A.jsxs)(o.A,{xs:"12",lg:"4",className:"pt-1 pb-2",children:["Import A CSV File From URL",(0,A.jsx)("br",{}),(0,A.jsx)("span",{className:"text-small",children:"csv must be publicly accessible"})]}),(0,A.jsx)(o.A,{xs:"12",lg:"4",children:w.error?(0,A.jsxs)("div",{className:"text-danger csv-status",children:[(0,A.jsx)("i",{className:"fa fa-exclamation-triangle me-3"}),w.error]}):w.uploading?(0,A.jsxs)("div",{className:"csv-status",children:[(0,A.jsx)("i",{className:"fa fa-spin fa-spinner me-3"}),"uploading .csv into ",s,".",a]}):(0,A.jsx)(d.A,{onChange:e=>C({csv_url:e.target.value}),type:"text",invalid:k.csv_url&&!(0,v.A)(k.csv_url),id:"csv_url",title:"csv url",placeholder:"CSV file URL",value:k.csv_url||"",disabled:w.submitted})}),(0,A.jsx)(o.A,{xs:"12",lg:"4",children:w.error?(0,A.jsx)(i.A,{id:"clearURL",block:!0,color:"danger",onClick:()=>{N({}),C({})},children:"Clear URL"}):(0,A.jsx)(i.A,{id:"importFromURL",disabled:!!Object.keys(w).length||!(0,v.A)(k.csv_url),block:!0,color:"success",onClick:()=>N({submitted:!0}),children:"Import From URL"})})]})})};var k=a(9379),C=a(1101),w=a(5996);var N=a(4549);const R=function(){const e=(0,n.Zp)(),{schema:s,table:a,customer_id:t,compute_stack_id:c}=(0,n.g)(),d=(0,u.O$)(x.A,(e=>e.auth)),m=(0,u.O$)(x.A,(e=>e.url)),[v,_]=(0,r.useState)({}),[R,y]=(0,r.useState)({}),[T,S]=(0,r.useState)(!1),L=(0,r.useCallback)((async r=>{try{const[{status:l,message:o}]=await f({auth:d,url:m,id:r});return"ERROR"===l?-1!==o.indexOf("transaction aborted due to record(s) with a hash value that contains a forward slash")?y({error:"The CSV file contains a row with a forward slash in the hash field."}):-1!==o.indexOf("Invalid column name")?y({error:"The CSV file contains an invalid column name."}):y({error:o}):"COMPLETE"!==l&&T?setTimeout((()=>L(r)),1e3):setTimeout((()=>e("/o/".concat(t,"/i/").concat(c,"/browse/").concat(s,"/").concat(a))),1e3)}catch(l){return setTimeout((()=>{e("/o/".concat(t,"/i/").concat(c,"/browse/").concat(s,"/").concat(a))}),2e3)}}),[T]),F=(0,r.useCallback)((e=>{e.forEach((e=>{const s=new FileReader;s.onabort=()=>y({error:"File reading was aborted"}),s.onerror=()=>y({error:"file reading has failed"}),s.onload=()=>{y({processing:!0});const e=s.result.split(/\r\n|\n/).filter((e=>e.trim().length)).length-1;_({records:e,csv_file:s.result}),y({processed:!0})},e.size>w.A.max_file_upload_size?y({error:"File exceeds 10MB Limit. Use URL Loader Above."}):s.readAsText(e)}))}),[]);return h()((async()=>{if(R.submitted)if(v.csv_file){y({uploading:!0});const e=await(async e=>{let{schema:s,table:a,csv_file:r,auth:t,url:c}=e;return(0,b.A)({operation:{operation:"csv_data_load",action:"insert",transact_to_cluster:!0,schema:s,table:a,data:r},auth:t,url:c})})({schema:s,table:a,csv_file:v.csv_file,auth:d,url:m}),r=e.message.replace("Starting job with id ","");setTimeout((()=>L(r)),1e3)}else y({error:"Please select a valid CSV file"})}),[R]),h()((()=>S(!0)),(()=>S(!1)),[]),(0,A.jsx)(p.tH,{onError:(e,s)=>(0,g.A)({error:{message:e.message,componentStack:s}}),FallbackComponent:j.A,children:(0,A.jsxs)(l.A,{children:[(0,A.jsxs)(o.A,{xs:"12",lg:"4",className:"pt-1 pb-2",children:["Upload A CSV File",(0,A.jsx)("br",{}),(0,A.jsx)("span",{className:"text-small",children:"from your computer (10MB limit)"})]}),(0,A.jsx)(o.A,{xs:"12",lg:"4",children:R.error?(0,A.jsx)("div",{className:"text-danger csv-status",children:R.error}):R.uploading?(0,A.jsxs)("div",{className:"csv-status",children:[(0,A.jsx)("i",{className:"fa fa-spin fa-spinner me-3"}),"inserting ",(0,N.A)(v.records)," records into ",s,".",a]}):R.processed?(0,A.jsx)(i.A,{id:"replaceFile",block:!0,color:"default",onClick:()=>{y({}),_({})},children:(0,A.jsxs)("span",{className:"text-nowrap text-small",children:[(0,A.jsx)("i",{className:"fa fa-thumbs-up text-success me-3"}),(0,N.A)(v.records)," records. Click here to replace file."]})}):R.processing?(0,A.jsxs)("div",{className:"csv-status",children:[(0,A.jsx)("i",{className:"fa fa-spin fa-spinner"})," processing ",(0,N.A)(v.records)," records"]}):(0,A.jsx)(C.Ay,{onDrop:F,children:e=>{let{getRootProps:s,getInputProps:a}=e;return(0,A.jsxs)("div",(0,k.A)((0,k.A)({},s()),{},{className:"drop-zone",children:[(0,A.jsx)("input",(0,k.A)({},a())),"Click or Drag to select a .csv file"]}))}})}),(0,A.jsx)(o.A,{xs:"12",lg:"4",children:R.error?(0,A.jsx)(i.A,{id:"clearFile",color:"danger",block:!0,className:"px-5 clear-files",onClick:()=>{y({}),_({})},children:"Clear File"}):(0,A.jsxs)(i.A,{id:"insertRecords",block:!0,disabled:R.uploading||!v.csv_file,color:"success",onClick:()=>y({submitted:!0}),children:["Insert ",(0,N.A)(v.records)," Records"]})})]})})};const y=function(){const e=(0,n.Zp)(),{schema:s,table:a,customer_id:r,compute_stack_id:d}=(0,n.g)();return(0,A.jsxs)("div",{id:"csv-upload",children:[(0,A.jsxs)("span",{className:"floating-card-header",children:[s," > ",a," > csv upload"]}),(0,A.jsx)(t.A,{className:"my-3",children:(0,A.jsxs)(c.A,{children:[(0,A.jsx)(_,{}),(0,A.jsx)("hr",{className:"my-3"}),(0,A.jsx)(R,{}),(0,A.jsx)("hr",{className:"my-3"}),(0,A.jsxs)(l.A,{children:[(0,A.jsxs)(o.A,{lg:"8",className:"py-1 d-none d-lg-inline-block",children:["Return to Table",(0,A.jsx)("br",{}),(0,A.jsx)("span",{className:"text-small",children:"do not upload csv data"})]}),(0,A.jsx)(o.A,{xs:"12",lg:"4",children:(0,A.jsx)(i.A,{id:"returnToTable",block:!0,color:"grey",onClick:()=>e("/o/".concat(r,"/i/").concat(d,"/browse/").concat(s,"/").concat(a)),children:"Return to Table"})})]})]})})]})}},2773:(e,s,a)=>{a.d(s,{A:()=>r});const r=e=>!!new RegExp("^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$","i").test(e)}}]);