harperdb
Version:
HarperDB is a distributed database, caching service, streaming broker, and application development platform focused on performance and ease of use.
1 lines • 15.8 kB
JavaScript
;(self.webpackChunkharperdb_studio=self.webpackChunkharperdb_studio||[]).push([[522],{7591:(e,t,r)=>{r.r(t),r.d(t,{default:()=>P});var n=r(9950),o=r(625),s=r(7176),i=r(6114),a=r(3452),l=r(4084),c=r(8156),u=r(6713),f=r(5269),p=r(9435),d=r(9708),m=r(5488),h=r(7348),y=r(2765),b=r(2415),g=r(6196),j=r(4414);const v=function(e){let{itemType:t,toggleDropItem:r,toggleCreate:l,baseUrl:c}=e;const{compute_stack_id:p,customer_id:v}=(0,o.g)(),x=(0,o.Zp)(),A=(0,h.MW)(),O=(0,u.O$)(f.A,(e=>e.auth)),w=(0,u.O$)(f.A,(e=>e.url)),N=(0,u.O$)(f.A,(e=>e.is_local)),_=(0,u.O$)(f.A,(e=>e.roles&&e.roles.map((e=>e.role)))),[k,R]=(0,n.useState)({});return(0,n.useEffect)((()=>{r()}),[r]),(0,j.jsx)(d.A,{onSubmit:async e=>{if(e.preventDefault(),!k.name)return R({...k,error:!0}),A.error("You must provide a role name");if(_.includes(k.name))return R({...k,error:!0}),A.error("Role with that name already exists");if(!(0,g.A)(k.name))return R({...k,error:!0}),A.error("Role names must have only letters and underscores");const r="cluster user"===t?{cluster_user:!0}:"super user"===t?{super_user:!0}:{},n=await(0,y.A)({auth:O,url:w,is_local:N,compute_stack_id:p,customer_id:v,role:k.name,permission:r});return n.error?(R({...k,error:!0}),A.error(n.message)):(R({}),await(0,b.A)({auth:O,url:w}),x(`${c}/${n.id}`))},children:(0,j.jsxs)(s.A,{className:"item-row form",children:[(0,j.jsx)(i.A,{className:"input-holder",children:(0,j.jsx)(m.A,{id:"name",invalid:k.error,onChange:e=>R({name:e.target.value.toString()}),type:"text",name:"name",placeholder:"name"})}),(0,j.jsxs)(i.A,{className:"item-action",children:[(0,j.jsx)(a.A,{id:"createRole",color:"success",className:"round me-1",children:(0,j.jsx)("i",{className:"fa fa-check text-white"})}),(0,j.jsx)(a.A,{color:"black",className:"round",onClick:()=>l(!1),children:(0,j.jsx)("i",{className:"fa fa-times text-white"})})]})]})})};var x=r(127);const A=function(e){let{item:t,baseUrl:r,isActive:l,toggleDropItem:c,isDropping:p}=e;const d=(0,o.Zp)(),m=(0,h.MW)(),[y,g]=(0,n.useState)(!1),v=(0,u.O$)(f.A,(e=>e.auth)),A=(0,u.O$)(f.A,(e=>e.url)),O=async()=>{if(!y)return!1;const e=await(async e=>{let{auth:t,id:r,url:n}=e;return(0,x.A)({operation:{operation:"drop_role",id:r},auth:t,url:n})})({auth:v,url:A,id:t.id});return e.error?m.error(e.message):((0,b.A)({auth:v,url:A}),!!l&&setTimeout((()=>d(r)),100))};return(0,j.jsxs)(s.A,{className:"item-row "+(l?"active":""),onClick:()=>!(l||p||y)&&d(`${r}/${t.id}`),children:[(0,j.jsx)(i.A,{className:"item-label "+(y?"text-danger text-nowrap":""),children:y?`drop ${t.role}?`:t.role}),(0,j.jsx)(i.A,{className:"item-action",children:y?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(a.A,{id:"confirmDropRole",color:"danger",className:"round me-1",title:`confirm drop ${t.role}`,onClick:()=>{g(!1),O()},children:(0,j.jsx)("i",{className:"fa fa-check text-white"})}),(0,j.jsx)(a.A,{color:"black",className:"round",title:`Cancel drop ${t.role}`,onClick:()=>{g(!1)},children:(0,j.jsx)("i",{className:"fa fa-times text-white"})})]}):p?(0,j.jsx)(a.A,{id:`drop${t.role}`,color:"danger",className:"round",title:`Drop ${t.role}`,onClick:()=>{g(t),c(!1)},children:(0,j.jsx)("i",{className:"fa fa-minus text-white"})}):l?(0,j.jsx)(a.A,{color:"purple",className:"round",title:`Viewing ${t.role}`,children:(0,j.jsx)("i",{className:"fa fa-chevron-right"})}):null})]},t)};const O=function(e){let{items:t,itemType:r,toggleDropItem:n,isDropping:o,toggleCreate:l,isCreating:c,showForm:u}=e;return(0,j.jsxs)(s.A,{className:"floating-card-header",children:[(0,j.jsxs)(i.A,{children:[r,"s"]}),u&&t&&t.length?(0,j.jsxs)(i.A,{className:"text-end",children:[(0,j.jsx)(a.A,{color:"link",title:`Remove ${r}s`,className:"add-remove me-3",onClick:()=>{n(!o),l(!1)},children:(0,j.jsx)("i",{className:"fa fa-minus"})}),(0,j.jsx)(a.A,{color:"link",title:`Add ${r}`,className:"add-remove me-1",onClick:()=>{l(!c),n(!1)},children:(0,j.jsx)("i",{className:"fa fa-plus"})})]}):null]})};var w=r(3150),N=r(3628);const _=function(e){let{items:t,activeItem:r,showForm:o,baseUrl:s,itemType:i}=e;const[a,u]=(0,n.useState)(!1),[f,d]=(0,n.useState)(!1);(0,n.useEffect)((()=>{d(),u()}),[r,t]);const m=t&&[...t].sort(((e,t)=>e.role<t.role?-1:1));return(0,j.jsx)(p.tH,{onError:(e,t)=>(0,N.A)({error:{message:e.message,componentStack:t}}),FallbackComponent:w.A,children:(0,j.jsxs)("div",{className:"entity-manager",children:[(0,j.jsx)(O,{items:t,itemType:i,isDropping:a,toggleDropItem:u,isCreating:f,toggleCreate:d,showForm:o}),(0,j.jsx)(l.A,{className:"my-3",children:(0,j.jsxs)(c.A,{children:[m&&m.length?m.map((e=>(0,j.jsx)(A,{item:e,baseUrl:s,isActive:r===e.id,isDropping:a,toggleDropItem:u},e.id))):null,(t&&!t.length||f)&&(0,j.jsx)(v,{itemType:i,baseUrl:s,isDropping:a,toggleDropItem:u,isCreating:f,toggleCreate:d})]})})]})})};var k=r(4979),R=r(717);const S=(0,n.lazy)((()=>Promise.all([r.e(239),r.e(831)]).then(r.bind(r,3109)))),C={roleName:!1,canEdit:!1,superUsers:[],clusterUsers:[],standardUsers:[],showAttributes:!1};const P=function(){const{role_id:e,customer_id:t}=(0,o.g)(),r=(0,u.O$)(f.A,(e=>e.compute_stack_id)),p=(0,u.O$)(f.A,(e=>e.auth)),d=(0,u.O$)(f.A,(e=>e.url)),m=(0,u.O$)(f.A,(e=>e.roles),[r]),[h,y]=(0,n.useState)(!1),[g,v]=(0,n.useState)(C),x=`/o/${t}/i/${r}/roles`,A=(0,u.O$)(f.A,(e=>{var t;return null===(t=e.registration)||void 0===t?void 0:t.version})),[O,w]=(null===A||void 0===A?void 0:A.split("."))||[],N=parseFloat(`${O}.${w}`),P=(0,n.useCallback)((async()=>{y(!0),await(0,b.A)({auth:p,url:d}),await(0,R.A)({auth:p,url:d}),y(!1)}),[p,d]);return(0,n.useEffect)((()=>{if(m){const t=e&&m.find((t=>t.id===e));v({...g,roleName:t&&t.role,canEdit:t&&!t.permission.cluster_user&&!t.permission.super_user,clusterUsers:m.filter((e=>e.permission.cluster_user)),superUsers:m.filter((e=>e.permission.super_user)),standardUsers:m.filter((e=>!e.permission.super_user&&!e.permission.cluster_user)),showAttributes:!1})}else v(C)}),[e,m]),(0,n.useEffect)((()=>{P()}),[P,r]),(0,j.jsxs)(s.A,{id:"roles",children:[(0,j.jsxs)(i.A,{xl:"3",lg:"4",md:"5",xs:"12",children:[(0,j.jsx)(_,{showForm:!0,activeItem:e,items:g.superUsers,baseUrl:x,itemType:"super user"}),(0,j.jsx)(_,{showForm:!0,activeItem:e,items:g.clusterUsers,baseUrl:x,itemType:"cluster user"}),(0,j.jsx)(_,{showForm:!0,activeItem:e,items:g.standardUsers,baseUrl:x,itemType:"standard role"})]}),(0,j.jsxs)(i.A,{xl:"9",lg:"8",md:"7",xs:"12",children:[(0,j.jsxs)(s.A,{className:"floating-card-header",children:[g.canEdit&&(0,j.jsxs)(i.A,{children:["edit role > ",g.roleName]}),(0,j.jsxs)(i.A,{className:"text-md-end",children:[g.canEdit&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(a.A,{color:"link",tabIndex:"0",title:"Show Attributes",onClick:()=>v({...g,showAttributes:!g.showAttributes}),children:[(0,j.jsx)("span",{className:"me-2",children:"show all attributes"}),(0,j.jsx)("i",{className:"fa fa-lg fa-toggle-"+(g.showAttributes?"on":"off")})]}),(0,j.jsx)("span",{className:"mx-3 text",children:"|"})]}),(0,j.jsxs)(a.A,{color:"link",onClick:P,className:"me-2",children:[(0,j.jsx)("span",{className:"me-2",children:"refresh roles"}),(0,j.jsx)("i",{title:"Refresh Roles",className:"fa "+(h?"fa-spinner fa-spin":"fa-sync-alt")})]})]})]}),g.canEdit?(0,j.jsx)(l.A,{className:"my-3",children:(0,j.jsx)(c.A,{className:"full-height",children:(0,j.jsx)(n.Suspense,{fallback:(0,j.jsx)(k.A,{header:" ",spinner:!0}),children:(0,j.jsx)(S,{showAttributes:g.showAttributes,fetchRoles:P})})})}):(0,j.jsx)(l.A,{className:"my-3",children:(0,j.jsx)(c.A,{children:e?(0,j.jsxs)("div",{className:"empty-prompt",children:["Super Users and Cluster Users have full access to all"," ",N>=4.2?"databases":"schemas",", tables, and attributes."]}):(0,j.jsx)("div",{className:"empty-prompt",children:"Please choose or add a role to manage it."})})})]})]})}},2765:(e,t,r)=>{r.d(t,{A:()=>o});var n=r(127);const o=async e=>{let{auth:t,url:r,role:o,permission:s}=e;return(0,n.A)({operation:{operation:"add_role",role:o,permission:s},auth:t,url:r})}},2415:(e,t,r)=>{r.d(t,{A:()=>s});var n=r(127),o=r(5269);const s=async e=>{let{auth:t,url:r}=e;const s=await(0,n.A)({operation:{operation:"list_roles"},auth:t,url:r}),i=[...Array.isArray(s)?s:[]].sort(((e,t)=>e.role.toLowerCase()>t.role.toLowerCase()?1:-1));return o.A.update((e=>{e.roles=i})),i}},6196:(e,t,r)=>{r.d(t,{A:()=>n});const n=e=>e.match(/^[a-zA-Z_]+$/)},9708:(e,t,r)=>{r.d(t,{A:()=>g});var n=r(9950),o=r(1942),s=r.n(o),i=r(1497);function a(e){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(e)}var l=["className","cssModule","tag","innerRef"];function c(){return c=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},c.apply(this,arguments)}function u(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},s=Object.keys(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function f(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function p(e,t){return p=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},p(e,t)}function d(e){var t=function(){if("undefined"===typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"===typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=h(e);if(t){var o=h(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return function(e,t){if(t&&("object"===a(t)||"function"===typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return m(e)}(this,r)}}function m(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function h(e){return h=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},h(e)}var y={children:s().node,tag:i.Wx,innerRef:s().oneOfType([s().object,s().func,s().string]),className:s().string,cssModule:s().object},b=function(e){!function(e,t){if("function"!==typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&p(e,t)}(a,e);var t,r,o,s=d(a);function a(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,a),(t=s.call(this,e)).getRef=t.getRef.bind(m(t)),t.submit=t.submit.bind(m(t)),t}return t=a,(r=[{key:"getRef",value:function(e){this.props.innerRef&&this.props.innerRef(e),this.ref=e}},{key:"submit",value:function(){this.ref&&this.ref.submit()}},{key:"render",value:function(){var e=this.props,t=e.className,r=e.cssModule,o=e.tag,s=void 0===o?"form":o,a=e.innerRef,f=u(e,l),p=(0,i.qO)(t,r);return n.createElement(s,c({},f,{ref:a,className:p}))}}])&&f(t.prototype,r),o&&f(t,o),Object.defineProperty(t,"prototype",{writable:!1}),a}(n.Component);b.propTypes=y;const g=b},5488:(e,t,r)=>{r.d(t,{A:()=>v});var n=r(9950),o=r(1942),s=r.n(o),i=r(8738),a=r.n(i),l=r(1497);function c(e){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c(e)}var u=["className","cssModule","type","bsSize","valid","invalid","tag","addon","plaintext","innerRef"];function f(){return f=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},f.apply(this,arguments)}function p(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},s=Object.keys(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(n=0;n<s.length;n++)r=s[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function d(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function m(e,t){return m=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},m(e,t)}function h(e){var t=function(){if("undefined"===typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"===typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=b(e);if(t){var o=b(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return function(e,t){if(t&&("object"===c(t)||"function"===typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return y(e)}(this,r)}}function y(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function b(e){return b=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},b(e)}var g={children:s().node,type:s().string,size:s().oneOfType([s().number,s().string]),bsSize:s().string,valid:s().bool,invalid:s().bool,tag:l.Wx,innerRef:s().oneOfType([s().object,s().func,s().string]),plaintext:s().bool,addon:s().bool,className:s().string,cssModule:s().object},j=function(e){!function(e,t){if("function"!==typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&m(e,t)}(i,e);var t,r,o,s=h(i);function i(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,i),(t=s.call(this,e)).getRef=t.getRef.bind(y(t)),t.focus=t.focus.bind(y(t)),t}return t=i,(r=[{key:"getRef",value:function(e){this.props.innerRef&&this.props.innerRef(e),this.ref=e}},{key:"focus",value:function(){this.ref&&this.ref.focus()}},{key:"render",value:function(){var e=this.props,t=e.className,r=e.cssModule,o=e.type,s=void 0===o?"text":o,i=e.bsSize,c=e.valid,d=e.invalid,m=e.tag,h=e.addon,y=e.plaintext,b=e.innerRef,g=p(e,u),j=["switch","radio","checkbox"].indexOf(s)>-1,v="select"===s,x="range"===s,A=m||(v||"textarea"===s?s:"input"),O="form-control";y?(O="".concat(O,"-plaintext"),A=m||"input"):x?O="form-range":v?O="form-select":j&&(O=h?null:"form-check-input"),g.size&&/\D/g.test(g.size)&&((0,l.mc)('Please use the prop "bsSize" instead of the "size" to bootstrap\'s input sizing.'),i=g.size,delete g.size);var w=(0,l.qO)(a()(t,d&&"is-invalid",c&&"is-valid",!!i&&(v?"form-select-".concat(i):"form-control-".concat(i)),O),r);return("input"===A||m&&"function"===typeof m)&&(g.type="switch"===s?"checkbox":s),g.children&&!y&&"select"!==s&&"string"===typeof A&&"select"!==A&&((0,l.mc)('Input with a type of "'.concat(s,'" cannot have children. Please use "value"/"defaultValue" instead.')),delete g.children),n.createElement(A,f({},g,{ref:b,className:w,"aria-invalid":d}))}}])&&d(t.prototype,r),o&&d(t,o),Object.defineProperty(t,"prototype",{writable:!1}),i}(n.Component);j.propTypes=g;const v=j}}]);