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 5.02 kB
"use strict";(self.webpackChunkharperdb_studio=self.webpackChunkharperdb_studio||[]).push([[374],{3888:(e,a,t)=>{t.r(a),t.d(a,{default:()=>g});var s=t(9379),c=t(9950),n=t(5023),r=t(4084),o=t(8156),l=t(7176),i=t(6114),d=t(3452),h=t(5077),u=t(9163),m=t.n(u),f=t(6713),b=t(7348),p=t(9435),j=t(5269),x=t(5553),_=t(127),A=t(3628),k=t(3150),N=t(4414);const g=function(e){let{newEntityAttributes:a,hashAttribute:t}=e;const{customer_id:u,schema:g,table:y,hash:v,action:w,compute_stack_id:C}=(0,h.g)(),S=decodeURIComponent(g),I=decodeURIComponent(y),O=decodeURIComponent(v),T=(0,b.MW)(),{state:D}=(0,h.zy)(),E=(0,h.Zp)(),F=(0,f.O$)(j.A,(e=>e.auth)),R=(0,f.O$)(j.A,(e=>e.url)),U=(0,f.O$)(x.A,(e=>e.theme)),J=(0,c.useRef)(null),[V,$]=(0,c.useState)("{}"),[M,Y]=(0,c.useState)(),[z,H]=(0,c.useState)(!0),[P,W]=(0,c.useState)(!1),[Z,q]=(0,c.useState)(!1),B="/o/".concat(u,"/i/").concat(C,"/browse/").concat(S,"/").concat(I),G=async e=>{if(e.preventDefault(),z||T.error("Please insert valid JSON to proceed"),!w||!z)return!1;W(!0);const a=JSON.parse(V),t={operation:{operation:"edit"===w?"update":"insert",schema:S,table:I,records:"edit"!==w&&Array.isArray(a)?a:[a]},auth:F,url:R},{error:s,message:c}=await(0,_.A)(t);return s?(T.error(c),W(!1)):(j.A.update((e=>{e.lastUpdate=Date.now()})),setTimeout((()=>E("/o/".concat(u,"/i/").concat(C,"/browse/").concat(S,"/").concat(I))),1e3))};return(0,c.useEffect)((()=>{var e,a;null!==(e=J.current)&&void 0!==e&&null!==(a=e.editor)&&void 0!==a&&a.setTheme&&J.current.editor.setTheme("dark"===U?"vs-dark":"light")}),[U]),m()((()=>{a||E(B)}),[]),m()((async()=>{if("edit"===w){let a;null!==D&&void 0!==D&&D.hashValue?a=[D.hashValue]:(e=O,a="".concat(parseFloat(e))===e?["".concat(O),parseInt(O,10)]:[O]);const c=await(0,_.A)({operation:{operation:"search_by_hash",schema:S,table:I,hash_values:a,get_attributes:["*"],onlyIfCached:!0,noCacheStore:!0},auth:F,url:R}),[n]=c;if(n){const e=n[t],a=n.__createdtime__,c=n.__updatedtime__;delete n.__createdtime__,delete n.__updatedtime__,delete n[t];const r=(0,s.A)((0,s.A)({[t]:e},n),{},{__createdtime__:a,__updatedtime__:c});$(JSON.stringify(r,null,4))}else E(B),T.error("Unable to find record with that hash_attribute")}else $(JSON.stringify(a||{},null,4));var e}),[O]),(0,N.jsxs)(p.tH,{onError:(e,a)=>(0,A.A)({error:{message:e.message,componentStack:a}}),FallbackComponent:k.A,children:[(0,N.jsxs)("span",{className:"floating-card-header",children:[S," ",I&&">"," ",I," ","add"===w?"> add new":O?"> edit > ".concat(O):"","\xa0"]}),(0,N.jsx)(r.A,{className:"my-3",children:(0,N.jsxs)(o.A,{children:[(0,N.jsx)("ul",{className:"text-small",children:"add"===w&&(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)("li",{children:['The hash_attribute for this table is "',(0,N.jsx)("b",{children:t}),'", and will auto-generate. You may manually add it if you want to specify its value.']}),(0,N.jsxs)("li",{children:[(0,N.jsx)("b",{children:"You may paste in an array"})," if you want to add more than one record at a time."]})]})}),(0,N.jsx)(r.A,{className:"mb-2 json-editor-holder",children:(0,N.jsx)(o.A,{children:(0,N.jsx)(n.Ay,{height:"350px",language:"json",value:V,theme:"vs-dark",onValidate:e=>{H(0===e.length)},onChange:e=>{$(e)},onMount:(e,a)=>{J.current=a}})})}),(0,N.jsxs)(l.A,{children:[(0,N.jsx)(i.A,{md:"4",className:"mt-2",children:M?(0,N.jsx)("div",{className:"pt-2",children:"Delete this record?"}):(0,N.jsx)(d.A,{disabled:P||Z,id:"backToTable",block:!0,color:"black",onClick:()=>E("/o/".concat(u,"/i/").concat(C,"/browse/").concat(S,"/").concat(I)),children:(0,N.jsx)("i",{className:"fa fa-chevron-left"})})}),"add"===w?(0,N.jsx)(i.A,{md:"8",children:(0,N.jsx)(d.A,{disabled:P||!z,id:"addEditItem",className:"mt-2",onClick:G,block:!0,color:"success",children:(0,N.jsx)("i",{className:"fa ".concat(P?"fa-spinner fa-spin":"fa-save")})})}):M?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(i.A,{md:"4",className:"mt-2",children:(0,N.jsx)(d.A,{disabled:P||Z,id:"cancelDelete",block:!0,color:"black",onClick:()=>Y(!1),children:(0,N.jsx)("i",{className:"fa fa-ban"})})}),(0,N.jsx)(i.A,{md:"4",children:(0,N.jsx)(d.A,{disabled:P||Z,id:"deleteRecord",className:"mt-2",onClick:async e=>{if(e.preventDefault(),!w)return!1;q(!0);const{error:a,message:t}=await(0,_.A)({operation:{operation:"delete",schema:S,table:I,hash_values:[D.hashValue]},auth:F,url:R});return a?(T.error(t),Y(!1),q(!1)):setTimeout((()=>E("/o/".concat(u,"/i/").concat(C,"/browse/").concat(S,"/").concat(I))),100)},block:!0,color:"success",children:(0,N.jsx)("i",{className:"fa ".concat(Z?"fa-spinner fa-spin":"fa-check")})})})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(i.A,{md:"4",className:"mt-2",children:(0,N.jsx)(d.A,{disabled:P||Z,id:"confirmDelete",block:!0,color:"danger",onClick:()=>Y(O),children:(0,N.jsx)("i",{className:"fa fa-trash"})})}),(0,N.jsx)(i.A,{md:"4",children:(0,N.jsx)(d.A,{disabled:P||!z,id:"addEditItem",className:"mt-2",onClick:G,block:!0,color:"success",children:(0,N.jsx)("i",{className:"fa ".concat(P?"fa-spinner fa-spin":"fa-save")})})})]})]})]})})]})}}}]);