| Current Path : /snap/lxd/38450/share/lxd-ui/assets/ |
| Current File : //snap/lxd/38450/share/lxd-ui/assets/StorageVolumeDetail-DgbMGyog.js |
import{d as a,E as F,v as T,c as z,j as e,P as G,x as b,dD as $,w as Q,R as _,r as N,Q as ue,dC as oe,dI as pe,s as q,V as M,b as ae,k as R,bD as he,S as ne,aY as ge,f as Y,h as P,a9 as xe,ej as J,bf as je,ay as fe,H as be,bi as ye,z as B,ck as Se,L as Ce,ek as Ne,e8 as Ve,cj as ke,aC as L,a3 as Fe,C as A,a6 as W,aV as we,aW as _e,T as E,ax as Pe,e4 as X,J as Te,b2 as Me,b3 as Re,bm as De,p as Ee}from"./index-BsQN_SZU.js";import{R as ve}from"./RenameHeader-BdCO5Nid.js";import{i as ie,j as re,h as Be,m as Le,k as Ie,r as $e,l as le}from"./storage-volumes-CG043sqG.js";import{u as w,D as ze}from"./DeleteStorageVolumeBtn-Cr5fXZmM.js";import{F as U,B as Z}from"./FormLink-3uUdaYvf.js";import{V}from"./VolumeLinkChip-BDzYNacj.js";import{P as ce}from"./ProjectRichChip-DZzjTfq6.js";import{S as qe,C as Oe,P as Ke}from"./ProjectSelectTable-Di9-f3cz.js";import{c as Ue,g as Qe,i as Ae}from"./snapshots-LtzKNDw1.js";import{S as He}from"./StoragePoolSelector-Bvqvds5t.js";import{a as Ye,c as Ge}from"./useVolumes-Bxw5lKYj.js";import{C as Je}from"./ClusterMemberSelector-o7hg9ebZ.js";import{u as We}from"./projects-CczQ3aFg.js";import{S as Xe}from"./StorageUsedBy-DAoQcJUS.js";import{S as Ze,g as et,u as tt,a as H,r as st,b as ot,d as at,c as nt,V as ee,f as it}from"./VolumeAddSnapshotBtn-BceLfSvp.js";import{a as rt}from"./ClusterMemberRichChip-Di9w-E3M.js";import{S as lt}from"./StoragePoolRichChip-Daex_aZU.js";import{v as de,a as ct,M as te,b as dt}from"./StorageVolumeForm-C6mvm1BU.js";import{F as mt}from"./FormFooterLayout-CcbL_-PB.js";import{F as ut}from"./FormSubmitBtn-DEfKgZu7.js";import{T as pt}from"./TabLinks-N89T_JJh.js";import{S as ht}from"./SnapshotForm-BuAjnGGJ.js";import{S as gt}from"./SelectableMainTable-DBx4rRiq.js";import{S as xt}from"./SelectedTableNotification-BpePAhdG.js";import{B as jt}from"./BulkDeleteButton-DbqPCHnz.js";import{u as ft}from"./useBulkDetails-ydqvQ5wa.js";import{u as bt}from"./useSortTableData-DkMx8bMp.js";import"./StoragePoolSize-BNbqTfwA.js";import"./Meter-cq8smrSm.js";import"./StoragePoolClusterMember-BaBZgKZ2.js";import"./images-dZFGKb1g.js";import"./UsedByRow-DlstYIKs.js";import"./UsedByItem-DYTdOZkC.js";import"./SshKeyForm-BNz7yPwa.js";import"./limits-yeXZOxhv.js";import"./AutoExpandingTextArea-Bd-45rZK.js";import"./formFields-DzJouV_d.js";import"./scroll-Dc7Cgzms.js";import"./ConfigFieldDescription-CjXKAIpa.js";import"./ExpandableList-DsGr0BpD.js";import"./ClusterMemberMemoryUsage-DYUQFY0n.js";import"./DiskSizeSelector-C9kWj54D.js";import"./formChangeCount-Kjdextdt.js";const yt=({volume:t,close:s,type:n,target:i})=>{const l=a.useToastNotification(),c=F(),d=T(),m=z(),x=()=>{let r="";const o=$(t),p=$({...t,project:n==="project"?i:t.project,pool:n==="pool"?i:t.pool,location:n==="cluster member"?i:t.location}),y=e.jsx(Q,{type:"pool",value:i,to:`${_}/ui/project/${encodeURIComponent(t.project)}/storage/pool/${encodeURIComponent(i)}`});n==="cluster member"&&(r=e.jsxs(e.Fragment,{children:["Volume ",e.jsx(V,{volume:{...t,location:i}})," ","successfully migrated to cluster member"," ",e.jsx(Q,{type:"cluster-member",value:i,to:`${_}/ui/cluster/member/${encodeURIComponent(i)}`})]}),o!==p&&m(p)),n==="pool"&&(r=e.jsxs(e.Fragment,{children:["Volume ",e.jsx(V,{volume:{...t,pool:i}}),"successfully migrated to pool ",y]}),o!==p&&m(p)),n==="project"&&(r=e.jsxs(e.Fragment,{children:["Volume ",e.jsx(V,{volume:{...t,project:i}}),"successfully moved to project ",e.jsx(ce,{projectName:i})]}),o!==p&&m(p)),l.success(r)},f=r=>{let o="";n==="cluster member"&&(o=`Cluster member migration failed for volume ${t.name}`),n==="pool"&&(o=`Migration failed for volume ${t.name} to pool ${i}`),n==="project"&&(o=`Project move failed for volume ${t.name}`),l.failure(o,r,e.jsx(V,{volume:t}))},j=r=>{f(new Error(r))},h=()=>{d.invalidateQueries({queryKey:[b.volumes,t.name,t.project]}),d.invalidateQueries({queryKey:[b.volumes,t.project]}),d.invalidateQueries({queryKey:[b.operations,t.project]})};return{handleMigrate:()=>{const r=n==="pool"?i:void 0,o=n==="project"?i:void 0;Le(t,t.project,r,t.location,o).then(p=>{c.set(p.metadata.id,()=>{x()},y=>{j(y)},h),l.info(e.jsxs(e.Fragment,{children:[G(n)," migration started for"," ",e.jsx(V,{volume:t}),"."]})),d.invalidateQueries({queryKey:[b.volumes,t.name,t.project]})}).catch(p=>{f(p)}).finally(()=>{s()})},handleMemberMigrate:()=>{const r=n==="cluster member"?i:void 0,o=t.location,p=ie(t,t.name,t.project);re(p,t.pool,t.project,r).then(y=>{l.info(e.jsxs(e.Fragment,{children:[G(n)," migration started for"," ",e.jsx(V,{volume:t}),"."]})),c.set(y.metadata.id,()=>{d.invalidateQueries({queryKey:[b.volumes,t.name,t.project]}),Be(t.name,t.pool,t.project,o).then(S=>{c.set(S.metadata.id,()=>{x()},k=>{j(k)},h),d.invalidateQueries({queryKey:[b.isoVolumes]}),d.invalidateQueries({queryKey:[b.projects,t.project]}),d.invalidateQueries({queryKey:[b.storage,t.pool,b.volumes,t.project,t.location]}),d.invalidateQueries({predicate:k=>k.queryKey[0]===b.volumes})})},S=>{j(S)},h)}).catch(y=>{f(y)}).finally(()=>{s()})}}},St=({volume:t,onSelect:s,onCancel:n,migrate:i})=>{const[l,c]=N.useState(""),d=e.jsx("div",{className:"migrate-instance-summary",children:e.jsxs("p",{children:["This will migrate volume ",e.jsx("strong",{children:t.name})," to storage pool"," ",e.jsx("b",{children:l}),"."]})});return e.jsxs(e.Fragment,{children:[l?d:e.jsx(qe,{onSelect:m=>{c(m),s(m)},disablePool:{name:t.pool,reason:"Volume is already in this pool"}}),e.jsxs("footer",{id:"migrate-volume-actions",className:"p-modal__footer",children:[e.jsx(a.Button,{className:"u-no-margin--bottom",type:"button","aria-label":"cancel migrate",appearance:"base",onClick:()=>{n(),c("")},children:"Cancel"}),e.jsx(a.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",onClick:()=>{i(l)},disabled:!l,children:"Migrate"})]})]})},Ct=({volume:t,onSelect:s,targetMember:n,onCancel:i,migrate:l})=>{const c=e.jsx("div",{className:"migrate-instance-summary",children:e.jsxs("p",{children:["This will migrate volume ",e.jsx("strong",{children:t.name})," to cluster member ",e.jsx("b",{children:n}),"."]})});return e.jsxs(e.Fragment,{children:[n&&c,!n&&e.jsx(Oe,{onSelect:s,disableMember:{name:t.location,reason:"Volume already on this member"}}),e.jsxs("footer",{id:"migrate-volume-actions",className:"p-modal__footer",children:[e.jsx(a.Button,{className:"u-no-margin--bottom",type:"button","aria-label":"cancel migrate",appearance:"base",onClick:i,children:"Cancel"}),e.jsx(a.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",onClick:()=>{l(n)},disabled:!n,children:"Migrate"})]})]})},Nt=({volume:t,onSelect:s,targetProject:n,onCancel:i,migrate:l})=>{const c=e.jsx("div",{className:"migrate-instance-summary",children:e.jsxs("p",{children:["This will migrate the volume ",e.jsx("strong",{children:t.name})," to the project ",e.jsx("b",{children:n}),"."]})});return e.jsxs(e.Fragment,{children:[n&&c,!n&&e.jsx(Ke,{onSelect:s,disableProject:{name:t.project,reason:"Volume already in this project"}}),e.jsxs("footer",{id:"migrate-volume-actions",className:"p-modal__footer",children:[e.jsx(a.Button,{className:"u-no-margin--bottom",type:"button","aria-label":"cancel migrate",appearance:"base",onClick:i,children:"Cancel"}),e.jsx(a.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",onClick:()=>{l(n)},disabled:!n,children:"Migrate"})]})]})},Vt=({close:t,volume:s})=>{const[n,i]=N.useState(""),[l,c]=N.useState(""),d=ue(),{data:m}=oe(s.pool),{handleMigrate:x,handleMemberMigrate:f}=yt({close:t,volume:s,type:n,target:l}),j=g=>{g.key==="Escape"&&t()},h=()=>{if(l){c("");return}if(n){i("");return}},u=()=>n?l?e.jsx(Z,{title:"Confirm migration",linkText:`Choose ${n}`,onClick:h}):e.jsx(Z,{title:e.jsxs(e.Fragment,{children:["Choose ",n," for volume ",e.jsx("strong",{children:s.name})]}),linkText:"Choose migration method",onClick:h}):"Choose migration method";return e.jsxs(a.Modal,{close:t,className:"migrate-instance-modal",onKeyDown:j,children:[e.jsxs("header",{className:"p-modal__header",children:[e.jsx("h2",{className:"p-modal__title",id:"migrate-title",children:u()},n?l?"confirm":"select":"start"),e.jsx("button",{className:"p-modal__close","aria-label":"Close active modal",onClick:t,children:"Close"})]}),!n&&e.jsxs("div",{className:"choose-migration-type",children:[d&&pe(m?.driver||"")&&e.jsx(U,{icon:"cluster-host",title:"Migrate volume to a different cluster member",onClick:()=>{i("cluster member")}}),e.jsx(U,{icon:"storage-pool",title:"Move volume to a different storage pool",onClick:()=>{i("pool")}}),e.jsx(U,{icon:"folder",title:"Move volume to a different project",onClick:()=>{i("project")}})]}),n==="cluster member"&&e.jsx(Ct,{volume:s,onSelect:c,targetMember:l,onCancel:h,migrate:f}),n==="pool"&&e.jsx(St,{volume:s,onSelect:c,onCancel:h,migrate:x}),n==="project"&&e.jsx(Nt,{volume:s,onSelect:c,targetProject:l,onCancel:h,migrate:x})]})},kt=({volume:t,classname:s,onClose:n})=>{const{openPortal:i,closePortal:l,isOpen:c,Portal:d}=a.usePortal(),{canEditVolume:m}=w(),x=t.used_by?.length===0,f=()=>{l(),n?.()},j=()=>m(t)?x?"Migrate volume":"Volume is in use":"You do not have permission to migrate this volume";return e.jsxs(e.Fragment,{children:[c&&e.jsx(d,{children:e.jsx(Vt,{close:f,volume:t})}),e.jsxs(a.ActionButton,{onClick:i,type:"button",className:q("u-no-margin--bottom has-icon",s),disabled:!m(t)||!x,title:j(),children:[e.jsx(a.Icon,{name:"machines"}),e.jsx("span",{children:"Migrate"})]})]})},Ft=({volume:t,close:s})=>{const n=F(),i=a.useToastNotification(),l=e.jsx(V,{volume:t}),{hasBackupMetadataVersion:c}=M(),{data:d}=ae(),m=d?.environment?.backup_metadata_version_range??[],x=u=>{const g=new URLSearchParams;g.set("project",t.project),he(g,t.location);const r=`${_}/1.0/storage-pools/${encodeURIComponent(t.pool)}/volumes/${encodeURIComponent(t.type)}/${encodeURIComponent(t.name)}/backups/${encodeURIComponent(u)}/export?${g.toString()}`,o=document.createElement("a");o.href=r,o.download=u,o.click(),window.URL.revokeObjectURL(r),i.success(e.jsxs(e.Fragment,{children:["Volume ",l," download started:",e.jsx("br",{}),e.jsx("a",{href:r,children:u})]}))},f=u=>{const g=new Date;return g.setHours(g.getHours()+u),g},j=u=>{const g=new Date().toISOString().replaceAll(":","-").split(".")[0],r=`${t.name}-${g}.tar${u.compression==="gzip"?".gz":""}`,o=JSON.stringify({name:r,expires_at:f(u.expirationHours).toISOString(),compression_algorithm:u.compression,volume_only:u.volumeOnly,optimized_storage:u.optimizedStorage,version:c?Number(u.exportVersion):void 0});Ie(t,o).then(p=>{i.info(e.jsxs(e.Fragment,{children:["Backing up volume ",l,".",e.jsx("br",{}),"Download will start, when the export is ready."]})),n.set(p.metadata.id,()=>{x(r)},y=>i.failure(`Could not download volume ${t.name}`,new Error(y),l))}).catch(p=>i.failure(`Could not download volume ${t.name}`,p,l)).finally(()=>{s()})},h=R({initialValues:{compression:"gzip",exportVersion:"2",expirationHours:6,volumeOnly:!1,optimizedStorage:!0},onSubmit:u=>{j(u)}});return e.jsx(a.Modal,{close:s,className:"export-volume-modal",title:"Export Volume",buttonRow:e.jsxs(e.Fragment,{children:[e.jsx(a.Button,{appearance:"base",className:"u-no-margin--bottom",type:"button",onClick:s,children:"Cancel"}),e.jsx(a.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",loading:h.isSubmitting,disabled:h.isSubmitting,onClick:()=>{h.submitForm()},children:"Export volume"})]}),children:e.jsxs(a.Form,{onSubmit:h.handleSubmit,children:[e.jsx(a.Select,{...h.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(a.Select,{...h.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"}]}),c&&e.jsx(a.Select,{...h.getFieldProps("exportVersion"),id:"exportVersion",label:"Export version",help:"Lower versions allow imports on older LXD versions",options:m.map(u=>({value:u.toString(),label:u.toString()}))}),e.jsx(a.Input,{...h.getFieldProps("optimizedStorage"),type:"checkbox",label:"Use storage driver optimized format",help:"Can only be restored on a similar pool",checked:h.values.optimizedStorage}),e.jsx(a.Input,{...h.getFieldProps("volumeOnly"),type:"checkbox",label:"Export without volume snapshots",error:h.touched.volumeOnly?h.errors.volumeOnly:null,checked:h.values.volumeOnly}),e.jsx(a.Input,{type:"submit",hidden:!0,value:"Hidden input"})]})})},wt=({volume:t,classname:s,onClose:n})=>{const{openPortal:i,closePortal:l,isOpen:c,Portal:d}=a.usePortal(),{canManageVolumeBackups:m}=w(),{project:x}=ne(),f=Ue(x),j=()=>{l(),n?.()},h=()=>m(t)?f?`Project "${x?.name}" doesn't allow for backup creation.`:"Export volume":"You do not have permission to export this volume.";return e.jsxs(e.Fragment,{children:[c&&e.jsx(d,{children:e.jsx(Ft,{close:j,volume:t})}),e.jsxs(a.Button,{appearance:"default",className:q("u-no-margin--bottom has-icon",s),onClick:i,title:h(),disabled:!m(t)||f,children:[e.jsx(a.Icon,{name:"export"}),e.jsx("span",{children:"Export"})]})]})},_t=({volume:t,close:s})=>{const n=a.useToastNotification(),i=N.useState(null),l=F(),{data:c=[],isLoading:d}=ge(),{data:m}=oe(t.pool),{data:x=[],isLoading:f}=Ye(t.project),j=o=>{const p={...t,name:o.name,project:o.project,pool:o.pool,location:o.location};n.success(e.jsxs(e.Fragment,{children:["Created volume ",e.jsx(V,{volume:p}),"."]}))},h=o=>{n.failure("Volume copy failed.",o,e.jsx(V,{volume:t}))},u=o=>{const p=o.name+"-copy";return je(p,x)},g=Y().shape({name:P().required("Volume name is required"),project:P().required(),pool:P().required(),location:P().optional()}).test("deduplicate","",async function(o){const{name:p,project:y,pool:S,location:k}=o;return await xe(p,y||"default",i,`storage-pools/${encodeURIComponent(S)}/volumes/custom`,k)?!0:this.createError({path:"name",message:"A volume with this name already exist in the target project and storage pool"})}),r=R({initialValues:{name:u(t),project:t.project,copySnapshots:!0,pool:t.pool,location:J(m?.driver??"")?"":t.location},enableReinitialize:!0,validationSchema:g,onSubmit:o=>{const p=ie(t,o.name,o.project,!o.copySnapshots);re(p,o.pool,o.project,o.location).then(y=>{n.info(e.jsxs(e.Fragment,{children:["Copy of volume ",e.jsx(V,{volume:t})," started."]})),l.set(y.metadata.id,()=>{j(o)},S=>{h(new Error(S))})}).catch(y=>{n.failure("Volume copy failed.",y)}).finally(()=>{s()})}});return e.jsx(a.Modal,{close:s,className:"copy-volumes-modal",title:"Copy volume",buttonRow:e.jsxs(e.Fragment,{children:[e.jsx(a.Button,{appearance:"base",className:"u-no-margin--bottom",type:"button",onClick:s,children:"Cancel"}),e.jsx(a.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",loading:r.isSubmitting,disabled:!r.isValid||r.isSubmitting||d||f,onClick:()=>{r.submitForm()},children:"Copy"})]}),children:e.jsxs(a.Form,{onSubmit:r.handleSubmit,children:[e.jsx(a.Input,{...r.getFieldProps("name"),type:"text",label:"New volume name",error:r.touched.name?r.errors.name:null}),e.jsx(He,{value:r.values.pool,setValue:o=>{r.setFieldValue("pool",o)},selectProps:{id:"pool",label:"Storage pool"}}),!J(m?.driver??"")&&e.jsx(Je,{...r.getFieldProps("location")}),e.jsx(a.Select,{...r.getFieldProps("project"),id:"project",label:"Target project",options:c.map(o=>({label:o.name,value:o.name}))}),e.jsx(a.Input,{...r.getFieldProps("copySnapshots"),type:"checkbox",label:"Copy with snapshots",checked:r.values.copySnapshots,error:r.touched.copySnapshots?r.errors.copySnapshots:null}),e.jsx(a.Input,{type:"submit",hidden:!0,value:"Hidden input"})]})})},Pt=({volume:t,classname:s,onClose:n})=>{const{openPortal:i,closePortal:l,isOpen:c,Portal:d}=a.usePortal(),{canCreateStorageVolumes:m}=We(),{data:x}=fe(t.project),f=()=>{l(),n?.()};return e.jsxs(e.Fragment,{children:[c&&e.jsx(d,{children:e.jsx(_t,{close:f,volume:t})}),e.jsxs(a.Button,{appearance:"default","aria-label":"Copy volume",className:q("u-no-margin--bottom has-icon",s),onClick:i,title:m(x)?"Copy volume":"You do not have permission to copy this volume",disabled:!m(x),children:[e.jsx(a.Icon,{name:"canvas"}),e.jsx("span",{children:"Copy"})]})]})},Tt=({volume:t,project:s})=>{const n=be(ye),{hasClusterInternalCustomVolumeCopy:i}=M(),l=z(),c=a.useToastNotification(),d=n?"p-contextual-menu__link":"p-segmented-control__button",m=[e.jsx(kt,{volume:t,classname:d},"migrate"),...i?[e.jsx(Pt,{volume:t,classname:d},"copy")]:[],e.jsx(wt,{volume:t,classname:d},"export"),e.jsx(ze,{label:"Delete",volume:t,project:s,appearance:"",hasIcon:!0,onFinish:()=>{l(`${_}/ui/project/${encodeURIComponent(s)}/storage/volumes`),c.success(e.jsxs(e.Fragment,{children:["Storage volume"," ",e.jsx(B,{bold:!0,type:"volume",value:t.name})," deleted."]}))},classname:d},"delete")];return e.jsx(e.Fragment,{children:n?e.jsx(a.ContextualMenu,{closeOnOutsideClick:!1,toggleLabel:"Actions",position:"left",hasToggleIcon:!0,title:"actions",children:x=>e.jsx("span",{children:[...m].map(f=>N.cloneElement(f,{onClose:x}))})}):e.jsx("div",{className:"p-segmented-control",children:e.jsx("div",{className:"p-segmented-control__list",children:m})})})},Mt=({volume:t,project:s})=>{const n=z(),i=a.useNotify(),l=a.useToastNotification(),c=N.useState(null),{canEditVolume:d}=w(),m=F(),{hasStorageAndProfileOperations:x}=M(),f=o=>{if((o.used_by?.length??0)>0)return"Can not rename, volume is currently in use.";if(!d(o))return"You do not have permission to rename this volume"},j=Y().shape({name:P().test(...Se(s,t.type,c,t)).required("This field is required")}),h=o=>{const p=Ne(t)?`${_}/ui/project/${encodeURIComponent(s)}/storage/pool/${encodeURIComponent(t.pool)}/member/${encodeURIComponent(t.location)}/volumes/${encodeURIComponent(t.type)}/${encodeURIComponent(o.name)}`:`${_}/ui/project/${encodeURIComponent(s)}/storage/pool/${encodeURIComponent(t.pool)}/volumes/${encodeURIComponent(t.type)}/${encodeURIComponent(o.name)}`;n(p),l.success(e.jsxs(e.Fragment,{children:["Storage volume ",e.jsx("strong",{children:t.name})," renamed to"," ",e.jsx(Q,{type:"volume",value:o.name,to:p}),"."]})),r.setFieldValue("isRenaming",!1)},u=o=>{i.failure("Renaming failed",o)},g=()=>{r.setSubmitting(!1)},r=R({initialValues:{name:t.name,isRenaming:!1},validationSchema:j,onSubmit:o=>{if(t.name===o.name){r.setFieldValue("isRenaming",!1),r.setSubmitting(!1);return}$e(s,t,o.name,t.location).then(p=>{x?m.set(p.metadata.id,()=>{h(o)},y=>{u(new Error(y))},g):(h(o),g())}).catch(u)}});return e.jsx(ve,{name:t.name,parentItems:[e.jsx(Ce,{to:`${_}/ui/project/${encodeURIComponent(s)}/storage/volumes`,children:"Storage volumes"},1)],controls:t?e.jsx(Tt,{project:s,volume:t}):null,isLoaded:!0,formik:r,renameDisabledReason:f(t)})},Rt=({volume:t})=>{const s=()=>{Fe("storage-overview-tab")};N.useEffect(s,[t]),a.useListener(window,s,"resize",!0);const{data:n}=ae();return e.jsxs("div",{className:"storage-overview-tab",children:[e.jsxs(a.Row,{className:"section",children:[e.jsx(a.Col,{size:3,children:e.jsx("h2",{className:"p-heading--5",children:"General"})}),e.jsx(a.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:t.name})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Type"}),e.jsx("td",{children:Ve(t)})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Content type"}),e.jsx("td",{children:ke(t)})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Description"}),e.jsx("td",{children:t.description?t.description:"-"})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Cluster member"}),e.jsx("td",{children:n?.environment?.server_clustered&&t.location?e.jsx(rt,{clusterMember:t.location}):"-"})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Pool"}),e.jsx("td",{children:e.jsx(lt,{poolName:t.pool,projectName:t.project,location:t.location})})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Date created"}),e.jsx("td",{children:L(t.created_at)})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Size"}),e.jsx("td",{children:e.jsx(Ze,{volume:t})})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Custom config"}),e.jsx("td",{children:Object.entries(t.config).length===0?"-":e.jsx("table",{children:e.jsx("tbody",{children:Object.entries(t.config).map(([i,l],c)=>e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:i}),e.jsx("td",{children:l})]},c))})})})]})]})})})]}),e.jsxs(a.Row,{className:"section",children:[e.jsx(a.Col,{size:3,children:e.jsx("h2",{className:"p-heading--5",children:"Used by"})}),e.jsx(a.Col,{size:7,children:e.jsx(Xe,{storage:t})})]})]})},I=(t,s)=>({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:s,clusterMember:t.location}),Dt=({volume:t})=>{const s=z(),n=a.useNotify(),i=a.useToastNotification(),l=T(),{section:c}=A(),{project:d}=A(),{canEditVolume:m}=w(),x=F(),{hasStorageAndProfileOperations:f}=M();if(!d)return e.jsx(e.Fragment,{children:"Missing project"});const j=Y().shape({name:P().required("This field is required")}),h=m(t)?void 0:"You do not have permission to edit this volume",u=S=>{o.setValues(I(S)),l.invalidateQueries({queryKey:[b.storage]}),l.invalidateQueries({queryKey:[b.storage,t.pool,d,S.type,S.name]}),i.success(e.jsxs(e.Fragment,{children:["Storage volume ",e.jsx(V,{volume:t})," updated."]}))},g=S=>{n.failure("Storage volume update failed",S)},r=()=>{o.setSubmitting(!1)},o=R({initialValues:I(t,h),validationSchema:j,enableReinitialize:!0,onSubmit:S=>{const k=de(S,d,t);le(S.pool,d,{...k,etag:t.etag},t.location).then(D=>{f?x.set(D.metadata.id,()=>{u(k)},O=>{g(new Error(O))},r):(u(k),r())}).catch(g)}}),p=`${$(t)}/configuration`,y=S=>{s(S===te?p:`${p}/${W(S)}`)};return e.jsxs("div",{className:"edit-storage-volume",children:[e.jsx(ct,{formik:o,section:c??W(te),setSection:y}),e.jsx(mt,{children:o.values.readOnly?null:e.jsxs(e.Fragment,{children:[e.jsx(a.Button,{appearance:"base",onClick:async()=>o.setValues(I(t)),children:"Cancel"}),e.jsx(ut,{formik:o,baseUrl:p,disabled:!o.values.name})]})})]})},Et=({volume:t,snapshot:s,close:n})=>{const i=F(),{hasStorageAndProfileOperations:l}=M(),c=a.useToastNotification(),d=T(),m=N.useState(null),x=async g=>new Promise((r,o)=>{st(t,s,g).then(p=>{i.set(p.metadata.id,()=>{r()},y=>{o(new Error(y))})}).catch(p=>{o(p)})}),[f,j]=s.expires_at?we(new Date(s.expires_at)).slice(0,16).split(" "):[null,null],h=async g=>{let r=!0;g.name!==s.name&&await x(g.name).catch(o=>{c.failure("Snapshot update failed",o),r=!1}),r&&c.success(e.jsxs(e.Fragment,{children:["Snapshot ",e.jsx(H,{name:g.name,volume:t})," ","saved."]})),d.invalidateQueries({predicate:o=>o.queryKey[0]===b.volumes||o.queryKey[0]===b.storage}),u.setSubmitting(!1),n()},u=R({initialValues:{name:s.name,expirationDate:f,expirationTime:j},validateOnMount:!0,validationSchema:et(t,m,s.name),onSubmit:async g=>{const r=g.expirationDate&&g.expirationTime?_e(Qe(g.expirationDate,g.expirationTime)):null;r!==s.expires_at&&await tt(t,s,r).then(o=>{l?i.set(o.metadata.id,()=>{h(g)},p=>{c.failure("Snapshot update failed",new Error(p))}):h(g)}).catch(o=>{c.failure("Snapshot update failed",o)})}});return e.jsx(ht,{isEdit:!0,formik:u,close:n})},vt=({volume:t,snapshot:s,isDeleting:n,isRestoring:i})=>{const{openPortal:l,closePortal:c,isOpen:d,Portal:m}=a.usePortal(),{canManageStorageVolumeSnapshots:x}=w();return e.jsxs(e.Fragment,{children:[d&&e.jsx(m,{children:e.jsx(Et,{close:c,volume:t,snapshot:s})}),e.jsx(a.Button,{appearance:"base",hasIcon:!0,dense:!0,disabled:!x(t)||n||i,onClick:l,type:"button","aria-label":"Edit snapshot",title:x(t)?"Edit":"You do not have permission to edit this snapshot",children:e.jsx(a.Icon,{name:"edit"})})]})},Bt=({volume:t,snapshot:s})=>{const n=F(),i=a.useNotify(),l=a.useToastNotification(),[c,d]=N.useState(!1),[m,x]=N.useState(!1),f=T(),{canManageStorageVolumeSnapshots:j}=w(),h=r=>j(t)?`${r} snapshot`:`You do not have permission to ${r.toLowerCase()} this snapshot`,u=()=>{d(!0);const r=e.jsx(H,{name:s.name,volume:t});at(t,s).then(o=>{n.set(o.metadata.id,()=>l.success(e.jsxs(e.Fragment,{children:["Snapshot"," ",e.jsx(B,{bold:!0,type:"snapshot",value:s.name})," ","deleted for volume ",e.jsx(V,{volume:t}),"."]})),p=>l.failure(`Snapshot ${s.name} deletion failed`,new Error(p),r),()=>{d(!1),f.invalidateQueries({predicate:p=>p.queryKey[0]===b.volumes||p.queryKey[0]===b.storage})})}).catch(o=>{i.failure("Snapshot deletion failed",o,r),d(!1)})},g=()=>{x(!0),ot(t,s).then(()=>{l.success(e.jsxs(e.Fragment,{children:["Snapshot"," ",e.jsx(H,{name:s.name,volume:t})," ","restored for volume ",e.jsx(V,{volume:t}),"."]}))}).catch(r=>{i.failure("Snapshot restore failed",r)}).finally(()=>{x(!1),f.invalidateQueries({predicate:r=>r.queryKey[0]===b.volumes||r.queryKey[0]===b.storage})})};return e.jsx(e.Fragment,{children:e.jsx(a.List,{inline:!0,className:q("u-no-margin--bottom","actions-list",{"u-snapshot-actions":!c&&!m}),items:[e.jsx(vt,{volume:t,snapshot:s,isDeleting:c,isRestoring:m},"edit"),e.jsx(a.ConfirmationButton,{appearance:"base",loading:m,className:"has-icon is-dense",title:"Confirm restore",confirmationModalProps:{title:"Confirm restore",children:e.jsxs("p",{children:["This will restore snapshot"," ",e.jsx(B,{type:"snapshot",value:s.name,bold:!0}),".",e.jsx("br",{}),"This action cannot be undone, and can result in data loss."]}),confirmButtonLabel:h("Restore"),confirmButtonAppearance:"positive",onConfirm:g},disabled:!j(t)||c||m,shiftClickEnabled:!0,showShiftClickHint:!0,children:e.jsx(a.Icon,{name:"change-version"})},"restore"),e.jsx(a.ConfirmationButton,{appearance:"base",loading:c,className:"has-icon is-dense",confirmationModalProps:{title:"Confirm delete",children:e.jsxs("p",{children:["This will permanently delete snapshot"," ",e.jsx(B,{type:"snapshot",value:s.name,bold:!0}),".",e.jsx("br",{}),"This action cannot be undone, and can result in data loss."]}),confirmButtonLabel:h("Delete"),onConfirm:u},disabled:!j(t)||c||m,shiftClickEnabled:!0,showShiftClickHint:!0,children:e.jsx(a.Icon,{name:"delete"})},"delete")]})})},Lt=({volume:t,snapshotNames:s,onStart:n,onFinish:i})=>{const l=F(),c=a.useToastNotification(),[d,m]=N.useState(!1),x=T(),{canManageStorageVolumeSnapshots:f}=w(),j=ft(),h=s.length,u=()=>{m(!0),n(),nt(t,s,l).then(g=>{const{fulfilledCount:r,rejectedCount:o}=Pe(g);r===h?c.success(`${s.length} ${E("snapshot",s.length)} deleted`,j(g)):o===h?c.failure("Snapshot bulk deletion failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:h})," ",E("snapshot",h)," could not be deleted."]}),j(g)):c.failure("Snapshot bulk deletion partially failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:r})," ",E("snapshot",r)," ","deleted.",e.jsx("br",{}),e.jsx("b",{children:o})," ",E("snapshot",o)," ","could not be deleted."]}),j(g)),x.invalidateQueries({predicate:p=>p.queryKey[0]===b.volumes||p.queryKey[0]===b.storage}),m(!1),i()}).catch(g=>{c.failure("Snapshot bulk deletion failed",g),m(!1)})};return e.jsx(jt,{confirmationButtonProps:{loading:d,disabled:!f(t)||d,appearance:""},onDelete:u,entityType:"snapshot",entities:s,deletableEntities:s,buttonLabel:`Delete ${E("snapshot",s.length)}`,disabledReason:f(t)?void 0:"You do not have permission to manage snapshots for this volume"})},It=({volume:t,close:s})=>{const n=a.useNotify(),i=a.useToastNotification(),l=T(),c=F(),{hasStorageAndProfileOperations:d}=M(),m=()=>{i.success(e.jsxs(e.Fragment,{children:["Snapshot configuration updated for volume"," ",e.jsx(V,{volume:t}),"."]})),l.invalidateQueries({queryKey:[b.storage],predicate:u=>u.queryKey[0]===b.volumes||u.queryKey[0]===b.storage})},x=u=>{n.failure("Configuration update failed",u)},f=()=>{s(),j.setSubmitting(!1)},j=R({initialValues:I(t),onSubmit:u=>{const g=de(u,t.project,t);le(t.pool,t.project,{...g,etag:t.etag},t.location).then(r=>{d?c.set(r.metadata.id,m,o=>{x(new Error(o))},f):(m(),f())}).catch(x)}}),h=u=>{u.key==="Escape"&&s()};return e.jsx(a.Modal,{close:s,className:"edit-snapshot-config",title:"Snapshot configuration",buttonRow:j.values.readOnly?e.jsx(a.Button,{className:"u-no-margin--bottom u-no-margin--right",onClick:s,children:"Close"}):e.jsxs(e.Fragment,{children:[e.jsx(a.Button,{appearance:"base",className:"u-no-margin--bottom",type:"button",onClick:s,children:"Cancel"}),e.jsx(a.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",loading:j.isSubmitting,disabled:j.isSubmitting,onClick:()=>{j.submitForm()},children:"Save"})]}),onKeyDown:h,children:e.jsx(dt,{formik:j})})},se=({volume:t,isDisabled:s,className:n})=>{const{openPortal:i,closePortal:l,isOpen:c,Portal:d}=a.usePortal(),{canEditVolume:m}=w();return e.jsxs(e.Fragment,{children:[c&&e.jsx(d,{children:e.jsx("div",{className:"snapshot-list",children:e.jsx(It,{close:l,volume:t})})}),e.jsx(a.Button,{onClick:i,className:n,disabled:!m(t)||s,title:m(t)?"Configure snapshot":"You do not have permission to configure this volume",children:"See configuration"})]})},$t=({volume:t})=>{const[s,n]=N.useState(""),[i,l]=N.useState([]),[c,d]=N.useState([]),[m,x]=N.useState(X()),f=a.useNotify(),{project:j,isLoading:h}=ne(),{data:u,error:g,isLoading:r}=Te({queryKey:[b.storage,b.snapshots,t.pool,t.project,t.type,t.name,t.location],queryFn:async()=>it(t)}),o=Ae(j);N.useEffect(()=>{const C=new Set(u?.map(K=>K.name)),v=i.filter(K=>C.has(K));v.length!==i.length&&l(v)},[u,i]);const p=u?.filter(C=>!(s&&!C.name.toLowerCase().includes(s.toLowerCase())))??[],y=u&&u.length>0,S=[{content:m?e.jsxs(e.Fragment,{children:["Name",e.jsx("br",{}),e.jsx("div",{className:"header-second-row",children:"Date created"})]}):"Name",sortKey:m?"created_at":"name",className:"name"},...m?[]:[{content:"Date created",sortKey:"created_at",className:"created"}],{content:"Expiry date",sortKey:"expires_at",className:"expiration"},{"aria-label":"Actions",className:"actions"}],k=p.map(C=>{const v=e.jsx(Bt,{volume:t,snapshot:C});return{key:C.name,className:"u-row",name:C.name,columns:[{content:e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"u-truncate",title:C.name,children:e.jsx(Me,{item:C})}),m&&e.jsx("div",{className:"u-text--muted",children:L(C.created_at)})]}),role:"rowheader","aria-label":"Name",className:"name"},...m?[]:[{content:L(C.created_at),role:"cell","aria-label":"Created at",className:"created"}],{content:L(C.expires_at??""),role:"cell","aria-label":"Expires at",className:"expiration"},{content:v,role:"cell","aria-label":"Actions",className:"u-align--right actions"}],sortData:{name:C.name.toLowerCase(),created_at:C.created_at,expires_at:C.expires_at}}}),{rows:D,updateSort:O}=bt({rows:k,defaultSort:"created_at",defaultSortDirection:"descending"}),me=()=>{x(X())};return a.useListener(window,me,"resize",!0),g&&f.failure("Loading storage volume snapshots failed",g),r||h?e.jsx(a.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0}):u?e.jsxs("div",{className:"snapshot-list",children:[y&&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(a.SearchBox,{name:"search-snapshot",className:"search-box margin-right",type:"text",onChange:C=>{n(C)},placeholder:"Search for snapshots",value:s,"aria-label":"Search for snapshots"})}),e.jsx(se,{volume:t,className:"u-no-margin--right"}),e.jsx(ee,{volume:t,className:"u-float-right",isDisabled:o})]}):e.jsx("div",{className:"p-panel__controls",children:e.jsx(Lt,{volume:t,snapshotNames:i,onStart:()=>{d(i)},onFinish:()=>{d([])}})})}),y?e.jsx(e.Fragment,{children:e.jsx(a.ScrollableTable,{dependencies:[p],tableId:"volume-snapshot-table",belowIds:["status-bar"],children:e.jsx(a.TablePagination,{data:D,id:"pagination",itemName:"snapshot",className:"u-no-margin--top","aria-label":"Table pagination control",description:i.length>0&&e.jsx(xt,{totalCount:u.length??0,itemName:"snapshot",parentName:"volume",selectedNames:i,setSelectedNames:l,filteredNames:p.map(C=>C.name)}),children:e.jsx(gt,{id:"volume-snapshot-table",headers:S,rows:D,responsive:!0,sortable:!0,emptyStateMsg:"No snapshot found matching this search",itemName:"snapshot",parentName:"instance",selectedNames:i,setSelectedNames:l,disabledNames:c,filteredNames:p.map(C=>C.name),onUpdateSort:O,defaultSort:"created_at",defaultSortDirection:"descending"})})})}):e.jsxs(a.EmptyState,{className:"empty-state",image:e.jsx(a.Icon,{name:"snapshot",className:"empty-state-icon"}),title:"No snapshots found",children:[e.jsx("p",{children:j&&o?e.jsxs(e.Fragment,{children:["Snapshots are disabled for project"," ",e.jsx(ce,{projectName:j.name,urlSuffix:"/configuration"}),"."]}):"There are no snapshots for this volume."}),e.jsx("p",{children:e.jsx(Re,{docPath:"/howto/storage_backup_volume/#storage-backup-snapshots",hasExternalIcon:!0,children:"Learn more about snapshots"})}),e.jsx(se,{volume:t,isDisabled:o}),e.jsx(ee,{volume:t,className:"empty-state-button",isDisabled:o})]})]}):e.jsx(e.Fragment,{children:"Loading storage volume snapshots failed"})},zt=["Overview","Configuration","Snapshots"],Ts=()=>{const{pool:t,project:s,member:n,activeTab:i,type:l,volume:c}=A();if(!t)return e.jsx(e.Fragment,{children:"Missing storage pool"});if(!s)return e.jsx(e.Fragment,{children:"Missing project"});if(!l)return e.jsx(e.Fragment,{children:"Missing type"});if(!c)return e.jsx(e.Fragment,{children:"Missing volume"});const{data:d,error:m,isLoading:x}=Ge(t,s,l,c,n);return x?e.jsx(a.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0}):d?e.jsx(a.CustomLayout,{header:e.jsx(Mt,{volume:d,project:s}),contentClassName:"detail-page storage-volume-form u-no-padding--bottom",children:e.jsxs(a.Row,{children:[e.jsx(pt,{tabs:zt,activeTab:i,tabUrl:$(d)}),e.jsx(Ee,{}),!i&&e.jsx("div",{role:"tabpanel","aria-labelledby":"overview",children:e.jsx(Rt,{volume:d})}),i==="configuration"&&e.jsx("div",{role:"tabpanel","aria-labelledby":"configuration",children:e.jsx(Dt,{volume:d})}),i==="snapshots"&&e.jsx("div",{role:"tabpanel","aria-labelledby":"snapshots",children:e.jsx($t,{volume:d})})]})}):e.jsx(De,{entityType:"volume",entityName:c,errorMessage:m?.message})};export{Ts as default};