| 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/LocalImageList-Dh2hyx7f.js |
import{J as F,d as s,r as w,t as T,j as e,y as R,w as v,U as S,ak as Q,c as q,O as K,R as B,v as M,al as z,k as _,am as H,f as O,h as Y,a0 as P,L as V,I as J,an as G,p as W}from"./index-BFGypnt-.js";import{d as X,b as Z,e as ee,f as te,a as ae}from"./useImages-DavKpFTt.js";import{u as D}from"./images-CNjYzWxH.js";import{g as E,l as se,d as oe,e as ne}from"./images-C6WqBeZG.js";import{C as ie}from"./CreateInstanceFromImageBtn-D60qjybc.js";import{u as le}from"./useSortTableData-DMPSUVcX.js";import{S as re}from"./SelectableMainTable-BZaSR8Vv.js";import{B as ce}from"./BulkDeleteButton-Cy-zhz39.js";import{u as me}from"./useBulkDetails-_NNE1L7C.js";import{E as de}from"./ExpandableList-DK5_MQFC.js";import{H as ue}from"./HelpLink-l4aaXUp-.js";import{P as k}from"./PageHeader-DZVSTM6q.js";import{S as pe}from"./SelectedTableNotification-D7txT2Gz.js";import{P as ge}from"./ProgressBar-BgH9rTvH.js";import{u as U}from"./projects-DAlFlfjH.js";import{a as he}from"./architectures-BcTUUUGa.js";import"./image-registries-YAuyq4CZ.js";const fe=({image:o,project:n})=>{const p=F(),i=s.useToastNotification(),[m,r]=w.useState(!1),c=T(),{canDeleteImage:d}=D(),f=E(o),h=()=>{r(!0);const g=e.jsx(R,{bold:!0,type:"image",value:f});X(o,n).then(I=>{p.set(I.metadata.id,()=>{c.invalidateQueries({predicate:b=>b.queryKey[0]===v.images}),c.invalidateQueries({queryKey:[v.projects,n]}),i.success(e.jsxs(e.Fragment,{children:["Image ",g," deleted."]}))},b=>i.failure(`Image ${f} deletion failed`,new Error(b),g),()=>{r(!1)})}).catch(I=>{i.failure(`Image ${f} deletion failed`,I,g),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(R,{type:"image",value:f,bold:!0}),".",e.jsx("br",{}),"This action cannot be undone, and can result in data loss."]}),confirmButtonLabel:d(o)?"Delete":"You do not have permission to delete this image",onConfirm:h},className:"has-icon",appearance:"base",disabled:m||!d(o),shiftClickEnabled:!0,showShiftClickHint:!0,children:e.jsx(s.Icon,{name:"delete"})})},be=({images:o,project:n,onStart:p,onFinish:i})=>{const m=F(),r=s.useToastNotification(),[c,d]=w.useState(!1),f=T(),{canDeleteImage:h}=D(),g=me(),I=o.length,b=o.filter(u=>h(u)),l=b.map(u=>u.fingerprint),a=b.length,x=()=>{d(!0),p(),Z(l,n,m).then(u=>{const{fulfilledCount:y,rejectedCount:t}=Q(u);y===a?r.success(e.jsxs(e.Fragment,{children:[e.jsx("b",{children:l.length})," ",S("image",l.length)," deleted."]}),g(u)):t===a?r.failure("Image bulk deletion failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:a})," ",S("image",a)," could not be deleted."]}),g(u)):r.failure("Image bulk deletion partially failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:y})," ",S("image",y)," ","deleted.",e.jsx("br",{}),e.jsx("b",{children:t})," ",S("image",t)," could not be deleted."]}),g(u)),f.invalidateQueries({predicate:N=>{const C=N.queryKey[0];return C===v.images||C===v.projects}}),d(!1),i()}).catch(u=>{d(!1),r.failure("Image bulk deletion failed",u)})},j=()=>{if(a===I)return;const u=I-a;return[`${a} ${S("image",a)} will be deleted.`,`${u} ${S("image",u)} that you do not have permission to delete will be ignored.`]};return e.jsx(ce,{entities:o,deletableEntities:b,entityType:"image",onDelete:x,disabledReason:a===0?`You do not have permission to delete the selected ${S("image",a)}`:void 0,buttonLabel:`Delete ${S("image",I)}`,confirmationButtonProps:{appearance:"",disabled:c||a===0,loading:c},bulkDeleteBreakdown:j(),className:"u-no-margin--bottom"})},xe=({project:o})=>{const n=q(),p=`${B}/ui/project/${encodeURIComponent(o)}/storage/custom-isos`,i=K(),m=()=>r=>{r.preventDefault(),n(p)};return e.jsxs(s.Button,{className:"u-no-margin--bottom u-float-right",hasIcon:!i,href:p,onClick:m,element:"a",children:[!i&&e.jsx(s.Icon,{name:"iso"}),e.jsx("span",{children:"Custom ISOs"})]})},je=({image:o,project:n})=>{const p=s.useToastNotification(),[i,m]=w.useState(!1),r=E(o),c=o.update_source==null,d=`${B}/1.0/images/${encodeURIComponent(o.fingerprint)}/export?project=${encodeURIComponent(n)}`,f=()=>{m(!0);const h=e.jsx(M,{to:`${B}/ui/project/${encodeURIComponent(n)}/local-images`,type:"image",value:r});try{const g=document.createElement("a");g.href=d,g.download="download",g.click(),window.URL.revokeObjectURL(d),p.success(e.jsxs(e.Fragment,{children:["Image ",h," download started. Please check your downloads folder."]}))}catch(g){p.failure(`Image ${r} was unable to download.`,g,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"})})},Ie=({close:o,projectName:n})=>{const p=F(),i=s.useToastNotification(),[m,r]=w.useState(null),c=T(),{canCreateImageAliases:d}=U(),{data:f}=z(n),h=()=>{const a=e.jsx(V,{to:`${B}/ui/project/${encodeURIComponent(n)}/local-images`,children:"imported"});i.success(e.jsxs(e.Fragment,{children:["Image ",a,"."]}))},g=a=>{a.target.files&&l.setFieldValue("fileList",a.target.files)},I=a=>{if(a.length===1)return a[0];{const x=new FormData,j=Array.from(a).sort((u,y)=>u.size-y.size);return x.append("metadata",j[0]),x.append("rootfs.img",j[1]),x}},b=()=>{c.invalidateQueries({predicate:a=>a.queryKey[0]===v.images})},l=_({initialValues:{alias:"",isPublic:!1,fileList:null},validationSchema:O().shape({alias:Y()}),onSubmit:a=>{if(a.fileList){if(a.fileList.length>2){o(),i.failure("Image import failed.",new Error("Too many files selected"));return}ee(I(a.fileList),a.isPublic,r,n).then(x=>{i.info(e.jsx(e.Fragment,{children:"Creation of image from file started."})),p.set(x.metadata.id,j=>{if(a.alias){const u=H(j);te(u,a.alias,n).then(b).catch(y=>{i.failure("Image import succeeded. Failed to create an alias.",y)})}b(),h()},j=>{i.failure("Image import failed.",new Error(j))})}).catch(x=>{const j=new Error(x.response?.data.error);i.failure("Image import failed",j)}).finally(()=>{o()})}else o(),i.failure("Image import failed",new Error("Missing files"))}});return e.jsx(s.Modal,{close:o,title:"Import image from file",className:"import-image-modal",buttonRow:e.jsxs(e.Fragment,{children:[m&&e.jsxs(e.Fragment,{children:[e.jsx(ge,{percentage:Math.floor(m.percentage)}),e.jsxs("p",{children:[P(m.loaded)," loaded of"," ",P(m.total??0)]})]}),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:l.isSubmitting,disabled:!l.isValid||l.isSubmitting||!l.values.fileList,onClick:()=>{l.submitForm()},children:"Import 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:g,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:!d(f),title:d(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})]})})},ye=({projectName:o})=>{const{openPortal:n,closePortal:p,isOpen:i,Portal:m}=s.usePortal(),r=K(),{data:c}=z(o),{canCreateImages:d}=U();return e.jsxs(e.Fragment,{children:[i&&e.jsx(m,{children:e.jsx(Ie,{close:p,projectName:o})}),e.jsxs(s.Button,{className:"u-no-margin--bottom",onClick:n,hasIcon:!r,disabled:!d(c),title:d(c)?"":"You do not have permission to create images",children:[!r&&e.jsx(s.Icon,{name:"import"}),e.jsx("span",{children:r?"Import":"Import image"})]})]})},ze=()=>{const o=s.useNotify(),{project:n}=J(),[p,i]=w.useState(""),[m,r]=w.useState([]),[c,d]=w.useState([]),{canDeleteImage:f}=D();if(!n)return e.jsx(e.Fragment,{children:"Missing project"});const{data:h=[],error:g,isLoading:I}=ae(n);g&&o.failure("Loading images failed",g),w.useEffect(()=>{const t=new Set(h?.map(C=>C.fingerprint)),N=c.filter(C=>t.has(C));N.length!==c.length&&d(N)},[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:"Import date",sortKey:"uploaded_at",className:"uploaded_at"},{content:"Size",sortKey:"size",className:"u-align--right size"},{"aria-label":"Actions",className:"actions"}],l=h.filter(t=>!p||(t.properties?.description??"").toLowerCase().includes(p.toLowerCase())||t.aliases.map(N=>N.name).join(", ").toLowerCase().includes(p.toLowerCase())),a=l.filter(f).map(t=>t.fingerprint),x=h.filter(t=>c.includes(t.fingerprint)),j=l.map(t=>{const N=e.jsx(s.List,{inline:!0,className:"actions-list u-no-margin--bottom",items:[e.jsx(ie,{projectName:n,image:se(t)},"launch"),e.jsx(je,{image:t,project:n},"download"),e.jsx(fe,{image:t,project:n},"delete")]}),C=oe(t),$=E(t),A=t.aliases&&Array.isArray(t.aliases)?t.aliases.filter(L=>L&&L.name).map(L=>e.jsx("div",{className:"u-truncate",title:L.name,children:L.name},L.name)):[];return{key:t.fingerprint,name:t.fingerprint,columns:[{content:$,role:"rowheader","aria-label":"Name"},{content:A.length>0?e.jsx(de,{items:A,displayCount:2}):null,role:"cell","aria-label":"Aliases",className:"aliases"},{content:he(t.architecture),role:"cell","aria-label":"Architecture",className:"architecture"},{content:t.cached?"Yes":"No",role:"cell","aria-label":"Cached",className:"cached"},{content:ne(t),role:"cell","aria-label":"Type",className:"type"},{content:G(t.uploaded_at),role:"cell","aria-label":"Import date",className:"uploaded_at"},{content:P(t.size),role:"cell","aria-label":"Size",className:"u-align--right size"},{content:N,role:"cell","aria-label":"Actions",className:"u-align--right actions"}],sortData:{name:$.toLowerCase(),alias:C.toLowerCase(),architecture:t.architecture,cached:t.cached,type:t.type,size:+t.size,uploaded_at:t.uploaded_at}}}),{rows:u,updateSort:y}=le({rows:j});return I?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(k,{children:[e.jsxs(k.Left,{children:[e.jsx(k.Title,{children:e.jsx(ue,{docPath:"/image-handling/",title:"Learn more about local images",children:"Local images"})}),c.length===0&&h.length>0&&e.jsx(k.Search,{children:e.jsx(s.SearchBox,{name:"search-images",className:"search-box u-no-margin--bottom",type:"text",onChange:t=>{i(t)},placeholder:"Search",value:p,"aria-label":"Search for images"})}),x.length>0&&e.jsx(be,{images:x,project:n,onStart:()=>{r(c)},onFinish:()=>{r([])}})]}),e.jsxs(k.BaseActions,{children:[e.jsx(ye,{projectName:n}),e.jsx(xe,{project:n})]})]}),children:[e.jsx(W,{}),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 local images found in this project",children:e.jsx("p",{children:"Local 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:u,id:"pagination",itemName:"image",className:"u-no-margin--top","aria-label":"Table pagination control",description:c.length>0&&e.jsx(pe,{totalCount:a.length??0,itemName:"image",parentName:"project",selectedNames:c,setSelectedNames:d,filteredNames:a}),children:e.jsx(re,{id:"image-table",headers:b,sortable:!0,className:"image-table",defaultSortKey:"uploaded_at",emptyStateMsg:"No images found matching this search",onUpdateSort:y,selectedNames:c,setSelectedNames:d,itemName:"image",parentName:"project",filteredNames:l.map(t=>t.fingerprint),disabledNames:m,rows:[]})})})]})]})};export{ze as default};