Your IP : 216.73.216.189


Current Path : /proc/thread-self/root/snap/lxd/current/share/lxd-ui/assets/
Upload File :
Current File : //proc/thread-self/root/snap/lxd/current/share/lxd-ui/assets/InstanceList-B-HM7Xsx.js

import{O as ye,j as e,U as v,d as i,s as Q,b5 as M,r as I,J as Ae,t as ze,at as Oe,D as Ee,b6 as lt,ak as He,w as ue,b7 as dt,b8 as Ue,S as Se,c as Ce,R as Z,b9 as ut,ba as mt,aN as _e,aW as pt,bb as Ke,bc as qe,ap as Qe,aq as ne,L as ee,an as be,v as ht,b2 as jt,b1 as Je,bd as xt,be as Ye,$ as se,T as gt,al as ft,aJ as bt,ae as yt,bf as Nt,p as St,M as Ct,bg as wt,bh as Te,bi as It,bj as vt}from"./index-BFGypnt-.js";import{u as We,p as $t}from"./usePanelParams-CV5ZHNeu.js";import{S as Fe}from"./SelectableMainTable-BZaSR8Vv.js";import{u as Ve}from"./useBulkDetails-_NNE1L7C.js";import{e as kt,c as Rt,d as Me,D as Lt,u as Ze,f as Pt,I as Et,h as Tt,b as Ft}from"./DeleteInstanceBtn-DYpBrIzO.js";import{B as Mt}from"./BulkDeleteButton-Cy-zhz39.js";import{s as Bt,p as Dt}from"./searchAndFilter-DtC_P-vv.js";import{C as At}from"./CancelOperationBtn-CNxiuMjf.js";import{S as zt}from"./SelectedTableNotification-D7txT2Gz.js";import{H as Ot}from"./HelpLink-l4aaXUp-.js";import{u as Ht}from"./useSortTableData-DMPSUVcX.js";import{P as te}from"./PageHeader-DZVSTM6q.js";import{E as Ge}from"./ExpandableList-DK5_MQFC.js";import{P as Ut}from"./ProfileRichChip-XiLIeCE5.js";import{D as _t}from"./ProfileResourceLimits-DkY60ueM.js";import{N as Kt}from"./NetworkRichChip-D2iomVd3.js";import{a as Xe}from"./ClusterMemberRichChip-h3WaiYeI.js";import{S as qt}from"./StoragePoolRichChip-CxRTjvv2.js";import{u as Qt}from"./projects-DAlFlfjH.js";import{h as Jt}from"./images-C6WqBeZG.js";import{P as Yt}from"./ProjectRichChip-CtiU36yR.js";import"./Meter-VGEmUMfL.js";import"./useImages-DavKpFTt.js";import"./image-registries-YAuyq4CZ.js";import"./useProfiles-CErbukD2.js";import"./useNetworks-B1lu5MbM.js";import"./useClusterMembers-B29_ixY7.js";import"./cluster-members-CG6XHzn4.js";import"./ClusterMemberMemoryUsage-UO8J-hw2.js";import"./useStoragePools-qBtKr1j9.js";import"./StoragePoolSize-ChYxPd_8.js";const Wt={start:{Frozen:"unfreeze",Stopped:"start"},restart:{Freezing:"restart",Running:"restart"},freeze:{Running:"freeze"},stop:{Freezing:"stop",Running:"stop",Starting:"stop",Frozen:"stop"}},Ne=(t,c)=>{const o=Wt[t];return o?o[c]:void 0},Vt=(t,c)=>{const o=[];return t.forEach(s=>{const r=Ne(c,s.status);r&&o.push({name:s.name,project:s.project,action:r})}),o},Zt=t=>({unfreeze:"started",start:"started",restart:"restarted",freeze:"frozen",stop:"stopped"})[t],Gt=t=>({Frozen:"frozen",Stopped:"stopped",Running:"running"})[t],de=({action:t,confirmAppearance:c,confirmExtra:o,confirmLabel:s,icon:r,instances:p,isLoading:b,isDisabled:R,onClick:j,restrictedInstances:x})=>{const l=ye(),y=new Set(p.map(h=>h.status)),d=y.size>1,g=d?e.jsxs(e.Fragment,{children:[e.jsx("b",{children:p.length})," ",v("instance",p.length)," ","selected:",e.jsx("br",{}),e.jsx("br",{})]}):null,L=[...y].some(h=>Ne(t,h)!==void 0),S=(h,$)=>{const T=p.filter(Y=>Y.status===h&&!x.includes(M(Y))).length;if(T===0)return null;const k=Gt(h)??"";if(Ne($,h)===void 0){const Y=T===1?"instance that is":"instances that are",me=$!=="restart"?"already ":"";return e.jsxs(I.Fragment,{children:["- No action for ",e.jsx("b",{children:T})," ",Y," ",me,h.toLowerCase(),".",e.jsx("br",{})]},h+$)}const oe=d?"- ":"";return e.jsxs(I.Fragment,{children:[oe,"This will ",$," ",e.jsx("b",{children:T}),` ${k} ${v("instance",T)}.`,e.jsx("br",{})]},h+$)},P=()=>{switch(t){case"start":return["Frozen","Stopped","Running"];case"restart":return["Running","Freezing","Stopped","Frozen"];case"freeze":return["Running","Stopped","Frozen"];case"stop":return["Frozen","Freezing","Running","Starting","Stopped"];default:return[]}},N=x.length===p.length,u=()=>x.length===0?null:e.jsxs(I.Fragment,{children:["- No action for ",e.jsx("b",{children:x.length})," ",v("instance",x.length)," that you do not have permission to ",s.toLowerCase(),".",e.jsx("br",{})]},"restricted"),C=b&&t!=="stop";return e.jsxs(i.ConfirmationButton,{appearance:"base",disabled:R||!L||N||C,loading:b,className:Q({"has-icon":!l},"u-no-margin--right u-no-margin--bottom bulk-action"),confirmationModalProps:{title:`Confirm ${s.toLowerCase()}`,children:e.jsxs("p",{children:[g,P().map(h=>S(h,t)),u()]}),confirmExtra:o,onConfirm:j,confirmButtonLabel:s,confirmButtonAppearance:c},shiftClickEnabled:!0,showShiftClickHint:!0,onHoverText:N?`You do not have permission to ${s.toLowerCase()} the selected ${v("instance",p.length)}`:s,children:[e.jsx(i.Icon,{name:r}),e.jsx("span",{className:"u-hide--small",children:s})]})},Xt=({instances:t,onStart:c,onFinish:o})=>{const s=Ae(),r=i.useToastNotification(),p=ze(),[b,R]=I.useState(null),[j,x]=I.useState(!1),{canUpdateInstanceState:l}=Oe(),y=Ve(),d=()=>{p.invalidateQueries({queryKey:[ue.instances]})},g=()=>{setTimeout(d,1500)},L=P=>{R(P),c();const N=t.filter(l),u=Vt(N,P);lt(u,j,s).then(C=>{const h=Zt(P),$=u.length,{fulfilledCount:T,rejectedCount:k}=He(C);T===$?(r.success(e.jsxs(e.Fragment,{children:[e.jsx("b",{children:$})," ",v("instance",$)," ",h,"."]}),y(C)),d()):k===$?(r.failure(`Instance ${P} failed`,void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:$})," ",v("instance",$)," could not be"," ",h,"."]}),y(C)),g()):(r.failure(`Instance ${P} partially failed`,void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:T})," ",v("instance",T)," ",h,".",e.jsx("br",{}),e.jsx("b",{children:k})," ",v("instance",k)," ","could not be ",h,"."]}),y(C)),g()),x(!1),o(),R(null)}).catch(C=>{r.failure(`Instance ${P} failed`,C),g()})},S=t.filter(P=>!l(P)).map(M);return e.jsx("div",{className:"p-segmented-control bulk-actions",children:e.jsxs("div",{className:"p-segmented-control__list bulk-action-frame",children:[e.jsx(de,{icon:"play",isLoading:b==="start",isDisabled:b==="start",onClick:()=>{L("start")},confirmAppearance:"positive",action:"start",instances:t,confirmLabel:"Start",restrictedInstances:S}),e.jsx(de,{icon:"restart",isLoading:b==="restart",isDisabled:b==="restart",onClick:()=>{L("restart")},action:"restart",instances:t,confirmLabel:"Restart",confirmExtra:e.jsx(Ee,{label:"Force restart",confirmed:[j,x]}),restrictedInstances:S}),e.jsx(de,{icon:"pause",isLoading:b==="freeze",isDisabled:b==="freeze",onClick:()=>{L("freeze")},action:"freeze",instances:t,confirmLabel:"Freeze",restrictedInstances:S}),e.jsx(de,{icon:"stop",isLoading:b==="stop",isDisabled:!1,onClick:()=>{L("stop")},action:"stop",instances:t,confirmLabel:"Stop",confirmExtra:e.jsx(Ee,{label:"Force stop",confirmed:[j,x]}),restrictedInstances:S})]})})},es=({instances:t,onStart:c,onFinish:o})=>{const s=Ae(),r=i.useToastNotification(),p=ze(),[b,R]=I.useState(!1),{canDeleteInstance:j}=Oe(),x=t.filter(u=>!j(u)),l=t.filter(u=>kt.includes(u.status)&&j(u)),y=t.length,d=l.length,g=x.length,L=y-d-g,S=Ve(),P=()=>{R(!0),c(l.map(u=>u.name)),dt(l,s).then(u=>{const{fulfilledCount:C,rejectedCount:h}=He(u);C===d?r.success(`${d} ${v("instance",d)} deleted`,S(u)):h===d?r.failure("Instance bulk deletion failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:d})," ",v("instance",d)," could not be deleted."]}),S(u)):r.failure("Instance bulk deletion partially failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:C})," ",v("instance",C)," ","deleted.",e.jsx("br",{}),e.jsx("b",{children:h})," ",v("instance",h)," ","could not be deleted."]}),S(u)),p.invalidateQueries({queryKey:[ue.instances]}),p.invalidateQueries({queryKey:[ue.projects,t[0].project]}),R(!1),o()}).catch(u=>{r.failure("Instance bulk deletion failed",u),R(!1)})},N=()=>{if(L+g===0)return;const u=[];return d&&u.push(`${d} stopped ${v("instance",d)} will be deleted`),g&&u.push(`${g} ${v("instance",g)} that you do not have permission to delete will be ignored`),L&&u.push(`${L} other ${v("instance",L)} will be ignored`),u};return e.jsx("div",{className:"p-segmented-control bulk-actions",children:e.jsx("div",{className:"p-segmented-control__list bulk-action-frame",children:e.jsx(Mt,{entities:t,deletableEntities:l,entityType:"instance",onDelete:P,disabledReason:g===y?`You do not have permission to delete the selected ${v("instance",t.length)}`:void 0,confirmationButtonProps:{loading:b,appearance:"base"},bulkDeleteBreakdown:N(),className:"u-no-margin--bottom"})})})},ts=["Running","Stopped","Frozen","Error"],ss=["Container","VM"],ns=t=>(t.includes("Frozen")&&t.push("Freezing"),t.includes("Running")&&t.push("Restarting","Starting"),t.includes("Stopped")&&t.push("Stopping"),t),as="query",et="status",tt="type",st="profile",nt="member",rs="project",Be=[as,et,tt,st,nt,rs],os=({instances:t,hasProjectFilter:c})=>{const[o,s]=Ue(),r=Se(),p=[...new Set(t.flatMap(l=>l.profiles))],b=[...new Set(t.flatMap(l=>l.location))],R=[...new Set(t.flatMap(l=>l.project))],j=[{id:1,heading:"Status",chips:ts.map(l=>({lead:et,value:l}))},{id:2,heading:"Instance type",chips:ss.map(l=>({lead:tt,value:l}))},{id:3,heading:"Profile",chips:p.map(l=>({lead:st,value:l}))},...r?[{id:4,heading:"Cluster member",chips:b.map(l=>({lead:nt,value:l}))}]:[],...c?[{id:5,heading:"Project",chips:R.map(l=>({lead:"project",value:l}))}]:[]],x=l=>{const y=Dt(l,o,Be);y.toString()!==o.toString()&&s(y)};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"u-off-screen",children:"Search and filter"}),e.jsx(i.SearchAndFilter,{existingSearchData:Bt(o,Be),filterPanelData:j,returnSearchData:x,onExpandChange:()=>{window.dispatchEvent(new CustomEvent("resize",{detail:"search-and-filter"}))},onPanelToggle:()=>{window.dispatchEvent(new CustomEvent("sfp-toggle"))}})]})},is=I.memo(os),B="Status",J="Name",O="Type",E="Cluster member",H="Description",D="Memory",A="Root filesystem",U="IPv4",_="IPv6",K="Snapshots",V="Project",ae="Actions",m={[J]:170,[O]:130,[E]:150,[D]:150,[A]:150,[H]:150,[U]:150,[_]:330,[K]:110,[V]:160,[B]:160,[ae]:210},cs=[K,_,U,H,E,A,D,O,B,ae],at=[O,D,A,E,H,U,_,K],ls=[O,H,D,A,U,_,K],ds=({instance:t})=>{const c=Ce(),o=()=>{c(`${Z}/ui/project/${encodeURIComponent(t.project)}/instance/${encodeURIComponent(t.name)}/terminal`)},s=t.status!=="Running";return e.jsx(i.Button,{appearance:"base",dense:!0,hasIcon:!0,onClick:o,disabled:s,title:"Terminal","aria-label":"Open Terminal",children:e.jsx(i.Icon,{name:"code"})})},us=({instance:t})=>{const c=Ce(),o=()=>{c(`${Z}/ui/project/${encodeURIComponent(t.project)}/instance/${encodeURIComponent(t.name)}/console`)};return e.jsx(i.Button,{"aria-label":"Open console",appearance:"base",dense:!0,hasIcon:!0,onClick:o,title:"Console",children:e.jsx(i.Icon,{name:"canvas"})})},ms=({instance:t})=>{const c=ut(t);return c.length?e.jsx(Ge,{items:c.map(o=>e.jsx("div",{className:"ip u-truncate",title:`MAC address ${o}`,children:o},o))}):e.jsx(e.Fragment,{children:"-"})},De=5,ps=({instance:t})=>{const c=Object.values(t?.expanded_devices??{}).filter(mt),s=_e().getType(t),r=`${Z}/ui/project/${encodeURIComponent(t.project)}/instance/${encodeURIComponent(t.name)}`,p=Se(),b=!t.state||t.state.pid===0?"-":t.state.pid,R=pt(t);return e.jsx("table",{className:"u-table-layout--auto u-no-margin--bottom",children:e.jsxs("tbody",{children:[e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Name"}),e.jsx("td",{children:e.jsx(Ke,{instance:t})})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Base image"}),e.jsx("td",{children:e.jsx("div",{className:"u-truncate base-image",title:t.config["image.description"],children:e.jsx(Rt,{instance:t})})})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Status"}),e.jsx("td",{children:e.jsx(qe,{instance:t})},t.status+s)]}),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:"Type"}),e.jsx("td",{children:Qe(t)})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"IPv4"}),e.jsx("td",{children:e.jsx(Me,{instance:t,family:"inet"})},ne(t,"inet").length)]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"IPv6"}),e.jsx("td",{children:e.jsx(Me,{instance:t,family:"inet6"})},ne(t,"inet6").length)]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"MAC addresses"}),e.jsx("td",{children:e.jsx(ms,{instance:t})},ne(t,"inet6").length)]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Architecture"}),e.jsx("td",{children:t.architecture})]}),p&&e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Cluster member"}),e.jsx("td",{children:e.jsx(Xe,{clusterMember:t.location})})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Root storage"}),e.jsx("td",{children:e.jsx(qt,{poolName:R,projectName:t.project,location:t.location})})]}),e.jsxs("tr",{className:"list-wrapper",children:[e.jsx("th",{className:"u-text--muted",children:"Networks"}),e.jsx("td",{children:c.length>0?e.jsx(Ge,{items:c.map(j=>e.jsx(Kt,{networkName:j.network,projectName:t.project},j.network))}):e.jsxs("p",{children:["No networks found.",e.jsx("br",{}),e.jsx(ee,{to:`${Z}/ui/project/${encodeURIComponent(t.project)}/instance/${encodeURIComponent(t.name)}/configuration/networks`,children:"Configure instance networks"})]})})]}),e.jsxs("tr",{className:"list-wrapper",children:[e.jsx("th",{className:"u-text--muted",children:"Devices"}),e.jsx("td",{children:e.jsx(_t,{devices:Object.values(t.expanded_devices)})})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"PID"}),e.jsx("td",{children:b})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Created"}),e.jsx("td",{children:be(t.created_at)})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Last used"}),e.jsx("td",{children:be(t.last_used_at)})]}),e.jsxs("tr",{children:[e.jsx("th",{children:e.jsx("h3",{className:"p-muted-heading p-heading--5",children:e.jsx(ee,{to:`${r}/configuration`,children:"Profiles"})})}),e.jsx("td",{children:e.jsx(i.List,{className:"list u-no-margin--bottom",items:t.profiles.map(j=>e.jsx(Ut,{profileName:j,projectName:t.project},j))})})]}),e.jsx("tr",{className:"u-no-border",children:e.jsx("th",{colSpan:2,className:"snapshots-header",children:e.jsx("h3",{className:"p-muted-heading p-heading--5",children:e.jsx(ee,{to:`${r}/snapshots`,children:"Snapshots"})})})}),t.snapshots?.length?e.jsxs(e.Fragment,{children:[t.snapshots.slice().sort((j,x)=>{const l=j.created_at,y=x.created_at;return l>y?-1:l<y?1:0}).slice(0,De).map(j=>e.jsxs("tr",{className:"u-no-border",children:[e.jsx("th",{children:e.jsx(ht,{type:"snapshot",value:j.name,to:`${r}/snapshots`},j.name)}),e.jsx("td",{className:"u-text--muted",children:e.jsx("i",{children:be(j.created_at)})})]},j.name)),t.snapshots.length>De&&e.jsx("tr",{children:e.jsx("td",{colSpan:2,children:e.jsx(ee,{to:`${r}/snapshots`,children:`View all (${t.snapshots.length})`})})})]}):e.jsx("tr",{children:e.jsx("td",{colSpan:2,children:e.jsxs("p",{className:"no-snapshots",children:["No snapshots found.",e.jsx("br",{}),e.jsx(ee,{to:`${r}/snapshots`,children:"Manage instance snapshots"})]})})})]})})},hs=()=>{const t=i.useNotify(),c=We(),o=c.instance!==null,{data:s,error:r,isLoading:p}=jt(c.instance??"",c.project,o);return r&&t.failure("Loading instance failed",r),e.jsxs(i.SidePanel,{loading:p,hasError:!s,className:"u-hide--medium u-hide--small detail-panel instance-detail-panel",pinned:!0,width:"narrow",children:[e.jsxs(i.SidePanel.Sticky,{children:[e.jsxs(i.SidePanel.Header,{children:[e.jsx(i.SidePanel.HeaderTitle,{children:"Instance summary"}),e.jsx(i.SidePanel.HeaderControls,{children:e.jsx(i.Button,{appearance:"base",className:"u-no-margin--bottom",hasIcon:!0,onClick:c.clear,"aria-label":"Close",children:e.jsx(i.Icon,{name:"close"})})})]}),s&&e.jsxs("div",{className:"actions",children:[e.jsx(i.List,{inline:!0,className:"primary actions-list",items:[e.jsx(ds,{instance:s},"terminal"),e.jsx(us,{instance:s},"console"),e.jsx(Lt,{instance:s,label:"",classname:"is-dense p-button--base"},"delete")]}),e.jsx("div",{className:"state",children:e.jsx(Je,{instance:s})})]})]}),e.jsx(i.SidePanel.Content,{children:s&&e.jsx(ps,{instance:s})})]})},js=({instance:t})=>{const{data:c=[]}=Ze(t.location),o=Pt(c,t);return e.jsx(Et,{memory:o})},xs=({instance:t})=>{const{data:c=[]}=Ze(t.location),[o]=Tt(c,t);return e.jsx(Ft,{filesystem:o})},gs=({operation:t})=>{const{operationProgress:c}=xt(),o=t.id in c?c[t.id]:t.metadata??{};if(Ye(t))return`Restoring backup for ${se(t)}`;if(o.format_progress_progress)return e.jsx("div",{children:o.format_progress_progress});const s=Object.entries(o).find(([r])=>r.endsWith("_progress"));if(s){const[r,p]=s;return e.jsxs("div",{children:[r,": ",p]})}return null},fs=()=>{const t=localStorage.getItem("instanceListHiddenColumns"),c=new Set(at);return t?JSON.parse(t).filter(o=>c.has(o)):[D,A]},bs=t=>{localStorage.setItem("instanceListHiddenColumns",JSON.stringify(t))},Zs=()=>{const t=_e(),c=Ce(),o=i.useNotify(),s=We(),{project:r,isAllProjects:p}=gt(),{data:b}=ft("default",p),[R,j]=I.useState("Create instance"),[x]=Ue(),l=Se(),{canCreateInstances:y}=Qt(),d={queries:x.getAll("query").map(n=>n.toLowerCase()),statuses:ns(x.getAll("status")),types:x.getAll("type").map(Jt),profiles:x.getAll("profile"),clusterMembers:x.getAll("member"),projects:x.getAll("project")},[g,L]=I.useState(fs()),[S,P]=I.useState([]),[N,u]=I.useState([]),[C,h]=I.useState([]),$=ye(),T=ye(It);if(!r&&!p)return e.jsx(e.Fragment,{children:"Missing project"});I.useEffect(()=>{l||!g.includes(E)||L(g.filter(n=>n!==E))},[l]);const{data:k=[],error:re,isLoading:oe}=bt(r?.name??null);re&&o.failure("Loading instances failed",re);const Y=()=>{j(T?"Create":"Create instance")};i.useListener(window,Y,"resize",!0);const me=()=>{const n=document.getElementById("instances-table");n&&(n.style.display="none",n.offsetHeight,n.style.display="table")};i.useListener(window,me,"resize",!0);const rt=n=>{L(n),bs(n)},{data:pe,error:we}=yt({queryKey:[ue.operations,r?.name],queryFn:async()=>vt(r?.name??null)});we&&!re&&o.failure("Loading operations failed",we);const ot=(pe?.running??[]).filter(n=>n.description==="Migrating instance").map(se),he=[],ie=(pe?.running??[]).concat(pe?.success??[]).filter(n=>{const f=se(n),z=Nt(n)||Ye(n),G=C.includes(f),W=ot.includes(f);if(!z||G||W||!f)return!1;const a=k.some(F=>F.name===f);return!(n.status==="Running")&&a?!1:(he.push(f),!0)}),q=k.filter(n=>!(he.includes(n.name)||!d.queries.every(f=>n.name.toLowerCase().includes(f)||n.description.toLowerCase().includes(f)||n.config["image.description"]?.toLowerCase().includes(f))||d.statuses.length>0&&!d.statuses.includes(n.status)||d.types.length>0&&!d.types.includes(n.type)||d.profiles.length>0&&!d.profiles.every(f=>n.profiles.includes(f))||d.clusterMembers.length>0&&!d.clusterMembers.includes(n.location)||d.projects.length>0&&!d.projects.includes(n.project)));I.useEffect(()=>{const n=new Set(q.map(M)),f=N.filter(z=>n.has(z));f.length!==N.length&&u(f)},[q]),I.useEffect(()=>{s.instance&&(k.some(n=>n.name===s.instance&&n.project===s.project)||s.clear())},[k]);const Ie=[{content:J,sortKey:"name",style:{width:`${m[J]}px`}},{content:O,sortKey:"type",style:{width:`${m[O]}px`}},...p?[{content:V,sortKey:"project",style:{width:`${m[V]}px`}}]:[],...l?[{content:E,sortKey:"member",style:{width:`${m[E]}px`}}]:[],{content:D,style:{width:`${m[D]}px`}},{content:A,style:{width:`${m[A]}px`}},{content:H,sortKey:"description",style:{width:`${m[H]}px`}},{content:U,className:"u-align--right",style:{width:`${m[U]}px`}},{content:_,id:"header-ipv6",style:{width:`${m[_]}px`}},{content:K,sortKey:"snapshots",className:"u-align--right",style:{width:`${m[K]}px`}},{content:B,sortKey:"status",className:"status-header status",style:{width:`${m[B]}px`}},{"aria-label":"Actions",className:Q({"u-hide":s.instance}),style:{width:`${m[ae]}px`}}],ve=i.visibleHeaderColumns(Ie,g.concat(S)),$e=n=>{const f=ls.filter(a=>!n.includes(a)).concat(...l&&!n.includes(E)?[E]:[]).concat(...p?[V]:[]).reduce((a,w)=>a+m[w],0),z=ve.length,G=ie.map(a=>({key:a.id,className:"u-row",columns:[{content:se(a),className:"u-truncate",title:se(a),role:"rowheader","aria-label":J,style:{width:`${m[J]}px`}},...z>3?[{content:e.jsx("i",{children:e.jsx(gs,{operation:a})},JSON.stringify(a.metadata??{})),role:"cell",colSpan:z-3,style:{width:`${f}px`}}]:[],...S.includes(B)?[]:[{content:e.jsxs(e.Fragment,{children:[e.jsx(i.Spinner,{className:"status-icon"})," Setting up"]}),role:"cell","aria-label":B,style:{width:`${m[B]}px`}}],{content:e.jsx(At,{operation:a,project:r?.name}),role:"cell",className:Q("u-align--right",{"u-hide":s.instance}),"aria-label":"Actions",style:{width:`${m[ae]}px`}}],sortData:{name:null}})),W=q.map(a=>{const w=()=>{s.openInstanceSummary(a.name,a.project)},F=ne(a,"inet"),X=wt(ne(a,"inet6")),xe=t.getType(a),ge=s.instance===a.name&&s.project===a.project;return{key:M(a),className:ge?"u-row-selected":"u-row",name:M(a),columns:[{content:e.jsx(Ke,{instance:a}),className:"u-truncate",title:`Instance ${a.name}`,role:"rowheader",style:{width:`${m[J]}px`},"aria-label":J,onClick:w},{content:Qe(a),role:"cell","aria-label":O,onClick:w,className:"clickable-cell",style:{width:`${m[O]}px`}},...p?[{content:e.jsx(Yt,{projectName:a.project,urlSuffix:"/instances"}),role:"cell","aria-label":V,style:{width:`${m[V]}px`}}]:[],...l?[{content:e.jsx(Xe,{clusterMember:a.location}),role:"cell","aria-label":E,style:{width:`${m[E]}px`}}]:[],{content:e.jsx(js,{instance:a}),role:"cell","aria-label":D,onClick:w,className:"clickable-cell",style:{width:`${m[D]}px`}},{content:e.jsx(xs,{instance:a}),role:"cell","aria-label":A,onClick:w,className:"clickable-cell",style:{width:`${m[A]}px`}},{content:e.jsx("div",{className:"u-truncate",title:a.description,children:a.description}),role:"cell","aria-label":H,onClick:w,className:"clickable-cell",style:{width:`${m[H]}px`}},{key:`ipv4-${F.length}`,content:e.jsx(Te,{items:F.map(fe=>fe.address)}),role:"cell",className:"u-align--right clickable-cell","aria-label":U,onClick:w,style:{width:`${m[U]}px`}},{key:`ipv6-${X.length}`,content:e.jsx(Te,{items:X.map(fe=>fe.address)}),role:"cell","aria-label":_,onClick:w,className:"clickable-cell",style:{width:`${m[_]}px`}},{content:a.snapshots?.length??"0",role:"cell",className:"u-align--right clickable-cell","aria-label":K,onClick:w,style:{width:`${m[K]}px`}},{key:a.status+xe,content:e.jsx(qe,{instance:a}),role:"cell",className:"clickable-cell","aria-label":B,onClick:w,style:{width:`${m[B]}px`}},{content:e.jsx(Je,{className:Q("instance-actions","u-no-margin--bottom"),instance:a}),role:"cell",className:Q("u-align--right",{"u-hide":s.instance}),"aria-label":"Actions",style:{width:`${m[ae]}px`}}],sortData:{name:a.name.toLowerCase(),member:a.location,description:a.description.toLowerCase(),status:a.status,type:a.type,snapshots:a.snapshots?.length??0,project:a.project}}});return i.visibleRowColumns(G.concat(W),n)},{rows:ke,updateSort:it}=Ht({rows:$e(g.concat(S))}),Re=()=>{const n=document.getElementById("instance-table-measure"),f=n?.children[0]?.children[0]?.children[0];if(!n||!f)return;const z=n.getBoundingClientRect().width,G=f.getBoundingClientRect().width,W=new Map;f.childNodes.forEach(F=>{const X=F,xe=X.innerHTML,ge=X.getBoundingClientRect().width;W.set(xe,ge)});let a=0;const w=[];cs.forEach(F=>{F===E&&!l||G-a>z&&!g.includes(F)&&(a+=W.get(F),w.push(F))}),JSON.stringify(w)!==JSON.stringify(S)&&P(w)};i.useListener(window,Re,"resize",!0),I.useEffect(Re,[s.instance,g,k,ie]);const ce=oe||k.length>0||ie.length>0,Le=k.filter(n=>N.includes(M(n))),ct=k.filter(n=>!he.includes(n.name)).length+ie.length,Pe=p?b:r,je=Pe?.name??"default",le=y(Pe)?"":`You do not have permission to create instances in project ${je}`;return e.jsxs(e.Fragment,{children:[e.jsxs(i.CustomLayout,{mainClassName:Q("instance-list",{"has-side-panel":!!s.instance}),contentClassName:"instance-content",header:e.jsxs(te,{children:[e.jsxs(te.Left,{children:[e.jsx(te.Title,{children:e.jsx(Ot,{docPath:"/explanation/instances/#expl-instances",title:"Learn more about instances",children:"Instances"})}),ce&&N.length===0&&e.jsx(te.Search,{children:e.jsx(is,{instances:k,hasProjectFilter:p},`${r?.name??""}-${x.get("search")}`)}),N.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Xt,{instances:Le,onStart:()=>{h(N)},onFinish:()=>{h([])}}),e.jsx(es,{instances:Le,onStart:h,onFinish:()=>{h([])}})]})]}),ce&&N.length===0&&e.jsx(te.BaseActions,{children:e.jsxs(i.Button,{appearance:"positive",className:"u-float-right u-no-margin--bottom",onClick:async()=>c(`${Z}/ui/project/${encodeURIComponent(je)}/instances/create`),hasIcon:!$,disabled:!!le,title:le,children:[!$&&e.jsx(i.Icon,{name:"plus",light:!0}),e.jsx("span",{children:R})]})})]}),children:[e.jsx(St,{}),e.jsx(i.Row,{className:"no-grid-gap",children:e.jsxs(i.Col,{size:12,children:[ce&&e.jsxs(e.Fragment,{children:[e.jsx(i.ScrollableTable,{dependencies:[q,o.notification],tableId:"instances-table",belowIds:["status-bar"],children:e.jsxs(i.TablePagination,{data:ke,id:"pagination",itemName:"instance",className:"u-no-margin--top","aria-label":"Table pagination control",description:N.length>0&&e.jsx(zt,{totalCount:ct,itemName:"instance",parentName:r?`project: ${r?.name}`:void 0,selectedNames:N,setSelectedNames:u,filteredNames:q.map(M)}),children:[e.jsx(i.ColumnSelector,{columns:at.filter(n=>!(n===E&&!l)),userHidden:g,sizeHidden:S,setUserHidden:rt,className:Q({"u-hide":s.instance})}),e.jsx(Fe,{id:"instances-table",headers:ve,rows:ke,sortable:!0,emptyStateMsg:oe?e.jsx(i.Spinner,{className:"u-loader",text:"Loading instances..."}):e.jsx(e.Fragment,{children:"No instance found matching this search"}),itemName:"instance",parentName:"project",selectedNames:N,setSelectedNames:u,disabledNames:C,filteredNames:q.map(M),onUpdateSort:it})]})}),e.jsx("div",{id:"instance-table-measure",children:e.jsx(Fe,{headers:i.visibleHeaderColumns(Ie,g),rows:$e(g),className:"scrollable-table",itemName:"instance",parentName:"project",selectedNames:N,setSelectedNames:u,disabledNames:C,filteredNames:q.map(M)})})]}),!ce&&e.jsxs(i.EmptyState,{className:"empty-state",image:e.jsx(i.Icon,{name:"pods",className:"empty-state-icon"}),title:"No instances found",children:[e.jsxs("p",{children:["There are no instances in ",r?"this":"any"," project.",y(r)?" Spin up your first instance!":""]}),e.jsx("p",{children:e.jsx(Ct,{docPath:"/howto/instances_create/",hasExternalIcon:!0,children:"How to create instances"})}),e.jsx(i.Button,{className:"empty-state-button",appearance:"positive",onClick:async()=>c(`${Z}/ui/project/${encodeURIComponent(je)}/instances/create`),disabled:!!le,title:le,children:"Create instance"})]})]})})]}),s.panel===$t.instanceSummary&&e.jsx(hs,{})]})};export{Zs as default};