/
snap
/
lxd
/
current
/
share
/
lxd-ui
/
assets
/
File Upload :
llllll
Current File: //snap/lxd/current/share/lxd-ui/assets/EditStorageBucketPanel-k9jgAmS0.js
import{a_ as S,C as p,ax as P,az as y,ay as I,cx as q,cX as K,bM as f,u as g,A as B,q as d,ah as U,d as i,r as v,l as F,F as w,c as _,j as r,n as E,y as z,aQ as A,v as R,cY as O,co as D,i as Q,e as H,aj as V,R as G}from"./index-B3cgCbnJ.js";import{u as L}from"./usePanelParams-CZsrUgz_.js";import{A as M}from"./AutoExpandingTextArea-BmFqLvbw.js";import{S as Y}from"./StoragePoolSelector-_Ij9bIB_.js";import{D as J}from"./DiskSizeSelector-CIkNkBL4.js";import{g as N}from"./storageBucket-Ct9MZnMG.js";const x=["can_delete","can_edit"],X=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(p).then(n=>n.metadata.map(o=>({...o,pool:e})))},W=async(e,a)=>{const t=(await q(e)).filter(o=>K(o.driver)).map(async o=>X(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),S(o,n),f(o,t,x),fetch(`/1.0/storage-pools/${encodeURIComponent(e)}/buckets/${encodeURIComponent(s)}?${o.toString()}`).then(p).then(c=>({...c.metadata,pool:e}))},pe=async(e,a,s,t)=>{const n=new URLSearchParams;return n.set("project",a),S(n,t),fetch(`/1.0/storage-pools/${encodeURIComponent(s)}/buckets?${n.toString()}`,{method:"POST",headers:{"Content-Type":"application/json"},body:e}).then(p).then(o=>o)},ee=async(e,a,s,t)=>{const n=new URLSearchParams;n.set("project",s),S(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(p)},b=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(p)},he=async(e,a)=>{const s=[];return new Promise((t,n)=>{Promise.allSettled(e.map(async o=>{const c={name:o.name,type:"bucket",href:N(o.name,o.pool,a)};return b(o.name,o.pool,a).then(()=>{P(s,c),y(s,e.length,t)}).catch(u=>{I(s,u instanceof Error?u.message:"",c),y(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(p).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(p).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",headers:{"Content-Type":"application/json"},body:e}).then(p).then(o=>o)},ye=async(e,a,s,t,n)=>{const o=new URLSearchParams;o.set("project",t),S(o,n),await fetch(`/1.0/storage-pools/${encodeURIComponent(s)}/buckets/${encodeURIComponent(e)}/keys/${encodeURIComponent(a.name)}?${o.toString()}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}).then(p)},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(p)},Se=async(e,a,s)=>{const t=[];return new Promise((n,o)=>{Promise.allSettled(a.map(async c=>{const u={name:c.name,type:"bucket-key",href:N(e.name,e.pool,s)};return se(e.name,c.name,e.pool,s).then(()=>{P(t,u),y(t,a.length,n)}).catch(l=>{I(t,l instanceof Error?l.message:"",u),y(t,a.length,n)})})).catch(o)})},fe=e=>{const{isFineGrained:a}=g();return B({queryKey:[d.storage,e,d.buckets],queryFn:async()=>W(a,e)})},Be=(e,a,s,t)=>{const{isFineGrained:n}=g();return B({queryKey:[d.storage,a,s,d.buckets,e,t],queryFn:async()=>Z(a,s,e,n,t??null)})},xe=(e,a,s)=>{const{isFineGrained:t}=g();return B({queryKey:[d.storage,e.pool,s,d.buckets,e.name,d.keys,a],queryFn:async()=>ne(e,a,t,s)})},Ce=(e,a)=>{const{isFineGrained:s}=g();return B({queryKey:[d.storage,e.pool,a,d.buckets,e.name,d.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:u}=$(),{project:l}=w(),h=(l==null?void 0:l.name)||"",m=_(),C=i.useToastNotification(),j=()=>{m(`/ui/project/${l==null?void 0:l.name}/storage/buckets`),C.success(r.jsxs(r.Fragment,{children:["Storage bucket ",r.jsx(E,{bold:!0,type:"bucket",value:e.name})," ","deleted."]}))},k=()=>{o(!0),b(e.name,e.pool,h).then(j).catch(T=>{t.failure("Storage bucket deletion failed",T)}).finally(()=>{o(!1),c.invalidateQueries({queryKey:[d.storage,h,d.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:k},appearance:s?"default":"base",className:a,shiftClickEnabled:!0,showShiftClickHint:!0,disabled:!u(e),onHoverText:u(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=L(),{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(A),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(u=>v.cloneElement(u,{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(O).filter(c=>c!==D),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=L(),s=i.useNotify(),t=i.useToastNotification(),{project:n}=w(),o=F(),c=()=>{a.clear(),s.clear()},u=m=>{t.success(r.jsxs(r.Fragment,{children:["Bucket"," ",r.jsx(G,{type:"bucket",value:m,to:`/ui/project/${encodeURIComponent((n==null?void 0:n.name)??"")}/storage/buckets`})," ","updated."]})),c()},l=Q({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:m=>{const C={name:m.name,config:{size:m.size},description:m.description};ee(C,m.pool,(n==null?void 0:n.name)||"",m.target).then(()=>{o.invalidateQueries({queryKey:[d.storage,e.pool,(n==null?void 0:n.name)??"",d.buckets,e.name]}),o.invalidateQueries({queryKey:[d.storage,(n==null?void 0:n.name)??"",d.buckets]}),u(m.name)}).catch(j=>{l.setSubmitting(!1),s.failure("Bucket update failed",j)})}}),h=(l.values.description!==e.description?1:0)+(l.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(i.ScrollableContainer,{dependencies:[s.notification],belowIds:["panel-footer"],children:r.jsx(re,{formik:l,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:l.isSubmitting,onClick:()=>void l.submitForm(),className:"u-no-margin--bottom",disabled:!l.isValid||l.isSubmitting||h===0,children:h===0?"Save changes":`Save ${h} ${V("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,Se as g,ge as h,xe as i,ye as j,Be as k,$ as u};
Copyright ©2k19 -
Hexid
|
Tex7ure