| Current Path : /snap/lxd/38450/share/lxd-ui/assets/ |
| Current File : //snap/lxd/38450/share/lxd-ui/assets/OperationList-rsI-WnzF.js |
import{c2 as d,$ as p,j as e,Z as I,z as R,c3 as x,v as T,H as v,r as j,d as t,s as O,x as F,c4 as g,aC as h,p as B}from"./index-BsQN_SZU.js";import{C as k}from"./CancelOperationBtn-C5TQ8C6V.js";import{u as A}from"./useSortTableData-DkMx8bMp.js";import{P as o}from"./PageHeader-BkhUaI4-.js";const E=({operation:a})=>{const n=d(a),i=p(a);if(!i)return null;const r=["Restarting instance","Starting instance","Stopping instance","Unfreezing instance","Freezing instance","Snapshotting instance","Restoring snapshot","Deleting snapshot","Updating snapshot","Updating instance","Renaming instance","Executing command","Showing console"];return(a.status==="Success"&&a.description==="Creating instance"||r.includes(a.description))&&n?e.jsx(I,{instanceName:i,projectName:n}):e.jsx("div",{className:"u-truncate u-text--muted",children:e.jsx(R,{type:"instance",value:i})})},K=()=>{const{isFetching:a}=x(),n=T(),i=v(),r=()=>{n.invalidateQueries({queryKey:[F.operations]})};return j.useEffect(r,[]),e.jsxs(t.ActionButton,{className:O("u-no-margin--bottom",{"has-icon":!i}),onClick:r,loading:a,disabled:a,children:[!i&&e.jsx(t.Icon,{name:"restart"}),e.jsx("span",{children:"Refresh"})]})},Q=()=>{const a=t.useNotify(),{operations:n,isLoading:i,error:r}=x(),[l,N]=j.useState("");r&&a.failure("Loading operations failed",r);const f=[{content:"Time",className:"time",sortKey:"created_at"},{content:"Action",className:"action",sortKey:"action"},{content:"Info",className:"info"},{content:"Status",className:"status status-header",sortKey:"status"},{"aria-label":"Actions",className:"cancel u-align--right"}],b=s=>({Cancelled:"status-failed-small",Failure:"status-failed-small",Running:"status-in-progress-small",Success:"status-succeeded-small"})[s],u=n.filter(s=>{const c=l.toLowerCase();return s.description.toLowerCase().includes(c)||d(s).toLowerCase().includes(c)||s.status.toLowerCase().includes(c)||p(s).toLowerCase().includes(c)}),S=u.map(s=>{const c=d(s);return{key:s.id,columns:[{content:e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"date-pair",children:["Initiated:"," ",g(h(s.created_at))]}),e.jsxs("div",{className:"date-pair u-text--muted",children:["Last update:"," ",g(h(s.updated_at))]})]}),role:"cell","aria-label":"Time",className:"time"},{content:e.jsxs(e.Fragment,{children:[e.jsx("div",{children:s.description}),e.jsx(E,{operation:s}),e.jsxs("div",{className:"u-text--muted u-truncate",title:c,children:["Project: ",c]})]}),role:"rowheader","aria-label":"Action",className:"action"},{content:e.jsxs(e.Fragment,{children:[s.err&&e.jsx("div",{children:s.err}),Object.entries(s.metadata??{}).map(([w,m],L)=>e.jsxs("span",{title:JSON.stringify(m),children:[w,": ",JSON.stringify(m)]},L))]}),role:"cell","aria-label":"Info",className:"info"},{content:e.jsxs(e.Fragment,{children:[e.jsx(t.Icon,{name:b(s.status),className:"status-icon"}),s.status]}),role:"cell","aria-label":"Status",className:"status"},{content:e.jsx(k,{operation:s}),role:"cell",className:"u-align--right cancel","aria-label":"Actions"}],sortData:{created_at:s.created_at,action:s.description,status:s.status}}}),{rows:y,updateSort:C}=A({rows:S});return e.jsx(e.Fragment,{children:e.jsxs(t.CustomLayout,{mainClassName:"operation-list",contentClassName:"u-no-padding--bottom",header:e.jsxs(o,{children:[e.jsxs(o.Left,{children:[e.jsx(o.Title,{children:"Ongoing operations"}),n.length>0&&e.jsx(o.Search,{children:e.jsx(t.SearchBox,{className:"search-box margin-right u-no-margin--bottom",name:"search-operations",onChange:N,placeholder:"Search",value:l,"aria-label":"Search"})})]}),e.jsx(o.BaseActions,{children:e.jsx(K,{})})]}),children:[e.jsx(B,{}),e.jsxs(t.Row,{children:[n.length>0&&e.jsx(t.ScrollableTable,{dependencies:[u,a.notification],tableId:"operation-table",belowIds:["status-bar"],children:e.jsx(t.TablePagination,{data:y,id:"pagination",itemName:"operation",className:"u-no-margin--top","aria-label":"Table pagination control",children:e.jsx(t.MainTable,{id:"operation-table",headers:f,sortable:!0,responsive:!0,onUpdateSort:C,emptyStateMsg:i?e.jsx(t.Spinner,{className:"u-loader",text:"Loading operations..."}):"No matching operations found"})})}),!i&&n.length===0&&e.jsx(t.EmptyState,{className:"empty-state",image:e.jsx(t.Icon,{name:"status",className:"empty-state-icon"}),title:"No operations found",children:e.jsx("p",{children:"There are no ongoing operations."})})]})]})})};export{Q as default};