/
snap
/
lxd
/
35210
/
share
/
lxd-ui
/
assets
/
File Upload :
llllll
Current File: //snap/lxd/35210/share/lxd-ui/assets/EditStorageBucketPanel-CgvzJxUU.js
import{aW as y,B as m,av as P,ax as S,aw as I,c9 as q,cD as T,b9 as f,u as g,z as B,q as l,af as U,d as i,r as v,l as F,F as w,c as K,j as r,m as E,x as z,aM as _,t as R,cE as D,c8 as O,i as A,e as H,ah as Q,R as V}from"./index-dL2n30-Z.js";import{u as b}from"./usePanelParams-BJBr0ywH.js";import{S as G}from"./ScrollableContainer-ceiHesUW.js";import{A as M}from"./AutoExpandingTextArea-CQuEMXHF.js";import{S as Y}from"./StoragePoolSelector-BbIrdWMX.js";import{D as J}from"./DiskSizeSelector-DZsA03GF.js";const x=["can_delete","can_edit"],W=async(e,a,s)=>{const t=new URLSearchParams;return t.set("project",s),t.set("recursion","1"),f(t,a,x),fetch(`/1.0/storage-pools/${encodeURIComponent(e)}/buckets?${t.toString()}`).then(m).then(n=>n.metadata.map(o=>({...o,pool:e})))},X=async(e,a)=>{const t=(await q(e)).filter(o=>T(o.driver)).map(async o=>W(o.name,e,a));return(await Promise.all(t)).flat()},Z=async(e,a,s,t,n)=>{const o=new URLSearchParams;return o.set("project",a),y(o,n),f(o,t,x),fetch(`/1.0/storage-pools/${encodeURIComponent(e)}/buckets/${encodeURIComponent(s)}?${o.toString()}`).then(m).then(c=>({...c.metadata,pool:e}))},pe=async(e,a,s,t)=>{const n=new URLSearchParams;return n.set("project",a),y(n,t),fetch(`/1.0/storage-pools/${encodeURIComponent(s)}/buckets?${n.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:e}).then(m).then(o=>o)},ee=async(e,a,s,t)=>{const n=new URLSearchParams;n.set("project",s),y(n,t),await fetch(`/1.0/storage-pools/${encodeURIComponent(a)}/buckets/${encodeURIComponent(e.name)}?${n.toString()}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(m)},k=async(e,a,s)=>{const t=new URLSearchParams;t.set("project",s),await fetch(`/1.0/storage-pools/${encodeURIComponent(a)}/buckets/${encodeURIComponent(e)}?${t.toString()}`,{method:"DELETE"}).then(m)},he=async(e,a)=>{const s=[];return new Promise((t,n)=>{Promise.allSettled(e.map(async o=>k(o.name,o.pool,a).then(()=>{P(s),S(s,e.length,t)}).catch(c=>{I(s,c instanceof Error?c.message:""),S(s,e.length,t)}))).catch(n)})},te=async(e,a,s)=>{const t=new URLSearchParams;return t.set("project",s),t.set("recursion","1"),f(t,a,x),fetch(`/1.0/storage-pools/${encodeURIComponent(e.pool)}/buckets/${encodeURIComponent(e.name)}/keys?${t.toString()}`).then(m).then(n=>n.metadata)},ne=async(e,a,s,t)=>{const n=new URLSearchParams;return n.set("project",t),f(n,s,x),fetch(`/1.0/storage-pools/${encodeURIComponent(e.pool)}/buckets/${encodeURIComponent(e.name)}/keys/${encodeURIComponent(a)}?${n.toString()}`).then(m).then(o=>o.metadata)},ge=async(e,a,s,t)=>{const n=new URLSearchParams;return n.set("project",a),fetch(`/1.0/storage-pools/${encodeURIComponent(s)}/buckets/${encodeURIComponent(t)}/keys?${n.toString()}`,{method:"POST",body:e}).then(m).then(o=>o)},Se=async(e,a,s,t,n)=>{const o=new URLSearchParams;o.set("project",t),y(o,n),await fetch(`/1.0/storage-pools/${encodeURIComponent(s)}/buckets/${encodeURIComponent(e)}/keys/${encodeURIComponent(a.name)}?${o.toString()}`,{method:"PUT",body:JSON.stringify(a)}).then(m)},se=async(e,a,s,t)=>{const n=new URLSearchParams;n.set("project",t),await fetch(`/1.0/storage-pools/${encodeURIComponent(s)}/buckets/${encodeURIComponent(e)}/keys/${encodeURIComponent(a)}?${n.toString()}`,{method:"DELETE"}).then(m)},ye=async(e,a,s)=>{const t=[];return new Promise((n,o)=>{Promise.allSettled(a.map(async c=>se(e.name,c.name,e.pool,s).then(()=>{P(t),S(t,a.length,n)}).catch(p=>{I(t,p instanceof Error?p.message:""),S(t,a.length,n)}))).catch(o)})},fe=e=>{const{isFineGrained:a}=g();return B({queryKey:[l.storage,e,l.buckets],queryFn:async()=>X(a,e)})},Be=(e,a,s,t)=>{const{isFineGrained:n}=g();return B({queryKey:[l.storage,a,s,l.buckets,e,t],queryFn:async()=>Z(a,s,e,n,t??null)})},xe=(e,a,s)=>{const{isFineGrained:t}=g();return B({queryKey:[l.storage,e.pool,s,l.buckets,e.name,l.keys,a],queryFn:async()=>ne(e,a,t,s)})},Ce=(e,a)=>{const{isFineGrained:s}=g();return B({queryKey:[l.storage,e.pool,a,l.buckets,e.name,l.keys],queryFn:async()=>te(e,s,a)})},$=()=>{const{isFineGrained:e}=g();return{canDeleteBucket:t=>U(e,"can_delete",t==null?void 0:t.access_entitlements),canEditBucket:t=>U(e,"can_edit",t==null?void 0:t.access_entitlements)}},ae=({bucket:e,classname:a,isDetailPage:s})=>{const t=i.useNotify(),[n,o]=v.useState(!1),c=F(),{canDeleteBucket:p}=$(),{project:d}=w(),h=(d==null?void 0:d.name)||"",u=K(),C=i.useToastNotification(),j=()=>{u(`/ui/project/${d==null?void 0:d.name}/storage/buckets`),C.success(r.jsxs(r.Fragment,{children:["Storage bucket ",r.jsx(E,{bold:!0,type:"bucket",value:e.name})," ","deleted."]}))},L=()=>{o(!0),k(e.name,e.pool,h).then(j).catch(N=>{t.failure("Storage bucket deletion failed",N)}).finally(()=>{o(!1),c.invalidateQueries({queryKey:[l.storage,h,l.buckets]})})};return r.jsxs(i.ConfirmationButton,{loading:n,confirmationModalProps:{title:"Confirm delete",children:r.jsxs("p",{children:["This will permanently delete bucket"," ",r.jsx(E,{type:"bucket",value:e.name,bold:!0}),".",r.jsx("br",{}),"This action cannot be undone, and can result in data loss."]}),confirmButtonLabel:"Delete",onConfirm:L},appearance:s?"default":"base",className:a,shiftClickEnabled:!0,showShiftClickHint:!0,disabled:!p(e),onHoverText:p(e)?"Delete bucket":"You do not have permission to delete this bucket.",children:[r.jsx(i.Icon,{name:"delete"}),s&&r.jsx("span",{children:"Delete"})]})},oe=({bucket:e,classname:a,isDetailPage:s})=>{const t=b(),{canEditBucket:n}=$();return r.jsxs(i.Button,{className:a,appearance:s?"default":"base",hasIcon:!0,onClick:()=>{t.openEditStorageBucket(e.name,e.pool,e.location)},title:n(e)?"Edit bucket":"You do not have permission to edit this bucket",children:[r.jsx(i.Icon,{name:"edit"}),s&&r.jsx("span",{children:"Configure"})]},`${e.name}-edit`)},je=({bucket:e,className:a,isDetailPage:s})=>{const t=z(_),n=s?t?"p-contextual-menu__link":"p-segmented-control__button":"",o=[r.jsx(oe,{classname:R(n,"has-icon",{"is-dense":!s}),bucket:e,isDetailPage:s},"edit"),r.jsx(ae,{classname:R(n,"has-icon",{"is-dense":!s}),bucket:e,isDetailPage:s},"delete")];return s?r.jsx(r.Fragment,{children:t?r.jsx(i.ContextualMenu,{closeOnOutsideClick:!1,toggleLabel:"Actions",position:"left",hasToggleIcon:!0,title:"actions",children:c=>r.jsx("span",{children:[...o].map(p=>v.cloneElement(p,{onClose:c}))})}):r.jsx("div",{className:"p-segmented-control",children:r.jsx("div",{className:"p-segmented-control__list",children:o})})}):r.jsx(i.List,{inline:!0,className:R(a,"actions-list"),items:o})},re=({formik:e,bucket:a})=>{const{canEditBucket:s}=$(),t=c=>({id:c,name:c,onBlur:e.handleBlur,onChange:e.handleChange,value:e.values[c]??"",error:e.touched[c]?e.errors[c]:null,placeholder:`Enter ${c.replaceAll("_"," ")}`}),n=!!a,o=!n||s(a)?"":"You do not have permission to modify this bucket";return r.jsxs(i.Form,{onSubmit:e.handleSubmit,className:"bucket-create-form",children:[r.jsx(i.Input,{type:"submit",hidden:!0,value:"Hidden input"}),r.jsx(Y,{value:e.values.pool,setValue:c=>void e.setFieldValue("pool",c),invalidDrivers:Object.keys(D).filter(c=>c!==O),selectProps:{id:"bucket-create-pool",label:"Storage pool",disabled:!!o||n,help:n?"Storage bucket pool can't be changed":e.errors.pool?null:"Pool must have a Ceph Object driver",error:e.errors.pool,onBlur:e.handleBlur,takeFocus:!0,required:!0}}),r.jsx(i.Input,{...t("name"),type:"text",label:"Name",required:!0,disabled:!!o||n,help:n&&"Storage bucket name can't be changed",title:o}),r.jsx(J,{label:"Size",value:e.values.size,setMemoryLimit:c=>{e.setFieldValue("size",c)},disabled:!!o,disabledReason:o}),r.jsx(M,{...t("description"),label:"Description",disabled:!!o,title:o})]})},Re=({bucket:e})=>{const a=b(),s=i.useNotify(),t=i.useToastNotification(),{project:n}=w(),o=F(),c=()=>{a.clear(),s.clear()},p=u=>{t.success(r.jsxs(r.Fragment,{children:["Bucket"," ",r.jsx(V,{type:"bucket",value:u,to:`/ui/project/${encodeURIComponent((n==null?void 0:n.name)??"")}/storage/buckets`})," ","updated."]})),c()},d=A({initialValues:{name:e==null?void 0:e.name,pool:e==null?void 0:e.pool,size:e==null?void 0:e.config.size,description:e==null?void 0:e.description,target:e==null?void 0:e.location},enableReinitialize:!0,onSubmit:u=>{const C={name:u.name,config:{size:u.size},description:u.description};ee(C,u.pool,(n==null?void 0:n.name)||"",u.target).then(()=>{o.invalidateQueries({queryKey:[l.storage,e.pool,(n==null?void 0:n.name)??"",l.buckets,e.name]}),o.invalidateQueries({queryKey:[l.storage,(n==null?void 0:n.name)??"",l.buckets]}),p(u.name)}).catch(j=>{d.setSubmitting(!1),s.failure("Bucket update failed",j)})}}),h=(d.values.description!==e.description?1:0)+(d.values.size!==e.config.size?1:0);return r.jsx(r.Fragment,{children:r.jsxs(i.SidePanel,{children:[r.jsx(i.SidePanel.Header,{children:r.jsxs(i.SidePanel.HeaderTitle,{children:["Edit storage bucket ",e.name]})}),r.jsx(H,{className:"u-no-padding"}),r.jsx(i.SidePanel.Content,{className:"u-no-padding",children:r.jsx(G,{dependencies:[s.notification],belowIds:["panel-footer"],children:r.jsx(re,{formik:d,bucket:e})})}),r.jsxs(i.SidePanel.Footer,{className:"u-align--right",children:[r.jsx(i.Button,{appearance:"base",onClick:c,className:"u-no-margin--bottom",children:"Cancel"}),r.jsx(i.ActionButton,{appearance:"positive",loading:d.isSubmitting,onClick:()=>void d.submitForm(),className:"u-no-margin--bottom",disabled:!d.isValid||d.isSubmitting||h===0,children:h===0?"Save changes":`Save ${h} ${Q("change",h)}`})]})]})})};export{Re as E,re as S,Ce as a,fe as b,pe as c,he as d,je as e,se as f,ye as g,ge as h,xe as i,Se as j,Be as k,$ as u};
Copyright ©2k19 -
Hexid
|
Tex7ure