Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

carbon capture modal #1979

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions .github/workflows/chromatic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
branches:
- develop
- feature/redesign-explore-btn
- feature/carbon_capture_modal
- feature/merge-from-develop
# List of jobs
jobs:
Expand Down
16 changes: 14 additions & 2 deletions public/static/locales/en/projectDetails.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,20 @@
"fieldReviewed": "Field Reviewed",
"offSiteReviewed": "Off-Site reviewed",
"report": "Report",
"seeLess": "see less",
"seeMore": "see more",
"beforeIntervention": "Before intervention",
"co₂Quantity": "~{quantity}t",
"totalCO₂Captured": "Total CO2 Captured (tons)",
"site": "<areaContainer>Site</areaContainer>({area} ha)",
"entireProject": "<areaContainer>Entire Project</areaContainer>({area} ha)",
"before": "before {date}",
"byProject": "By Project",
"byProjectCO₂Quantity": "v{quantity}t",
"since": "since {date}",
"sitePotential": "Site Potential",
"seeMore": "See More",
"seeLess": "See Less",
"totalCo2Captured": "Total CO₂ Captured",
"tons": "tons",
"forestFire": "Forest Fire",
"hoursAgo": "{hours}h ago",
"highAlertConfidenceText": "<important>High</important> alert confidence",
Expand Down
101 changes: 101 additions & 0 deletions src/temp/CarbonCapture/BarGraph.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import style from './CarbonCapture.module.scss';
import { useTranslations, useLocale } from 'next-intl';
import { getFormattedNumber } from '../../utils/getFormattedNumber';

interface CO2BarGraphProps {
beforeIntervation: number;
byProject: number;
sitePotential: number;
}

export const CO2BarGraph = ({
beforeIntervation,
byProject,
sitePotential,
}: CO2BarGraphProps) => {
const calculatePercentage = (value: number, sitePotential: number) => {
return (value / sitePotential) * 100;
};

const beforeIntervationPercentage = calculatePercentage(
beforeIntervation,
sitePotential
);
const byProjectPercentage = calculatePercentage(byProject, sitePotential);

return (
<div className={style.carbonCaptureIndicator}>
<div
style={{
width: `${beforeIntervationPercentage}%`,
}}
className={style.beforeIntervationIndicator}
/>

<div
style={{
width: `${byProjectPercentage}%`,
}}
className={style.byProjectIndicator}
/>

<div
style={{
width: `${
100 - (beforeIntervationPercentage + byProjectPercentage)
}%`,
}}
className={style.projectPotential}
/>
</div>
);
};
Comment on lines +11 to +52
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

LGTM with a minor optimization suggestion.

The CO2BarGraph component is well-implemented and correctly visualizes the carbon capture data. Consider this small optimization:

You can optimize the percentage calculations by computing them once and reusing the results:

-  const beforeIntervationPercentage = calculatePercentage(
-    beforeIntervation,
-    sitePotential
-  );
-  const byProjectPercentage = calculatePercentage(byProject, sitePotential);
+  const beforeIntervationPercentage = calculatePercentage(beforeIntervation, sitePotential);
+  const byProjectPercentage = calculatePercentage(byProject, sitePotential);
+  const remainingPercentage = 100 - (beforeIntervationPercentage + byProjectPercentage);

   // ... in the JSX
-          width: `${
-            100 - (beforeIntervationPercentage + byProjectPercentage)
-          }%`,
+          width: `${remainingPercentage}%`,

This change improves readability and avoids recalculating the remaining percentage.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const CO2BarGraph = ({
beforeIntervation,
byProject,
sitePotential,
}: CO2BarGraphProps) => {
const calculatePercentage = (value: number, sitePotential: number) => {
return (value / sitePotential) * 100;
};
const beforeIntervationPercentage = calculatePercentage(
beforeIntervation,
sitePotential
);
const byProjectPercentage = calculatePercentage(byProject, sitePotential);
return (
<div className={style.carbonCaptureIndicator}>
<div
style={{
width: `${beforeIntervationPercentage}%`,
}}
className={style.beforeIntervationIndicator}
/>
<div
style={{
width: `${byProjectPercentage}%`,
}}
className={style.byProjectIndicator}
/>
<div
style={{
width: `${
100 - (beforeIntervationPercentage + byProjectPercentage)
}%`,
}}
className={style.projectPotential}
/>
</div>
);
};
export const CO2BarGraph = ({
beforeIntervation,
byProject,
sitePotential,
}: CO2BarGraphProps) => {
const calculatePercentage = (value: number, sitePotential: number) => {
return (value / sitePotential) * 100;
};
const beforeIntervationPercentage = calculatePercentage(beforeIntervation, sitePotential);
const byProjectPercentage = calculatePercentage(byProject, sitePotential);
const remainingPercentage = 100 - (beforeIntervationPercentage + byProjectPercentage);
return (
<div className={style.carbonCaptureIndicator}>
<div
style={{
width: `${beforeIntervationPercentage}%`,
}}
className={style.beforeIntervationIndicator}
/>
<div
style={{
width: `${byProjectPercentage}%`,
}}
className={style.byProjectIndicator}
/>
<div
style={{
width: `${remainingPercentage}%`,
}}
className={style.projectPotential}
/>
</div>
);
};


export const CO2CaptureData = ({
beforeIntervation,
byProject,
sitePotential,
}: CO2BarGraphProps) => {
const t = useTranslations('ProjectDetails');
const locale = useLocale();
return (
<div className={style.carbonCaptureDataContainerMain}>
<div>
<p className={style.beforeIntervationData}>
{t('co₂Quantity', {
quantity: getFormattedNumber(locale, beforeIntervation),
})}
</p>
<p className={style.beforeIntervationLabel}>
{t('beforeIntervention')}
</p>
<p className={style.beforeIntervationDate}>
{t('before', {
date: 2018,
})}
</p>
</div>
<div>
<p className={style.byProjectData}>
{t('byProjectCO₂Quantity', {
quantity: getFormattedNumber(locale, byProject),
})}
</p>
<p className={style.byProjectLabel}>{t('byProject')}</p>
<p className={style.byProjectDate}>
{t('since', {
date: 2018,
})}
</p>
</div>
<div className={style.sitePotentialDataContainer}>
<p className={style.sitePotentialData}>
{t('co₂Quantity', {
quantity: getFormattedNumber(locale, sitePotential),
})}
</p>
<p className={style.sitePotentialLabel}>{t('sitePotential')}</p>
</div>
</div>
);
};
Comment on lines +1 to +101
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider overall structural and type improvements.

  1. The CO2BarGraph and CO2CaptureData components are closely related. Consider combining them into a single component or creating a wrapper component that manages both, to reduce prop drilling and improve cohesion.

  2. Enhance type safety by creating a more specific type for the formatted numbers:

type FormattedNumber = string;

interface CO2CaptureProps {
  beforeIntervation: number;
  byProject: number;
  sitePotential: number;
  getFormattedNumber: (locale: string, value: number) => FormattedNumber;
}

This change will make the component more robust and easier to maintain in the long run.

Comment on lines +54 to +101
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider extracting the hardcoded year to a constant or prop.

The year 2018 is used multiple times in the component. To improve maintainability and flexibility, consider extracting it to a constant or passing it as a prop.

+ const INTERVENTION_YEAR = 2018;
// or add it to the component props

// Then use it in the component
-            date: 2018,
+            date: INTERVENTION_YEAR,

This change will make it easier to update the year in the future if needed.

Committable suggestion was skipped due to low confidence.

185 changes: 185 additions & 0 deletions src/temp/CarbonCapture/CarbonCapture.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
@import '../../theme/theme';

.carbonCaptureMainContainer {
width: 100%;
display: flex;
flex-direction: column;
}

.carbonCaptureInfoContainer {
display: flex;
height: 111px;
flex-direction: column;
gap: 12px;
padding-left: 15.5px;
padding-right: 15.5px;
}

.carbonCaptureLabelMainContainer {
font-size: $fontXXSmall;
display: flex;
justify-content: space-between;
}

.carbonCaptureLabelContainer {
display: flex;
align-items: center;
> .carbonCapture {
display: flex;
font-weight: 700;
gap: 2px;
p {
font-weight: 400;
}
}
.unit {
margin-left: 1px;
}
}

.carbonCaptureDetailContainer {
padding-left: 16px;
padding-right: 16px;
padding-top: 16px;
border: 1px solid rgba(111, 207, 151, 0.02);
background: linear-gradient(
0deg,
rgba(33, 150, 83, 0.1) 0%,
rgba(33, 150, 83, 0.1) 100%
),
$light;

height: 70px;
border-radius: 12px;
display: flex;
flex-direction: column;
gap: 10px;
}

.carbonCaptureIndicator {
max-width: 274px;
height: 11px;
display: flex;
border-radius: 3px;

.beforeIntervationIndicator {
width: 100%;
height: 100%;
background: rgba(0, 122, 73, 1);
border-top-left-radius: 3px;
border-bottom-left-radius: 3px;
}
.byProjectIndicator {
width: 100%;
background: rgba(104, 176, 48, 1);
height: 100%;
}
.projectPotential {
width: 100%;
background: $light;
height: 100%;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
}
}

.carbonCaptureDataContainerMain {
display: flex;
width: 100%;
justify-content: space-between;
}
.carbonCaptureDataContainer {
display: flex;
padding-left: 16px;
padding-top: 4px;
padding-right: 16px;
}
.beforeIntervationData {
color: $primaryColorNew;
font-size: $fontXXXSmallNew;
font-weight: 700;
}
.beforeIntervationLabel {
font-size: $fontXXXSmallNew;
font-weight: 400;
}
.beforeIntervationDate {
font-size: 6px;
color: $nonDonatableProjectBackgroundColor;
}
.byProjectData {
color: $primaryColor;
font-size: $fontXXXSmallNew;
font-weight: 700;
}
.byProjectLabel {
font-size: $fontXXXSmallNew;
font-weight: 400;
}
.byProjectDate {
font-size: 6px;
color: $nonDonatableProjectBackgroundColor;
}
.sitePotentialDataContainer {
display: flex;
align-items: flex-end;
flex-direction: column;
.sitePotentialData {
color: #333;
font-size: $fontXXXSmallNew;
font-weight: bold;
}
.sitePotentialLabel {
font-size: $fontXXXSmallNew;
font-weight: 400;
}
}

.carbonCaptureModal {
max-width: 338px;
border-radius: 16px;
overflow: hidden;
background-color: $light;
}

.infoIconContainer {
cursor: pointer;
}

.seeMoreButton {
background: linear-gradient(0deg, $primaryColorNew 0%, $primaryColorNew 100%),
$light;
width: 100%;
height: 27px;
margin-top: 24px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
}

.seeMoreLabel {
font-size: $fontXXXSmallNew;
font-weight: 700;
color: $light;
}

.downArrow {
margin-left: 5px;
margin-bottom: 5px;
}

.horizontalLine {
position: relative;
top: -8px;
}

.carbonCaptureValue {
margin-left: 2px;
font-weight: 400;
}

.areaCount {
margin-right: 2px;
font-weight: 700;
}
33 changes: 33 additions & 0 deletions src/temp/CarbonCapture/CustomMuiTabs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { styled, Tabs } from '@mui/material';

const CustomMuiTabs = styled(Tabs)(() => ({
'.MuiTabs-flexContainer': {
justifyContent: 'center',
marginTop: '24px',
gap: '30px',
},
'.MuiButtonBase-root': {
textTransform: 'none',
fontSize: '12px',
color: `var(--primary-font-color)`,
},
'.MuiButtonBase-root-MuiTab-root.Mui-selected': {
color: `var(--primary-color-new)`,
},
'.MuiTabs-indicator': {
backgroundColor: `var(--primary-color-new)`,
},
'.MuiTab-root.Mui-selected': {
color: `var(--primary-color-new)`,
display: 'flex',
flexDirection: 'row',
},
'.MuiTab-root': {
minHeight: '0px',
padding: '0px 0px',
display: 'flex',
flexDirection: 'row',
},
}));
Comment on lines +3 to +31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider enhancing responsiveness and reusability of the CustomMuiTabs component.

The styled component effectively customizes the Material-UI Tabs with specific styles. However, there are a few suggestions for improvement:

  1. Replace pixel values with relative units (e.g., rem or em) for better responsiveness. For example:

    - fontSize: '12px',
    + fontSize: '0.75rem',
  2. Consider making some styles configurable through props for better reusability. For instance:

    const CustomMuiTabs = styled(Tabs)<{ gap?: string }>(({ gap = '30px' }) => ({
      // ...
      '.MuiTabs-flexContainer': {
        gap: gap,
        // ...
      },
      // ...
    }));
  3. Ensure that the CSS variables (e.g., --primary-font-color, --primary-color-new) are defined in your global styles or theme provider.

Would you like assistance in implementing these suggestions?


export default CustomMuiTabs;
Loading
Loading