| Current Path : /snap/lxd/38768/share/lxd-ui/assets/ |
| Current File : //snap/lxd/38768/share/lxd-ui/assets/CreateStorageVolume-DlPx9r7D.js |
import{S as G,E as O,d as a,v as B,c as L,r as h,aZ as H,t as W,k as z,f as A,h as E,ck as I,dI as X,j as e,s as Y,z as Z,R,Y as J,dD as ee,x as S,w as oe,p as Q,a0 as q,a6 as w,C as te,bu as ae,V as se}from"./index-BsQN_SZU.js";import{B as le}from"./BaseLayout-D3ZT4TU8.js";import{M as ie,v as re,a as ne}from"./StorageVolumeForm-C6mvm1BU.js";import{P as ce}from"./StorageVolumesFilter-DpWoiZ3T.js";import{F as ue}from"./FormFooterLayout-CcbL_-PB.js";import{u as me,c as de}from"./storage-volumes-CG043sqG.js";import{V as pe}from"./VolumeLinkChip-BDzYNacj.js";import{P as ge}from"./ProgressBar-CZqVHpuJ.js";import{S as fe}from"./StoragePoolSelector-Bvqvds5t.js";import{C as ve}from"./ClusterMemberSelector-o7hg9ebZ.js";import"./SshKeyForm-BNz7yPwa.js";import"./limits-yeXZOxhv.js";import"./AutoExpandingTextArea-Bd-45rZK.js";import"./formFields-DzJouV_d.js";import"./scroll-Dc7Cgzms.js";import"./ProjectRichChip-DZzjTfq6.js";import"./ConfigFieldDescription-CjXKAIpa.js";import"./snapshots-LtzKNDw1.js";import"./DiskSizeSelector-C9kWj54D.js";import"./searchAndFilter-DtC_P-vv.js";import"./StoragePoolSize-BNbqTfwA.js";import"./Meter-cq8smrSm.js";const he=({close:n,uploadState:u,setUploadState:s,defaultVolumeName:r})=>{const{project:m,isLoading:y}=G(),M=O(),l=a.useToastNotification(),b=a.useNotify(),P=B(),C=L(),[V,x]=h.useState(null),N=h.useState(null),{data:c=[]}=H(),{data:i=[]}=W(),p=(o,f,v)=>{const d=ee({location:f,name:o,pool:v,project:m?.name,type:"custom"}),T=e.jsxs(e.Fragment,{children:["Created volume"," ",e.jsx(oe,{type:"volume",value:o,to:d}),"."]}),_=[{label:"Configure",onClick:async()=>C(`${d}/configuration`)}];l.success(T,_)},F=o=>{l.failure("Volume creation failed.",new Error(o))},j=()=>{P.invalidateQueries({predicate:o=>o.queryKey[0]===S.volumes})},$=o=>{const f=new AbortController;x(f);const v=k?o.clusterMember:"";me(o.volumeFile,o.name,m?.name??"",o.pool,s,f,v).then(d=>{l.info(e.jsxs(e.Fragment,{children:["Upload completed. Now creating volume"," ",e.jsx(Z,{bold:!0,type:"volume",value:o.name}),"."]})),M.set(d.metadata.id,()=>{p(o.name,o.clusterMember,o.pool)},F,j),U(),C(`${R}/ui/project/${encodeURIComponent(m?.name??"")}/storage/volumes`)}).catch(d=>{const T=new Error(d.response?.data.error);b.failure("Volume upload failed",T),t.setSubmitting(!1),s(null)})},t=z({initialValues:{name:r||"",pool:"",volumeFile:null,clusterMember:i?.[0]?.server_name??""},validateOnMount:!0,enableReinitialize:!0,validationSchema:A().shape({name:E().test(...I(m?.name||"","custom",N)).optional()}),onSubmit:$}),D=c.find(o=>o.name===t.values.pool),k=X(D?.driver||""),U=h.useCallback(()=>{V?.abort(),s(null),x(null),t.resetForm(),n(),b.clear()},[V,t.resetForm,n,b]),K=async o=>{const{onChange:f}=t.getFieldProps("volumeFile");if(f(o),o.currentTarget.files){const v=o.currentTarget.files[0];if(await t.setFieldValue("volumeFile",v),!r){const d=J(v.name,"-import");await t.setFieldValue("name",d),await t.validateField("name"),t.setFieldTouched("name",!0,!0),t.errors.name||t.setFieldError("name",void 0)}}},g=t.values.volumeFile?"":"Please select a file before adding custom configuration.";return e.jsxs(e.Fragment,{children:[e.jsxs(a.Form,{onSubmit:t.handleSubmit,className:Y({"u-hide":u}),children:[e.jsx(a.Input,{id:"volume-file",name:"volumeFile",type:"file",accept:".tar, application/gzip, application/x-bzip, application/x-xz, application/x-lzma, application/x-squashfs, application/x-qcow2, application/zstd",label:"LXD backup archive (.tar.gz)",onChange:o=>{K(o)}}),e.jsx(a.Input,{...t.getFieldProps("name"),id:"name",type:"text",label:"New volume name",placeholder:"Enter name",error:t.touched.name?t.errors.name:null,disabled:!!g,title:g}),e.jsx(fe,{value:t.values.pool,setValue:o=>{t.setFieldValue("pool",o)},selectProps:{id:"volume-import-pool",label:"Storage pool",disabled:y||!!g,title:g}}),e.jsx(ve,{...t.getFieldProps("clusterMember"),id:"clusterMember",label:"Target cluster member",disabled:!!g||!k,disableReason:k?g:"The selected pool is not cluster specific"})]}),e.jsxs("footer",{className:"p-modal__footer",id:"modal-footer",children:[e.jsx(a.Button,{appearance:"base",className:"u-no-margin--bottom",type:"button",onClick:U,children:"Cancel"}),e.jsx(a.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",loading:t.isSubmitting||!!u,disabled:!t.isValid||t.isSubmitting||y||!t.values.volumeFile,onClick:()=>{t.submitForm()},children:"Upload and create"})]})]})},be=({close:n,name:u})=>{const[s,r]=h.useState(null);return e.jsxs(a.Modal,{close:n,className:"upload-volume-modal",title:"Upload volume file",closeOnOutsideClick:!1,children:[e.jsx(Q,{className:"u-no-padding u-no-margin"}),s&&e.jsxs(e.Fragment,{children:[e.jsx(ge,{percentage:Math.floor(s.percentage)}),e.jsxs("p",{children:[q(s.loaded)," loaded of"," ",q(s.total??0)]})]}),e.jsx(he,{close:n,uploadState:s,setUploadState:r,defaultVolumeName:u})]})},xe=({name:n})=>{const{openPortal:u,closePortal:s,isOpen:r,Portal:m}=a.usePortal();return e.jsxs(e.Fragment,{children:[e.jsx(a.Button,{onClick:u,type:"button",children:e.jsx("span",{children:"Upload volume file"})}),r&&e.jsxs(m,{children:[e.jsx(be,{close:s,name:n}),e.jsx("div",{})]})]})},Qe=()=>{const n=L(),u=a.useNotify(),s=a.useToastNotification(),r=B(),[m,y]=h.useState(w(ie)),M=h.useState(null),{project:l}=te(),[b]=ae(),P=O(),{hasStorageAndProfileOperations:C}=se();if(!l)return e.jsx(e.Fragment,{children:"Missing project"});const V=A().shape({name:E().test(...I(l,"custom",M)).required("This field is required")}),x=(i,p)=>{r.invalidateQueries({queryKey:[S.storage]}),r.invalidateQueries({queryKey:[S.customVolumes,l]}),r.invalidateQueries({queryKey:[S.projects,l]}),r.invalidateQueries({predicate:j=>j.queryKey[0]===S.volumes}),n(`${R}/ui/project/${encodeURIComponent(l)}/storage/volumes`);const F={...i,location:p??"none"};s.success(e.jsxs(e.Fragment,{children:["Storage volume ",e.jsx(pe,{volume:F})," created."]}))},N=i=>{c.setSubmitting(!1),u.failure("Storage volume creation failed",i)},c=z({initialValues:{content_type:"filesystem",volumeType:"custom",name:"",project:l,pool:b.get(ce)||"",size:"GiB",readOnly:!1,isCreating:!0,entityType:"storageVolume"},validationSchema:V,onSubmit:i=>{const p=re(i,l);de(i.pool,l,p,i.clusterMember).then(F=>{C?P.set(F.metadata.id,()=>{x(p,i.clusterMember)},j=>{N(new Error(j))}):x(p,i.clusterMember)}).catch(N)}});return e.jsxs(le,{title:"Create volume",contentClassName:"storage-volume-form",children:[e.jsx(Q,{}),e.jsx(ne,{formik:c,section:m,setSection:i=>{y(w(i))}}),e.jsxs(ue,{children:[e.jsx(a.Button,{appearance:"base",onClick:async()=>n(`${R}/ui/project/${encodeURIComponent(l)}/storage/volumes`),children:"Cancel"}),e.jsx(xe,{name:c.values.name}),e.jsx(a.ActionButton,{appearance:"positive",loading:c.isSubmitting,disabled:!c.isValid||c.isSubmitting,onClick:()=>{c.submitForm()},children:"Create"})]})]})};export{Qe as default};