/
proc
/
3430793
/
root
/
snap
/
lxd
/
current
/
share
/
lxd-ui
/
assets
/
File Upload :
llllll
Current File: //proc/3430793/root/snap/lxd/current/share/lxd-ui/assets/StorageVolumeDetail-D0WeXAKi.js
import{r as V,j as e,d as s,s as $,l as v,c as q,t as O,m as U,R as I,q as C,cK as Z,G as ee,b as te,i as T,aW as ie,aD as re,cJ as le,f as Q,g as L,Y as ce,cL as H,aL as de,ak as me,al as pe,x as ue,aM as he,bs as ge,L as xe,bX as je,br as fe,ao as z,T as be,o as K,bT as oe,V as Y,aA as ye,aB as Se,ah as B,aj as Ce,n as Ne,bU as G,F as Ve,z as ke,e as Fe}from"./index-dL2n30-Z.js";import{R as we}from"./RenameHeader-BZc6vaTG.js";import{m as Re,i as _e,j as Ie,r as Le,k as se}from"./storage-volumes-DY5ibnP4.js";import{u as _,D as $e}from"./DeleteStorageVolumeBtn-BooO3e9W.js";import{S as ve}from"./StoragePoolSelectTable-OnqfmjE1.js";import{V as R}from"./VolumeLinkChip-BdiZokmn.js";import{S as Te}from"./StoragePoolSelector-BbIrdWMX.js";import{a as Ee,c as De}from"./useVolumes-DkjZCOr_.js";import{C as Pe}from"./ClusterMemberSelector-CzVwwYbB.js";import{S as Be}from"./StorageUsedBy-DczqZZyc.js";import{S as Ue,g as ze,u as Me,a as A,r as qe,b as Oe,d as Ke,c as Ae,V as J,f as Qe}from"./VolumeAddSnapshotBtn-DcXN7aNE.js";import{v as ne,a as He,M as W,b as Ye}from"./StorageVolumeForm-BktJTI1i.js";import{F as Ge}from"./FormFooterLayout-Bmq4RXkd.js";import{F as Je}from"./FormSubmitBtn-D3jUuO6-.js";import{T as We}from"./TabLinks-BqmE_r1L.js";import{S as Xe}from"./SnapshotForm-DR60de46.js";import{g as Ze,i as et}from"./snapshots-AS6hXv2C.js";import{I as tt}from"./ItemName-BzCTqTL3.js";import{S as ot}from"./SelectableMainTable-DeGTWeiA.js";import{S as st}from"./ScrollableTable-CQDmfMtz.js";import{S as nt}from"./SelectedTableNotification-BHmDbErh.js";import{B as at}from"./BulkDeleteButton-DzyTAjHk.js";import{u as it}from"./useSortTableData-8PACcjA7.js";import"./StoragePoolSize-BwIynhzl.js";import"./Meter-BBGrNnHA.js";import"./StoragePoolClusterMember-CcrqLmFp.js";import"./images-BNK9xDRN.js";import"./ExpandableList-Cjp4v1_P.js";import"./UsedByItem-Ber64JUd.js";import"./storageBucket-Bz2jIa5m.js";import"./FormMenuItem-DRePjRCl.js";import"./limits-CLEFMbq-.js";import"./AutoExpandingTextArea-CQuEMXHF.js";import"./scroll-Dmr9Jl9h.js";import"./instanceOptions-D4bz_1Ev.js";import"./ConfigFieldDescription-B5-bOr1x.js";import"./DiskSizeSelector-DZsA03GF.js";import"./ScrollableContainer-ceiHesUW.js";const rt=({close:t,migrate:o,storageVolume:c})=>{const[m,i]=V.useState(""),r=x=>{x.key==="Escape"&&t()},p=()=>{if(m){i("");return}t()},a=m?"Confirm migration":`Choose storage pool for volume ${c.name}`,h=e.jsx("div",{className:"migrate-instance-summary",children:e.jsxs("p",{children:["This will migrate volume ",e.jsx("strong",{children:c.name})," to storage pool ",e.jsx("b",{children:m}),"."]})});return e.jsx(s.Modal,{close:t,className:"migrate-instance-modal",title:a,buttonRow:e.jsxs("div",{id:"migrate-instance-actions",children:[e.jsx(s.Button,{className:"u-no-margin--bottom",type:"button","aria-label":"cancel migrate",appearance:"base",onClick:p,children:"Cancel"}),e.jsx(s.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",onClick:()=>{o(m)},disabled:!m,children:"Migrate"})]}),onKeyDown:r,children:m?h:e.jsx(ve,{onSelect:i,disablePool:{name:c.pool,reason:"Volume is already in this pool"}})})},lt=({volume:t,project:o,classname:c,onClose:m})=>{const i=$(),r=s.useToastNotification(),{openPortal:p,closePortal:a,isOpen:h,Portal:x}=s.usePortal(),g=v(),d=q(),[b,l]=V.useState(!1),{canEditVolume:n}=_(),u=(S,y)=>{const F=Z(t)?`/member/${encodeURIComponent(t.location)}`:"",f=`/ui/project/${encodeURIComponent(y.project)}/storage/pool/${encodeURIComponent(y.pool)}${F}/volumes/${encodeURIComponent(y.type)}/${encodeURIComponent(y.name)}`,w=`/ui/project/${encodeURIComponent(y.project)}/storage/pool/${encodeURIComponent(S)}${F}/volumes/${encodeURIComponent(y.type)}/${encodeURIComponent(y.name)}`,P=e.jsx(I,{type:"volume",value:y.name,to:w}),ae=e.jsx(I,{type:"pool",value:S,to:`/ui/project/${encodeURIComponent(y.project)}/storage/pool/${encodeURIComponent(S)}`});r.success(e.jsxs(e.Fragment,{children:["Volume ",P," successfully migrated to pool ",ae]})),window.location.pathname.startsWith(f)&&d(w)},j=(S,y,F)=>{l(!1),r.failure(`Migration failed for volume ${y} to pool ${F}`,S,e.jsx(R,{volume:t}))},N=(S,y,F)=>{j(new Error(S),y,F)},k=()=>{g.invalidateQueries({queryKey:[C.storage,t.name]}),l(!1)},E=S=>{l(!0),Re(t,S,t.project,t.location).then(y=>{i.set(y.metadata.id,()=>{u(S,t)},w=>{N(w,t.name,S)},k);const F=e.jsx(U,{bold:!0,type:"volume",value:t.name}),f=e.jsx(I,{type:"pool",value:S,to:`/ui/project/${encodeURIComponent(t.project)}/storage/pool/${encodeURIComponent(S)}`});r.info(e.jsxs(e.Fragment,{children:["Migration started for volume ",F," to pool ",f]})),g.invalidateQueries({queryKey:[C.storage,t.name,o]})}).catch(y=>{j(y,t.name,S)}).finally(()=>{D()})},D=()=>{a(),m==null||m()};return e.jsxs(e.Fragment,{children:[h&&e.jsx(x,{children:e.jsx(rt,{close:D,migrate:E,storageVolume:t})}),e.jsxs(s.ActionButton,{onClick:p,type:"button",className:O("u-no-margin--bottom has-icon",c),loading:b,disabled:!n(t)||b,title:n(t)?"Migrate volume":"You do not have permission to migrate this volume",children:[e.jsx(s.Icon,{name:"machines"}),e.jsx("span",{children:"Migrate"})]})]})},ct=({volume:t,close:o})=>{var b;const c=$(),m=s.useToastNotification(),i=e.jsx(R,{volume:t}),{hasBackupMetadataVersion:r}=ee(),{data:p}=te(),a=((b=p==null?void 0:p.environment)==null?void 0:b.backup_metadata_version_range)??[],h=l=>{const n=new URLSearchParams;n.set("project",t.project),ie(n,t.location);const u=`/1.0/storage-pools/${encodeURIComponent(t.pool)}/volumes/${encodeURIComponent(t.type)}/${encodeURIComponent(t.name)}/backups/${encodeURIComponent(l)}/export?${n.toString()}`,j=document.createElement("a");j.href=u,j.download=l,j.click(),window.URL.revokeObjectURL(u),m.success(e.jsxs(e.Fragment,{children:["Volume ",i," download started:",e.jsx("br",{}),e.jsx("a",{href:u,children:l})]}))},x=l=>{const n=new Date;return n.setHours(n.getHours()+l),n},g=l=>{const n=new Date().toISOString().replaceAll(":","-").split(".")[0],u=`${t.name}-${n}.tar${l.compression==="gzip"?".gz":""}`,j=JSON.stringify({name:u,expires_at:x(l.expirationHours).toISOString(),compression_algorithm:l.compression,volume_only:l.volumeOnly,optimized_storage:l.optimizedStorage,version:r?Number(l.exportVersion):void 0});_e(t,j).then(N=>{m.info(e.jsxs(e.Fragment,{children:["Backing up volume ",i,".",e.jsx("br",{}),"Download will start, when the export is ready."]})),c.set(N.metadata.id,()=>{h(u)},k=>m.failure(`Could not download volume ${t.name}`,new Error(k),i))}).catch(N=>m.failure(`Could not download volume ${t.name}`,N,i)).finally(()=>{o()})},d=T({initialValues:{compression:"gzip",exportVersion:"2",expirationHours:6,volumeOnly:!1,optimizedStorage:!0},onSubmit:l=>{g(l)}});return e.jsx(s.Modal,{close:o,className:"export-volume-modal",title:"Export Volume",buttonRow:e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{appearance:"base",className:"u-no-margin--bottom",type:"button",onClick:o,children:"Cancel"}),e.jsx(s.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",loading:d.isSubmitting,disabled:d.isSubmitting,onClick:()=>void d.submitForm(),children:"Export volume"})]}),children:e.jsxs(s.Form,{onSubmit:d.handleSubmit,children:[e.jsx(s.Select,{...d.getFieldProps("compression"),id:"project",label:"Compression",help:"No compression will be faster, but larger",options:[{value:"gzip",label:"Gzip"},{value:"none",label:"None"}]}),e.jsx(s.Select,{...d.getFieldProps("expirationHours"),id:"project",label:"Expiration",help:"Duration that the backup remains on the server",options:[{value:1,label:"1 hour"},{value:6,label:"6 hours"},{value:12,label:"12 hours"},{value:24,label:"1 day"},{value:72,label:"3 days"},{value:168,label:"7 days"}]}),r&&e.jsx(s.Select,{...d.getFieldProps("exportVersion"),id:"exportVersion",label:"Export version",help:"Lower versions allow imports on older LXD versions",options:a.map(l=>({value:l.toString(),label:l.toString()}))}),e.jsx(s.Input,{...d.getFieldProps("optimizedStorage"),type:"checkbox",label:"Use storage driver optimized format",help:"Can only be restored on a similar pool",checked:d.values.optimizedStorage}),e.jsx(s.Input,{...d.getFieldProps("volumeOnly"),type:"checkbox",label:"Export without volume snapshots",error:d.touched.volumeOnly?d.errors.volumeOnly:null,checked:d.values.volumeOnly}),e.jsx(s.Input,{type:"submit",hidden:!0,value:"Hidden input"})]})})},dt=({volume:t,classname:o,onClose:c})=>{const{openPortal:m,closePortal:i,isOpen:r,Portal:p}=s.usePortal(),{canManageVolumeBackups:a}=_(),h=()=>{i(),c==null||c()};return e.jsxs(e.Fragment,{children:[r&&e.jsx(p,{children:e.jsx(ct,{close:h,volume:t})}),e.jsxs(s.Button,{appearance:"default",className:O("u-no-margin--bottom has-icon",o),onClick:m,title:a(t)?"Export volume":"You do not have permission to export this volume.",disabled:!a(t),children:[e.jsx(s.Icon,{name:"export"}),e.jsx("span",{children:"Export"})]})]})},mt=({volume:t,close:o})=>{const c=s.useToastNotification(),m=V.useState(null),i=$(),{data:r=[],isLoading:p}=re(),{data:a}=le(t.pool),{data:h=[],isLoading:x}=Ee(t.project),g=u=>{const j={...t,name:u.name,project:u.project,pool:u.pool,location:u.location};c.success(e.jsxs(e.Fragment,{children:["Created volume ",e.jsx(R,{volume:j}),"."]}))},d=u=>{c.failure("Volume copy failed.",u,e.jsx(R,{volume:t}))},b=u=>{const j=u.name+"-copy";return de(j,h)},l=Q().shape({name:L().required("Volume name is required"),project:L().required(),pool:L().required(),location:L().optional()}).test("deduplicate","",async function(u){const{name:j,project:N,pool:k,location:E}=u;return await ce(j,N||"default",m,`storage-pools/${encodeURIComponent(k)}/volumes/custom`,E)?!0:this.createError({path:"name",message:"A volume with this name already exist in the target project and storage pool"})}),n=T({initialValues:{name:b(t),project:t.project,copySnapshots:!0,pool:t.pool,location:H((a==null?void 0:a.driver)??"")?"":t.location},enableReinitialize:!0,validationSchema:l,onSubmit:u=>{const j={name:u.name,type:"custom",config:t.config,description:t.description,content_type:t.content_type,source:{name:t.name,type:"copy",pool:t.pool,volume_only:!u.copySnapshots,project:u.project!==t.project?t.project:void 0,location:t.location}};Ie(j,u.pool,u.project,u.location).then(N=>{c.info(e.jsxs(e.Fragment,{children:["Copy of volume ",e.jsx(R,{volume:t})," started."]})),i.set(N.metadata.id,()=>{g(u)},k=>{d(new Error(k))})}).catch(N=>{c.failure("Volume copy failed.",N)}).finally(()=>{o()})}});return e.jsx(s.Modal,{close:o,className:"copy-volumes-modal",title:"Copy volume",buttonRow:e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{appearance:"base",className:"u-no-margin--bottom",type:"button",onClick:o,children:"Cancel"}),e.jsx(s.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",loading:n.isSubmitting,disabled:!n.isValid||n.isSubmitting||p||x,onClick:()=>void n.submitForm(),children:"Copy"})]}),children:e.jsxs(s.Form,{onSubmit:n.handleSubmit,children:[e.jsx(s.Input,{...n.getFieldProps("name"),type:"text",label:"New volume name",error:n.touched.name?n.errors.name:null}),e.jsx(Te,{value:n.values.pool,setValue:u=>void n.setFieldValue("pool",u),selectProps:{id:"pool",label:"Storage pool"}}),!H((a==null?void 0:a.driver)??"")&&e.jsx(Pe,{...n.getFieldProps("location")}),e.jsx(s.Select,{...n.getFieldProps("project"),id:"project",label:"Target project",options:r.map(u=>({label:u.name,value:u.name}))}),e.jsx(s.Input,{...n.getFieldProps("copySnapshots"),type:"checkbox",label:"Copy with snapshots",checked:n.values.copySnapshots,error:n.touched.copySnapshots?n.errors.copySnapshots:null}),e.jsx(s.Input,{type:"submit",hidden:!0,value:"Hidden input"})]})})},pt=({volume:t,classname:o,onClose:c})=>{const{openPortal:m,closePortal:i,isOpen:r,Portal:p}=s.usePortal(),{canCreateStorageVolumes:a}=me(),{data:h}=pe(t.project),x=()=>{i(),c==null||c()};return e.jsxs(e.Fragment,{children:[r&&e.jsx(p,{children:e.jsx(mt,{close:x,volume:t})}),e.jsxs(s.Button,{appearance:"default","aria-label":"Copy volume",className:O("u-no-margin--bottom has-icon",o),onClick:m,title:a(h)?"Copy volume":"You do not have permission to copy this volume",disabled:!a(h),children:[e.jsx(s.Icon,{name:"canvas"}),e.jsx("span",{children:"Copy"})]})]})},ut=({volume:t,project:o})=>{const c=ue(he),{hasClusterInternalCustomVolumeCopy:m}=ee(),i=q(),r=s.useToastNotification(),p=c?"p-contextual-menu__link":"p-segmented-control__button",a=[e.jsx(lt,{volume:t,project:o,classname:p},"migrate"),...m?[e.jsx(pt,{volume:t,classname:p},"copy")]:[],e.jsx(dt,{volume:t,classname:p},"export"),e.jsx($e,{label:"Delete",volume:t,project:o,appearance:"",hasIcon:!0,onFinish:()=>{i(`/ui/project/${encodeURIComponent(o)}/storage/volumes`),r.success(e.jsxs(e.Fragment,{children:["Storage volume"," ",e.jsx(U,{bold:!0,type:"volume",value:t.name})," deleted."]}))},classname:p},"delete")];return e.jsx(e.Fragment,{children:c?e.jsx(s.ContextualMenu,{closeOnOutsideClick:!1,toggleLabel:"Actions",position:"left",hasToggleIcon:!0,title:"actions",children:h=>e.jsx("span",{children:[...a].map(x=>V.cloneElement(x,{onClose:h}))})}):e.jsx("div",{className:"p-segmented-control",children:e.jsx("div",{className:"p-segmented-control__list",children:a})})})},ht=({volume:t,project:o})=>{const c=q(),m=s.useNotify(),i=s.useToastNotification(),r=V.useState(null),{canEditVolume:p}=_(),a=g=>{var d;if((((d=g.used_by)==null?void 0:d.length)??0)>0)return"Can not rename, volume is currently in use.";if(!p(g))return"You do not have permission to rename this volume"},h=Q().shape({name:L().test(...ge(o,t.type,r,t)).required("This field is required")}),x=T({initialValues:{name:t.name,isRenaming:!1},validationSchema:h,onSubmit:g=>{if(t.name===g.name){x.setFieldValue("isRenaming",!1),x.setSubmitting(!1);return}Le(o,t,g.name,t.location).then(()=>{const d=Z(t)?`/ui/project/${encodeURIComponent(o)}/storage/pool/${encodeURIComponent(t.pool)}/member/${encodeURIComponent(t.location)}/volumes/${encodeURIComponent(t.type)}/${encodeURIComponent(g.name)}`:`/ui/project/${encodeURIComponent(o)}/storage/pool/${encodeURIComponent(t.pool)}/volumes/${encodeURIComponent(t.type)}/${encodeURIComponent(g.name)}`;c(d),i.success(e.jsxs(e.Fragment,{children:["Storage volume ",e.jsx("strong",{children:t.name})," renamed to"," ",e.jsx(I,{type:"volume",value:g.name,to:d}),"."]})),x.setFieldValue("isRenaming",!1)}).catch(d=>{m.failure("Renaming failed",d)}).finally(()=>{x.setSubmitting(!1)})}});return e.jsx(we,{name:t.name,parentItems:[e.jsx(xe,{to:`/ui/project/${encodeURIComponent(o)}/storage/volumes`,children:"Storage volumes"},1)],controls:t?e.jsx(ut,{project:o,volume:t}):null,isLoaded:!0,formik:x,renameDisabledReason:a(t)})},gt=({project:t,volume:o})=>{var i,r;const c=()=>{be("storage-overview-tab")};V.useEffect(c,[o]),s.useListener(window,c,"resize",!0);const{data:m}=te();return e.jsxs("div",{className:"storage-overview-tab",children:[e.jsxs(s.Row,{className:"section",children:[e.jsx(s.Col,{size:3,children:e.jsx("h2",{className:"p-heading--5",children:"General"})}),e.jsx(s.Col,{size:7,children:e.jsx("table",{children:e.jsxs("tbody",{children:[e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Name"}),e.jsx("td",{children:o.name})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Type"}),e.jsx("td",{children:je(o)})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Content type"}),e.jsx("td",{children:fe(o)})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Description"}),e.jsx("td",{children:o.description?o.description:"-"})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Cluster member"}),e.jsx("td",{children:(i=m==null?void 0:m.environment)!=null&&i.server_clustered&&o.location?e.jsx(I,{type:"cluster-member",value:o.location,to:`/ui/cluster/member/${encodeURIComponent(o.location)}`}):"-"})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Pool"}),e.jsx("td",{children:e.jsx(I,{type:"pool",value:o.pool,to:`/ui/project/${encodeURIComponent(o.project)}/storage/pool/${encodeURIComponent(o.pool)}`})})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Date created"}),e.jsx("td",{children:z(o.created_at)})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Size"}),e.jsx("td",{children:e.jsx(Ue,{volume:o})})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Custom config"}),e.jsx("td",{children:Object.entries(o.config).length===0?"-":e.jsx("table",{children:e.jsx("tbody",{children:Object.entries(o.config).map(([p,a],h)=>e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:p}),e.jsx("td",{children:a})]},h))})})})]})]})})})]}),e.jsxs(s.Row,{className:"section",children:[e.jsx(s.Col,{size:3,children:e.jsxs("h2",{className:"p-heading--5",children:["Used by (",((r=o.used_by)==null?void 0:r.length)??0,")"]})}),e.jsx(s.Col,{size:7,children:e.jsx(Be,{storage:o,project:t})})]})]})},M=(t,o)=>({name:t.name,project:t.project,pool:t.pool,size:t.config.size??"GiB",content_type:t.content_type,volumeType:t.type,security_shifted:t.config["security.shifted"],security_unmapped:t.config["security.unmapped"],snapshots_expiry:t.config["snapshots.expiry"],snapshots_pattern:t.config["snapshots.pattern"],snapshots_schedule:t.config["snapshots.schedule"],block_filesystem:t.config["block.filesystem"],block_mount_options:t.config["block.mount_options"],block_type:t.config["block.type"],zfs_blocksize:t.config["zfs.blocksize"],zfs_block_mode:t.config["zfs.block_mode"],zfs_delegate:t.config["zfs.delegate"],zfs_remove_snapshots:t.config["zfs.remove_snapshots"],zfs_use_refquota:t.config["zfs.use_refquota"],zfs_reserve_space:t.config["zfs.reserve_space"],readOnly:!0,isCreating:!1,entityType:"storageVolume",editRestriction:o,clusterMember:t.location}),xt=({volume:t})=>{const o=q(),c=s.useNotify(),m=s.useToastNotification(),i=v(),{section:r}=K(),{project:p}=K(),{canEditVolume:a}=_();if(!p)return e.jsx(e.Fragment,{children:"Missing project"});const h=Q().shape({name:L().required("This field is required")}),x=a(t)?void 0:"You do not have permission to edit this volume",g=T({initialValues:M(t,x),validationSchema:h,enableReinitialize:!0,onSubmit:l=>{const n=ne(l,p,t);se(l.pool,p,{...n,etag:t.etag},t.location).then(()=>{g.setValues(M(n)),i.invalidateQueries({queryKey:[C.storage]}),i.invalidateQueries({queryKey:[C.storage,t.pool,p,n.type,n.name]}),m.success(e.jsxs(e.Fragment,{children:["Storage volume ",e.jsx(R,{volume:t})," updated."]}))}).catch(u=>{c.failure("Storage volume update failed",u)}).finally(()=>{g.setSubmitting(!1)})}}),d=`${oe(t)}/configuration`,b=l=>{o(l===W?d:`${d}/${Y(l)}`)};return e.jsxs("div",{className:"edit-storage-volume",children:[e.jsx(He,{formik:g,section:r??Y(W),setSection:b}),e.jsx(Ge,{children:g.values.readOnly?null:e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{appearance:"base",onClick:async()=>g.setValues(M(t)),children:"Cancel"}),e.jsx(Je,{formik:g,baseUrl:d,disabled:!g.values.name})]})})]})},jt=({volume:t,snapshot:o,close:c})=>{const m=$(),i=s.useToastNotification(),r=v(),p=V.useState(null),a=async d=>new Promise((b,l)=>{qe(t,o,d).then(n=>{m.set(n.metadata.id,()=>{b()},u=>{l(new Error(u))})}).catch(n=>{l(n)})}),[h,x]=o.expires_at?ye(new Date(o.expires_at)).slice(0,16).split(" "):[null,null],g=T({initialValues:{name:o.name,expirationDate:h,expirationTime:x},validateOnMount:!0,validationSchema:ze(t,p,o.name),onSubmit:async d=>{let b=!0;const l=d.expirationDate&&d.expirationTime?Se(Ze(d.expirationDate,d.expirationTime)):null;l!==o.expires_at&&await Me(t,o,l).catch(n=>{i.failure("Snapshot update failed",n),b=!1}),d.name!==o.name&&await a(d.name).catch(n=>{i.failure("Snapshot update failed",n),b=!1}),b&&i.success(e.jsxs(e.Fragment,{children:["Snapshot"," ",e.jsx(A,{name:d.name,volume:t})," saved."]})),r.invalidateQueries({predicate:n=>n.queryKey[0]===C.volumes||n.queryKey[0]===C.storage}),g.setSubmitting(!1),c()}});return e.jsx(Xe,{isEdit:!0,formik:g,close:c})},ft=({volume:t,snapshot:o,isDeleting:c,isRestoring:m})=>{const{openPortal:i,closePortal:r,isOpen:p,Portal:a}=s.usePortal(),{canManageStorageVolumeSnapshots:h}=_();return e.jsxs(e.Fragment,{children:[p&&e.jsx(a,{children:e.jsx(jt,{close:r,volume:t,snapshot:o})}),e.jsx(s.Button,{appearance:"base",hasIcon:!0,dense:!0,disabled:!h(t)||c||m,onClick:i,type:"button","aria-label":"Edit snapshot",title:h(t)?"Edit":"You do not have permission to edit this snapshot",children:e.jsx(s.Icon,{name:"edit"})})]})},bt=({volume:t,snapshot:o})=>{const c=$(),m=s.useNotify(),i=s.useToastNotification(),[r,p]=V.useState(!1),[a,h]=V.useState(!1),x=v(),{canManageStorageVolumeSnapshots:g}=_(),d=n=>g(t)?`${n} snapshot`:`You do not have permission to ${n.toLowerCase()} this snapshot`,b=()=>{p(!0);const n=e.jsx(A,{name:o.name,volume:t});Ke(t,o).then(u=>{c.set(u.metadata.id,()=>i.success(e.jsxs(e.Fragment,{children:["Snapshot"," ",e.jsx(U,{bold:!0,type:"snapshot",value:o.name})," ","deleted for volume ",e.jsx(R,{volume:t}),"."]})),j=>i.failure(`Snapshot ${o.name} deletion failed`,new Error(j),n),()=>{p(!1),x.invalidateQueries({predicate:j=>j.queryKey[0]===C.volumes||j.queryKey[0]===C.storage})})}).catch(u=>{m.failure("Snapshot deletion failed",u,n),p(!1)})},l=()=>{h(!0),Oe(t,o).then(()=>{i.success(e.jsxs(e.Fragment,{children:["Snapshot"," ",e.jsx(A,{name:o.name,volume:t})," ","restored for volume ",e.jsx(R,{volume:t}),"."]}))}).catch(n=>{m.failure("Snapshot restore failed",n)}).finally(()=>{h(!1),x.invalidateQueries({predicate:n=>n.queryKey[0]===C.volumes||n.queryKey[0]===C.storage})})};return e.jsx(e.Fragment,{children:e.jsx(s.List,{inline:!0,className:O("u-no-margin--bottom","actions-list",{"u-snapshot-actions":!r&&!a}),items:[e.jsx(ft,{volume:t,snapshot:o,isDeleting:r,isRestoring:a},"edit"),e.jsx(s.ConfirmationButton,{appearance:"base",loading:a,className:"has-icon is-dense",title:"Confirm restore",confirmationModalProps:{title:"Confirm restore",children:e.jsxs("p",{children:["This will restore snapshot"," ",e.jsx(U,{type:"snapshot",value:o.name,bold:!0}),".",e.jsx("br",{}),"This action cannot be undone, and can result in data loss."]}),confirmButtonLabel:d("Restore"),confirmButtonAppearance:"positive",onConfirm:l},disabled:!g(t)||r||a,shiftClickEnabled:!0,showShiftClickHint:!0,children:e.jsx(s.Icon,{name:"change-version"})},"restore"),e.jsx(s.ConfirmationButton,{appearance:"base",loading:r,className:"has-icon is-dense",confirmationModalProps:{title:"Confirm delete",children:e.jsxs("p",{children:["This will permanently delete snapshot"," ",e.jsx(U,{type:"snapshot",value:o.name,bold:!0}),".",e.jsx("br",{}),"This action cannot be undone, and can result in data loss."]}),confirmButtonLabel:d("Delete"),onConfirm:b},disabled:!g(t)||r||a,shiftClickEnabled:!0,showShiftClickHint:!0,children:e.jsx(s.Icon,{name:"delete"})},"delete")]})})},yt=({volume:t,snapshotNames:o,onStart:c,onFinish:m})=>{const i=$(),r=s.useToastNotification(),[p,a]=V.useState(!1),h=v(),{canManageStorageVolumeSnapshots:x}=_(),g=o.length,d=()=>{a(!0),c(),Ae(t,o,i).then(b=>{const{fulfilledCount:l,rejectedCount:n}=Ce(b);l===g?r.success(`${o.length} ${B("snapshot",o.length)} deleted`):n===g?r.failure("Snapshot bulk deletion failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:g})," ",B("snapshot",g)," could not be deleted."]})):r.failure("Snapshot bulk deletion partially failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:l})," ",B("snapshot",l)," ","deleted.",e.jsx("br",{}),e.jsx("b",{children:n})," ",B("snapshot",n)," ","could not be deleted."]})),h.invalidateQueries({predicate:u=>u.queryKey[0]===C.volumes||u.queryKey[0]===C.storage}),a(!1),m()}).catch(b=>{r.failure("Snapshot bulk deletion failed",b),a(!1)})};return e.jsx(at,{confirmationButtonProps:{loading:p,disabled:!x(t)||p,appearance:""},onDelete:d,entityType:"snapshot",entities:o,deletableEntities:o,buttonLabel:`Delete ${B("snapshot",o.length)}`,disabledReason:x(t)?void 0:"You do not have permission to manage snapshots for this volume"})},St=({volume:t,close:o})=>{const c=s.useNotify(),m=s.useToastNotification(),i=v(),r=T({initialValues:M(t),onSubmit:a=>{const h=ne(a,t.project);se(t.pool,t.project,{...h,etag:t.etag},t.location).then(()=>{m.success(e.jsxs(e.Fragment,{children:["Snapshot configuration updated for volume"," ",e.jsx(R,{volume:t}),"."]})),i.invalidateQueries({queryKey:[C.storage],predicate:x=>x.queryKey[0]===C.volumes||x.queryKey[0]===C.storage})}).catch(x=>{c.failure("Configuration update failed",x)}).finally(()=>{o(),r.setSubmitting(!1)})}}),p=a=>{a.key==="Escape"&&o()};return e.jsx(s.Modal,{close:o,className:"edit-snapshot-config",title:"Snapshot configuration",buttonRow:r.values.readOnly?e.jsx(s.Button,{className:"u-no-margin--bottom u-no-margin--right",onClick:o,children:"Close"}):e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{appearance:"base",className:"u-no-margin--bottom",type:"button",onClick:o,children:"Cancel"}),e.jsx(s.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",loading:r.isSubmitting,disabled:r.isSubmitting,onClick:()=>void r.submitForm(),children:"Save"})]}),onKeyDown:p,children:e.jsx(Ye,{formik:r})})},X=({volume:t,isDisabled:o,className:c})=>{const{openPortal:m,closePortal:i,isOpen:r,Portal:p}=s.usePortal(),{canEditVolume:a}=_();return e.jsxs(e.Fragment,{children:[r&&e.jsx(p,{children:e.jsx("div",{className:"snapshot-list",children:e.jsx(St,{close:i,volume:t})})}),e.jsx(s.Button,{onClick:m,className:c,disabled:!a(t)||o,title:a(t)?"Configure snapshot":"You do not have permission to configure this volume",children:"See configuration"})]})},Ct=({volume:t})=>{const o=Ne(),[c,m]=V.useState(""),[i,r]=V.useState([]),[p,a]=V.useState([]),[h,x]=V.useState(G()),g=s.useNotify(),{project:d,isLoading:b}=Ve(),{data:l,error:n,isLoading:u}=ke({queryKey:[C.storage,C.snapshots,t.pool,t.project,t.type,t.name,t.location],queryFn:async()=>Qe(t)}),j=et(d);V.useEffect(()=>{const f=new Set(l==null?void 0:l.map(P=>P.name)),w=i.filter(P=>f.has(P));w.length!==i.length&&r(w)},[l,i]);const N=(l==null?void 0:l.filter(f=>!(c&&!f.name.toLowerCase().includes(c.toLowerCase()))))??[],k=l&&l.length>0,E=[{content:h?e.jsxs(e.Fragment,{children:["Name",e.jsx("br",{}),e.jsx("div",{className:"header-second-row",children:"Date created"})]}):"Name",sortKey:h?"created_at":"name",className:"name"},...h?[]:[{content:"Date created",sortKey:"created_at",className:"created"}],{content:"Expiry date",sortKey:"expires_at",className:"expiration"},{"aria-label":"Actions",className:"actions"}],D=N.map(f=>{const w=e.jsx(bt,{volume:t,snapshot:f});return{key:f.name,className:"u-row",name:f.name,columns:[{content:e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"u-truncate",title:f.name,children:e.jsx(tt,{item:f})}),h&&e.jsx("div",{className:"u-text--muted",children:z(f.created_at)})]}),role:"rowheader","aria-label":"Name",className:"name"},...h?[]:[{content:z(f.created_at),role:"cell","aria-label":"Created at",className:"created"}],{content:z(f.expires_at??""),role:"cell","aria-label":"Expires at",className:"expiration"},{content:w,role:"cell","aria-label":"Actions",className:"u-align--right actions"}],sortData:{name:f.name.toLowerCase(),created_at:f.created_at,expires_at:f.expires_at}}}),{rows:S,updateSort:y}=it({rows:D,defaultSort:"created_at",defaultSortDirection:"descending"}),F=()=>{x(G())};return s.useListener(window,F,"resize",!0),n&&g.failure("Loading storage volume snapshots failed",n),u||b?e.jsx(s.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0}):l?e.jsxs("div",{className:"snapshot-list",children:[k&&e.jsx("div",{className:"upper-controls-bar",children:i.length===0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"search-box-wrapper",children:e.jsx(s.SearchBox,{name:"search-snapshot",className:"search-box margin-right",type:"text",onChange:f=>{m(f)},placeholder:"Search for snapshots",value:c,"aria-label":"Search for snapshots"})}),e.jsx(X,{volume:t,className:"u-no-margin--right"}),e.jsx(J,{volume:t,className:"u-float-right",isDisabled:j})]}):e.jsx("div",{className:"p-panel__controls",children:e.jsx(yt,{volume:t,snapshotNames:i,onStart:()=>{a(i)},onFinish:()=>{a([])}})})}),k?e.jsx(e.Fragment,{children:e.jsx(st,{dependencies:[N],tableId:"volume-snapshot-table",belowIds:["status-bar"],children:e.jsx(s.TablePagination,{data:S,id:"pagination",itemName:"snapshot",className:"u-no-margin--top","aria-label":"Table pagination control",description:i.length>0&&e.jsx(nt,{totalCount:l.length??0,itemName:"snapshot",parentName:"volume",selectedNames:i,setSelectedNames:r,filteredNames:N.map(f=>f.name)}),children:e.jsx(ot,{id:"volume-snapshot-table",headers:E,rows:S,sortable:!0,emptyStateMsg:"No snapshot found matching this search",itemName:"snapshot",parentName:"instance",selectedNames:i,setSelectedNames:r,disabledNames:p,filteredNames:N.map(f=>f.name),onUpdateSort:y,defaultSort:"created_at",defaultSortDirection:"descending"})})})}):e.jsxs(s.EmptyState,{className:"empty-state",image:e.jsx(s.Icon,{name:"snapshot",className:"empty-state-icon"}),title:"No snapshots found",children:[e.jsx("p",{children:d&&j?e.jsxs(e.Fragment,{children:["Snapshots are disabled for project"," ",e.jsx(I,{type:"project",value:d.name,to:`/ui/project/${d.name}/configuration`}),"."]}):"There are no snapshots for this volume."}),e.jsx("p",{children:e.jsxs("a",{href:`${o}/howto/storage_backup_volume/#storage-backup-snapshots`,target:"_blank",rel:"noopener noreferrer",children:["Learn more about snapshots",e.jsx(s.Icon,{className:"external-link-icon",name:"external-link"})]})}),e.jsx(X,{volume:t,isDisabled:j}),e.jsx(J,{volume:t,className:"empty-state-button",isDisabled:j})]})]}):e.jsx(e.Fragment,{children:"Loading storage volume snapshots failed"})},Nt=["Overview","Configuration","Snapshots"],lo=()=>{const t=s.useNotify(),{pool:o,project:c,member:m,activeTab:i,type:r,volume:p}=K();if(!o)return e.jsx(e.Fragment,{children:"Missing storage pool"});if(!c)return e.jsx(e.Fragment,{children:"Missing project"});if(!r)return e.jsx(e.Fragment,{children:"Missing type"});if(!p)return e.jsx(e.Fragment,{children:"Missing volume"});const{data:a,error:h,isLoading:x}=De(o,c,r,p,m);return h&&t.failure("Loading storage volume failed",h),x?e.jsx(s.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0}):a?e.jsx(s.CustomLayout,{header:e.jsx(ht,{volume:a,project:c}),contentClassName:"detail-page storage-volume-form u-no-padding--bottom",children:e.jsxs(s.Row,{children:[e.jsx(We,{tabs:Nt,activeTab:i,tabUrl:oe(a)}),e.jsx(Fe,{}),!i&&e.jsx("div",{role:"tabpanel","aria-labelledby":"overview",children:e.jsx(gt,{volume:a,project:c})}),i==="configuration"&&e.jsx("div",{role:"tabpanel","aria-labelledby":"configuration",children:e.jsx(xt,{volume:a})}),i==="snapshots"&&e.jsx("div",{role:"tabpanel","aria-labelledby":"snapshots",children:e.jsx(Ct,{volume:a})})]})}):e.jsx(e.Fragment,{children:"Loading storage volume failed"})};export{lo as default};
Copyright ©2k19 -
Hexid
|
Tex7ure