diff --git a/sge-frontend/src/views/DataCenter.js b/sge-frontend/src/views/DataCenter.js index b1b9d60..374b2be 100644 --- a/sge-frontend/src/views/DataCenter.js +++ b/sge-frontend/src/views/DataCenter.js @@ -18,10 +18,10 @@ const DataCenter = () => { const [refreshInterval, setRefreshInterval] = useState(null); const getAllPhysicalMachines = (dataCenter) => { - if (!dataCenter.projects) return []; - return dataCenter.projects.flatMap(project => - project.physicalMachines || [] - ); + // Physical machines are directly in the dataCenter object, not in projects + const pms = dataCenter.physicalMachines || []; + console.log(`Physical machines for ${dataCenter.dataCenter}:`, pms); + return pms; }; // Table columns following your pattern @@ -38,18 +38,23 @@ const DataCenter = () => { sortable: true, minWidth: "200px", }, - // Projects + // Projects - Based on API response, this field might not exist or be structured differently { name: "Projects", - selector: (row) => (row.projects || []).length, + selector: (row) => row.projects?.length || 0, sortable: true, minWidth: "200px", cell: (row) => (
- {(row.projects || []).length > 0 ? ( + {row.projects && row.projects.length > 0 ? (
{row.projects.map((project, index) => ( -
0 ? 'mt-1' : ''}`}> +
0 ? "mt-1" : "" + }`} + > {project.name}
))} @@ -80,27 +85,39 @@ const DataCenter = () => { name: "Virtual Machines", selector: (row) => { const pms = getAllPhysicalMachines(row); - const vms = pms.reduce((acc, pm) => { - if (!pm.vms) return acc; - return { - active: acc.active + pm.vms.filter(vm => vm.state?.toLowerCase() === "active").length, - total: acc.total + pm.vms.length - }; - }, { active: 0, total: 0 }); + const vms = pms.reduce( + (acc, pm) => { + if (!pm.vms) return acc; + return { + active: + acc.active + + pm.vms.filter((vm) => vm.state?.toLowerCase() === "active") + .length, + total: acc.total + pm.vms.length, + }; + }, + { active: 0, total: 0 } + ); return vms.total; }, sortable: true, minWidth: "200px", cell: (row) => { const pms = getAllPhysicalMachines(row); - const vms = pms.reduce((acc, pm) => { - if (!pm.vms) return acc; - return { - active: acc.active + pm.vms.filter(vm => vm.state?.toLowerCase() === "active").length, - total: acc.total + pm.vms.length - }; - }, { active: 0, total: 0 }); - + const vms = pms.reduce( + (acc, pm) => { + if (!pm.vms) return acc; + return { + active: + acc.active + + pm.vms.filter((vm) => vm.state?.toLowerCase() === "active") + .length, + total: acc.total + pm.vms.length, + }; + }, + { active: 0, total: 0 } + ); + return (
@@ -109,7 +126,9 @@ const DataCenter = () => {
{vms.active} Active - {vms.total - vms.active} Inactive + + {vms.total - vms.active} Inactive +
@@ -183,14 +202,23 @@ const DataCenter = () => { {pm.vms.map((vm) => { - const isActive = vm.state && ["ACTIVE", "active"].includes(vm.state); + const isActive = + vm.state && ["ACTIVE", "active"].includes(vm.state); return ( - {vm.vmName || vm.vm_name} + + {vm.vmName || vm.vm_name} + -
+
{vm.state}
@@ -204,23 +232,48 @@ const DataCenter = () => {
- CPU - {(vm.config?.cpu || (vm.confg && vm.confg[1])) || '-'} + + CPU + + + {vm.config?.cpu || + (vm.confg && vm.confg[1]) || + "-"} +
- RAM - {(vm.config?.ram || (vm.confg && vm.confg[2])) || '-'} GB + + RAM + + + {vm.config?.ram || + (vm.confg && vm.confg[2]) || + "-"}{" "} + GB +
- Disk - {(vm.config?.disk || (vm.confg && vm.confg[3])) || '-'} GB + + Disk + + + {vm.config?.disk || + (vm.confg && vm.confg[3]) || + "-"}{" "} + GB +
- {vm.host || vm.hostingPm || (vm.confg && vm.confg[4]) || '-'} + + {vm.host || + vm.hostingPm || + (vm.confg && vm.confg[4]) || + "-"} +
@@ -241,8 +294,6 @@ const DataCenter = () => { ); }; - - return (