diff --git a/app/seed-data/emissions_factors/data_processed/EFDB_2006_IPCC_guidelines/Emissions_Factor_Stationary_Energy_Scope1.csv b/app/seed-data/emissions_factors/data_processed/EFDB_2006_IPCC_guidelines/EmissionsFactor_Stationary_Energy_Scope1.csv similarity index 100% rename from app/seed-data/emissions_factors/data_processed/EFDB_2006_IPCC_guidelines/Emissions_Factor_Stationary_Energy_Scope1.csv rename to app/seed-data/emissions_factors/data_processed/EFDB_2006_IPCC_guidelines/EmissionsFactor_Stationary_Energy_Scope1.csv diff --git a/app/seeders/20231114094254-emissions-factors.cjs b/app/seeders/20231114094254-emissions-factors.cjs index 4e687b579..f3441fa25 100644 --- a/app/seeders/20231114094254-emissions-factors.cjs +++ b/app/seeders/20231114094254-emissions-factors.cjs @@ -31,7 +31,11 @@ module.exports = { "DataSourceEmissionsFactor", folder, ); - const emissionsFactors = await parseFile("EmissionsFactor", folder); + + const emissionsFactorsStationaryEnergy = await parseFile("EmissionsFactor_Stationary_Energy", folder); + const emissionsFactorsStationaryEnergyScope1 = await parseFile("EmissionsFactor_Stationary_Energy_Scope1", folder); + const emissionsFactors = emissionsFactorsStationaryEnergy.concat(emissionsFactorsStationaryEnergyScope1); + const publishers = await parseFile("Publisher", folder); await bulkUpsert( diff --git a/app/src/app/[lng]/[inventory]/data/[step]/[subsector]/page.tsx b/app/src/app/[lng]/[inventory]/data/[step]/[subsector]/page.tsx index 85fa1adf0..95ba6c4d1 100644 --- a/app/src/app/[lng]/[inventory]/data/[step]/[subsector]/page.tsx +++ b/app/src/app/[lng]/[inventory]/data/[step]/[subsector]/page.tsx @@ -11,6 +11,7 @@ import HeadingText from "@/components/heading-text"; import LoadingState from "@/components/loading-state"; import { useTranslation } from "@/i18n/client"; import { RootState } from "@/lib/store"; +import { ActivityDataAttributes } from "@/models/ActivityData"; import { api } from "@/services/api"; import { AddIcon, ArrowBackIcon, ChevronRightIcon } from "@chakra-ui/icons"; import { @@ -24,7 +25,6 @@ import { BreadcrumbItem, BreadcrumbLink, Button, - Card, Icon, IconButton, Link, @@ -59,12 +59,10 @@ import { motion } from "framer-motion"; import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import { Trans } from "react-i18next"; -import { BsTrash2 } from "react-icons/bs"; import { FaNetworkWired } from "react-icons/fa"; import { FiTrash2 } from "react-icons/fi"; import { MdMoreVert, MdOutlineHomeWork } from "react-icons/md"; -import { TbTrash } from "react-icons/tb"; -import { useDispatch, useSelector } from "react-redux"; +import { useSelector } from "react-redux"; function SubSectorPage({ params: { lng, step, inventory, subsector }, @@ -73,17 +71,20 @@ function SubSectorPage({ }) { const router = useRouter(); const { t } = useTranslation(lng, "data"); - const [isSelected, setIsSelected] = useState(false); - const [selectedValue, setSelectedValue] = useState(""); + const [isMethodologySelected, setIsMethodologySelected] = useState(false); + const [selectedMethodology, setSelectedMethodology] = useState(""); - const [isChecked, setIsChecked] = useState(false); + const { data: userActivities, isLoading: areActivitiesLoading } = api.useGetActivityValuesQuery({inventoryId: inventory, subSectorId: subsector}); + + const [isUnavailableChecked, setIsChecked] = useState(false); const [hasActivityData, setHasActivityData] = useState(false); - const handleSwitch = () => { - setIsChecked(!isChecked); + const handleSwitch = (e: any) => { + setIsChecked(!isUnavailableChecked); }; + // TODO add to DB and get from there const METHODOLOGIES = [ { name: t("fuel-combustion-consumption"), @@ -110,24 +111,22 @@ function SubSectorPage({ disabled: false, }, ]; - const BUILDINGS = [ + const suggestedActivities = [ { - id: 1, + id: "1", name: t("commercial-buildings"), }, { - id: 2, + id: "2", name: t("institutional-buildings"), }, { - id: 3, + id: "3", name: t("street-lighting"), }, ]; - const handleCardClick = () => { - setIsSelected(!isSelected); - }; + const handleCardClick = () => setIsMethodologySelected(!isMethodologySelected); const { isOpen: isAddActivityModalOpen, @@ -159,23 +158,9 @@ function SubSectorPage({ onClose: onDeleteActivityModalClose, } = useDisclosure(); - const { data } = api.useMockDataQuery({}); - const [isLoadingScope1, setIsloadingScope1] = useState(false); - const [isLoadingScope2, setIsloadingScope2] = useState(false); - - const handleTabLoadingStateScope1 = () => { - setIsloadingScope1(true); - setTimeout(() => { - setIsloadingScope1(false); - }, 1000); - }; + const [selectedActivity, setSelectedActivity] = useState(null); - const handleTabLoadingStateScope2 = () => { - setIsloadingScope2(true); - setTimeout(() => { - setIsloadingScope2(false); - }, 1000); - }; + const [selectedTab, setSelectedTab] = useState(1); // sector ID (1/2/3) const getSectorName = (currentStep: string) => { switch (currentStep) { @@ -193,6 +178,32 @@ function SubSectorPage({ (state: RootState) => state.subsector.subsector, ); + const changeMethodology = () => { + setSelectedMethodology(""); + setIsMethodologySelected(false); + onChangeMethodologyClose(); + } + + const [deleteActivity, isDeleteActivityLoading] = api.useDeleteActivityValueMutation(); + + const deleteAllActivities = () => { + if (areActivitiesLoading || userActivities.length === 0) { + onDeleteActivitiesModalClose(); + return; + } + + for (const activity of userActivities) { + deleteActivity({ inventoryId: inventory, activityValueId: activity.id }); + } + + onDeleteActivitiesModalClose(); + } + + // calculate total consumption and emissions + const totalConsumption = 123.3; + const totalConsumptionUnit = "M gallons"; + const totalEmissions = 11.465; // MtCO2e + const [scrollPosition, setScrollPosition] = useState(0); const handleScroll = () => { @@ -351,7 +362,7 @@ function SubSectorPage({ }} transition={{ duration: 0.2 }} > - + setSelectedTab(1)}> - + setSelectedTab(2)}> {" "} - + {t("scope-not-applicable")} - {isLoadingScope1 ? ( - - ) : ( - - + {isMethodologySelected ? ( + <> + + + {hasActivityData ? ( + + + +

+ + + + + {t("commercial-buildings")} + + + 4 {t("activities-added")} + + + + + {t("total-consumption")}:  + + + 715,4M gallons + + + + + {t("emissions")}:  + + 15,MtCO2e + + + + + + + +

+ + + + + + + + + + + + + + {userActivities?.map( + (activity: any, i: number) => { + return ( + + + + + + + + ); + }, + )} + +
{t("fuel-type")}{t("data-quality")}{t("fuel-consumption")}{t("emissions")}
{activity?.fuelType} + + + {activity?.dataQuality} + + + + {activity?.fuelConsumption!} + {activity?.emissions} + + } + /> +
+
+
+
+
+ + + + + {t("total-emissions")} + + + {totalEmissions} MtCO2e + + + +
+ ) : ( + + { + areActivitiesLoading ? ( + + ) : ( + // TODO add activityData and metadata to ActivityData model + userActivities?.map((activity: ActivityDataAttributes & { activityData: any, metadata: any }) => ( + { + setSelectedActivity(activity.activitydataId); + setTimeout(onAddActivityModalOpen, 500); + }} + /> + )) + ) + } + + )} +
+
+ {" "} - {isChecked ? ( - "" - ) : ( - - {hasActivityData ? ( - "" - ) : ( - - )} - - )} - {isSelected ? ( + {isMethodologySelected ? ( - {!hasActivityData ? ( - - {t("activity-suggestion")} - - ) : ( - "" - )} {hasActivityData ? ( - 715,4M gallons + {totalConsumption}M {totalConsumptionUnit} - 15,MtCO2e + {totalEmissions} MtCO2e - + - + @@ -635,7 +790,7 @@ function SubSectorPage({ borderRadius="20px" bg="base.light" > - + {t("fuel-type")} {t("data-quality")} @@ -645,13 +800,11 @@ function SubSectorPage({ - {data?.map( + {userActivities?.map( (activity: any, i: number) => { return ( - - {activity?.fuelType} - + {activity?.fuelType} - { - activity?.dataQuality - } + {activity?.dataQuality} - { - activity?.fuelConsumption! - }{" "} + {activity?.fuelConsumption!}{" "} {t("gallons")} - {activity?.emissions}{" "} - tCO2e + {activity?.emissions} tCO2e - - - - } - aria-label="more-icon" - variant="ghost" - color="content.tertiary" - /> - - - - - - - - Edit activity - - - - - - Delete activity - - - - - + + } + /> ); @@ -773,150 +850,631 @@ function SubSectorPage({ ) : ( + <> + + {t("activity-suggestion")} + - {BUILDINGS.map(({ id, name }) => ( - - ))} - + {suggestedActivities.map(({ id, name }) => ( + + ))} +
+ )}
) : ( - - {isChecked ? ( - - - + + + )} + + + ) : ( + + {isUnavailableChecked ? ( + + + + {t("scope-unavailable-description")} + + + + {t("select-reason")} + + + + - {t("scope-unavailable-description")} -
- + {t("select-reason-1")} + + + {t("select-reason-2")} + + + {t("select-reason-3")} + + + {t("select-reason-4")} + + + + + {t("explanation-justification")} + +