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