forked from BLC/sgeUpdated
filtering raw data page
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import ApplicationService from "../../../services/ApplicationService";
|
import ApplicationService from "../../../services/ApplicationService";
|
||||||
|
|
||||||
export const getVMEmissionSummary = () => {
|
export const getVMEmissionSummary = (datacenterId) => {
|
||||||
return async (dispatch) => {
|
return async (dispatch) => {
|
||||||
try {
|
try {
|
||||||
const response = await ApplicationService.http()
|
const response = await ApplicationService.http()
|
||||||
@@ -8,8 +8,8 @@ export const getVMEmissionSummary = () => {
|
|||||||
"/graphql",
|
"/graphql",
|
||||||
{
|
{
|
||||||
query: `
|
query: `
|
||||||
{
|
query GetVMEmissions($datacenterId: ID) {
|
||||||
vmEmissionSummary {
|
vmEmissionSummary(datacenterId: $datacenterId) {
|
||||||
vmId
|
vmId
|
||||||
vmName
|
vmName
|
||||||
vmPower
|
vmPower
|
||||||
@@ -17,7 +17,6 @@ export const getVMEmissionSummary = () => {
|
|||||||
totalEmission
|
totalEmission
|
||||||
createdDate
|
createdDate
|
||||||
physicalMachine
|
physicalMachine
|
||||||
project
|
|
||||||
dataCenter
|
dataCenter
|
||||||
co2
|
co2
|
||||||
ch4
|
ch4
|
||||||
@@ -25,7 +24,10 @@ export const getVMEmissionSummary = () => {
|
|||||||
reportGeneratedTime
|
reportGeneratedTime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`,
|
||||||
|
variables: {
|
||||||
|
datacenterId: datacenterId
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -2,21 +2,47 @@ import React, { useState, useEffect } from "react";
|
|||||||
import { MaterialReactTable } from "material-react-table";
|
import { MaterialReactTable } from "material-react-table";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { useTranslation } from "react-i18next";
|
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 { getVMEmissionSummary } from "../../redux/actions/mainDataTables/index";
|
||||||
|
import { getDataCenters } from "../../redux/actions/dataCenter";
|
||||||
import { editNumbers } from "../../components/edit-numbers";
|
import { editNumbers } from "../../components/edit-numbers";
|
||||||
|
import Select from "react-select";
|
||||||
|
|
||||||
function MainDataTables() {
|
function MainDataTables() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const mainDataTablesStore = useSelector((state) => state.mainDataTables);
|
const mainDataTablesStore = useSelector((state) => state.mainDataTables);
|
||||||
|
const dataCenterStore = useSelector((state) => state.dataCenter);
|
||||||
const [error, setError] = useState(null);
|
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(() => {
|
useEffect(() => {
|
||||||
|
dispatch(getDataCenters());
|
||||||
|
}, [dispatch]);
|
||||||
|
|
||||||
|
// 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 () => {
|
const fetchData = async () => {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
await dispatch(getVMEmissionSummary());
|
setError(null);
|
||||||
|
await dispatch(getVMEmissionSummary(selectedDataCenter.value));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error in MainDataTables:', err);
|
console.error('Error in MainDataTables:', err);
|
||||||
setError(err.message);
|
setError(err.message);
|
||||||
@@ -25,15 +51,14 @@ function MainDataTables() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchData();
|
fetchData();
|
||||||
}, [dispatch]);
|
}
|
||||||
|
}, [selectedDataCenter, dispatch]);
|
||||||
|
|
||||||
// Debug log for store data
|
// Debug log for store data
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('Current store data:', mainDataTablesStore);
|
console.log('Current store data:', mainDataTablesStore);
|
||||||
}, [mainDataTablesStore]);
|
}, [mainDataTablesStore]);
|
||||||
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
{ header: t("VM ID"), accessorKey: "vmId", Cell: ({ cell }) => <span>{cell.getValue() || "-"}</span> },
|
{ header: t("VM ID"), accessorKey: "vmId", Cell: ({ cell }) => <span>{cell.getValue() || "-"}</span> },
|
||||||
{ header: t("VM Name"), accessorKey: "vmName", Cell: ({ cell }) => <span>{cell.getValue() || "-"}</span> },
|
{ header: t("VM Name"), accessorKey: "vmName", Cell: ({ cell }) => <span>{cell.getValue() || "-"}</span> },
|
||||||
@@ -42,13 +67,15 @@ function MainDataTables() {
|
|||||||
{ header: t("Total Emission"), accessorKey: "totalEmission", Cell: ({ cell }) => <span>{editNumbers(cell.getValue()) || "-"}</span> },
|
{ header: t("Total Emission"), accessorKey: "totalEmission", Cell: ({ cell }) => <span>{editNumbers(cell.getValue()) || "-"}</span> },
|
||||||
{ header: t("Created Date"), accessorKey: "createdDate", Cell: ({ cell }) => (<span>{cell.getValue() ? new Date(cell.getValue()).toLocaleString() : "-"}</span>), sortable: true },
|
{ header: t("Created Date"), accessorKey: "createdDate", Cell: ({ cell }) => (<span>{cell.getValue() ? new Date(cell.getValue()).toLocaleString() : "-"}</span>), sortable: true },
|
||||||
{ header: t("Physical Machine"), accessorKey: "physicalMachine", Cell: ({ cell }) => <span>{cell.getValue() || "-"}</span> },
|
{ header: t("Physical Machine"), accessorKey: "physicalMachine", Cell: ({ cell }) => <span>{cell.getValue() || "-"}</span> },
|
||||||
{ header: t("Project"), accessorKey: "project", Cell: ({ cell }) => <span>{cell.getValue() || "-"}</span> },
|
|
||||||
{ header: t("Data Center"), accessorKey: "dataCenter", Cell: ({ cell }) => <span>{cell.getValue() || "-"}</span> },
|
{ header: t("Data Center"), accessorKey: "dataCenter", Cell: ({ cell }) => <span>{cell.getValue() || "-"}</span> },
|
||||||
{ header: "CO2", accessorKey: "co2", Cell: ({ cell }) => <span>{editNumbers(cell.getValue()) || "-"}</span> },
|
{ header: "CO2", accessorKey: "co2", Cell: ({ cell }) => <span>{editNumbers(cell.getValue()) || "-"}</span> },
|
||||||
{ header: "CH4", accessorKey: "ch4", Cell: ({ cell }) => <span>{editNumbers(cell.getValue()) || "-"}</span> },
|
{ header: "CH4", accessorKey: "ch4", Cell: ({ cell }) => <span>{editNumbers(cell.getValue()) || "-"}</span> },
|
||||||
{ header: "N2O", accessorKey: "n2o", Cell: ({ cell }) => <span>{editNumbers(cell.getValue()) || "-"}</span> },
|
{ header: "N2O", accessorKey: "n2o", Cell: ({ cell }) => <span>{editNumbers(cell.getValue()) || "-"}</span> },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const tableData = mainDataTablesStore?.vmEmissionSummary || [];
|
const tableData = mainDataTablesStore?.vmEmissionSummary || [];
|
||||||
console.log('VM Emission data:', tableData);
|
console.log('VM Emission data:', tableData);
|
||||||
|
|
||||||
@@ -66,6 +93,27 @@ function MainDataTables() {
|
|||||||
<CardHeader className="border-bottom">
|
<CardHeader className="border-bottom">
|
||||||
<CardTitle tag="h4">{t("Raw Data")}</CardTitle>
|
<CardTitle tag="h4">{t("Raw Data")}</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|
||||||
|
{/* Datacenter Selection */}
|
||||||
|
<div className="p-3 border-bottom">
|
||||||
|
<Row>
|
||||||
|
<Col md="6">
|
||||||
|
<Label for="datacenter-select">{t("Data Center")}</Label>
|
||||||
|
<Select
|
||||||
|
id="datacenter-select"
|
||||||
|
value={selectedDataCenter}
|
||||||
|
onChange={setSelectedDataCenter}
|
||||||
|
options={dataCenterOptions}
|
||||||
|
placeholder={t("Select a data center...")}
|
||||||
|
isClearable
|
||||||
|
isSearchable
|
||||||
|
isLoading={dataCenterStore?.loading}
|
||||||
|
noOptionsMessage={() => t("No data centers available")}
|
||||||
|
/>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
</div>
|
||||||
|
{selectedDataCenter ? (
|
||||||
<MaterialReactTable
|
<MaterialReactTable
|
||||||
columns={columns}
|
columns={columns}
|
||||||
data={tableData}
|
data={tableData}
|
||||||
@@ -97,6 +145,11 @@ function MainDataTables() {
|
|||||||
showSkeletons: true,
|
showSkeletons: true,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="p-4 text-center text-muted">
|
||||||
|
{t("Please select a data center to view raw data")}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user