Your IP : 216.73.216.52


Current Path : /snap/lxd/current/share/lxd-ui/assets/
Upload File :
Current File : //snap/lxd/current/share/lxd-ui/assets/InstanceList-C2cF8-bj.js

import{H as ye,j as e,T as v,bn as Pe,d as i,s as J,r as I,bo as B,bp as lt,E as Ae,v as He,aJ as Oe,b0 as Ee,bq as ct,br as dt,ax as Ue,bs as ut,x as ue,bt as mt,bu as _e,Q as Ne,c as Ce,R as Z,bv as ht,bw as pt,bd as ze,bc as xt,bx as Ke,aE as jt,by as qe,aF as Qe,aG as se,L as ee,aC as be,w as gt,bl as ft,bk as Je,S as bt,ay as yt,a_ as Nt,J as Ct,$ as ce,p as St,b3 as wt,bz as It,bA as Te,bB as vt,bC as $t}from"./index-BsQN_SZU.js";import{u as Ye,p as kt}from"./usePanelParams-CNAJZsSX.js";import{S as Fe}from"./SelectableMainTable-DBx4rRiq.js";import{u as Ve}from"./useBulkDetails-ydqvQ5wa.js";import{d as Lt,c as Be,D as Rt,u as We,e as Pt,I as Et,f as Tt,b as Ft}from"./DeleteInstanceBtn-C0d6l5Yt.js";import{B as Bt}from"./BulkDeleteButton-DbqPCHnz.js";import{s as Mt,p as Dt}from"./searchAndFilter-DtC_P-vv.js";import{C as At}from"./CancelOperationBtn-C5TQ8C6V.js";import{S as Ht}from"./SelectedTableNotification-BpePAhdG.js";import{H as Ot}from"./HelpLink-BJF9zWZL.js";import{u as Ut}from"./useSortTableData-DkMx8bMp.js";import{P as te}from"./PageHeader-BkhUaI4-.js";import{E as Ge}from"./ExpandableList-DsGr0BpD.js";import{K as _t,w as zt}from"./SshKeyForm-BNz7yPwa.js";import{N as Kt}from"./NetworkRichChip-Cp8QBNS_.js";import{a as Ze}from"./ClusterMemberRichChip-Di9w-E3M.js";import{S as qt}from"./StoragePoolRichChip-Daex_aZU.js";import{u as Qt}from"./projects-CczQ3aFg.js";import{P as Jt}from"./ProjectRichChip-DZzjTfq6.js";import"./Meter-cq8smrSm.js";import"./limits-yeXZOxhv.js";import"./AutoExpandingTextArea-Bd-45rZK.js";import"./formFields-DzJouV_d.js";import"./scroll-Dc7Cgzms.js";import"./ConfigFieldDescription-CjXKAIpa.js";import"./snapshots-LtzKNDw1.js";import"./useNetworks-1j5RF-bH.js";import"./ClusterMemberMemoryUsage-DYUQFY0n.js";import"./StoragePoolSize-BNbqTfwA.js";const de=({action:t,confirmAppearance:l,confirmExtra:c,confirmLabel:a,icon:r,instances:p,isLoading:b,isDisabled:L,onClick:x,restrictedInstances:j})=>{const o=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,R=[...y].some(h=>Pe(t,h)!==void 0),S=(h,$)=>{const F=p.filter(V=>V.status===h&&!j.includes(B(V))).length;if(F===0)return null;const k=lt(h)??"";if(Pe($,h)===void 0){const V=F===1?"instance that is":"instances that are",me=$!=="restart"?"already ":"";return e.jsxs(I.Fragment,{children:["- No action for ",e.jsx("b",{children:F})," ",V," ",me,h.toLowerCase(),".",e.jsx("br",{})]},h+$)}const ie=d?"- ":"";return e.jsxs(I.Fragment,{children:[ie,"This will ",$," ",e.jsx("b",{children:F}),` ${k} ${v("instance",F)}.`,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=j.length===p.length,u=()=>j.length===0?null:e.jsxs(I.Fragment,{children:["- No action for ",e.jsx("b",{children:j.length})," ",v("instance",j.length)," that you do not have permission to ",a.toLowerCase(),".",e.jsx("br",{})]},"restricted"),w=b&&t!=="stop";return e.jsxs(i.ConfirmationButton,{appearance:"base",disabled:L||!R||N||w,loading:b,className:J({"has-icon":!o},"u-no-margin--right u-no-margin--bottom bulk-action"),confirmationModalProps:{title:`Confirm ${a.toLowerCase()}`,children:e.jsxs("p",{children:[g,P().map(h=>S(h,t)),u()]}),confirmExtra:c,onConfirm:x,confirmButtonLabel:a,confirmButtonAppearance:l},shiftClickEnabled:!0,showShiftClickHint:!0,onHoverText:N?`You do not have permission to ${a.toLowerCase()} the selected ${v("instance",p.length)}`:a,children:[e.jsx(i.Icon,{name:r}),e.jsx("span",{className:"u-hide--small",children:a})]})},Yt=({instances:t,onStart:l,onFinish:c})=>{const a=Ae(),r=i.useToastNotification(),p=He(),[b,L]=I.useState(null),[x,j]=I.useState(!1),{canUpdateInstanceState:o}=Oe(),y=Ve(),d=()=>{p.invalidateQueries({queryKey:[ue.instances]})},g=()=>{setTimeout(d,1500)},R=P=>{L(P),l();const N=t.filter(o),u=ct(N,P);dt(u,x,a).then(w=>{const h=ut(P),$=u.length,{fulfilledCount:F,rejectedCount:k}=Ue(w);F===$?(r.success(e.jsxs(e.Fragment,{children:[e.jsx("b",{children:$})," ",v("instance",$)," ",h,"."]}),y(w)),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(w)),g()):(r.failure(`Instance ${P} partially failed`,void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:F})," ",v("instance",F)," ",h,".",e.jsx("br",{}),e.jsx("b",{children:k})," ",v("instance",k)," ","could not be ",h,"."]}),y(w)),g()),j(!1),c(),L(null)}).catch(w=>{r.failure(`Instance ${P} failed`,w),g()})},S=t.filter(P=>!o(P)).map(B);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:()=>{R("start")},confirmAppearance:"positive",action:"start",instances:t,confirmLabel:"Start",restrictedInstances:S}),e.jsx(de,{icon:"restart",isLoading:b==="restart",isDisabled:b==="restart",onClick:()=>{R("restart")},action:"restart",instances:t,confirmLabel:"Restart",confirmExtra:e.jsx(Ee,{label:"Force restart",confirmed:[x,j]}),restrictedInstances:S}),e.jsx(de,{icon:"pause",isLoading:b==="freeze",isDisabled:b==="freeze",onClick:()=>{R("freeze")},action:"freeze",instances:t,confirmLabel:"Freeze",restrictedInstances:S}),e.jsx(de,{icon:"stop",isLoading:b==="stop",isDisabled:!1,onClick:()=>{R("stop")},action:"stop",instances:t,confirmLabel:"Stop",confirmExtra:e.jsx(Ee,{label:"Force stop",confirmed:[x,j]}),restrictedInstances:S})]})})},Vt=({instances:t,onStart:l,onFinish:c})=>{const a=Ae(),r=i.useToastNotification(),p=He(),[b,L]=I.useState(!1),{canDeleteInstance:x}=Oe(),j=t.filter(u=>!x(u)),o=t.filter(u=>Lt.includes(u.status)&&x(u)),y=t.length,d=o.length,g=j.length,R=y-d-g,S=Ve(),P=()=>{L(!0),l(o.map(u=>u.name)),mt(o,a).then(u=>{const{fulfilledCount:w,rejectedCount:h}=Ue(u);w===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:w})," ",v("instance",w)," ","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]}),L(!1),c()}).catch(u=>{r.failure("Instance bulk deletion failed",u),L(!1)})},N=()=>{if(R+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`),R&&u.push(`${R} other ${v("instance",R)} 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(Bt,{entities:t,deletableEntities:o,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"})})})},Wt=["Running","Stopped","Frozen","Error"],Gt=["Container","VM"],Zt=t=>(t.includes("Frozen")&&t.push("Freezing"),t.includes("Running")&&t.push("Restarting","Starting"),t.includes("Stopped")&&t.push("Stopping"),t),Xt="query",Xe="status",et="type",tt="profile",st="member",es="project",Me=[Xt,Xe,et,tt,st,es],ts=({instances:t,hasProjectFilter:l})=>{const[c,a]=_e(),r=Ne(),p=[...new Set(t.flatMap(o=>o.profiles))],b=[...new Set(t.flatMap(o=>o.location))],L=[...new Set(t.flatMap(o=>o.project))],x=[{id:1,heading:"Status",chips:Wt.map(o=>({lead:Xe,value:o}))},{id:2,heading:"Instance type",chips:Gt.map(o=>({lead:et,value:o}))},{id:3,heading:"Profile",chips:p.map(o=>({lead:tt,value:o}))},...r?[{id:4,heading:"Cluster member",chips:b.map(o=>({lead:st,value:o}))}]:[],...l?[{id:5,heading:"Project",chips:L.map(o=>({lead:"project",value:o}))}]:[]],j=o=>{const y=Dt(o,c,Me);y.toString()!==c.toString()&&a(y)};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"u-off-screen",children:"Search and filter"}),e.jsx(i.SearchAndFilter,{existingSearchData:Mt(c,Me),filterPanelData:x,returnSearchData:j,onExpandChange:()=>{window.dispatchEvent(new CustomEvent("resize",{detail:"search-and-filter"}))},onPanelToggle:()=>{window.dispatchEvent(new CustomEvent("sfp-toggle"))}})]})},ss=I.memo(ts),M="Status",Y="Name",O="Type",T="Cluster member",U="Description",D="Memory",A="Root filesystem",_="IPv4",z="IPv6",K="Snapshots",G="Project",ne="Actions",m={[Y]:170,[O]:130,[T]:150,[D]:150,[A]:150,[U]:150,[_]:150,[z]:330,[K]:110,[G]:160,[M]:160,[ne]:210},ns=[K,z,_,U,T,A,D,O,M,ne],nt=[O,D,A,T,U,_,z,K],as=[O,U,D,A,_,z,K],is=({instance:t})=>{const l=Ce(),c=()=>{l(`${Z}/ui/project/${encodeURIComponent(t.project)}/instance/${encodeURIComponent(t.name)}/terminal`)},a=t.status!=="Running";return e.jsx(i.Button,{appearance:"base",dense:!0,hasIcon:!0,onClick:c,disabled:a,title:"Terminal","aria-label":"Open Terminal",children:e.jsx(i.Icon,{name:"code"})})},os=({instance:t})=>{const l=Ce(),c=()=>{l(`${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:c,title:"Console",children:e.jsx(i.Icon,{name:"canvas"})})},rs=({instance:t})=>{const l=ht(t);return l.length?e.jsx(Ge,{items:l.map(c=>e.jsx("div",{className:"ip u-truncate",title:`MAC address ${c}`,children:c},c))}):e.jsx(e.Fragment,{children:"-"})},De=5,ls=({instance:t})=>{const l=Object.values(t?.expanded_devices??{}).filter(pt),a=ze().getType(t),r=`${Z}/ui/project/${encodeURIComponent(t.project)}/instance/${encodeURIComponent(t.name)}`,p=Ne(),b=!t.state||t.state.pid===0?"-":t.state.pid,L=xt(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:jt(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+a)]}),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(Be,{instance:t,family:"inet"})},se(t,"inet").length)]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"IPv6"}),e.jsx("td",{children:e.jsx(Be,{instance:t,family:"inet6"})},se(t,"inet6").length)]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"MAC addresses"}),e.jsx("td",{children:e.jsx(rs,{instance:t})},se(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(Ze,{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:L,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:l.length>0?e.jsx(Ge,{items:l.map(x=>e.jsx(Kt,{networkName:x.network,projectName:t.project},x.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(x=>e.jsx(zt,{profileName:x,projectName:t.project},x))})})]}),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((x,j)=>{const o=x.created_at,y=j.created_at;return o>y?-1:o<y?1:0}).slice(0,De).map(x=>e.jsxs("tr",{className:"u-no-border",children:[e.jsx("th",{children:e.jsx(gt,{type:"snapshot",value:x.name,to:`${r}/snapshots`},x.name)}),e.jsx("td",{className:"u-text--muted",children:e.jsx("i",{children:be(x.created_at)})})]},x.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"})]})})})]})})},cs=()=>{const t=i.useNotify(),l=Ye(),c=l.instance!==null,{data:a,error:r,isLoading:p}=ft(l.instance??"",l.project,c);return r&&t.failure("Loading instance failed",r),e.jsxs(i.SidePanel,{loading:p,hasError:!a,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:l.clear,"aria-label":"Close",children:e.jsx(i.Icon,{name:"close"})})})]}),a&&e.jsxs("div",{className:"actions",children:[e.jsx(i.List,{inline:!0,className:"primary actions-list",items:[e.jsx(is,{instance:a},"terminal"),e.jsx(os,{instance:a},"console"),e.jsx(Rt,{instance:a,label:"",classname:"is-dense p-button--base"},"delete")]}),e.jsx("div",{className:"state",children:e.jsx(Je,{instance:a})})]})]}),e.jsx(i.SidePanel.Content,{children:a&&e.jsx(ls,{instance:a})})]})},ds=({instance:t})=>{const{data:l=[]}=We(t.location),c=Pt(l,t);return e.jsx(Et,{memory:c})},us=({instance:t})=>{const{data:l=[]}=We(t.location),[c]=Tt(l,t);return e.jsx(Ft,{filesystem:c})},ms=()=>{const t=localStorage.getItem("instanceListHiddenColumns"),l=new Set(nt);return t?JSON.parse(t).filter(c=>l.has(c)):[D,A]},hs=t=>{localStorage.setItem("instanceListHiddenColumns",JSON.stringify(t))},zs=()=>{const t=ze(),l=Ce(),c=i.useNotify(),a=Ye(),{project:r,isAllProjects:p}=bt(),{data:b}=yt("default",p),[L,x]=I.useState("Create instance"),[j]=_e(),o=Ne(),{canCreateInstances:y}=Qt(),d={queries:j.getAll("query").map(s=>s.toLowerCase()),statuses:Zt(j.getAll("status")),types:j.getAll("type").map(s=>s==="VM"?"virtual-machine":"container"),profiles:j.getAll("profile"),clusterMembers:j.getAll("member"),projects:j.getAll("project")},[g,R]=I.useState(ms()),[S,P]=I.useState([]),[N,u]=I.useState([]),[w,h]=I.useState([]),$=ye(),F=ye(vt);if(!r&&!p)return e.jsx(e.Fragment,{children:"Missing project"});I.useEffect(()=>{o||!g.includes(T)||R(g.filter(s=>s!==T))},[o]);const{data:k=[],error:ae,isLoading:ie}=Nt(r?.name??null);ae&&c.failure("Loading instances failed",ae);const V=()=>{x(F?"Create":"Create instance")};i.useListener(window,V,"resize",!0);const me=()=>{const s=document.getElementById("instances-table");s&&(s.style.display="none",s.offsetHeight,s.style.display="table")};i.useListener(window,me,"resize",!0);const at=s=>{R(s),hs(s)},{data:he,error:Se}=Ct({queryKey:[ue.operations,r?.name],queryFn:async()=>$t(r?.name??null)});Se&&!ae&&c.failure("Loading operations failed",Se);const it=(he?.running??[]).filter(s=>s.description==="Migrating instance").map(ce),pe=[],oe=(he?.running??[]).concat(he?.success??[]).filter(s=>{const f=ce(s),H=s.description==="Creating instance",X=w.includes(f),W=it.includes(f);if(!H||X||W||!f)return!1;const n=k.some(E=>E.name===f);return!(s.status==="Running")&&n?!1:(pe.push(f),!0)}),q=k.filter(s=>!(pe.includes(s.name)||!d.queries.every(f=>s.name.toLowerCase().includes(f)||s.description.toLowerCase().includes(f)||s.config["image.description"]?.toLowerCase().includes(f))||d.statuses.length>0&&!d.statuses.includes(s.status)||d.types.length>0&&!d.types.includes(s.type)||d.profiles.length>0&&!d.profiles.every(f=>s.profiles.includes(f))||d.clusterMembers.length>0&&!d.clusterMembers.includes(s.location)||d.projects.length>0&&!d.projects.includes(s.project)));I.useEffect(()=>{const s=new Set(q.map(B)),f=N.filter(H=>s.has(H));f.length!==N.length&&u(f)},[q]),I.useEffect(()=>{a.instance&&(k.some(s=>s.name===a.instance&&s.project===a.project)||a.clear())},[k]);const we=[{content:Y,sortKey:"name",style:{width:`${m[Y]}px`}},{content:O,sortKey:"type",style:{width:`${m[O]}px`}},...p?[{content:G,sortKey:"project",style:{width:`${m[G]}px`}}]:[],...o?[{content:T,sortKey:"member",style:{width:`${m[T]}px`}}]:[],{content:D,style:{width:`${m[D]}px`}},{content:A,style:{width:`${m[A]}px`}},{content:U,sortKey:"description",style:{width:`${m[U]}px`}},{content:_,className:"u-align--right",style:{width:`${m[_]}px`}},{content:z,id:"header-ipv6",style:{width:`${m[z]}px`}},{content:K,sortKey:"snapshots",className:"u-align--right",style:{width:`${m[K]}px`}},{content:M,sortKey:"status",className:"status-header status",style:{width:`${m[M]}px`}},{"aria-label":"Actions",className:J({"u-hide":a.instance}),style:{width:`${m[ne]}px`}}],Ie=i.visibleHeaderColumns(we,g.concat(S)),ve=s=>{const f=as.filter(n=>!s.includes(n)).concat(...o?[T]:[]).concat(...p?[G]:[]).reduce((n,C)=>n+m[C],0),H=Ie.length,X=oe.map(n=>({key:n.id,className:"u-row",columns:[{content:ce(n),className:"u-truncate",title:ce(n),role:"rowheader","aria-label":Y,style:{width:`${m[Y]}px`}},...H>3?[{content:e.jsx("i",{children:Object.entries(n.metadata??{}).slice(0,1).map(([C,E],Q)=>e.jsxs("div",{children:[C,": ",E]},Q))},JSON.stringify(n.metadata??{})),role:"cell",colSpan:H-3,style:{width:`${f}px`}}]:[],...S.includes(M)?[]:[{content:e.jsxs(e.Fragment,{children:[e.jsx(i.Spinner,{className:"status-icon"})," Setting up"]}),role:"cell","aria-label":M,style:{width:`${m[M]}px`}}],{content:e.jsx(At,{operation:n,project:r?.name}),role:"cell",className:J("u-align--right",{"u-hide":a.instance}),"aria-label":"Actions",style:{width:`${m[ne]}px`}}],sortData:{name:null}})),W=q.map(n=>{const C=()=>{a.openInstanceSummary(n.name,n.project)},E=se(n,"inet"),Q=It(se(n,"inet6")),je=t.getType(n),ge=a.instance===n.name&&a.project===n.project;return{key:B(n),className:ge?"u-row-selected":"u-row",name:B(n),columns:[{content:e.jsx(Ke,{instance:n}),className:"u-truncate",title:`Instance ${n.name}`,role:"rowheader",style:{width:`${m[Y]}px`},"aria-label":Y,onClick:C},{content:Qe(n),role:"cell","aria-label":O,onClick:C,className:"clickable-cell",style:{width:`${m[O]}px`}},...p?[{content:e.jsx(Jt,{projectName:n.project,urlSuffix:"/instances"}),role:"cell","aria-label":G,style:{width:`${m[G]}px`}}]:[],...o?[{content:e.jsx(Ze,{clusterMember:n.location}),role:"cell","aria-label":T,style:{width:`${m[T]}px`}}]:[],{content:e.jsx(ds,{instance:n}),role:"cell","aria-label":D,onClick:C,className:"clickable-cell",style:{width:`${m[D]}px`}},{content:e.jsx(us,{instance:n}),role:"cell","aria-label":A,onClick:C,className:"clickable-cell",style:{width:`${m[A]}px`}},{content:e.jsx("div",{className:"u-truncate",title:n.description,children:n.description}),role:"cell","aria-label":U,onClick:C,className:"clickable-cell",style:{width:`${m[U]}px`}},{key:`ipv4-${E.length}`,content:e.jsx(Te,{items:E.map(fe=>fe.address)}),role:"cell",className:"u-align--right clickable-cell","aria-label":_,onClick:C,style:{width:`${m[_]}px`}},{key:`ipv6-${Q.length}`,content:e.jsx(Te,{items:Q.map(fe=>fe.address)}),role:"cell","aria-label":z,onClick:C,className:"clickable-cell",style:{width:`${m[z]}px`}},{content:n.snapshots?.length??"0",role:"cell",className:"u-align--right clickable-cell","aria-label":K,onClick:C,style:{width:`${m[K]}px`}},{key:n.status+je,content:e.jsx(qe,{instance:n}),role:"cell",className:"clickable-cell","aria-label":M,onClick:C,style:{width:`${m[M]}px`}},{content:e.jsx(Je,{className:J("instance-actions","u-no-margin--bottom"),instance:n}),role:"cell",className:J("u-align--right",{"u-hide":a.instance}),"aria-label":"Actions",style:{width:`${m[ne]}px`}}],sortData:{name:n.name.toLowerCase(),member:n.location,description:n.description.toLowerCase(),status:n.status,type:n.type,snapshots:n.snapshots?.length??0,project:n.project}}});return i.visibleRowColumns(X.concat(W),s)},{rows:$e,updateSort:ot}=Ut({rows:ve(g.concat(S))}),ke=()=>{const s=document.getElementById("instance-table-measure"),f=s?.children[0]?.children[0]?.children[0];if(!s||!f)return;const H=s.getBoundingClientRect().width,X=f.getBoundingClientRect().width,W=new Map;f.childNodes.forEach(E=>{const Q=E,je=Q.innerHTML,ge=Q.getBoundingClientRect().width;W.set(je,ge)});let n=0;const C=[];ns.forEach(E=>{E===T&&!o||X-n>H&&!g.includes(E)&&(n+=W.get(E),C.push(E))}),JSON.stringify(C)!==JSON.stringify(S)&&P(C)};i.useListener(window,ke,"resize",!0),I.useEffect(ke,[a.instance,g,k,oe]);const re=ie||k.length>0||oe.length>0,Le=k.filter(s=>N.includes(B(s))),rt=k.filter(s=>!pe.includes(s.name)).length+oe.length,Re=p?b:r,xe=Re?.name??"default",le=y(Re)?"":`You do not have permission to create instances in project ${xe}`;return e.jsxs(e.Fragment,{children:[e.jsxs(i.CustomLayout,{mainClassName:J("instance-list",{"has-side-panel":!!a.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"})}),re&&N.length===0&&e.jsx(te.Search,{children:e.jsx(ss,{instances:k,hasProjectFilter:p},`${r?.name??""}-${j.get("search")}`)}),N.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Yt,{instances:Le,onStart:()=>{h(N)},onFinish:()=>{h([])}}),e.jsx(Vt,{instances:Le,onStart:h,onFinish:()=>{h([])}})]})]}),re&&N.length===0&&e.jsx(te.BaseActions,{children:e.jsxs(i.Button,{appearance:"positive",className:"u-float-right u-no-margin--bottom",onClick:async()=>l(`${Z}/ui/project/${encodeURIComponent(xe)}/instances/create`),hasIcon:!$,disabled:!!le,title:le,children:[!$&&e.jsx(i.Icon,{name:"plus",light:!0}),e.jsx("span",{children:L})]})})]}),children:[e.jsx(St,{}),e.jsx(i.Row,{className:"no-grid-gap",children:e.jsxs(i.Col,{size:12,children:[re&&e.jsxs(e.Fragment,{children:[e.jsx(i.ScrollableTable,{dependencies:[q,c.notification],tableId:"instances-table",belowIds:["status-bar"],children:e.jsxs(i.TablePagination,{data:$e,id:"pagination",itemName:"instance",className:"u-no-margin--top","aria-label":"Table pagination control",description:N.length>0&&e.jsx(Ht,{totalCount:rt,itemName:"instance",parentName:r?`project: ${r?.name}`:void 0,selectedNames:N,setSelectedNames:u,filteredNames:q.map(B)}),children:[e.jsx(i.ColumnSelector,{columns:nt.filter(s=>!(s===T&&!o)),userHidden:g,sizeHidden:S,setUserHidden:at,className:J({"u-hide":a.instance})}),e.jsx(Fe,{id:"instances-table",headers:Ie,rows:$e,sortable:!0,emptyStateMsg:ie?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:w,filteredNames:q.map(B),onUpdateSort:ot})]})}),e.jsx("div",{id:"instance-table-measure",children:e.jsx(Fe,{headers:i.visibleHeaderColumns(we,g),rows:ve(g),className:"scrollable-table",itemName:"instance",parentName:"project",selectedNames:N,setSelectedNames:u,disabledNames:w,filteredNames:q.map(B)})})]}),!re&&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(wt,{docPath:"/howto/instances_create/",hasExternalIcon:!0,children:"How to create instances"})}),e.jsx(i.Button,{className:"empty-state-button",appearance:"positive",onClick:async()=>l(`${Z}/ui/project/${encodeURIComponent(xe)}/instances/create`),disabled:!!le,title:le,children:"Create instance"})]})]})})]}),a.panel===kt.instanceSummary&&e.jsx(cs,{})]})};export{zs as default};