| Current Path : /snap/lxd/38450/share/lxd-ui/assets/ |
| Current File : //snap/lxd/38450/share/lxd-ui/assets/EditStorageBucketPanel-CAwD6Ilg.js |
import{bD as j,R as m,O as h,ec as P,aQ as E,aS as y,aR as I,dF as K,ed as _,cH as f,u as S,J as b,x as l,au as R,d as i,r as v,v as F,S as w,c as z,j as r,z as U,H as O,bi as A,s as $,ee as D,dt as H,k as Q,p as V,T as G,w as J}from"./index-BsQN_SZU.js";import{u as L}from"./usePanelParams-CNAJZsSX.js";import{A as M}from"./AutoExpandingTextArea-Bd-45rZK.js";import{S as Y}from"./StoragePoolSelector-Bvqvds5t.js";import{D as W}from"./DiskSizeSelector-C9kWj54D.js";const B=["can_delete","can_edit"],X=async(e,s,n)=>{const t=new URLSearchParams;return t.set("project",n),t.set("recursion","1"),f(t,s,B),fetch(`${m}/1.0/storage-pools/${encodeURIComponent(e)}/buckets?${t.toString()}`).then(h).then(a=>a.metadata.map(o=>({...o,pool:e})))},Z=async(e,s)=>{const t=(await K(e)).filter(o=>_(o.driver)).map(async o=>X(o.name,e,s));return(await Promise.all(t)).flat()},ee=async(e,s,n,t,a)=>{const o=new URLSearchParams;return o.set("project",s),j(o,a),f(o,t,B),fetch(`${m}/1.0/storage-pools/${encodeURIComponent(e)}/buckets/${encodeURIComponent(n)}?${o.toString()}`).then(h).then(c=>({...c.metadata,pool:e}))},pe=async(e,s,n,t)=>{const a=new URLSearchParams;return a.set("project",s),j(a,t),fetch(`${m}/1.0/storage-pools/${encodeURIComponent(n)}/buckets?${a.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:e}).then(h).then(o=>o)},te=async(e,s,n,t)=>{const a=new URLSearchParams;a.set("project",n),j(a,t),await fetch(`${m}/1.0/storage-pools/${encodeURIComponent(s)}/buckets/${encodeURIComponent(e.name)}?${a.toString()}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(h)},T=async(e,s,n)=>{const t=new URLSearchParams;t.set("project",n),await fetch(`${m}/1.0/storage-pools/${encodeURIComponent(s)}/buckets/${encodeURIComponent(e)}?${t.toString()}`,{method:"DELETE"}).then(h)},he=async(e,s)=>{const n=[];return new Promise((t,a)=>{Promise.allSettled(e.map(async o=>{const c={name:o.name,type:"bucket",href:P(o.name,o.pool,s)};return T(o.name,o.pool,s).then(()=>{E(n,c),y(n,e.length,t)}).catch(d=>{I(n,d instanceof Error?d.message:"",c),y(n,e.length,t)})})).catch(a)})},ne=async(e,s,n)=>{const t=new URLSearchParams;return t.set("project",n),t.set("recursion","1"),f(t,s,B),fetch(`${m}/1.0/storage-pools/${encodeURIComponent(e.pool)}/buckets/${encodeURIComponent(e.name)}/keys?${t.toString()}`).then(h).then(a=>a.metadata)},se=async(e,s,n,t)=>{const a=new URLSearchParams;return a.set("project",t),f(a,n,B),fetch(`${m}/1.0/storage-pools/${encodeURIComponent(e.pool)}/buckets/${encodeURIComponent(e.name)}/keys/${encodeURIComponent(s)}?${a.toString()}`).then(h).then(o=>o.metadata)},ge=async(e,s,n,t)=>{const a=new URLSearchParams;return a.set("project",s),fetch(`${m}/1.0/storage-pools/${encodeURIComponent(n)}/buckets/${encodeURIComponent(t)}/keys?${a.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:e}).then(h).then(o=>o)},Se=async(e,s,n,t,a)=>{const o=new URLSearchParams;o.set("project",t),j(o,a),await fetch(`${m}/1.0/storage-pools/${encodeURIComponent(n)}/buckets/${encodeURIComponent(e)}/keys/${encodeURIComponent(s.name)}?${o.toString()}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)}).then(h)},ae=async(e,s,n,t)=>{const a=new URLSearchParams;a.set("project",t),await fetch(`${m}/1.0/storage-pools/${encodeURIComponent(n)}/buckets/${encodeURIComponent(e)}/keys/${encodeURIComponent(s)}?${a.toString()}`,{method:"DELETE"}).then(h)},ye=async(e,s,n)=>{const t=[];return new Promise((a,o)=>{Promise.allSettled(s.map(async c=>{const d={name:c.name,type:"bucket-key",href:P(e.name,e.pool,n)};return ae(e.name,c.name,e.pool,n).then(()=>{E(t,d),y(t,s.length,a)}).catch(u=>{I(t,u instanceof Error?u.message:"",d),y(t,s.length,a)})})).catch(o)})},je=e=>{const{isFineGrained:s}=S();return b({queryKey:[l.storage,e,l.buckets],queryFn:async()=>Z(s,e)})},fe=(e,s,n,t)=>{const{isFineGrained:a}=S();return b({queryKey:[l.storage,s,n,l.buckets,e,t],queryFn:async()=>ee(s,n,e,a,t??null)})},be=(e,s,n)=>{const{isFineGrained:t}=S();return b({queryKey:[l.storage,e.pool,n,l.buckets,e.name,l.keys,s],queryFn:async()=>se(e,s,t,n)})},Be=(e,s)=>{const{isFineGrained:n}=S();return b({queryKey:[l.storage,e.pool,s,l.buckets,e.name,l.keys],queryFn:async()=>ne(e,n,s)})},k=()=>{const{isFineGrained:e}=S();return{canDeleteBucket:t=>R(e,"can_delete",t?.access_entitlements),canEditBucket:t=>R(e,"can_edit",t?.access_entitlements)}},oe=({bucket:e,classname:s,isDetailPage:n})=>{const t=i.useNotify(),[a,o]=v.useState(!1),c=F(),{canDeleteBucket:d}=k(),{project:u}=w(),g=u?.name||"",p=z(),x=i.useToastNotification(),C=()=>{p(`${m}/ui/project/${u?.name}/storage/buckets`),x.success(r.jsxs(r.Fragment,{children:["Storage bucket ",r.jsx(U,{bold:!0,type:"bucket",value:e.name})," ","deleted."]}))},N=()=>{o(!0),T(e.name,e.pool,g).then(C).catch(q=>{t.failure("Storage bucket deletion failed",q)}).finally(()=>{o(!1),c.invalidateQueries({queryKey:[l.storage,g,l.buckets]})})};return r.jsxs(i.ConfirmationButton,{loading:a,confirmationModalProps:{title:"Confirm delete",children:r.jsxs("p",{children:["This will permanently delete bucket"," ",r.jsx(U,{type:"bucket",value:e.name,bold:!0}),".",r.jsx("br",{}),"This action cannot be undone, and can result in data loss."]}),confirmButtonLabel:"Delete",onConfirm:N},appearance:n?"default":"base",className:s,shiftClickEnabled:!0,showShiftClickHint:!0,disabled:!d(e),onHoverText:d(e)?"Delete bucket":"You do not have permission to delete this bucket.",children:[r.jsx(i.Icon,{name:"delete"}),n&&r.jsx("span",{children:"Delete"})]})},re=({bucket:e,classname:s,isDetailPage:n})=>{const t=L(),{canEditBucket:a}=k();return r.jsxs(i.Button,{className:s,appearance:n?"default":"base",hasIcon:!0,onClick:()=>{t.openEditStorageBucket(e.name,e.pool,e.location)},title:a(e)?"Edit bucket":"You do not have permission to edit this bucket",children:[r.jsx(i.Icon,{name:"edit"}),n&&r.jsx("span",{children:"Configure"})]},`${e.name}-edit`)},xe=({bucket:e,className:s,isDetailPage:n})=>{const t=O(A),a=n?t?"p-contextual-menu__link":"p-segmented-control__button":"",o=[r.jsx(re,{classname:$(a,"has-icon",{"is-dense":!n}),bucket:e,isDetailPage:n},"edit"),r.jsx(oe,{classname:$(a,"has-icon",{"is-dense":!n}),bucket:e,isDetailPage:n},"delete")];return n?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(d=>v.cloneElement(d,{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:$(s,"actions-list"),items:o})},ce=({formik:e,bucket:s})=>{const{canEditBucket:n}=k(),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("_"," ")}`}),a=!!s,o=!a||n(s)?"":"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=>{e.setFieldValue("pool",c)},invalidDrivers:Object.keys(D).filter(c=>c!==H),selectProps:{id:"bucket-create-pool",label:"Storage pool",disabled:!!o||a,help:a?"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||a,help:a&&"Storage bucket name can't be changed",title:o}),r.jsx(W,{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})]})},Ce=({bucket:e})=>{const s=L(),n=i.useNotify(),t=i.useToastNotification(),{project:a}=w(),o=F(),c=()=>{s.clear(),n.clear()},d=p=>{t.success(r.jsxs(r.Fragment,{children:["Storage bucket"," ",r.jsx(J,{type:"bucket",value:p,to:`${m}/ui/project/${encodeURIComponent(a?.name??"")}/storage/buckets`})," ","updated."]})),c()},u=Q({initialValues:{name:e?.name,pool:e?.pool,size:e?.config.size,description:e?.description,target:e?.location},enableReinitialize:!0,onSubmit:p=>{const x={name:p.name,config:{size:p.size},description:p.description};te(x,p.pool,a?.name||"",p.target).then(()=>{o.invalidateQueries({queryKey:[l.storage,e.pool,a?.name??"",l.buckets,e.name]}),o.invalidateQueries({queryKey:[l.storage,a?.name??"",l.buckets]}),d(p.name)}).catch(C=>{u.setSubmitting(!1),n.failure("Storage bucket update failed",C)})}}),g=(u.values.description!==e.description?1:0)+(u.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(V,{className:"u-no-padding"}),r.jsx(i.SidePanel.Content,{className:"u-no-padding",children:r.jsx(i.ScrollableContainer,{dependencies:[n.notification],belowIds:["panel-footer"],children:r.jsx(ce,{formik:u,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:u.isSubmitting,onClick:()=>{u.submitForm()},className:"u-no-margin--bottom",disabled:!u.isValid||u.isSubmitting||g===0,children:g===0?"Save changes":`Save ${g} ${G("change",g)}`})]})]})})};export{Ce as E,ce as S,Be as a,je as b,pe as c,he as d,xe as e,ae as f,ye as g,ge as h,be as i,Se as j,fe as k,k as u};