forked from Abdulbari/sgeUpdated
few translation edits and changing it to use vmEmission query
This commit is contained in:
@@ -28,3 +28,6 @@ spring.rabbitmq.template.retry.max-attempts=3
|
||||
spring.rabbitmq.template.retry.initial-interval=1000ms
|
||||
|
||||
logging.level.org.springframework.amqp=DEBUG
|
||||
spring.jpa.show-sql=true
|
||||
logging.level.org.hibernate.SQL=DEBUG
|
||||
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
|
||||
@@ -67,7 +67,11 @@
|
||||
|
||||
"Common": {
|
||||
"save": "Save",
|
||||
"cancel": "Cancel"
|
||||
"cancel": "Cancel",
|
||||
"yes": "Yes",
|
||||
"no": "No",
|
||||
"areYouSure": "Are you sure?",
|
||||
"cantRevert": "This action cannot be undone!"
|
||||
},
|
||||
|
||||
"DataInput": {
|
||||
|
||||
@@ -66,7 +66,11 @@
|
||||
|
||||
"Common": {
|
||||
"save": "Kaydet",
|
||||
"cancel": " İptal"
|
||||
"cancel": "İptal",
|
||||
"yes": "Evet",
|
||||
"no": "Hayır",
|
||||
"areYouSure": "Emin misiniz?",
|
||||
"cantRevert": "Bu işlem geri alınamaz!"
|
||||
},
|
||||
|
||||
"DataInput": {
|
||||
|
||||
@@ -122,7 +122,10 @@ const DataCenterManagement = () => {
|
||||
|
||||
const [mapPosition, setMapPosition] = useState(null);
|
||||
|
||||
const dataCenterStore = useSelector((state) => state.dataCenter);
|
||||
const dataCenterStore = useSelector((state) => {
|
||||
console.log('DataCenter Store:', state.dataCenter);
|
||||
return state.dataCenter;
|
||||
});
|
||||
const emissionScopeStore = useSelector((state) => state.emissionScope);
|
||||
const datasStore = useSelector((state) => state.datas);
|
||||
const emissionSourceStore = useSelector((state) => state.emissionSources);
|
||||
@@ -179,8 +182,9 @@ const DataCenterManagement = () => {
|
||||
},
|
||||
{
|
||||
name: t("Actions"),
|
||||
allowOverflow: false,
|
||||
maxWidth: "150px",
|
||||
allowOverflow: true,
|
||||
width: "150px",
|
||||
center: true,
|
||||
cell: (row) => {
|
||||
return (
|
||||
<div className="d-flex">
|
||||
@@ -189,7 +193,7 @@ const DataCenterManagement = () => {
|
||||
<MoreVertical size={15} />
|
||||
</DropdownToggle>
|
||||
<DropdownMenu container={"body"} end>
|
||||
{permissionCheck("datacenter_update") && (
|
||||
{permissionCheck("data_center_update") && (
|
||||
<DropdownItem
|
||||
tag="a"
|
||||
className="w-100"
|
||||
@@ -199,7 +203,7 @@ const DataCenterManagement = () => {
|
||||
<span className="align-middle ml-50">{t("Cruds.edit")}</span>
|
||||
</DropdownItem>
|
||||
)}
|
||||
{permissionCheck("datacenter_delete") && (
|
||||
{permissionCheck("data_center_delete") && (
|
||||
<DropdownItem
|
||||
tag="a"
|
||||
className="w-100"
|
||||
@@ -348,24 +352,25 @@ const DataCenterManagement = () => {
|
||||
}, [selectedDataCenter.areaId, areasStore?.areas]);
|
||||
|
||||
const handleEditDataCenter = (row) => {
|
||||
console.log('Editing data center:', row);
|
||||
setEditingDataCenter(row);
|
||||
setSelectedDataCenter({
|
||||
name: row.dataCenter,
|
||||
externalId: row.externalId,
|
||||
number: row.number,
|
||||
address: row.address,
|
||||
areaId: row.area?.id,
|
||||
cityId: null, // City is a string in the backend, not an object
|
||||
externalId: row.externalId?.toString(),
|
||||
number: row.number?.toString(),
|
||||
address: row.address || "",
|
||||
areaId: row.area?.id || null,
|
||||
cityId: null,
|
||||
latitude: row.latitude,
|
||||
longitude: row.longitude,
|
||||
ayposURL: row.ayposURL,
|
||||
ayposURL: row.ayposURL || "",
|
||||
city: row.city || "",
|
||||
emissionScopeId: row.emissionScope?.id,
|
||||
sectorId: row.sector?.id,
|
||||
subSectorId: row.subSector?.id,
|
||||
emissionSourceId: row.emissionSource?.id,
|
||||
consuptionUnitId: row.consuptionUnit?.id,
|
||||
activitySubUnitId: row.activitySubUnit?.id
|
||||
emissionScopeId: row.emissionScope?.id || null,
|
||||
sectorId: row.sector?.id || null,
|
||||
subSectorId: row.subSector?.id || null,
|
||||
emissionSourceId: row.emissionSource?.id || null,
|
||||
consuptionUnitId: row.consuptionUnit?.id || null,
|
||||
activitySubUnitId: row.activitySubUnit?.id || null
|
||||
});
|
||||
|
||||
// Set the selected sector and sub sector for cascading dropdowns
|
||||
@@ -409,34 +414,62 @@ const DataCenterManagement = () => {
|
||||
const validateForm = () => {
|
||||
const errors = [];
|
||||
|
||||
// Required fields
|
||||
if (!selectedDataCenter.name) {
|
||||
// Required fields validation
|
||||
if (!selectedDataCenter.name?.trim()) {
|
||||
errors.push(t("DataCenter.nameRequired"));
|
||||
}
|
||||
if (!selectedDataCenter.externalId) {
|
||||
if (!selectedDataCenter.externalId?.trim()) {
|
||||
errors.push(t("DataCenter.externalIdRequired"));
|
||||
}
|
||||
if (!selectedDataCenter.sectorId) {
|
||||
errors.push(t("DataCenter.sectorRequired"));
|
||||
}
|
||||
|
||||
// Validate external ID is a number
|
||||
if (selectedDataCenter.externalId && isNaN(parseInt(selectedDataCenter.externalId))) {
|
||||
errors.push(t("DataCenter.externalIdMustBeNumber"));
|
||||
// Number validations
|
||||
try {
|
||||
if (selectedDataCenter.externalId) {
|
||||
const externalId = parseInt(selectedDataCenter.externalId);
|
||||
if (isNaN(externalId) || externalId < 0) {
|
||||
errors.push(t("DataCenter.externalIdMustBePositiveNumber"));
|
||||
}
|
||||
}
|
||||
if (selectedDataCenter.number) {
|
||||
const number = parseInt(selectedDataCenter.number);
|
||||
if (isNaN(number) || number < 1) {
|
||||
errors.push(t("DataCenter.numberMustBePositive"));
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
errors.push(t("DataCenter.invalidNumberFormat"));
|
||||
}
|
||||
|
||||
// Validate coordinates if either is provided
|
||||
if ((selectedDataCenter.latitude && !selectedDataCenter.longitude) ||
|
||||
(!selectedDataCenter.latitude && selectedDataCenter.longitude)) {
|
||||
errors.push(t("DataCenter.bothCoordinatesRequired"));
|
||||
// Coordinate validations
|
||||
if (selectedDataCenter.latitude || selectedDataCenter.longitude) {
|
||||
try {
|
||||
const lat = parseFloat(selectedDataCenter.latitude);
|
||||
const lng = parseFloat(selectedDataCenter.longitude);
|
||||
|
||||
if (isNaN(lat) || lat < -90 || lat > 90) {
|
||||
errors.push(t("DataCenter.invalidLatitude"));
|
||||
}
|
||||
if (isNaN(lng) || lng < -180 || lng > 180) {
|
||||
errors.push(t("DataCenter.invalidLongitude"));
|
||||
}
|
||||
} catch (e) {
|
||||
errors.push(t("DataCenter.invalidCoordinates"));
|
||||
}
|
||||
}
|
||||
|
||||
// Validate area and city are selected together
|
||||
if (selectedDataCenter.areaId && !selectedDataCenter.cityId) {
|
||||
errors.push(t("DataCenter.cityRequired"));
|
||||
// URL validation
|
||||
if (selectedDataCenter.ayposURL?.trim()) {
|
||||
try {
|
||||
new URL(selectedDataCenter.ayposURL);
|
||||
} catch (e) {
|
||||
errors.push(t("DataCenter.invalidURL"));
|
||||
}
|
||||
}
|
||||
|
||||
// Validate sector hierarchy
|
||||
// Relationship validations
|
||||
if (selectedDataCenter.subSectorId && !selectedDataCenter.sectorId) {
|
||||
errors.push(t("DataCenter.sectorRequired"));
|
||||
}
|
||||
@@ -446,6 +479,9 @@ const DataCenterManagement = () => {
|
||||
if (selectedDataCenter.consuptionUnitId && !selectedDataCenter.emissionSourceId) {
|
||||
errors.push(t("DataCenter.emissionSourceRequired"));
|
||||
}
|
||||
if (selectedDataCenter.activitySubUnitId && !selectedDataCenter.subSectorId) {
|
||||
errors.push(t("DataCenter.subSectorRequiredForActivity"));
|
||||
}
|
||||
|
||||
return errors;
|
||||
};
|
||||
@@ -460,11 +496,16 @@ const DataCenterManagement = () => {
|
||||
}
|
||||
|
||||
try {
|
||||
// Ensure number is set for new data centers
|
||||
// Format data according to GraphQL input type
|
||||
const dataToSubmit = {
|
||||
...selectedDataCenter,
|
||||
number: selectedDataCenter.number || 1, // Default to 1 if not set
|
||||
city: selectedDataCenter.city, // Add city to the payload
|
||||
dataCenter: selectedDataCenter.name,
|
||||
externalId: parseInt(selectedDataCenter.externalId),
|
||||
number: parseInt(selectedDataCenter.number || "1"),
|
||||
address: selectedDataCenter.address,
|
||||
areaId: selectedDataCenter.areaId,
|
||||
latitude: selectedDataCenter.latitude ? parseFloat(selectedDataCenter.latitude) : null,
|
||||
longitude: selectedDataCenter.longitude ? parseFloat(selectedDataCenter.longitude) : null,
|
||||
ayposURL: selectedDataCenter.ayposURL,
|
||||
emissionScopeId: selectedDataCenter.emissionScopeId,
|
||||
sectorId: selectedDataCenter.sectorId,
|
||||
subSectorId: selectedDataCenter.subSectorId,
|
||||
@@ -483,6 +524,9 @@ const DataCenterManagement = () => {
|
||||
enqueueSnackbar(t("DataCenter.createSuccess"), { variant: "success" });
|
||||
}
|
||||
|
||||
// Refresh the data centers list
|
||||
await dispatch(getDataCenters());
|
||||
|
||||
handleCloseModal();
|
||||
} catch (error) {
|
||||
console.error("Submit error:", error);
|
||||
@@ -1035,7 +1079,9 @@ const DataCenterManagement = () => {
|
||||
sortIcon={<ChevronDown size={10} />}
|
||||
paginationDefaultPage={currentPage}
|
||||
paginationComponent={CustomPagination}
|
||||
data={dataCenterStore.dataCenters}
|
||||
data={dataCenterStore?.dataCenters || []}
|
||||
progressPending={dataCenterStore?.loading}
|
||||
progressComponent={<div className="text-center p-3">Loading...</div>}
|
||||
noDataComponent={
|
||||
<div className="p-2 text-center">
|
||||
{t("Common.noDataAvailable")}
|
||||
|
||||
@@ -3,7 +3,7 @@ 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 { getMainDataTablesWithPaginate } from "../../redux/actions/mainDataTables/index";
|
||||
import { getVMEmissionSummary } from "../../redux/actions/mainDataTables/index";
|
||||
import { editNumbers } from "../../components/edit-numbers";
|
||||
|
||||
function MainDataTables() {
|
||||
@@ -16,7 +16,7 @@ function MainDataTables() {
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
await dispatch(getMainDataTablesWithPaginate());
|
||||
await dispatch(getVMEmissionSummary());
|
||||
} catch (err) {
|
||||
console.error('Error in MainDataTables:', err);
|
||||
setError(err.message);
|
||||
@@ -35,74 +35,21 @@ function MainDataTables() {
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
const columns = [
|
||||
{
|
||||
header: t("ID"),
|
||||
accessorKey: "id",
|
||||
Cell: ({ cell }) => <span>{cell.getValue() || "-"}</span>,
|
||||
},
|
||||
{
|
||||
header: t("Year"),
|
||||
accessorKey: "year",
|
||||
Cell: ({ cell }) => <span>{cell.getValue() || "-"}</span>,
|
||||
},
|
||||
{
|
||||
header: t("Sector"),
|
||||
accessorKey: "sector",
|
||||
Cell: ({ cell, row }) => <span>{row.original?.sector?.tag || "-"}</span>,
|
||||
},
|
||||
{
|
||||
header: t("Sub Sector"),
|
||||
accessorKey: "subSector",
|
||||
Cell: ({ cell, row }) => <span>{row.original?.subSector?.tag || "-"}</span>,
|
||||
},
|
||||
{
|
||||
header: t("Activity Sub Unit"),
|
||||
accessorKey: "activitySubUnit",
|
||||
Cell: ({ cell, row }) => <span>{row.original?.activitySubUnit?.tag || "-"}</span>,
|
||||
},
|
||||
{
|
||||
header: t("Emission Source"),
|
||||
accessorKey: "emissionSource",
|
||||
Cell: ({ cell, row }) => <span>{row.original?.emissionSource?.tag || "-"}</span>,
|
||||
},
|
||||
{
|
||||
header: t("Emission Scope"),
|
||||
accessorKey: "emissionScope",
|
||||
Cell: ({ cell, row }) => <span>{row.original?.emissionScope?.tag || "-"}</span>,
|
||||
},
|
||||
{
|
||||
header: t("Total Emission"),
|
||||
accessorKey: "totalEmission",
|
||||
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: "N2O",
|
||||
accessorKey: "n2o",
|
||||
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("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 Power"), accessorKey: "vmPower", Cell: ({ cell }) => <span>{editNumbers(cell.getValue()) || "-"}</span> },
|
||||
{ header: t("VM Status"), accessorKey: "vmStatus", Cell: ({ cell }) => <span>{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("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: "CO2", accessorKey: "co2", 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> },
|
||||
];
|
||||
|
||||
const tableData = mainDataTablesStore?.mainDataTablesWithPaginate?.content || [];
|
||||
const tableData = mainDataTablesStore?.vmEmissionSummary || [];
|
||||
console.log('VM Emission data:', tableData);
|
||||
|
||||
if (error) {
|
||||
@@ -140,7 +87,7 @@ function MainDataTables() {
|
||||
pageIndex: 0
|
||||
},
|
||||
sorting: [
|
||||
{ id: 'dataCenter', desc: false }
|
||||
{ id: 'createdDate', desc: true }
|
||||
],
|
||||
density: 'compact'
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user