UNPKG

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.59 kB
"use strict";(self.webpackChunkharperdb_studio=self.webpackChunkharperdb_studio||[]).push([[417],{8086:(e,s,r)=>{r.r(s),r.d(s,{default:()=>N});var a=r(9950),t=r(4084),l=r(8156),c=r(7176),i=r(6114),o=r(3452),n=r(625),d=r(5488),u=r(6713),m=r(9163),h=r.n(m),p=r(9435),x=r(5269),b=r(127);const f=async e=>{let{auth:s,url:r,id:a}=e;return(0,b.A)({operation:{operation:"get_job",id:a},auth:s,url:r})};var v=r(2773);var g=r(3628),j=r(3150),A=r(4414);const _=function(){const e=(0,n.Zp)(),{schema:s,table:r,customer_id:t,compute_stack_id:l}=(0,n.g)(),m=(0,u.O$)(x.A,(e=>e.auth)),_=(0,u.O$)(x.A,(e=>e.url)),[k,C]=(0,a.useState)({}),[$,w]=(0,a.useState)({}),[N,R]=(0,a.useState)(!1),y=(0,a.useCallback)((async a=>{try{const[{status:c,message:i}]=await f({auth:m,url:_,id:a});return"ERROR"===c?["Error: CSV Load failed from URL","Error downloading CSV file"].some((e=>-1!==i.indexOf(e)))?w({error:"The URL did not return a valid csv file"}):["unsupported content type"].some((e=>-1!==i.indexOf(e)))?w({error:`File error: ${i.split(",")[1]}`}):w({error:i.split(":")[1]}):"COMPLETE"!==c&&N?setTimeout((()=>y(a)),2e3):(x.A.update((e=>{e.lastUpdate=Date.now()})),setTimeout((()=>e(`/o/${t}/i/${l}/browse/${s}/${r}`)),1e3))}catch(c){return setTimeout((()=>{x.A.update((e=>{e.lastUpdate=Date.now()})),e(`/o/${t}/i/${l}/browse/${s}/${r}`)}),2e3)}}),[N]);return h()((async()=>{if($.submitted)if((0,v.A)(k.csv_url)){w({uploading:!0});const e=await(async e=>{let{schema:s,table:r,csv_url:a,auth:t,url:l}=e;return(0,b.A)({operation:{operation:"csv_url_load",action:"insert",transact_to_cluster:!0,schema:s,table:r,csv_url:a},auth:t,url:l})})({schema:s,table:r,csv_url:k.csv_url,auth:m,url:_}),a=e.message.replace("Starting job with id ","");setTimeout((()=>y(a)),1e3)}else w({error:"Please provide a valid URL"}),setTimeout((()=>w({})),2e3)}),[$]),h()((()=>R(!0)),(()=>R(!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)(c.A,{children:[(0,A.jsxs)(i.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)(i.A,{xs:"12",lg:"4",children:$.error?(0,A.jsxs)("div",{className:"text-danger csv-status",children:[(0,A.jsx)("i",{className:"fa fa-exclamation-triangle me-3"}),$.error]}):$.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,".",r]}):(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:$.submitted})}),(0,A.jsx)(i.A,{xs:"12",lg:"4",children:$.error?(0,A.jsx)(o.A,{id:"clearURL",block:!0,color:"danger",onClick:()=>{w({}),C({})},children:"Clear URL"}):(0,A.jsx)(o.A,{id:"importFromURL",disabled:!!Object.keys($).length||!(0,v.A)(k.csv_url),block:!0,color:"success",onClick:()=>w({submitted:!0}),children:"Import From URL"})})]})})};var k=r(4472),C=r(5996);var $=r(4549);const w=function(){const e=(0,n.Zp)(),{schema:s,table:r,customer_id:t,compute_stack_id:l}=(0,n.g)(),d=(0,u.O$)(x.A,(e=>e.auth)),m=(0,u.O$)(x.A,(e=>e.url)),[v,_]=(0,a.useState)({}),[w,N]=(0,a.useState)({}),[R,y]=(0,a.useState)(!1),T=(0,a.useCallback)((async a=>{try{const[{status:c,message:i}]=await f({auth:d,url:m,id:a});return"ERROR"===c?-1!==i.indexOf("transaction aborted due to record(s) with a hash value that contains a forward slash")?N({error:"The CSV file contains a row with a forward slash in the hash field."}):-1!==i.indexOf("Invalid column name")?N({error:"The CSV file contains an invalid column name."}):N({error:i}):"COMPLETE"!==c&&R?setTimeout((()=>T(a)),1e3):setTimeout((()=>e(`/o/${t}/i/${l}/browse/${s}/${r}`)),1e3)}catch(c){return setTimeout((()=>{e(`/o/${t}/i/${l}/browse/${s}/${r}`)}),2e3)}}),[R]),S=(0,a.useCallback)((e=>{e.forEach((e=>{const s=new FileReader;s.onabort=()=>N({error:"File reading was aborted"}),s.onerror=()=>N({error:"file reading has failed"}),s.onload=()=>{N({processing:!0});const e=s.result.split(/\r\n|\n/).filter((e=>e.trim().length)).length-1;_({records:e,csv_file:s.result}),N({processed:!0})},e.size>C.A.max_file_upload_size?N({error:"File exceeds 10MB Limit. Use URL Loader Above."}):s.readAsText(e)}))}),[]);return h()((async()=>{if(w.submitted)if(v.csv_file){N({uploading:!0});const e=await(async e=>{let{schema:s,table:r,csv_file:a,auth:t,url:l}=e;return(0,b.A)({operation:{operation:"csv_data_load",action:"insert",transact_to_cluster:!0,schema:s,table:r,data:a},auth:t,url:l})})({schema:s,table:r,csv_file:v.csv_file,auth:d,url:m}),a=e.message.replace("Starting job with id ","");setTimeout((()=>T(a)),1e3)}else N({error:"Please select a valid CSV file"})}),[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)(c.A,{children:[(0,A.jsxs)(i.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)(i.A,{xs:"12",lg:"4",children:w.error?(0,A.jsx)("div",{className:"text-danger csv-status",children:w.error}):w.uploading?(0,A.jsxs)("div",{className:"csv-status",children:[(0,A.jsx)("i",{className:"fa fa-spin fa-spinner me-3"}),"inserting ",(0,$.A)(v.records)," records into ",s,".",r]}):w.processed?(0,A.jsx)(o.A,{id:"replaceFile",block:!0,color:"default",onClick:()=>{N({}),_({})},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,$.A)(v.records)," records. Click here to replace file."]})}):w.processing?(0,A.jsxs)("div",{className:"csv-status",children:[(0,A.jsx)("i",{className:"fa fa-spin fa-spinner"})," processing ",(0,$.A)(v.records)," records"]}):(0,A.jsx)(k.Ay,{onDrop:S,children:e=>{let{getRootProps:s,getInputProps:r}=e;return(0,A.jsxs)("div",{...s(),className:"drop-zone",children:[(0,A.jsx)("input",{...r()}),"Click or Drag to select a .csv file"]})}})}),(0,A.jsx)(i.A,{xs:"12",lg:"4",children:w.error?(0,A.jsx)(o.A,{id:"clearFile",color:"danger",block:!0,className:"px-5 clear-files",onClick:()=>{N({}),_({})},children:"Clear File"}):(0,A.jsxs)(o.A,{id:"insertRecords",block:!0,disabled:w.uploading||!v.csv_file,color:"success",onClick:()=>N({submitted:!0}),children:["Insert ",(0,$.A)(v.records)," Records"]})})]})})};const N=function(){const e=(0,n.Zp)(),{schema:s,table:r,customer_id:a,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," > ",r," > csv upload"]}),(0,A.jsx)(t.A,{className:"my-3",children:(0,A.jsxs)(l.A,{children:[(0,A.jsx)(_,{}),(0,A.jsx)("hr",{className:"my-3"}),(0,A.jsx)(w,{}),(0,A.jsx)("hr",{className:"my-3"}),(0,A.jsxs)(c.A,{children:[(0,A.jsxs)(i.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)(i.A,{xs:"12",lg:"4",children:(0,A.jsx)(o.A,{id:"returnToTable",block:!0,color:"grey",onClick:()=>e(`/o/${a}/i/${d}/browse/${s}/${r}`),children:"Return to Table"})})]})]})})]})}},2773:(e,s,r)=>{r.d(s,{A:()=>a});const a=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)}}]);