| Current Path : /snap/lxd/38450/share/lxd-ui/assets/ |
| Current File : //snap/lxd/38450/share/lxd-ui/assets/ImageList-DdaX_OCT.js |
import{u as K,au as z,E as F,d as s,r as w,v as P,j as e,z as $,av as _,x as k,T as S,aw as M,ax as Q,c as q,H as A,R as v,w as H,ay as R,k as O,f as V,az as Y,aA as G,aB as J,h as W,a0 as B,L as X,C as Z,K as ee,aC as ae,p as te}from"./index-BsQN_SZU.js";import{g as T,l as se,e as ne}from"./images-dZFGKb1g.js";import{C as oe}from"./CreateInstanceFromImageBtn-qtdjIDOh.js";import{u as ie}from"./useSortTableData-DkMx8bMp.js";import{S as le}from"./SelectableMainTable-DBx4rRiq.js";import{B as re}from"./BulkDeleteButton-DbqPCHnz.js";import{u as ce}from"./useBulkDetails-ydqvQ5wa.js";import{S as de}from"./SelectedTableNotification-BpePAhdG.js";import{H as me}from"./HelpLink-BJF9zWZL.js";import{P as L}from"./PageHeader-BkhUaI4-.js";import{P as ue}from"./ProgressBar-CZqVHpuJ.js";import{u as U}from"./projects-CczQ3aFg.js";const D=()=>{const{isFineGrained:n}=K();return{canDeleteImage:d=>z(n,"can_delete",d?.access_entitlements)}},ge=({image:n,project:o})=>{const d=F(),i=s.useToastNotification(),[m,r]=w.useState(!1),c=P(),{canDeleteImage:u}=D(),f=T(n),h=()=>{r(!0);const p=e.jsx($,{bold:!0,type:"image",value:f});_(n,o).then(y=>{d.set(y.metadata.id,()=>{c.invalidateQueries({predicate:b=>b.queryKey[0]===k.images}),c.invalidateQueries({queryKey:[k.projects,o]}),i.success(e.jsxs(e.Fragment,{children:["Image ",p," deleted."]}))},b=>i.failure(`Image ${f} deletion failed`,new Error(b),p),()=>{r(!1)})}).catch(y=>{i.failure(`Image ${f} deletion failed`,y,p),r(!1)})};return e.jsx(s.ConfirmationButton,{loading:m,confirmationModalProps:{title:"Confirm delete",children:e.jsxs("p",{children:["This will permanently delete image"," ",e.jsx($,{type:"image",value:f,bold:!0}),".",e.jsx("br",{}),"This action cannot be undone, and can result in data loss."]}),confirmButtonLabel:u(n)?"Delete":"You do not have permission to delete this image",onConfirm:h},className:"has-icon",appearance:"base",disabled:m||!u(n),shiftClickEnabled:!0,showShiftClickHint:!0,children:e.jsx(s.Icon,{name:"delete"})})},pe=({images:n,project:o,onStart:d,onFinish:i})=>{const m=F(),r=s.useToastNotification(),[c,u]=w.useState(!1),f=P(),{canDeleteImage:h}=D(),p=ce(),y=n.length,b=n.filter(g=>h(g)),l=b.map(g=>g.fingerprint),t=b.length,x=()=>{u(!0),d(),M(l,o,m).then(g=>{const{fulfilledCount:I,rejectedCount:a}=Q(g);I===t?r.success(e.jsxs(e.Fragment,{children:[e.jsx("b",{children:l.length})," ",S("image",l.length)," deleted."]}),p(g)):a===t?r.failure("Image bulk deletion failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:t})," ",S("image",t)," could not be deleted."]}),p(g)):r.failure("Image bulk deletion partially failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:I})," ",S("image",I)," ","deleted.",e.jsx("br",{}),e.jsx("b",{children:a})," ",S("image",a)," could not be deleted."]}),p(g)),f.invalidateQueries({predicate:C=>{const N=C.queryKey[0];return N===k.images||N===k.projects}}),u(!1),i()}).catch(g=>{u(!1),r.failure("Image bulk deletion failed",g)})},j=()=>{if(t===y)return;const g=y-t;return[`${t} ${S("image",t)} will be deleted.`,`${g} ${S("image",g)} that you do not have permission to delete will be ignored.`]};return e.jsx(re,{entities:n,deletableEntities:b,entityType:"image",onDelete:x,disabledReason:t===0?`You do not have permission to delete the selected ${S("image",t)}`:void 0,buttonLabel:`Delete ${S("image",y)}`,confirmationButtonProps:{appearance:"",disabled:c||t===0,loading:c},bulkDeleteBreakdown:j(),className:"u-no-margin--bottom"})},he=({project:n})=>{const o=q(),d=`${v}/ui/project/${encodeURIComponent(n)}/storage/custom-isos`,i=A(),m=()=>r=>{r.preventDefault(),o(d)};return e.jsxs(s.Button,{className:"u-no-margin--bottom u-float-right",hasIcon:!i,href:d,onClick:m,element:"a",children:[!i&&e.jsx(s.Icon,{name:"iso"}),e.jsx("span",{children:"Custom ISOs"})]})},fe=({image:n,project:o})=>{const d=s.useToastNotification(),[i,m]=w.useState(!1),r=T(n),c=n.update_source==null,u=`${v}/1.0/images/${encodeURIComponent(n.fingerprint)}/export?project=${encodeURIComponent(o)}`,f=()=>{m(!0);const h=e.jsx(H,{to:`${v}/ui/project/${encodeURIComponent(o)}/images`,type:"image",value:r});try{const p=document.createElement("a");p.href=u,p.download="download",p.click(),window.URL.revokeObjectURL(u),d.success(e.jsxs(e.Fragment,{children:["Image ",h," download started. Please check your downloads folder."]}))}catch(p){d.failure(`Image ${r} was unable to download.`,p,h)}finally{m(!1)}};return e.jsx(s.ActionButton,{title:c?"Export image":"Cannot export this image format.","aria-label":"export image",loading:i,onClick:f,className:"has-icon",appearance:"base",disabled:!c||i,children:e.jsx(s.Icon,{name:"export"})})},be=({close:n,projectName:o})=>{const d=F(),i=s.useToastNotification(),[m,r]=w.useState(null),c=P(),{canCreateImageAliases:u}=U(),{data:f}=R(o),h=()=>{const t=e.jsx(X,{to:`${v}/ui/project/${encodeURIComponent(o)}/images`,children:"uploaded"});i.success(e.jsxs(e.Fragment,{children:["Image ",t,"."]}))},p=t=>{t.target.files&&l.setFieldValue("fileList",t.target.files)},y=t=>{if(t.length===1)return t[0];{const x=new FormData,j=Array.from(t).sort((g,I)=>g.size-I.size);return x.append("metadata",j[0]),x.append("rootfs.img",j[1]),x}},b=()=>{c.invalidateQueries({predicate:t=>t.queryKey[0]===k.images})},l=O({initialValues:{alias:"",isPublic:!1,fileList:null},validationSchema:V().shape({alias:W()}),onSubmit:t=>{if(t.fileList){if(t.fileList.length>2){n(),i.failure("Image upload failed.",new Error("Too many files selected"));return}Y(y(t.fileList),t.isPublic,r,o).then(x=>{i.info(e.jsx(e.Fragment,{children:"Creation of image from file started."})),d.set(x.metadata.id,j=>{if(t.alias){const g=G(j);J(g,t.alias,o).then(b).catch(I=>{i.failure("Image upload succeeded. Failed to create an alias.",I)})}b(),h()},j=>{i.failure("Image upload failed.",new Error(j))})}).catch(x=>{const j=new Error(x.response?.data.error);i.failure("Image upload failed",j)}).finally(()=>{n()})}else n(),i.failure("Image upload failed",new Error("Missing files"))}});return e.jsx(s.Modal,{close:n,title:"Import image from file",className:"upload-image-modal",buttonRow:e.jsxs(e.Fragment,{children:[m&&e.jsxs(e.Fragment,{children:[e.jsx(ue,{percentage:Math.floor(m.percentage)}),e.jsxs("p",{children:[B(m.loaded)," loaded of"," ",B(m.total??0)]})]}),e.jsx(s.Button,{appearance:"base",className:"u-no-margin--bottom",type:"button",onClick:n,children:"Cancel"}),e.jsx(s.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",loading:l.isSubmitting,disabled:!l.isValid||l.isSubmitting||!l.values.fileList,onClick:()=>{l.submitForm()},children:"Upload image"})]}),children:e.jsxs(s.Form,{className:m?"u-hide":"",onSubmit:l.handleSubmit,children:[e.jsx(s.Input,{type:"file",name:"fileList",label:"Image backup file",onChange:p,multiple:!0}),e.jsx(s.Input,{...l.getFieldProps("alias"),type:"text",label:"Alias",placeholder:"Enter alias",error:l.touched.alias?l.errors.alias:null,disabled:!u(f),title:u(f)?"":"You do not have permission to create image aliases"}),e.jsx(s.Input,{...l.getFieldProps("isPublic"),type:"checkbox",label:"Make the image publicly available",error:l.touched.isPublic?l.errors.isPublic:null}),e.jsx(s.Input,{type:"submit",hidden:!0,value:"Hidden input",disabled:!l.isValid||!l.values.fileList})]})})},xe=({projectName:n})=>{const{openPortal:o,closePortal:d,isOpen:i,Portal:m}=s.usePortal(),r=A(),{data:c}=R(n),{canCreateImages:u}=U();return e.jsxs(e.Fragment,{children:[i&&e.jsx(m,{children:e.jsx(be,{close:d,projectName:n})}),e.jsxs(s.Button,{className:"u-no-margin--bottom",onClick:o,hasIcon:!r,disabled:!u(c),title:u(c)?"":"You do not have permission to create images",children:[!r&&e.jsx(s.Icon,{name:"upload"}),e.jsx("span",{children:r?"Upload":"Upload image"})]})]})},Pe=()=>{const n=s.useNotify(),{project:o}=Z(),[d,i]=w.useState(""),[m,r]=w.useState([]),[c,u]=w.useState([]),{canDeleteImage:f}=D();if(!o)return e.jsx(e.Fragment,{children:"Missing project"});const{data:h=[],error:p,isLoading:y}=ee(o);p&&n.failure("Loading images failed",p),w.useEffect(()=>{const a=new Set(h?.map(N=>N.fingerprint)),C=c.filter(N=>a.has(N));C.length!==c.length&&u(C)},[h]);const b=[{content:"Name",sortKey:"name"},{content:"Alias",sortKey:"alias",className:"aliases"},{content:"Architecture",sortKey:"architecture",className:"architecture"},{content:"Cached",sortKey:"cached",className:"cached"},{content:"Type",sortKey:"type",className:"type"},{content:"Upload date",sortKey:"uploaded_at",className:"uploaded_at"},{content:"Size",sortKey:"size",className:"u-align--right size"},{"aria-label":"Actions",className:"actions"}],l=h.filter(a=>!d||(a.properties?.description??"").toLowerCase().includes(d.toLowerCase())||a.aliases.map(C=>C.name).join(", ").toLowerCase().includes(d.toLowerCase())),t=l.filter(f).map(a=>a.fingerprint),x=h.filter(a=>c.includes(a.fingerprint)),j=l.map(a=>{const C=e.jsx(s.List,{inline:!0,className:"actions-list u-no-margin--bottom",items:[e.jsx(oe,{projectName:o,image:se(a)},"launch"),e.jsx(fe,{image:a,project:o},"download"),e.jsx(ge,{image:a,project:o},"delete")]}),N=ne(a),E=T(a);return{key:a.fingerprint,name:a.fingerprint,columns:[{content:E,role:"rowheader","aria-label":"Name"},{content:N,role:"cell","aria-label":"Aliases",className:"aliases"},{content:a.architecture,role:"cell","aria-label":"Architecture",className:"architecture"},{content:a.cached?"Yes":"No",role:"cell","aria-label":"Cached",className:"cached"},{content:a.type=="virtual-machine"?"VM":"Container",role:"cell","aria-label":"Type",className:"type"},{content:ae(a.uploaded_at),role:"cell","aria-label":"Upload date",className:"uploaded_at"},{content:B(a.size),role:"cell","aria-label":"Size",className:"u-align--right size"},{content:C,role:"cell","aria-label":"Actions",className:"u-align--right actions"}],sortData:{name:E.toLowerCase(),alias:N.toLowerCase(),architecture:a.architecture,cached:a.cached,type:a.type,size:+a.size,uploaded_at:a.uploaded_at}}}),{rows:g,updateSort:I}=ie({rows:j});return y?e.jsx(s.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0}):e.jsxs(s.CustomLayout,{mainClassName:"images-list",contentClassName:"u-no-padding--bottom",header:e.jsxs(L,{children:[e.jsxs(L.Left,{children:[e.jsx(L.Title,{children:e.jsx(me,{docPath:"/image-handling/",title:"Learn more about images",children:"Images"})}),c.length===0&&h.length>0&&e.jsx(L.Search,{children:e.jsx(s.SearchBox,{name:"search-images",className:"search-box u-no-margin--bottom",type:"text",onChange:a=>{i(a)},placeholder:"Search",value:d,"aria-label":"Search for images"})}),x.length>0&&e.jsx(pe,{images:x,project:o,onStart:()=>{r(c)},onFinish:()=>{r([])}})]}),e.jsxs(L.BaseActions,{children:[e.jsx(xe,{projectName:o}),e.jsx(he,{project:o})]})]}),children:[e.jsx(te,{}),e.jsxs(s.Row,{children:[h.length===0&&e.jsx(s.EmptyState,{className:"empty-state",image:e.jsx(s.Icon,{name:"image",className:"empty-state-icon"}),title:"No images found in this project",children:e.jsx("p",{children:"Images will appear here, when launching an instance from a remote."})}),h.length>0&&e.jsx(s.ScrollableTable,{dependencies:[h],tableId:"image-table",belowIds:["status-bar"],children:e.jsx(s.TablePagination,{data:g,id:"pagination",itemName:"image",className:"u-no-margin--top","aria-label":"Table pagination control",description:c.length>0&&e.jsx(de,{totalCount:t.length??0,itemName:"image",parentName:"project",selectedNames:c,setSelectedNames:u,filteredNames:t}),children:e.jsx(le,{id:"image-table",headers:b,sortable:!0,className:"image-table",defaultSortKey:"uploaded_at",emptyStateMsg:"No images found matching this search",onUpdateSort:I,selectedNames:c,setSelectedNames:u,itemName:"image",parentName:"project",filteredNames:l.map(a=>a.fingerprint),disabledNames:m,rows:[]})})})]})]})};export{Pe as default};