diff --git a/sge-frontend/src/redux/actions/mainDataTables/index.js b/sge-frontend/src/redux/actions/mainDataTables/index.js
index 0db497f..e3999b1 100644
--- a/sge-frontend/src/redux/actions/mainDataTables/index.js
+++ b/sge-frontend/src/redux/actions/mainDataTables/index.js
@@ -1,6 +1,6 @@
import ApplicationService from "../../../services/ApplicationService";
-export const getVMEmissionSummary = () => {
+export const getVMEmissionSummary = (datacenterId) => {
return async (dispatch) => {
try {
const response = await ApplicationService.http()
@@ -8,8 +8,8 @@ export const getVMEmissionSummary = () => {
"/graphql",
{
query: `
- {
- vmEmissionSummary {
+ query GetVMEmissions($datacenterId: ID) {
+ vmEmissionSummary(datacenterId: $datacenterId) {
vmId
vmName
vmPower
@@ -17,7 +17,6 @@ export const getVMEmissionSummary = () => {
totalEmission
createdDate
physicalMachine
- project
dataCenter
co2
ch4
@@ -25,7 +24,10 @@ export const getVMEmissionSummary = () => {
reportGeneratedTime
}
}
- `
+ `,
+ variables: {
+ datacenterId: datacenterId
+ }
},
{
headers: {
diff --git a/sge-frontend/src/views/DataSet/MainDataTables.js b/sge-frontend/src/views/DataSet/MainDataTables.js
index 88c7b11..88ce4fa 100644
--- a/sge-frontend/src/views/DataSet/MainDataTables.js
+++ b/sge-frontend/src/views/DataSet/MainDataTables.js
@@ -2,38 +2,63 @@ import React, { useState, useEffect } from "react";
import { MaterialReactTable } from "material-react-table";
import { useDispatch, useSelector } from "react-redux";
import { useTranslation } from "react-i18next";
-import { Card, CardHeader, CardTitle, Alert } from "reactstrap";
+import { Card, CardHeader, CardTitle, Alert, Row, Col, Label } from "reactstrap";
import { getVMEmissionSummary } from "../../redux/actions/mainDataTables/index";
+import { getDataCenters } from "../../redux/actions/dataCenter";
import { editNumbers } from "../../components/edit-numbers";
+import Select from "react-select";
function MainDataTables() {
const { t } = useTranslation();
const dispatch = useDispatch();
const mainDataTablesStore = useSelector((state) => state.mainDataTables);
+ const dataCenterStore = useSelector((state) => state.dataCenter);
const [error, setError] = useState(null);
+ const [selectedDataCenter, setSelectedDataCenter] = useState(null);
+ const [dataCenterOptions, setDataCenterOptions] = useState([]);
+ const [loading, setLoading] = useState(false);
+ // Fetch datacenters on component mount
useEffect(() => {
- const fetchData = async () => {
- try {
- setLoading(true);
- await dispatch(getVMEmissionSummary());
- } catch (err) {
- console.error('Error in MainDataTables:', err);
- setError(err.message);
- } finally {
- setLoading(false);
- }
- };
- fetchData();
+ dispatch(getDataCenters());
}, [dispatch]);
- // Debug log for store data
+ // Update datacenter options when datacenters are loaded
+ useEffect(() => {
+ if (dataCenterStore?.dataCenters?.length > 0) {
+ const options = dataCenterStore.dataCenters.map((dataCenter) => ({
+ value: dataCenter.id,
+ label: dataCenter.dataCenter,
+ externalId: dataCenter.externalId,
+ }));
+ setDataCenterOptions(options);
+ }
+ }, [dataCenterStore?.dataCenters]);
+
+ // Fetch VM emission data when datacenter is selected
+ useEffect(() => {
+ if (selectedDataCenter?.value) {
+ const fetchData = async () => {
+ try {
+ setLoading(true);
+ setError(null);
+ await dispatch(getVMEmissionSummary(selectedDataCenter.value));
+ } catch (err) {
+ console.error('Error in MainDataTables:', err);
+ setError(err.message);
+ } finally {
+ setLoading(false);
+ }
+ };
+ fetchData();
+ }
+ }, [selectedDataCenter, dispatch]);
+
+ // Debug log for store data
useEffect(() => {
console.log('Current store data:', mainDataTablesStore);
}, [mainDataTablesStore]);
- const [loading, setLoading] = useState(true);
-
const columns = [
{ header: t("VM ID"), accessorKey: "vmId", Cell: ({ cell }) => {cell.getValue() || "-"} },
{ header: t("VM Name"), accessorKey: "vmName", Cell: ({ cell }) => {cell.getValue() || "-"} },
@@ -42,13 +67,15 @@ function MainDataTables() {
{ header: t("Total Emission"), accessorKey: "totalEmission", Cell: ({ cell }) => {editNumbers(cell.getValue()) || "-"} },
{ header: t("Created Date"), accessorKey: "createdDate", Cell: ({ cell }) => ({cell.getValue() ? new Date(cell.getValue()).toLocaleString() : "-"}), sortable: true },
{ header: t("Physical Machine"), accessorKey: "physicalMachine", Cell: ({ cell }) => {cell.getValue() || "-"} },
- { header: t("Project"), accessorKey: "project", Cell: ({ cell }) => {cell.getValue() || "-"} },
{ header: t("Data Center"), accessorKey: "dataCenter", Cell: ({ cell }) => {cell.getValue() || "-"} },
{ header: "CO2", accessorKey: "co2", Cell: ({ cell }) => {editNumbers(cell.getValue()) || "-"} },
{ header: "CH4", accessorKey: "ch4", Cell: ({ cell }) => {editNumbers(cell.getValue()) || "-"} },
{ header: "N2O", accessorKey: "n2o", Cell: ({ cell }) => {editNumbers(cell.getValue()) || "-"} },
];
+
+
+
const tableData = mainDataTablesStore?.vmEmissionSummary || [];
console.log('VM Emission data:', tableData);
@@ -66,37 +93,63 @@ function MainDataTables() {