| Current Path : /proc/thread-self/root/snap/lxd/current/share/lxd-ui/assets/ |
| Current File : //proc/thread-self/root/snap/lxd/current/share/lxd-ui/assets/StorageVolumeDetail-BG7go1ST.js |
import{d as a,J as F,t as M,c as z,j as e,H as G,w as b,cS as v,v as Q,R as _,r as N,S as pe,s as q,K as T,b as oe,k as R,bk as ue,T as ae,aI as he,f as Y,h as P,E as ge,aY as xe,al as je,O as fe,a$ as be,y as I,c5 as ye,L as Se,di as Ce,dd as Ne,c4 as Ve,an as L,a2 as ke,I as A,a5 as J,aG as Fe,aH as we,U as B,ak as _e,d9 as X,ae as Pe,aM as Me,M as Te,b3 as Re,p as Ee}from"./index-BFGypnt-.js";import{R as Be}from"./RenameHeader-yxEpJNaX.js";import{i as ne,j as ie,h as De,m as Ie,k as Le,r as $e,l as re}from"./storage-volumes-CNe_c3nC.js";import{u as w,D as ve}from"./DeleteStorageVolumeBtn-DIlt1DOO.js";import{F as U,B as W}from"./FormLink-DYjWMIpw.js";import{V}from"./VolumeLinkChip-CgrDSaXC.js";import{P as le}from"./ProjectRichChip-CtiU36yR.js";import{S as ze,C as qe,P as Oe}from"./ProjectSelectTable-D0nW_Kqu.js";import{h as ce,l as Ke,X as Z}from"./useStoragePools-qBtKr1j9.js";import{c as Ue,g as Qe,i as Ae}from"./snapshots-DETOqD-5.js";import{S as He}from"./StoragePoolSelector-CIzPJc24.js";import{a as Ye,c as Ge}from"./useVolumes-CXLHz-Wc.js";import{C as Je}from"./ClusterMemberSelector-Bokudnyt.js";import{u as Xe}from"./projects-DAlFlfjH.js";import{S as We}from"./StorageUsedBy-IXQzaZEP.js";import{S as Ze,u as et,g 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-BVSGpQdK.js";import{a as rt}from"./ClusterMemberRichChip-h3WaiYeI.js";import{S as lt}from"./StoragePoolRichChip-CxRTjvv2.js";import{v as de,d as ct,M as te,e as dt}from"./StorageVolumeForm-CW2hs3vZ.js";import{F as mt}from"./FormFooterLayout-CMGxv4XX.js";import{F as pt}from"./FormSubmitBtn-NpEQWJ3F.js";import{T as ut}from"./TabLinks-BlmDr2on.js";import{S as ht}from"./SnapshotForm-9YABarEV.js";import{S as gt}from"./SelectableMainTable-BZaSR8Vv.js";import{S as xt}from"./SelectedTableNotification-D7txT2Gz.js";import{B as jt}from"./BulkDeleteButton-Cy-zhz39.js";import{u as ft}from"./useBulkDetails-_NNE1L7C.js";import{u as bt}from"./useSortTableData-DMPSUVcX.js";import"./useProfiles-CErbukD2.js";import"./useClusterMembers-B29_ixY7.js";import"./cluster-members-CG6XHzn4.js";import"./StoragePoolSize-ChYxPd_8.js";import"./Meter-VGEmUMfL.js";import"./StoragePoolClusterMember-BjRQEHXC.js";import"./images-C6WqBeZG.js";import"./UsedByRow-oKHc8A5r.js";import"./UsedByItem-DETYWHDN.js";import"./useImages-DavKpFTt.js";import"./image-registries-YAuyq4CZ.js";import"./ProfileRichChip-XiLIeCE5.js";import"./ProfileResourceLimits-DkY60ueM.js";import"./ExpandableList-DK5_MQFC.js";import"./ClusterMemberMemoryUsage-UO8J-hw2.js";import"./FormMenuItem-fhYfVpHc.js";import"./ConfigurationTable-CmO6jSmV.js";import"./ConfigFieldDescription-CY0sdTp6.js";import"./DiskSizeSelector-C_YZZUSe.js";import"./ScrollableForm-D-7nf2YI.js";import"./ScrollableConfigurationTable-Cdfv_OdM.js";import"./instanceAndProfilePayloads-DSYCnS-r.js";import"./formChangeCount-Dw7v2KcL.js";const yt=({volume:t,close:s,type:n,target:i})=>{const l=a.useToastNotification(),c=F(),d=M(),m=z(),x=()=>{let r="";const o=v(t),u=v({...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!==u&&m(u)),n==="pool"&&(r=e.jsxs(e.Fragment,{children:["Volume ",e.jsx(V,{volume:{...t,pool:i}}),"successfully migrated to pool ",y]}),o!==u&&m(u)),n==="project"&&(r=e.jsxs(e.Fragment,{children:["Volume ",e.jsx(V,{volume:{...t,project:i}}),"successfully moved to project ",e.jsx(le,{projectName:i})]}),o!==u&&m(u)),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))},g=()=>{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;Ie(t,t.project,r,t.location,o).then(u=>{c.set(u.metadata.id,()=>{x()},y=>{j(y)},g),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(u=>{f(u)}).finally(()=>{s()})},handleMemberMigrate:()=>{const r=n==="cluster member"?i:void 0,o=t.location,u=ne(t,t.name,t.project);ie(u,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]}),De(t.name,t.pool,t.project,o).then(S=>{c.set(S.metadata.id,()=>{x()},k=>{j(k)},g),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)},g)}).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(ze,{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(qe,{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(Oe,{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=pe(),{data:m}=ce(s.pool),{handleMigrate:x,handleMemberMigrate:f}=yt({close:t,volume:s,type:n,target:l}),j=h=>{h.key==="Escape"&&t()},g=()=>{if(l){c("");return}if(n){i("");return}},p=()=>n?l?e.jsx(W,{title:"Confirm migration",linkText:`Choose ${n}`,onClick:g}):e.jsx(W,{title:e.jsxs(e.Fragment,{children:["Choose ",n," for volume ",e.jsx("strong",{children:s.name})]}),linkText:"Choose migration method",onClick:g}):"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:p()},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&&Ke(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:g,migrate:f}),n==="pool"&&e.jsx(St,{volume:s,onSelect:c,onCancel:g,migrate:x}),n==="project"&&e.jsx(Nt,{volume:s,onSelect:c,targetProject:l,onCancel:g,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}=T(),{data:d}=oe(),m=d?.environment?.backup_metadata_version_range??[],x=p=>{const h=new URLSearchParams;h.set("project",t.project),ue(h,t.location);const r=`${_}/1.0/storage-pools/${encodeURIComponent(t.pool)}/volumes/${encodeURIComponent(t.type)}/${encodeURIComponent(t.name)}/backups/${encodeURIComponent(p)}/export?${h.toString()}`,o=document.createElement("a");o.href=r,o.download=p,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:p})]}))},f=p=>{const h=new Date;return h.setHours(h.getHours()+p),h},j=p=>{const h=new Date().toISOString().replaceAll(":","-").split(".")[0],r=`${t.name}-${h}.tar${p.compression==="gzip"?".gz":""}`,o=JSON.stringify({name:r,expires_at:f(p.expirationHours).toISOString(),compression_algorithm:p.compression,volume_only:p.volumeOnly,optimized_storage:p.optimizedStorage,version:c?Number(p.exportVersion):void 0});Le(t,o).then(u=>{i.info(e.jsxs(e.Fragment,{children:["Backing up volume ",l,".",e.jsx("br",{}),"Download will start, when the export is ready."]})),n.set(u.metadata.id,()=>{x(r)},y=>i.failure(`Could not download volume ${t.name}`,new Error(y),l))}).catch(u=>i.failure(`Could not download volume ${t.name}`,u,l)).finally(()=>{s()})},g=R({initialValues:{compression:"gzip",exportVersion:"2",expirationHours:6,volumeOnly:!1,optimizedStorage:!0},onSubmit:p=>{j(p)}});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:g.isSubmitting,disabled:g.isSubmitting,onClick:()=>{g.submitForm()},children:"Export volume"})]}),children:e.jsxs(a.Form,{onSubmit:g.handleSubmit,children:[e.jsx(a.Select,{...g.getFieldProps("compression"),id:"project",label:"Compression",help:"No compression will be faster, but larger",options:[{value:"gzip",label:"Gzip"},{value:"none",label:"None"}]}),c&&e.jsx(a.Select,{...g.getFieldProps("exportVersion"),id:"exportVersion",label:"Export version",help:"Lower versions allow imports on older LXD versions",options:m.map(p=>({value:p.toString(),label:p.toString()}))}),e.jsx(a.Input,{...g.getFieldProps("optimizedStorage"),type:"checkbox",label:"Use storage driver optimized format",help:"Can only be restored on a similar pool",checked:g.values.optimizedStorage}),e.jsx(a.Input,{...g.getFieldProps("volumeOnly"),type:"checkbox",label:"Export without volume snapshots",error:g.touched.volumeOnly?g.errors.volumeOnly:null,checked:g.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}=ae(),f=Ue(x),j=()=>{l(),n?.()},g=()=>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:g(),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}=he(),{data:m}=ce(t.pool),{data:x=[],isLoading:f}=Ye(t.project),j=o=>{const u={...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:u}),"."]}))},g=o=>{n.failure("Volume copy failed.",o,e.jsx(V,{volume:t}))},p=o=>{const u=o.name+"-copy";return xe(u,x)},h=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:u,project:y,pool:S,location:k}=o;return await ge(u,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:p(t),project:t.project,copySnapshots:!0,pool:t.pool,location:Z(m?.driver??"")?"":t.location},enableReinitialize:!0,validationSchema:h,onSubmit:o=>{const u=ne(t,o.name,o.project,!o.copySnapshots);ie(u,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=>{g(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"}}),!Z(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}=Xe(),{data:x}=je(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"})]})]})},Mt=({volume:t,project:s})=>{const n=fe(be),{hasClusterInternalCustomVolumeCopy:i}=T(),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(ve,{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(I,{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})})})},Tt=({volume:t,project:s})=>{const n=z(),i=a.useNotify(),l=a.useToastNotification(),c=N.useState(null),{canEditVolume:d}=w(),m=F(),{hasStorageAndProfileOperations:x}=T(),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(...ye(s,t.type,c,t)).required("This field is required")}),g=o=>{const u=Ce(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(u),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:u}),"."]})),r.setFieldValue("isRenaming",!1)},p=o=>{i.failure("Renaming failed",o)},h=()=>{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(u=>{x?m.set(u.metadata.id,()=>{g(o)},y=>{p(new Error(y))},h):(g(o),h())}).catch(p)}});return e.jsx(Be,{name:t.name,parentItems:[e.jsx(Se,{to:`${_}/ui/project/${encodeURIComponent(s)}/storage/volumes`,children:"Storage volumes"},1)],controls:t?e.jsx(Mt,{project:s,volume:t}):null,isLoaded:!0,formik:r,renameDisabledReason:f(t)})},Rt=({volume:t})=>{const s=()=>{ke("storage-overview-tab")};N.useEffect(s,[t]),a.useListener(window,s,"resize",!0);const{data:n}=oe();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:Ne(t)})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Content type"}),e.jsx("td",{children:Ve(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(We,{storage:t})})]})]})},$=(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}),Et=({volume:t})=>{const s=z(),n=a.useNotify(),i=a.useToastNotification(),l=M(),{section:c}=A(),{project:d}=A(),{canEditVolume:m}=w(),x=F(),{hasStorageAndProfileOperations:f}=T();if(!d)return e.jsx(e.Fragment,{children:"Missing project"});const j=Y().shape({name:P().required("This field is required")}),g=m(t)?void 0:"You do not have permission to edit this volume",p=S=>{o.setValues($(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."]}))},h=S=>{n.failure("Storage volume update failed",S)},r=()=>{o.setSubmitting(!1)},o=R({initialValues:$(t,g),validationSchema:j,enableReinitialize:!0,onSubmit:S=>{const k=de(S,d,t);re(S.pool,d,{...k,etag:t.etag},t.location).then(E=>{f?x.set(E.metadata.id,()=>{p(k)},O=>{h(new Error(O))},r):(p(k),r())}).catch(h)}}),u=`${v(t)}/configuration`,y=S=>{s(S===te?u:`${u}/${J(S)}`)};return e.jsxs("div",{className:"edit-storage-volume",children:[e.jsx(ct,{formik:o,section:c??J(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($(t)),children:"Cancel"}),e.jsx(pt,{formik:o,baseUrl:u,disabled:!o.values.name})]})})]})},Bt=({volume:t,snapshot:s,close:n})=>{const i=F(),{hasStorageAndProfileOperations:l}=T(),c=a.useToastNotification(),d=M(),m=N.useState(null),x=async h=>new Promise((r,o)=>{st(t,s,h).then(u=>{i.set(u.metadata.id,()=>{r()},y=>{o(new Error(y))})}).catch(u=>{o(u)})}),[f,j]=s.expires_at?Fe(new Date(s.expires_at)).slice(0,16).split(" "):[null,null],g=async h=>{let r=!0;h.name!==s.name&&await x(h.name).catch(o=>{c.failure("Snapshot update failed",o),r=!1}),r&&c.success(e.jsxs(e.Fragment,{children:["Snapshot ",e.jsx(H,{name:h.name,volume:t})," ","saved."]})),d.invalidateQueries({predicate:o=>o.queryKey[0]===b.volumes||o.queryKey[0]===b.storage}),p.setSubmitting(!1),n()},p=R({initialValues:{name:s.name,expirationDate:f,expirationTime:j},validateOnMount:!0,validationSchema:tt(t,m,s.name),onSubmit:async h=>{const r=h.expirationDate&&h.expirationTime?we(Qe(h.expirationDate,h.expirationTime)):null;r!==s.expires_at&&await et(t,s,r).then(o=>{l?i.set(o.metadata.id,()=>{g(h)},u=>{c.failure("Snapshot update failed",new Error(u))}):g(h)}).catch(o=>{c.failure("Snapshot update failed",o)})}});return e.jsx(ht,{isEdit:!0,formik:p,close:n})},Dt=({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(Bt,{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"})})]})},It=({volume:t,snapshot:s})=>{const n=F(),i=a.useNotify(),l=a.useToastNotification(),[c,d]=N.useState(!1),[m,x]=N.useState(!1),f=M(),{canManageStorageVolumeSnapshots:j}=w(),g=r=>j(t)?`${r} snapshot`:`You do not have permission to ${r.toLowerCase()} this snapshot`,p=()=>{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(I,{bold:!0,type:"snapshot",value:s.name})," ","deleted for volume ",e.jsx(V,{volume:t}),"."]})),u=>l.failure(`Snapshot ${s.name} deletion failed`,new Error(u),r),()=>{d(!1),f.invalidateQueries({predicate:u=>u.queryKey[0]===b.volumes||u.queryKey[0]===b.storage})})}).catch(o=>{i.failure("Snapshot deletion failed",o,r),d(!1)})},h=()=>{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(Dt,{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(I,{type:"snapshot",value:s.name,bold:!0}),".",e.jsx("br",{}),"This action cannot be undone, and can result in data loss."]}),confirmButtonLabel:g("Restore"),confirmButtonAppearance:"positive",onConfirm:h},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(I,{type:"snapshot",value:s.name,bold:!0}),".",e.jsx("br",{}),"This action cannot be undone, and can result in data loss."]}),confirmButtonLabel:g("Delete"),onConfirm:p},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=M(),{canManageStorageVolumeSnapshots:f}=w(),j=ft(),g=s.length,p=()=>{m(!0),n(),nt(t,s,l).then(h=>{const{fulfilledCount:r,rejectedCount:o}=_e(h);r===g?c.success(`${s.length} ${B("snapshot",s.length)} deleted`,j(h)):o===g?c.failure("Snapshot bulk deletion failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:g})," ",B("snapshot",g)," could not be deleted."]}),j(h)):c.failure("Snapshot bulk deletion partially failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:r})," ",B("snapshot",r)," ","deleted.",e.jsx("br",{}),e.jsx("b",{children:o})," ",B("snapshot",o)," ","could not be deleted."]}),j(h)),x.invalidateQueries({predicate:u=>u.queryKey[0]===b.volumes||u.queryKey[0]===b.storage}),m(!1),i()}).catch(h=>{c.failure("Snapshot bulk deletion failed",h),m(!1)})};return e.jsx(jt,{confirmationButtonProps:{loading:d,disabled:!f(t)||d,appearance:""},onDelete:p,entityType:"snapshot",entities:s,deletableEntities:s,buttonLabel:`Delete ${B("snapshot",s.length)}`,disabledReason:f(t)?void 0:"You do not have permission to manage snapshots for this volume"})},$t=({volume:t,close:s})=>{const n=a.useNotify(),i=a.useToastNotification(),l=M(),c=F(),{hasStorageAndProfileOperations:d}=T(),m=()=>{i.success(e.jsxs(e.Fragment,{children:["Snapshot configuration updated for volume"," ",e.jsx(V,{volume:t}),"."]})),l.invalidateQueries({queryKey:[b.storage],predicate:p=>p.queryKey[0]===b.volumes||p.queryKey[0]===b.storage})},x=p=>{n.failure("Configuration update failed",p)},f=()=>{s(),j.setSubmitting(!1)},j=R({initialValues:$(t),onSubmit:p=>{const h=de(p,t.project,t);re(t.pool,t.project,{...h,etag:t.etag},t.location).then(r=>{d?c.set(r.metadata.id,m,o=>{x(new Error(o))},f):(m(),f())}).catch(x)}}),g=p=>{p.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:g,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($t,{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"})]})},vt=({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:g}=ae(),{data:p,error:h,isLoading:r}=Pe({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(p?.map(K=>K.name)),D=i.filter(K=>C.has(K));D.length!==i.length&&l(D)},[p,i]);const u=p?.filter(C=>!(s&&!C.name.toLowerCase().includes(s.toLowerCase())))??[],y=p&&p.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=u.map(C=>{const D=e.jsx(It,{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:D,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:E,updateSort:O}=bt({rows:k,defaultSort:"created_at",defaultSortDirection:"descending"}),me=()=>{x(X())};return a.useListener(window,me,"resize",!0),h&&f.failure("Loading storage volume snapshots failed",h),r||g?e.jsx(a.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0}):p?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--large",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:[u],tableId:"volume-snapshot-table",belowIds:["status-bar"],children:e.jsx(a.TablePagination,{data:E,id:"pagination",itemName:"snapshot",className:"u-no-margin--top","aria-label":"Table pagination control",description:i.length>0&&e.jsx(xt,{totalCount:p.length??0,itemName:"snapshot",parentName:"volume",selectedNames:i,setSelectedNames:l,filteredNames:u.map(C=>C.name)}),children:e.jsx(gt,{id:"volume-snapshot-table",headers:S,rows:E,responsive:!0,sortable:!0,emptyStateMsg:"No snapshot found matching this search",itemName:"snapshot",parentName:"instance",selectedNames:i,setSelectedNames:l,disabledNames:c,filteredNames:u.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(le,{projectName:j.name,urlSuffix:"/configuration"}),"."]}):"There are no snapshots for this volume."}),e.jsx("p",{children:e.jsx(Te,{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"],$s=()=>{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(Tt,{volume:d,project:s}),contentClassName:"detail-page storage-volume-form u-no-padding--bottom",children:e.jsxs(a.Row,{children:[e.jsx(ut,{tabs:zt,activeTab:i,tabUrl:v(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(Et,{volume:d})}),i==="snapshots"&&e.jsx("div",{role:"tabpanel","aria-labelledby":"snapshots",children:e.jsx(vt,{volume:d})})]})}):e.jsx(Re,{entityType:"volume",entityName:c,errorMessage:m?.message})};export{$s as default};