0x1949 Team - FAZEMRX - MANAGER
Edit File: InstanceList-23508fa8.js
import{j as e,d as h,aa as M,r as L,x as fe,i as xe,ab as le,ar as we,ac as be,q as J,as as ve,at as Ie,au as je,av as Le,aw as ke,l as $e,ax as Fe,e as Pe,ay as Ee,m as Ae,f as ce,A as de,o as Te,C as Re,H as Be,b as De,P as ze,S as He,L as Me,az as ue,aA as Oe,t as _e,aB as qe,ao as Qe,aC as Ke,aD as Ue}from"./index-13b2882d.js";import{S as he}from"./SelectableMainTable-5a3f3fef.js";import{a as w,i as pe,s as We,b as Je,c as Ve,d as Ye,S as Ze}from"./instanceDelete-e714bd59.js";import{C as Ge,f as Xe}from"./CancelOperationBtn-5e4a9f41.js";import{g as me}from"./operations-beb03b33.js";const et=({className:n,columns:f,hidden:m,sizeHidden:x,setHidden:l})=>{const o=f.length-m.length,c=a=>{m.includes(a)?l(m.filter(u=>u!==a)):l([...m,a])},j=(a,u)=>x.includes(u)?e.jsx(h.Tooltip,{message:e.jsxs(e.Fragment,{children:["Screen is too narrow to fit the column.",e.jsx("br",{}),"Disable columns above or use a bigger screen."]}),position:"left",children:a}):a;return e.jsx(h.ContextualMenu,{className:M(n,"configurable-table-toggle"),dropdownProps:{"aria-label":"columns menu"},position:"right",toggleClassName:"has-icon",toggleProps:{"aria-label":"Columns selection toggle"},toggleLabel:e.jsx(h.Icon,{name:"settings"}),toggleAppearance:"base",title:"Columns",children:e.jsxs("div",{className:"table-column-select-list",children:[e.jsx(h.CheckboxInput,{checked:m.length===0,indeterminate:o>0&&o<f.length,label:`${o} out of ${f.length} columns selected`,onChange:()=>m.length>0?l([]):l(f)}),e.jsx("hr",{}),f.map(a=>e.jsx("div",{children:j(e.jsx(h.CheckboxInput,{"aria-label":a,checked:!m.includes(a),label:a,onChange:()=>c(a),disabled:x.includes(a)}),a)},a))]})})},X=({action:n,confirmAppearance:f,confirmExtra:m,confirmLabel:x,icon:l,instances:o,isLoading:c,isDisabled:j,onClick:a})=>{const u=new Set(o.map(r=>r.status)),i=u.size>1,C=i?e.jsxs(e.Fragment,{children:[e.jsx("b",{children:o.length})," ",w(o.length)," selected:",e.jsx("br",{}),e.jsx("br",{})]}):null,v=[...u].some(r=>pe(n,r)!==void 0),k=(r,I)=>{const y=o.filter(Y=>Y.status===r).length;if(y===0)return null;const $=We(r)??"";if(pe(I,r)===void 0){const Y=y===1?"instance that is":"instances that are",te=I!=="restart"?"already ":"";return e.jsxs(L.Fragment,{children:["- No action for ",e.jsx("b",{children:y})," ",Y," ",te,r.toLowerCase(),".",e.jsx("br",{})]},r+I)}const V=i?"- ":"";return e.jsxs(L.Fragment,{children:[V,"This will ",I," ",e.jsx("b",{children:y}),` ${$} ${w(y)}.`,e.jsx("br",{})]},r+I)},d=()=>{switch(n){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[]}};return e.jsxs(h.ConfirmationButton,{appearance:"base",disabled:j||!v,loading:c,className:"u-no-margin--right u-no-margin--bottom bulk-action has-icon",confirmationModalProps:{title:`Confirm ${x.toLowerCase()}`,children:e.jsxs("p",{children:[C,d().map(r=>k(r,n))]}),confirmExtra:m,onConfirm:a,confirmButtonLabel:x,confirmButtonAppearance:f},shiftClickEnabled:!0,showShiftClickHint:!0,children:[e.jsx(h.Icon,{name:l}),e.jsx("span",{children:x})]})},tt=({instances:n,onStart:f,onFinish:m})=>{const x=fe(),l=h.useNotify(),o=xe(),[c,j]=L.useState(null),[a,u]=L.useState(!1),i=C=>{j(C),f();const v=Je(n,C);we(v,a,x).then(k=>{const d=Ve(C),r=v.length,{fulfilledCount:I,rejectedCount:y}=be(k);I===r?l.success(e.jsxs(e.Fragment,{children:[e.jsx("b",{children:r})," ",w(r)," ",d,"."]})):y===r?l.failure(`Instance ${C} failed`,void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:r})," ",w(r)," could not be ",d,"."]})):l.failure(`Instance ${C} partially failed`,void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:I})," ",w(I)," ",d,".",e.jsx("br",{}),e.jsx("b",{children:y})," ",w(y)," could not be ",d,"."]})),u(!1),m(),j(null),o.invalidateQueries({queryKey:[J.instances]})})};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(X,{icon:"play",isLoading:c==="start",isDisabled:c==="start",onClick:()=>i("start"),confirmAppearance:"positive",action:"start",instances:n,confirmLabel:"Start"}),e.jsx(X,{icon:"restart",isLoading:c==="restart",isDisabled:c==="restart",onClick:()=>i("restart"),action:"restart",instances:n,confirmLabel:"Restart",confirmExtra:e.jsx(le,{label:"Force restart",force:[a,u]})}),e.jsx(X,{icon:"pause",isLoading:c==="freeze",isDisabled:c==="freeze",onClick:()=>i("freeze"),action:"freeze",instances:n,confirmLabel:"Freeze"}),e.jsx(X,{icon:"stop",isLoading:c==="stop",isDisabled:!1,onClick:()=>i("stop"),action:"stop",instances:n,confirmLabel:"Stop",confirmExtra:e.jsx(le,{label:"Force stop",force:[a,u]})})]})})},nt=({instances:n,onStart:f,onFinish:m})=>{const x=fe(),l=h.useNotify(),o=xe(),[c,j]=L.useState(!1),a=n.filter(k=>Ye.includes(k.status)),u=n.length,i=a.length,C=u-i,v=()=>{j(!0),f(a.map(k=>k.name)),ve(a,x).then(k=>{const{fulfilledCount:d,rejectedCount:r}=be(k);d===i?l.success(`${i} ${w(i)} deleted`):r===i?l.failure("Instance bulk deletion failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:i})," ",w(i)," could not be deleted."]})):l.failure("Instance bulk deletion partially failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:d})," ",w(d)," deleted.",e.jsx("br",{}),e.jsx("b",{children:r})," ",w(r)," could not be deleted."]})),o.invalidateQueries({queryKey:[J.instances]}),o.invalidateQueries({queryKey:[J.projects,n[0].project]}),j(!1),m()})};return e.jsx("div",{className:"p-segmented-control bulk-actions",children:e.jsx("div",{className:"p-segmented-control__list bulk-action-frame",children:e.jsxs(h.ConfirmationButton,{onHoverText:"Delete instances",appearance:"base",className:"u-no-margin--bottom has-icon",loading:c,confirmationModalProps:{title:"Confirm delete",children:e.jsxs("p",{children:[C>0&&e.jsxs(e.Fragment,{children:[e.jsx("b",{children:u})," instances selected:",e.jsx("br",{}),e.jsx("br",{}),`- ${i} stopped ${w(i)} will be deleted`,e.jsx("br",{}),`- ${C} other ${w(C)} will be ignored`,e.jsx("br",{}),e.jsx("br",{})]}),"This will permanently delete ",e.jsx("b",{children:i})," ",w(i),".",` `,"This action cannot be undone, and can result in data loss."]}),confirmButtonLabel:"Delete",onConfirm:v},disabled:i===0,shiftClickEnabled:!0,showShiftClickHint:!0,children:[e.jsx(h.Icon,{name:"delete"}),e.jsx("span",{children:"Delete"})]})})})},st=["Running","Stopped","Frozen","Error"],at=["Container","VM"],it=n=>(n.includes("Frozen")&&n.push("Freezing"),n.includes("Running")&&n.push("Restarting","Starting"),n.includes("Stopped")&&n.push("Stopping"),n),rt="query",ye="status",Ce="type",Se="profile",ge=[rt,ye,Ce,Se],ot=({instances:n})=>{const[f,m]=je(),x=[...new Set(n.flatMap(c=>c.profiles))],l=[{id:1,heading:"Status",chips:st.map(c=>({lead:ye,value:c}))},{id:2,heading:"Instance type",chips:at.map(c=>({lead:Ce,value:c}))},{id:3,heading:"Profile",chips:x.map(c=>({lead:Se,value:c}))}],o=c=>{const j=ke(c,f,ge);j.toString()!==f.toString()&&m(j)};return e.jsx("div",{className:"search-wrapper margin-right u-no-margin--bottom",children:e.jsx(h.SearchAndFilter,{existingSearchData:Le(f,ge),filterPanelData:l,returnSearchData:o,onExpandChange:()=>{window.dispatchEvent(new CustomEvent("resize",{detail:"search-and-filter"}))},onPanelToggle:()=>{window.dispatchEvent(new CustomEvent("sfp-toggle"))}})})},lt=Ie.memo(ot),E="Status",O="Name",R="Type",B="Description",D="IPv4",z="IPv6",H="Snapshots",ee="Actions",p={[O]:170,[R]:130,[B]:150,[D]:150,[z]:330,[H]:110,[E]:160,[ee]:210},ct=[H,z,D,B,R,E],dt=[R,B,D,z,H],ut=()=>{const n=localStorage.getItem("instanceListHiddenColumns");return n?JSON.parse(n):[]},ht=n=>{localStorage.setItem("instanceListHiddenColumns",JSON.stringify(n))},pt=()=>Ke(820),jt=()=>{const n=$e(),f=Fe(),m=Pe(),x=h.useNotify(),l=Ee(),{project:o}=Ae(),[c,j]=L.useState("Create instance"),[a]=je(),u={queries:a.getAll("query"),statuses:it(a.getAll("status")),types:a.getAll("type").map(t=>t==="VM"?"virtual-machine":"container"),profileQueries:a.getAll("profile")},[i,C]=L.useState(ut()),[v,k]=L.useState([]),[d,r]=L.useState([]),[I,y]=L.useState([]);if(!o)return e.jsx(e.Fragment,{children:"Missing project"});const{data:$=[],error:q,isLoading:V}=ce({queryKey:[J.instances,o],queryFn:()=>Ue(o)});q&&x.failure("Loading instances failed",q),de("resize",()=>{j(pt()?"Create":"Create instance")});const te=t=>{C(t),ht(t)},{data:_}=ce({queryKey:[J.operations,o],queryFn:()=>Xe(o)});q&&x.failure("Loading operations failed",q);const ne=[],Q=((_==null?void 0:_.running)??[]).concat((_==null?void 0:_.success)??[]).filter(t=>{if(!(t.description==="Creating instance"))return!1;const S=me(t),K=$.some(b=>b.name===S);return!(t.status==="Running")&&K?!1:(ne.push(S),!0)}),F=$.filter(t=>!(ne.includes(t.name)||!u.queries.every(g=>{var S;return t.name.toLowerCase().includes(g)||t.description.toLowerCase().includes(g)||((S=t.config["image.description"])==null?void 0:S.toLowerCase().includes(g))})||u.statuses.length>0&&!u.statuses.includes(t.status)||u.types.length>0&&!u.types.includes(t.type)||u.profileQueries.length>0&&!u.profileQueries.every(g=>t.profiles.includes(g))));L.useEffect(()=>{const t=new Set(F.map(S=>S.name)),g=d.filter(S=>t.has(S));g.length!==d.length&&r(g)},[F]);const se=t=>[{content:O,sortKey:"name",style:{width:`${p[O]}px`}},{content:R,sortKey:"type",style:{width:`${p[R]}px`}},{content:B,sortKey:"description",style:{width:`${p[B]}px`}},{content:D,className:"u-align--right",style:{width:`${p[D]}px`}},{content:z,id:"header-ipv6",style:{width:`${p[z]}px`}},{content:H,sortKey:"snapshots",className:"u-align--right",style:{width:`${p[H]}px`}},{content:E,sortKey:"status",className:"status-header status",style:{width:`${p[E]}px`}},{"aria-label":"Actions",className:M({"u-hide":l.instance}),style:{width:`${p[ee]}px`}}].filter(g=>typeof g.content!="string"||!t.includes(g.content)),ae=t=>{const g=dt.filter(s=>!t.includes(s)).reduce((s,b)=>s+p[b],0),S=Q.map(s=>({className:"u-row",columns:[{content:me(s),role:"rowheader","aria-label":O,style:{width:`${p[O]}px`}},...t.length<5?[{content:e.jsx("i",{children:Object.entries(s.metadata??{}).slice(0,1).map(([b,P],A)=>e.jsxs("div",{children:[b,": ",P]},A))}),role:"rowheader",colSpan:5-t.length,style:{width:`${g}px`}}]:[],...v.includes(E)?[]:[{content:e.jsxs(e.Fragment,{children:[e.jsx(h.Spinner,{className:"status-icon"})," Setting up"]}),role:"rowheader","aria-label":E,style:{width:`${p[E]}px`}}],{content:e.jsx(Ge,{operation:s,project:o}),role:"rowheader",className:M("u-align--right",{"u-hide":l.instance}),"aria-label":"Actions",style:{width:`${p[ee]}px`}}],sortData:{name:null}})),K=F.map(s=>{var U,T,W;const b=()=>l.openInstanceSummary(s.name,o),P=ue(s,"inet").filter(N=>!N.address.startsWith("127")).map(N=>N.address),A=ue(s,"inet6").filter(N=>!N.address.startsWith("fe80")).map(N=>N.address);return{className:l.instance===s.name?"u-row-selected":"u-row",name:s.name,columns:[{content:e.jsx("div",{className:"u-truncate",title:s.name,children:e.jsx(Oe,{instance:s})}),role:"rowheader",style:{width:`${p[O]}px`},"aria-label":O,onClick:b},{content:e.jsx(e.Fragment,{children:(U=_e.find(N=>N.value===s.type))==null?void 0:U.label}),role:"rowheader","aria-label":R,onClick:b,className:"clickable-cell",style:{width:`${p[R]}px`}},{content:e.jsx("div",{className:"u-truncate",title:s.description,children:s.description}),role:"rowheader","aria-label":B,onClick:b,className:"clickable-cell",style:{width:`${p[B]}px`}},{content:P.length>1?`${P.length} addresses`:P,role:"rowheader",className:"u-align--right clickable-cell","aria-label":D,onClick:b,style:{width:`${p[D]}px`}},{content:A.length>1?`${A.length} addresses`:A,role:"rowheader","aria-label":z,onClick:b,className:"clickable-cell",style:{width:`${p[z]}px`}},{content:((T=s.snapshots)==null?void 0:T.length)??"0",role:"rowheader",className:"u-align--right clickable-cell","aria-label":H,onClick:b,style:{width:`${p[H]}px`}},{content:e.jsx(qe,{instance:s}),role:"rowheader",className:"clickable-cell","aria-label":E,onClick:b,style:{width:`${p[E]}px`}},{content:e.jsx(Qe,{className:M("instance-actions","u-no-margin--bottom",{"u-hide":!!f.getType(s)}),instance:s}),role:"rowheader",className:M("u-align--right",{"u-hide":l.instance}),"aria-label":"Actions",style:{width:`${p[ee]}px`}}].filter(N=>!t.includes(N["aria-label"])),sortData:{name:s.name.toLowerCase(),description:s.description.toLowerCase(),status:s.status,type:s.type,snapshots:((W=s.snapshots)==null?void 0:W.length)??0}}});return S.concat(K)},Z=Te(ae(i.concat(v))),ie=()=>{var A,U;const t=document.getElementById("instance-table-measure"),g=(U=(A=t==null?void 0:t.children[0])==null?void 0:A.children[0])==null?void 0:U.children[0];if(!t||!g)return;const S=t.getBoundingClientRect().width,K=g.getBoundingClientRect().width,s=new Map;g.childNodes.forEach(T=>{const W=T,N=W.innerHTML,Ne=W.getBoundingClientRect().width;s.set(N,Ne)});let b=0;const P=[];ct.forEach(T=>{K-b>S&&!i.includes(T)&&(b+=s.get(T),P.push(T))}),JSON.stringify(P)!==JSON.stringify(v)&&k(P)};de("resize",ie),L.useEffect(ie,[l.instance,i,$,Q]);const G=V||$.length>0||Q.length>0,re=$.filter(t=>d.includes(t.name)),oe=$.filter(t=>!ne.includes(t.name)).length+Q.length;return e.jsxs(Re,{mainClassName:M("instance-list",{"has-side-panel":!!l.instance}),contentClassName:"instance-content",header:e.jsxs("div",{className:"p-panel__header instance-list-header",children:[e.jsxs("div",{className:"instance-header-left",children:[e.jsx("h1",{className:"p-heading--4 u-no-margin--bottom",children:e.jsx(Be,{href:`${n}/explanation/instances/#expl-instances`,title:"Learn more about instances",children:"Instances"})}),d.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(tt,{instances:re,onStart:()=>y(d),onFinish:()=>y([])}),e.jsx(nt,{instances:re,onStart:y,onFinish:()=>y([])})]}),G&&d.length===0&&e.jsx(lt,{instances:$},o)]}),G&&d.length===0&&e.jsx("div",{className:"create-button-wrapper",children:e.jsx(h.Button,{appearance:"positive",className:"u-float-right u-no-margin--bottom",onClick:()=>m(`/ui/project/${o}/instances/create`),children:c})})]}),children:[e.jsx(De,{}),e.jsx(h.Row,{className:"no-grid-gap",children:e.jsxs(h.Col,{size:12,children:[G&&e.jsxs(e.Fragment,{children:[e.jsx(ze,{...Z,id:"pagination",className:"u-no-margin--top",totalCount:oe,selectedNotification:d.length>0&&e.jsx(Ze,{totalCount:oe,itemName:"instance",parentName:`project: ${o}`,selectedNames:d,setSelectedNames:r,filteredNames:F.map(t=>t.name)}),visibleCount:F.length===$.length?Z.pageData.length:F.length+Q.length,keyword:"instance"}),e.jsx(et,{columns:[R,B,D,z,H],hidden:i,sizeHidden:v,setHidden:te,className:M({"u-hide":l.instance})}),e.jsx(He,{dependencies:[F,x.notification],children:e.jsx(he,{headers:se(i.concat(v)),rows:Z.pageData,sortable:!0,emptyStateMsg:V?e.jsx(Me,{text:"Loading instances..."}):e.jsx(e.Fragment,{children:"No instance found matching this search"}),itemName:"instance",parentName:"project",selectedNames:d,setSelectedNames:r,processingNames:I,filteredNames:F.map(t=>t.name),onUpdateSort:Z.updateSort})}),e.jsx("div",{id:"instance-table-measure",children:e.jsx(he,{headers:se(i),rows:ae(i),className:"scrollable-table",itemName:"instance",parentName:"project",selectedNames:d,setSelectedNames:r,processingNames:I,filteredNames:F.map(t=>t.name)})})]}),!G&&e.jsxs(h.EmptyState,{className:"empty-state",image:e.jsx(h.Icon,{name:"containers",className:"empty-state-icon"}),title:"No instances found",children:[e.jsx("p",{children:"There are no instances in this project. Spin up your first instance!"}),e.jsx("p",{children:e.jsxs("a",{href:`${n}/howto/instances_create/`,target:"_blank",rel:"noreferrer",children:["How to create instances",e.jsx(h.Icon,{className:"external-link-icon",name:"external-link"})]})}),e.jsx(h.Button,{className:"empty-state-button",appearance:"positive",onClick:()=>m(`/ui/project/${o}/instances/create`),children:"Create instance"})]})]})})]})};export{jt as default};