few translation edits and changing it to use vmEmission query

This commit is contained in:
2025-08-09 20:08:56 +03:00
parent 39fffadbd2
commit 89b4644983
5 changed files with 422 additions and 418 deletions

View File

@@ -28,3 +28,6 @@ spring.rabbitmq.template.retry.max-attempts=3
spring.rabbitmq.template.retry.initial-interval=1000ms spring.rabbitmq.template.retry.initial-interval=1000ms
logging.level.org.springframework.amqp=DEBUG 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

View File

@@ -67,7 +67,11 @@
"Common": { "Common": {
"save": "Save", "save": "Save",
"cancel": "Cancel" "cancel": "Cancel",
"yes": "Yes",
"no": "No",
"areYouSure": "Are you sure?",
"cantRevert": "This action cannot be undone!"
}, },
"DataInput": { "DataInput": {

View File

@@ -66,7 +66,11 @@
"Common": { "Common": {
"save": "Kaydet", "save": "Kaydet",
"cancel": " İptal" "cancel": "İptal",
"yes": "Evet",
"no": "Hayır",
"areYouSure": "Emin misiniz?",
"cantRevert": "Bu işlem geri alınamaz!"
}, },
"DataInput": { "DataInput": {

View File

@@ -122,7 +122,10 @@ const DataCenterManagement = () => {
const [mapPosition, setMapPosition] = useState(null); 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 emissionScopeStore = useSelector((state) => state.emissionScope);
const datasStore = useSelector((state) => state.datas); const datasStore = useSelector((state) => state.datas);
const emissionSourceStore = useSelector((state) => state.emissionSources); const emissionSourceStore = useSelector((state) => state.emissionSources);
@@ -179,8 +182,9 @@ const DataCenterManagement = () => {
}, },
{ {
name: t("Actions"), name: t("Actions"),
allowOverflow: false, allowOverflow: true,
maxWidth: "150px", width: "150px",
center: true,
cell: (row) => { cell: (row) => {
return ( return (
<div className="d-flex"> <div className="d-flex">
@@ -189,7 +193,7 @@ const DataCenterManagement = () => {
<MoreVertical size={15} /> <MoreVertical size={15} />
</DropdownToggle> </DropdownToggle>
<DropdownMenu container={"body"} end> <DropdownMenu container={"body"} end>
{permissionCheck("datacenter_update") && ( {permissionCheck("data_center_update") && (
<DropdownItem <DropdownItem
tag="a" tag="a"
className="w-100" className="w-100"
@@ -199,7 +203,7 @@ const DataCenterManagement = () => {
<span className="align-middle ml-50">{t("Cruds.edit")}</span> <span className="align-middle ml-50">{t("Cruds.edit")}</span>
</DropdownItem> </DropdownItem>
)} )}
{permissionCheck("datacenter_delete") && ( {permissionCheck("data_center_delete") && (
<DropdownItem <DropdownItem
tag="a" tag="a"
className="w-100" className="w-100"
@@ -348,24 +352,25 @@ const DataCenterManagement = () => {
}, [selectedDataCenter.areaId, areasStore?.areas]); }, [selectedDataCenter.areaId, areasStore?.areas]);
const handleEditDataCenter = (row) => { const handleEditDataCenter = (row) => {
console.log('Editing data center:', row);
setEditingDataCenter(row); setEditingDataCenter(row);
setSelectedDataCenter({ setSelectedDataCenter({
name: row.dataCenter, name: row.dataCenter,
externalId: row.externalId, externalId: row.externalId?.toString(),
number: row.number, number: row.number?.toString(),
address: row.address, address: row.address || "",
areaId: row.area?.id, areaId: row.area?.id || null,
cityId: null, // City is a string in the backend, not an object cityId: null,
latitude: row.latitude, latitude: row.latitude,
longitude: row.longitude, longitude: row.longitude,
ayposURL: row.ayposURL, ayposURL: row.ayposURL || "",
city: row.city || "", city: row.city || "",
emissionScopeId: row.emissionScope?.id, emissionScopeId: row.emissionScope?.id || null,
sectorId: row.sector?.id, sectorId: row.sector?.id || null,
subSectorId: row.subSector?.id, subSectorId: row.subSector?.id || null,
emissionSourceId: row.emissionSource?.id, emissionSourceId: row.emissionSource?.id || null,
consuptionUnitId: row.consuptionUnit?.id, consuptionUnitId: row.consuptionUnit?.id || null,
activitySubUnitId: row.activitySubUnit?.id activitySubUnitId: row.activitySubUnit?.id || null
}); });
// Set the selected sector and sub sector for cascading dropdowns // Set the selected sector and sub sector for cascading dropdowns
@@ -409,34 +414,62 @@ const DataCenterManagement = () => {
const validateForm = () => { const validateForm = () => {
const errors = []; const errors = [];
// Required fields // Required fields validation
if (!selectedDataCenter.name) { if (!selectedDataCenter.name?.trim()) {
errors.push(t("DataCenter.nameRequired")); errors.push(t("DataCenter.nameRequired"));
} }
if (!selectedDataCenter.externalId) { if (!selectedDataCenter.externalId?.trim()) {
errors.push(t("DataCenter.externalIdRequired")); errors.push(t("DataCenter.externalIdRequired"));
} }
if (!selectedDataCenter.sectorId) { if (!selectedDataCenter.sectorId) {
errors.push(t("DataCenter.sectorRequired")); errors.push(t("DataCenter.sectorRequired"));
} }
// Validate external ID is a number // Number validations
if (selectedDataCenter.externalId && isNaN(parseInt(selectedDataCenter.externalId))) { try {
errors.push(t("DataCenter.externalIdMustBeNumber")); 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 // Coordinate validations
if ((selectedDataCenter.latitude && !selectedDataCenter.longitude) || if (selectedDataCenter.latitude || selectedDataCenter.longitude) {
(!selectedDataCenter.latitude && selectedDataCenter.longitude)) { try {
errors.push(t("DataCenter.bothCoordinatesRequired")); 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 // URL validation
if (selectedDataCenter.areaId && !selectedDataCenter.cityId) { if (selectedDataCenter.ayposURL?.trim()) {
errors.push(t("DataCenter.cityRequired")); try {
new URL(selectedDataCenter.ayposURL);
} catch (e) {
errors.push(t("DataCenter.invalidURL"));
}
} }
// Validate sector hierarchy // Relationship validations
if (selectedDataCenter.subSectorId && !selectedDataCenter.sectorId) { if (selectedDataCenter.subSectorId && !selectedDataCenter.sectorId) {
errors.push(t("DataCenter.sectorRequired")); errors.push(t("DataCenter.sectorRequired"));
} }
@@ -446,6 +479,9 @@ const DataCenterManagement = () => {
if (selectedDataCenter.consuptionUnitId && !selectedDataCenter.emissionSourceId) { if (selectedDataCenter.consuptionUnitId && !selectedDataCenter.emissionSourceId) {
errors.push(t("DataCenter.emissionSourceRequired")); errors.push(t("DataCenter.emissionSourceRequired"));
} }
if (selectedDataCenter.activitySubUnitId && !selectedDataCenter.subSectorId) {
errors.push(t("DataCenter.subSectorRequiredForActivity"));
}
return errors; return errors;
}; };
@@ -460,11 +496,16 @@ const DataCenterManagement = () => {
} }
try { try {
// Ensure number is set for new data centers // Format data according to GraphQL input type
const dataToSubmit = { const dataToSubmit = {
...selectedDataCenter, dataCenter: selectedDataCenter.name,
number: selectedDataCenter.number || 1, // Default to 1 if not set externalId: parseInt(selectedDataCenter.externalId),
city: selectedDataCenter.city, // Add city to the payload 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, emissionScopeId: selectedDataCenter.emissionScopeId,
sectorId: selectedDataCenter.sectorId, sectorId: selectedDataCenter.sectorId,
subSectorId: selectedDataCenter.subSectorId, subSectorId: selectedDataCenter.subSectorId,
@@ -483,6 +524,9 @@ const DataCenterManagement = () => {
enqueueSnackbar(t("DataCenter.createSuccess"), { variant: "success" }); enqueueSnackbar(t("DataCenter.createSuccess"), { variant: "success" });
} }
// Refresh the data centers list
await dispatch(getDataCenters());
handleCloseModal(); handleCloseModal();
} catch (error) { } catch (error) {
console.error("Submit error:", error); console.error("Submit error:", error);
@@ -1035,7 +1079,9 @@ const DataCenterManagement = () => {
sortIcon={<ChevronDown size={10} />} sortIcon={<ChevronDown size={10} />}
paginationDefaultPage={currentPage} paginationDefaultPage={currentPage}
paginationComponent={CustomPagination} paginationComponent={CustomPagination}
data={dataCenterStore.dataCenters} data={dataCenterStore?.dataCenters || []}
progressPending={dataCenterStore?.loading}
progressComponent={<div className="text-center p-3">Loading...</div>}
noDataComponent={ noDataComponent={
<div className="p-2 text-center"> <div className="p-2 text-center">
{t("Common.noDataAvailable")} {t("Common.noDataAvailable")}

View File

@@ -3,7 +3,7 @@ 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 } from "reactstrap";
import { getMainDataTablesWithPaginate } from "../../redux/actions/mainDataTables/index"; import { getVMEmissionSummary } from "../../redux/actions/mainDataTables/index";
import { editNumbers } from "../../components/edit-numbers"; import { editNumbers } from "../../components/edit-numbers";
function MainDataTables() { function MainDataTables() {
@@ -16,7 +16,7 @@ function MainDataTables() {
const fetchData = async () => { const fetchData = async () => {
try { try {
setLoading(true); setLoading(true);
await dispatch(getMainDataTablesWithPaginate()); await dispatch(getVMEmissionSummary());
} catch (err) { } catch (err) {
console.error('Error in MainDataTables:', err); console.error('Error in MainDataTables:', err);
setError(err.message); setError(err.message);
@@ -35,74 +35,21 @@ function MainDataTables() {
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const columns = [ const columns = [
{ { header: t("VM ID"), accessorKey: "vmId", Cell: ({ cell }) => <span>{cell.getValue() || "-"}</span> },
header: t("ID"), { header: t("VM Name"), accessorKey: "vmName", Cell: ({ cell }) => <span>{cell.getValue() || "-"}</span> },
accessorKey: "id", { header: t("VM Power"), accessorKey: "vmPower", Cell: ({ cell }) => <span>{editNumbers(cell.getValue()) || "-"}</span> },
Cell: ({ cell }) => <span>{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("Year"), { header: t("Physical Machine"), accessorKey: "physicalMachine", Cell: ({ cell }) => <span>{cell.getValue() || "-"}</span> },
accessorKey: "year", { header: t("Project"), accessorKey: "project", Cell: ({ cell }) => <span>{cell.getValue() || "-"}</span> },
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: t("Sector"), { header: "N2O", accessorKey: "n2o", Cell: ({ cell }) => <span>{editNumbers(cell.getValue()) || "-"}</span> },
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,
},
]; ];
const tableData = mainDataTablesStore?.mainDataTablesWithPaginate?.content || []; const tableData = mainDataTablesStore?.vmEmissionSummary || [];
console.log('VM Emission data:', tableData); console.log('VM Emission data:', tableData);
if (error) { if (error) {
@@ -140,7 +87,7 @@ function MainDataTables() {
pageIndex: 0 pageIndex: 0
}, },
sorting: [ sorting: [
{ id: 'dataCenter', desc: false } { id: 'createdDate', desc: true }
], ],
density: 'compact' density: 'compact'
}} }}