diff --git a/.vscode/settings.json b/.vscode/settings.json index be8d3a75feabec73b75003c7cfda7244dbdc6c54..0e5f3bdeb4d2f1eb764100934b95dbd24786c3ba 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -89,6 +89,7 @@ "firstname", "fluidchart", "fluidchartslide", + "FLUIDNAME", "fluidsprices", "fluidtype", "Folinge", diff --git a/src/components/Analysis/ElecHalfHourMonthlyAnalysis/__snapshots__/ElecHalfHourChart.spec.tsx.snap b/src/components/Analysis/ElecHalfHourMonthlyAnalysis/__snapshots__/ElecHalfHourChart.spec.tsx.snap index 7ec215c0aee87c294490ac0a9bf075397e9e3a7b..1f0c220c490f82d9382dd7825eb5f08f85f72bc1 100644 --- a/src/components/Analysis/ElecHalfHourMonthlyAnalysis/__snapshots__/ElecHalfHourChart.spec.tsx.snap +++ b/src/components/Analysis/ElecHalfHourMonthlyAnalysis/__snapshots__/ElecHalfHourChart.spec.tsx.snap @@ -112,7 +112,7 @@ exports[`ElecHalfHourChart component should be rendered correctly 1`] = ` </lineargradient> </defs> <path - class="bar-ELECTRICITY weekend bounce-3 delay--0" + class="bar-ELECTRICITY weekend bounce-3 delay--0" d=" M0,4 a4,4 0 0 1 4,-4 @@ -128,7 +128,7 @@ exports[`ElecHalfHourChart component should be rendered correctly 1`] = ` > <defs> <lineargradient - class="bar-ELECTRICITY weekend bounce-3 delay--0" + class="bar-ELECTRICITY weekend bounce-3 delay--0" id="gradient" x1="0" x2="0" @@ -146,7 +146,7 @@ exports[`ElecHalfHourChart component should be rendered correctly 1`] = ` </lineargradient> </defs> <path - class="bar-ELECTRICITY weekend bounce-3 delay--0" + class="bar-ELECTRICITY weekend bounce-3 delay--0" d=" M0,4 a4,4 0 0 1 4,-4 @@ -195,7 +195,7 @@ exports[`ElecHalfHourChart component should be rendered correctly 1`] = ` </lineargradient> </defs> <path - class="bar-ELECTRICITY weekend bounce-3 delay--1" + class="bar-ELECTRICITY weekend bounce-3 delay--1" d=" M0,4 a4,4 0 0 1 4,-4 @@ -211,7 +211,7 @@ exports[`ElecHalfHourChart component should be rendered correctly 1`] = ` > <defs> <lineargradient - class="bar-ELECTRICITY weekend bounce-3 delay--1" + class="bar-ELECTRICITY weekend bounce-3 delay--1" id="gradient" x1="0" x2="0" @@ -229,7 +229,7 @@ exports[`ElecHalfHourChart component should be rendered correctly 1`] = ` </lineargradient> </defs> <path - class="bar-ELECTRICITY weekend bounce-3 delay--1" + class="bar-ELECTRICITY weekend bounce-3 delay--1" d=" M0,4 a4,4 0 0 1 4,-4 @@ -278,7 +278,7 @@ exports[`ElecHalfHourChart component should be rendered correctly 1`] = ` </lineargradient> </defs> <path - class="bar-ELECTRICITY weekend bounce-3 delay--2" + class="bar-ELECTRICITY weekend bounce-3 delay--2" d=" M0,4 a4,4 0 0 1 4,-4 @@ -294,7 +294,7 @@ exports[`ElecHalfHourChart component should be rendered correctly 1`] = ` > <defs> <lineargradient - class="bar-ELECTRICITY weekend bounce-3 delay--2" + class="bar-ELECTRICITY weekend bounce-3 delay--2" id="gradient" x1="0" x2="0" @@ -312,7 +312,7 @@ exports[`ElecHalfHourChart component should be rendered correctly 1`] = ` </lineargradient> </defs> <path - class="bar-ELECTRICITY weekend bounce-3 delay--2" + class="bar-ELECTRICITY weekend bounce-3 delay--2" d=" M0,4 a4,4 0 0 1 4,-4 @@ -361,7 +361,7 @@ exports[`ElecHalfHourChart component should be rendered correctly 1`] = ` </lineargradient> </defs> <path - class="bar-ELECTRICITY weekend bounce-3 delay--3" + class="bar-ELECTRICITY weekend bounce-3 delay--3" d=" M0,4 a4,4 0 0 1 4,-4 @@ -377,7 +377,7 @@ exports[`ElecHalfHourChart component should be rendered correctly 1`] = ` > <defs> <lineargradient - class="bar-ELECTRICITY weekend bounce-3 delay--3" + class="bar-ELECTRICITY weekend bounce-3 delay--3" id="gradient" x1="0" x2="0" @@ -395,7 +395,7 @@ exports[`ElecHalfHourChart component should be rendered correctly 1`] = ` </lineargradient> </defs> <path - class="bar-ELECTRICITY weekend bounce-3 delay--3" + class="bar-ELECTRICITY weekend bounce-3 delay--3" d=" M0,4 a4,4 0 0 1 4,-4 diff --git a/src/components/Analysis/MaxConsumptionCard/__snapshots__/MaxConsumptionCard.spec.tsx.snap b/src/components/Analysis/MaxConsumptionCard/__snapshots__/MaxConsumptionCard.spec.tsx.snap index b731c1f5e66d493e2b636cc801f6d70b22245e9c..c81e97ba95ea3b07a785396678f5e3460c2ca20b 100644 --- a/src/components/Analysis/MaxConsumptionCard/__snapshots__/MaxConsumptionCard.spec.tsx.snap +++ b/src/components/Analysis/MaxConsumptionCard/__snapshots__/MaxConsumptionCard.spec.tsx.snap @@ -152,7 +152,7 @@ exports[`MaxConsumptionCard component should be rendered correctly 1`] = ` </lineargradient> </defs> <path - class="bar-ELECTRICITY undefined disabled bounce-3 delay--0" + class="bar-ELECTRICITY disabled bounce-3 delay--0" d=" M0,4 a4,4 0 0 1 4,-4 @@ -168,7 +168,7 @@ exports[`MaxConsumptionCard component should be rendered correctly 1`] = ` > <defs> <lineargradient - class="bar-ELECTRICITY undefined disabled bounce-3 delay--0" + class="bar-ELECTRICITY disabled bounce-3 delay--0" id="gradient" x1="0" x2="0" @@ -186,7 +186,7 @@ exports[`MaxConsumptionCard component should be rendered correctly 1`] = ` </lineargradient> </defs> <path - class="bar-ELECTRICITY undefined disabled bounce-3 delay--0" + class="bar-ELECTRICITY disabled bounce-3 delay--0" d=" M0,4 a4,4 0 0 1 4,-4 @@ -235,7 +235,7 @@ exports[`MaxConsumptionCard component should be rendered correctly 1`] = ` </lineargradient> </defs> <path - class="bar-ELECTRICITY undefined disabled bounce-3 delay--1" + class="bar-ELECTRICITY disabled bounce-3 delay--1" d=" M0,4 a4,4 0 0 1 4,-4 @@ -251,7 +251,7 @@ exports[`MaxConsumptionCard component should be rendered correctly 1`] = ` > <defs> <lineargradient - class="bar-ELECTRICITY undefined disabled bounce-3 delay--1" + class="bar-ELECTRICITY disabled bounce-3 delay--1" id="gradient" x1="0" x2="0" @@ -269,7 +269,7 @@ exports[`MaxConsumptionCard component should be rendered correctly 1`] = ` </lineargradient> </defs> <path - class="bar-ELECTRICITY undefined disabled bounce-3 delay--1" + class="bar-ELECTRICITY disabled bounce-3 delay--1" d=" M0,4 a4,4 0 0 1 4,-4 @@ -318,7 +318,7 @@ exports[`MaxConsumptionCard component should be rendered correctly 1`] = ` </lineargradient> </defs> <path - class="bar-ELECTRICITY bar-UNCOMING undefined disabled bounce-3 delay--2" + class="bar-ELECTRICITY bar-UNCOMING disabled bounce-3 delay--2" d=" M0,4 a4,4 0 0 1 4,-4 diff --git a/src/components/Analysis/ProfileComparator/ProfileComparator.tsx b/src/components/Analysis/ProfileComparator/ProfileComparator.tsx index 284593ddff4158a6a47295e975ef8843fa33fb6d..23e00858b499b9f757f2832af1a12482b3f1a3d5 100644 --- a/src/components/Analysis/ProfileComparator/ProfileComparator.tsx +++ b/src/components/Analysis/ProfileComparator/ProfileComparator.tsx @@ -167,7 +167,7 @@ const ProfileComparator = ({ <div className="average-title">{t(`analysis.comparison`)}</div> </div> <ProfileComparatorRow - fluid={FluidType.MULTIFLUID} + fluidType={FluidType.MULTIFLUID} userPriceConsumption={userPriceConsumption} homePriceConsumption={homePriceConsumption} performanceValue={null} @@ -180,7 +180,7 @@ const ProfileComparator = ({ Boolean(indicator.value) && ( <ProfileComparatorRow key={FluidType[index]} - fluid={index} + fluidType={index} userPriceConsumption={userPriceConsumption} homePriceConsumption={homePriceConsumption} performanceValue={indicator.value} @@ -194,7 +194,7 @@ const ProfileComparator = ({ {emptyFluidTypes.map(fluid => ( <ProfileComparatorRow key={fluid} - fluid={fluid} + fluidType={fluid} userPriceConsumption={userPriceConsumption} homePriceConsumption={homePriceConsumption} performanceValue={null} diff --git a/src/components/Analysis/ProfileComparator/ProfileComparatorRow.spec.tsx b/src/components/Analysis/ProfileComparator/ProfileComparatorRow.spec.tsx index c1f7609879ef1d7bd1bd3e18a9515a17f560732e..62845a52f0cebe1be5cba0856bd46af2285133bc 100644 --- a/src/components/Analysis/ProfileComparator/ProfileComparatorRow.spec.tsx +++ b/src/components/Analysis/ProfileComparator/ProfileComparatorRow.spec.tsx @@ -14,7 +14,7 @@ describe('AnalysisConsumptionRow component', () => { it('should be rendered correctly for Multifluid and at least fluid connected', async () => { const { container } = render( <ProfileComparatorRow - fluid={FluidType.MULTIFLUID} + fluidType={FluidType.MULTIFLUID} userPriceConsumption={20} homePriceConsumption={18} performanceValue={null} @@ -38,7 +38,7 @@ describe('AnalysisConsumptionRow component', () => { const mockConnected = false const { container } = render( <ProfileComparatorRow - fluid={FluidType.MULTIFLUID} + fluidType={FluidType.MULTIFLUID} userPriceConsumption={userPriceConsumption} homePriceConsumption={homePriceConsumption} performanceValue={null} @@ -65,7 +65,7 @@ describe('AnalysisConsumptionRow component', () => { it('should be rendered correctly for singleFluid connected for average', async () => { const { container } = render( <ProfileComparatorRow - fluid={FluidType.ELECTRICITY} + fluidType={FluidType.ELECTRICITY} userPriceConsumption={userPriceConsumption} homePriceConsumption={homePriceConsumption} performanceValue={performanceValue} @@ -94,7 +94,7 @@ describe('AnalysisConsumptionRow component', () => { const mockConnected = false const { container } = render( <ProfileComparatorRow - fluid={FluidType.ELECTRICITY} + fluidType={FluidType.ELECTRICITY} userPriceConsumption={userPriceConsumption} homePriceConsumption={homePriceConsumption} performanceValue={performanceValue} @@ -123,7 +123,7 @@ describe('AnalysisConsumptionRow component', () => { const mockPerformanceValue: number | null = null const { container } = render( <ProfileComparatorRow - fluid={FluidType.ELECTRICITY} + fluidType={FluidType.ELECTRICITY} userPriceConsumption={userPriceConsumption} homePriceConsumption={homePriceConsumption} performanceValue={mockPerformanceValue} @@ -162,7 +162,7 @@ describe('AnalysisConsumptionRow component', () => { } const { container } = render( <ProfileComparatorRow - fluid={FluidType.ELECTRICITY} + fluidType={FluidType.ELECTRICITY} userPriceConsumption={userPriceConsumption} homePriceConsumption={homePriceConsumption} performanceValue={performanceValue} diff --git a/src/components/Analysis/ProfileComparator/ProfileComparatorRow.tsx b/src/components/Analysis/ProfileComparator/ProfileComparatorRow.tsx index 0ba4dd6f8bd20e733be73cf931d4f7fc505be4e2..6ca531524e14aee6a0b38d27aa3d933997f86beb 100644 --- a/src/components/Analysis/ProfileComparator/ProfileComparatorRow.tsx +++ b/src/components/Analysis/ProfileComparator/ProfileComparatorRow.tsx @@ -7,11 +7,11 @@ import { MonthlyForecast } from 'models' import React from 'react' import ConverterService from 'services/converter.service' import { getPicto } from 'utils/picto' -import { formatNumberValues } from 'utils/utils' +import { formatNumberValues, getFluidName } from 'utils/utils' import './profileComparatorRow.scss' interface ProfileComparatorRowProps { - fluid: FluidType + fluidType: FluidType userPriceConsumption: number homePriceConsumption: number performanceValue: number | null @@ -21,7 +21,7 @@ interface ProfileComparatorRowProps { } const ProfileComparatorRow = ({ - fluid, + fluidType, userPriceConsumption, homePriceConsumption, performanceValue, @@ -31,91 +31,86 @@ const ProfileComparatorRow = ({ }: ProfileComparatorRowProps) => { const { t } = useI18n() const converterService: ConverterService = new ConverterService() - const maxPriceConsumption: number = Math.max( + const maxPriceConsumption = Math.max( userPriceConsumption, homePriceConsumption ) - const fluidLoad: number = - forecast && fluid !== FluidType.MULTIFLUID - ? forecast.fluidForecast[fluid].load - : 0 + const isMulti = fluidType === FluidType.MULTIFLUID + const isElecOrGas = + fluidType === FluidType.ELECTRICITY || fluidType === FluidType.GAS + const FLUIDNAME = getFluidName(fluidType).toUpperCase() - const formatFluidConsumptionForConso = (_fluid: FluidType) => { - if (_fluid === FluidType.MULTIFLUID) { + const fluidLoad = + forecast && !isMulti ? forecast.fluidForecast[fluidType].load : 0 + + const formatFluidConsumptionForConso = () => { + if (isMulti) { return `${formatNumberValues(userPriceConsumption).toString()} €` } else { if (performanceValue) { // keeps unit in kWh for electricity and gas - if (_fluid === FluidType.ELECTRICITY || _fluid === FluidType.GAS) { + if (isElecOrGas) { return `${Math.round(performanceValue)} ${t( - `FLUID.${FluidType[_fluid]}.UNIT` + `FLUID.${FLUIDNAME}.UNIT` )}` } return performanceValue >= 1000 || fluidLoad >= 1000 ? formatNumberValues(performanceValue / 1000).toString() + ' ' + - t(`FLUID.${FluidType[_fluid]}.MEGAUNIT`) - : Math.round(performanceValue) + - ' ' + - t(`FLUID.${FluidType[_fluid]}.UNIT`) + t(`FLUID.${FLUIDNAME}.MEGAUNIT`) + : Math.round(performanceValue) + ' ' + t(`FLUID.${FLUIDNAME}.UNIT`) } else { return '-' } } } - const formatFluidConsumptionForForecast = (_fluid: FluidType) => { - if (_fluid === FluidType.MULTIFLUID) { + const formatFluidConsumptionForForecast = () => { + if (isMulti) { return `${formatNumberValues(homePriceConsumption).toString()} €` } else { // keeps unit in kWh for electricity and gas - if (_fluid === FluidType.ELECTRICITY || _fluid === FluidType.GAS) { - return `${Math.round(fluidLoad)} ${t( - `FLUID.${FluidType[_fluid]}.UNIT` - )}` + if (isElecOrGas) { + return `${Math.round(fluidLoad)} ${t(`FLUID.${FLUIDNAME}.UNIT`)}` } return (performanceValue && performanceValue >= 1000) || fluidLoad >= 1000 ? formatNumberValues(fluidLoad / 1000).toString() + ' ' + - t(`FLUID.${FluidType[_fluid]}.MEGAUNIT`) - : Math.round(fluidLoad) + ' ' + t(`FLUID.${FluidType[_fluid]}.UNIT`) + t(`FLUID.${FLUIDNAME}.MEGAUNIT`) + : Math.round(fluidLoad) + ' ' + t(`FLUID.${FLUIDNAME}.UNIT`) } } - const getWidthForConso = (_fluid: FluidType) => { - if (_fluid === FluidType.MULTIFLUID) { + const getWidthForConso = () => { + if (isMulti) { return `${(userPriceConsumption / maxPriceConsumption) * 100}%` } else { return `${ - (converterService.LoadToEuro(performanceValue || 0, _fluid) / + (converterService.LoadToEuro(performanceValue || 0, fluidType) / maxPriceConsumption) * 100 }%` } } - const getWidthForForecast = (_fluid: FluidType) => { - if (_fluid === FluidType.MULTIFLUID) { + const getWidthForForecast = () => { + if (isMulti) { return `${(homePriceConsumption / maxPriceConsumption) * 100}%` } else { - const fluidValue: number = forecast - ? forecast.fluidForecast[_fluid].value - : 0 + const fluidValue = forecast ? forecast.fluidForecast[fluidType].value : 0 return `${(fluidValue / maxPriceConsumption) * 100}%` } } const comparaisonText = connected - ? formatFluidConsumptionForConso(fluid) + ? formatFluidConsumptionForConso() : t(`analysis.no_data`) return ( - <div - className={`analysisRow consumption-${FluidType[fluid].toLowerCase()}`} - > + <div className={`analysisRow consumption-${FLUIDNAME.toLowerCase()}`}> <div className="user-graph"> <div - className={classNames('price', 'text-15-bold', { + className={classNames('price text-15-bold', { ['not-connected']: !connected || noData, })} data-testid="userPrice" @@ -127,7 +122,7 @@ const ProfileComparatorRow = ({ <div className="graph" style={{ - width: getWidthForConso(fluid), + width: getWidthForConso(), }} /> </div> @@ -135,9 +130,7 @@ const ProfileComparatorRow = ({ </div> <div className="icon-container"> <StyledIcon - icon={ - fluid === FluidType.MULTIFLUID ? EuroIcon : getPicto(fluid, true) - } + icon={isMulti ? EuroIcon : getPicto(fluidType, true)} size={22} className={noData ? 'noData' : ''} /> @@ -148,7 +141,7 @@ const ProfileComparatorRow = ({ <div className="graph" style={{ - width: getWidthForForecast(fluid), + width: getWidthForForecast(), }} /> )} @@ -159,7 +152,7 @@ const ProfileComparatorRow = ({ })} data-testid="averagePrice" > - {formatFluidConsumptionForForecast(fluid)} + {formatFluidConsumptionForForecast()} </div> </div> </div> diff --git a/src/components/Analysis/ProfileComparator/__snapshots__/ProfileComparator.spec.tsx.snap b/src/components/Analysis/ProfileComparator/__snapshots__/ProfileComparator.spec.tsx.snap index c8c370b1e1cd54cf3b3e63cd84f919ea15d67680..0ec6fdfe3f1938edb876719ba7253d5b03b1752c 100644 --- a/src/components/Analysis/ProfileComparator/__snapshots__/ProfileComparator.spec.tsx.snap +++ b/src/components/Analysis/ProfileComparator/__snapshots__/ProfileComparator.spec.tsx.snap @@ -136,14 +136,14 @@ exports[`AnalysisConsumption component should be rendered correctly with profile </div> <mock-profilecomparatorrow connected="true" - fluid="3" + fluidtype="3" homepriceconsumption="0" nodata="false" userpriceconsumption="156.161853" /> <mock-profilecomparatorrow connected="true" - fluid="0" + fluidtype="0" homepriceconsumption="0" nodata="false" performancevalue="178.54" @@ -151,7 +151,7 @@ exports[`AnalysisConsumption component should be rendered correctly with profile /> <mock-profilecomparatorrow connected="true" - fluid="1" + fluidtype="1" homepriceconsumption="0" nodata="false" performancevalue="7763.98" @@ -159,7 +159,7 @@ exports[`AnalysisConsumption component should be rendered correctly with profile /> <mock-profilecomparatorrow connected="true" - fluid="2" + fluidtype="2" homepriceconsumption="0" nodata="false" performancevalue="1317.67" diff --git a/src/components/Charts/AxisRight.tsx b/src/components/Charts/AxisRight.tsx index 71b7dac5e957d07822b173b39ec51f0656aa850e..7780c52ac0beb1e062554e7160423c5306a35883 100644 --- a/src/components/Charts/AxisRight.tsx +++ b/src/components/Charts/AxisRight.tsx @@ -5,6 +5,7 @@ import { ScaleLinear } from 'd3-scale' import { select, selectAll } from 'd3-selection' import { FluidType } from 'enums' import React, { useEffect, useRef } from 'react' +import { getFluidName } from 'utils/utils' interface AxisRightProps { yScale: ScaleLinear<number, number> @@ -24,12 +25,10 @@ const AxisRight = ({ isAnalysis, }: AxisRightProps) => { const { t } = useI18n() - const fluidStyle = - fluidType === FluidType.MULTIFLUID ? 'MULTIFLUID' : FluidType[fluidType] - const isMultiFluid = fluidStyle !== 'MULTIFLUID' + const isMulti = fluidType === FluidType.MULTIFLUID + const fluidStyle = getFluidName(fluidType).toLocaleUpperCase() const yAxisRef = useRef<SVGGElement>(null) - const newMarginRight = - fluidType === FluidType.MULTIFLUID ? marginRight - 10 : marginRight + const newMarginRight = isMulti ? marginRight - 10 : marginRight const formatFluidValue = (value: NumberValue, unit: 'UNIT' | 'MEGAUNIT') => { const fluidUnit = t(`FLUID.${fluidStyle}.${unit}`) @@ -54,7 +53,7 @@ const AxisRight = ({ .tickSize(-width) .tickSizeOuter(0) .tickFormat(d => - Number(d) >= 1000 && isMultiFluid + Number(d) >= 1000 && !isMulti ? formatMultiFluidValue(d) : formatSingleFluidValue(d) ) diff --git a/src/components/Charts/Bar.tsx b/src/components/Charts/Bar.tsx index 62ca898f1ec8a8c770095689814a9ab8bb715593..c8cdd159dda614466af49e8f7ebbb498f18fd064 100644 --- a/src/components/Charts/Bar.tsx +++ b/src/components/Charts/Bar.tsx @@ -10,6 +10,7 @@ import { setSelectedDate, } from 'store/chart/chart.slice' import { useAppDispatch, useAppSelector } from 'store/hooks' +import { getFluidName } from 'utils/utils' interface BarProps { index: number @@ -56,9 +57,8 @@ const Bar = ({ const [compareAnimationEnded, setCompareAnimationEnded] = useState(false) const browser = detect() - const fluidStyle = - fluidType === FluidType.MULTIFLUID ? 'MULTIFLUID' : FluidType[fluidType] const isMulti = fluidType === FluidType.MULTIFLUID + const FLUIDNAME = getFluidName(fluidType).toUpperCase() const handleClick = () => { if (!isSwitching && !isDuel && clickable) { @@ -133,7 +133,16 @@ const Bar = ({ const edgeBrowser = browser && browser.name !== 'edge' const bounce = edgeBrowser ? '1' : '3' - const baseStyles = `bar-${fluidStyle} ${upcoming} ${weekdays} ${selected} ${disabled}` + const baseStyles = [ + `bar-${FLUIDNAME}`, + upcoming, + weekdays, + selected, + disabled, + ] + .filter(Boolean) + .join(' ') + if (clicked) { return `${baseStyles} ${clickedAnim}` } @@ -147,7 +156,7 @@ const Bar = ({ const animate = `bounce-2 delay--${clicked ? 0 : index}` const animationClass = compareAnimationEnded ? '' : animate - return `bar-compare-${fluidStyle} ${selected} ${animationClass} ${clickedAnim}` + return `bar-compare-${FLUIDNAME} ${selected} ${animationClass} ${clickedAnim}` } const barBackgroundClass = isSelectedDate diff --git a/src/components/Charts/__snapshots__/Bar.spec.tsx.snap b/src/components/Charts/__snapshots__/Bar.spec.tsx.snap index e3916b074b4eaaf5f36842494457fd46f1c40607..4b70e2896a14a9e91562af3834b1a8ffaae5d9cd 100644 --- a/src/components/Charts/__snapshots__/Bar.spec.tsx.snap +++ b/src/components/Charts/__snapshots__/Bar.spec.tsx.snap @@ -40,7 +40,7 @@ exports[`Bar component test should correctly render Bar with isDuel 1`] = ` </lineargradient> </defs> <path - class="bar-MULTIFLUID undefined bounce-3 delay--4" + class="bar-MULTIFLUID bounce-3 delay--4" d=" M0,-12.295074999999997 a-12.295074999999997,-12.295074999999997 0 0 1 -12.295074999999997,12.295074999999997 @@ -56,7 +56,7 @@ exports[`Bar component test should correctly render Bar with isDuel 1`] = ` > <defs> <lineargradient - class="bar-MULTIFLUID undefined bounce-3 delay--4" + class="bar-MULTIFLUID bounce-3 delay--4" id="gradient" x1="0" x2="0" @@ -130,7 +130,7 @@ exports[`Bar component test should correctly render Bar with isSwitching 1`] = ` </lineargradient> </defs> <path - class="bar-MULTIFLUID undefined selected bounce-2 delay" + class="bar-MULTIFLUID selected bounce-2 delay" d=" M0,-12.295074999999997 a-12.295074999999997,-12.295074999999997 0 0 1 -12.295074999999997,12.295074999999997 @@ -146,7 +146,7 @@ exports[`Bar component test should correctly render Bar with isSwitching 1`] = ` > <defs> <lineargradient - class="bar-MULTIFLUID undefined selected bounce-2 delay" + class="bar-MULTIFLUID selected bounce-2 delay" id="gradient" x1="0" x2="0" @@ -164,7 +164,7 @@ exports[`Bar component test should correctly render Bar with isSwitching 1`] = ` </lineargradient> </defs> <path - class="bar-MULTIFLUID undefined selected bounce-2 delay" + class="bar-MULTIFLUID selected bounce-2 delay" d=" M0,-12.295074999999997 a-12.295074999999997,-12.295074999999997 0 0 1 -12.295074999999997,12.295074999999997 @@ -220,7 +220,7 @@ exports[`Bar component test should correctly render Bar with showCompare 1`] = ` </lineargradient> </defs> <path - class="bar-MULTIFLUID undefined selected bounce-2 delay" + class="bar-MULTIFLUID selected bounce-2 delay" d=" M1.2500000000000002,-12.295074999999997 a-12.295074999999997,-12.295074999999997 0 0 1 -12.295074999999997,12.295074999999997 @@ -236,7 +236,7 @@ exports[`Bar component test should correctly render Bar with showCompare 1`] = ` > <defs> <lineargradient - class="bar-MULTIFLUID undefined selected bounce-2 delay" + class="bar-MULTIFLUID selected bounce-2 delay" id="gradient" x1="0" x2="0" @@ -254,7 +254,7 @@ exports[`Bar component test should correctly render Bar with showCompare 1`] = ` </lineargradient> </defs> <path - class="bar-MULTIFLUID undefined selected bounce-2 delay" + class="bar-MULTIFLUID selected bounce-2 delay" d=" M1.2500000000000002,-12.295074999999997 a-12.295074999999997,-12.295074999999997 0 0 1 -12.295074999999997,12.295074999999997 @@ -344,7 +344,7 @@ exports[`Bar component test should correctly render Electricity Bar 1`] = ` </lineargradient> </defs> <path - class="bar-ELECTRICITY undefined selected bounce-2 delay" + class="bar-ELECTRICITY selected bounce-2 delay" d=" M0,-12.295074999999997 a-12.295074999999997,-12.295074999999997 0 0 1 -12.295074999999997,12.295074999999997 @@ -360,7 +360,7 @@ exports[`Bar component test should correctly render Electricity Bar 1`] = ` > <defs> <lineargradient - class="bar-ELECTRICITY undefined selected bounce-2 delay" + class="bar-ELECTRICITY selected bounce-2 delay" id="gradient" x1="0" x2="0" @@ -378,7 +378,7 @@ exports[`Bar component test should correctly render Electricity Bar 1`] = ` </lineargradient> </defs> <path - class="bar-ELECTRICITY undefined selected bounce-2 delay" + class="bar-ELECTRICITY selected bounce-2 delay" d=" M0,-12.295074999999997 a-12.295074999999997,-12.295074999999997 0 0 1 -12.295074999999997,12.295074999999997 @@ -434,7 +434,7 @@ exports[`Bar component test should correctly render Gas Bar 1`] = ` </lineargradient> </defs> <path - class="bar-GAS undefined selected bounce-2 delay" + class="bar-GAS selected bounce-2 delay" d=" M0,-12.295074999999997 a-12.295074999999997,-12.295074999999997 0 0 1 -12.295074999999997,12.295074999999997 @@ -450,7 +450,7 @@ exports[`Bar component test should correctly render Gas Bar 1`] = ` > <defs> <lineargradient - class="bar-GAS undefined selected bounce-2 delay" + class="bar-GAS selected bounce-2 delay" id="gradient" x1="0" x2="0" @@ -468,7 +468,7 @@ exports[`Bar component test should correctly render Gas Bar 1`] = ` </lineargradient> </defs> <path - class="bar-GAS undefined selected bounce-2 delay" + class="bar-GAS selected bounce-2 delay" d=" M0,-12.295074999999997 a-12.295074999999997,-12.295074999999997 0 0 1 -12.295074999999997,12.295074999999997 @@ -524,7 +524,7 @@ exports[`Bar component test should correctly render Multifluid Bar 1`] = ` </lineargradient> </defs> <path - class="bar-MULTIFLUID undefined selected bounce-2 delay" + class="bar-MULTIFLUID selected bounce-2 delay" d=" M0,-12.295074999999997 a-12.295074999999997,-12.295074999999997 0 0 1 -12.295074999999997,12.295074999999997 @@ -540,7 +540,7 @@ exports[`Bar component test should correctly render Multifluid Bar 1`] = ` > <defs> <lineargradient - class="bar-MULTIFLUID undefined selected bounce-2 delay" + class="bar-MULTIFLUID selected bounce-2 delay" id="gradient" x1="0" x2="0" @@ -558,7 +558,7 @@ exports[`Bar component test should correctly render Multifluid Bar 1`] = ` </lineargradient> </defs> <path - class="bar-MULTIFLUID undefined selected bounce-2 delay" + class="bar-MULTIFLUID selected bounce-2 delay" d=" M0,-12.295074999999997 a-12.295074999999997,-12.295074999999997 0 0 1 -12.295074999999997,12.295074999999997 @@ -614,7 +614,7 @@ exports[`Bar component test should correctly render Water Bar 1`] = ` </lineargradient> </defs> <path - class="bar-WATER undefined selected bounce-2 delay" + class="bar-WATER selected bounce-2 delay" d=" M0,-12.295074999999997 a-12.295074999999997,-12.295074999999997 0 0 1 -12.295074999999997,12.295074999999997 @@ -630,7 +630,7 @@ exports[`Bar component test should correctly render Water Bar 1`] = ` > <defs> <lineargradient - class="bar-WATER undefined selected bounce-2 delay" + class="bar-WATER selected bounce-2 delay" id="gradient" x1="0" x2="0" @@ -648,7 +648,7 @@ exports[`Bar component test should correctly render Water Bar 1`] = ` </lineargradient> </defs> <path - class="bar-WATER undefined selected bounce-2 delay" + class="bar-WATER selected bounce-2 delay" d=" M0,-12.295074999999997 a-12.295074999999997,-12.295074999999997 0 0 1 -12.295074999999997,12.295074999999997 diff --git a/src/components/Charts/__snapshots__/BarChart.spec.tsx.snap b/src/components/Charts/__snapshots__/BarChart.spec.tsx.snap index 57ffaf1973a018c655d6a057bfe19515c1e904a5..f7ffac763245b3d4f9ce24a9a7ead187a69d44e2 100644 --- a/src/components/Charts/__snapshots__/BarChart.spec.tsx.snap +++ b/src/components/Charts/__snapshots__/BarChart.spec.tsx.snap @@ -127,7 +127,7 @@ exports[`BarChart component should render correctly 1`] = ` </lineargradient> </defs> <path - class="bar-ELECTRICITY undefined selected bounce-2 delay" + class="bar-ELECTRICITY selected bounce-2 delay" d=" M0,4 a4,4 0 0 1 4,-4 @@ -143,7 +143,7 @@ exports[`BarChart component should render correctly 1`] = ` > <defs> <lineargradient - class="bar-ELECTRICITY undefined selected bounce-2 delay" + class="bar-ELECTRICITY selected bounce-2 delay" id="gradient" x1="0" x2="0" @@ -161,7 +161,7 @@ exports[`BarChart component should render correctly 1`] = ` </lineargradient> </defs> <path - class="bar-ELECTRICITY undefined selected bounce-2 delay" + class="bar-ELECTRICITY selected bounce-2 delay" d=" M0,4 a4,4 0 0 1 4,-4 @@ -210,7 +210,7 @@ exports[`BarChart component should render correctly 1`] = ` </lineargradient> </defs> <path - class="bar-ELECTRICITY undefined selected bounce-2 delay" + class="bar-ELECTRICITY selected bounce-2 delay" d=" M0,4 a4,4 0 0 1 4,-4 @@ -226,7 +226,7 @@ exports[`BarChart component should render correctly 1`] = ` > <defs> <lineargradient - class="bar-ELECTRICITY undefined selected bounce-2 delay" + class="bar-ELECTRICITY selected bounce-2 delay" id="gradient" x1="0" x2="0" @@ -244,7 +244,7 @@ exports[`BarChart component should render correctly 1`] = ` </lineargradient> </defs> <path - class="bar-ELECTRICITY undefined selected bounce-2 delay" + class="bar-ELECTRICITY selected bounce-2 delay" d=" M0,4 a4,4 0 0 1 4,-4 @@ -293,7 +293,7 @@ exports[`BarChart component should render correctly 1`] = ` </lineargradient> </defs> <path - class="bar-ELECTRICITY bar-UNCOMING undefined selected bounce-2 delay" + class="bar-ELECTRICITY bar-UNCOMING selected bounce-2 delay" d=" M0,4 a4,4 0 0 1 4,-4 diff --git a/src/components/CommonKit/Switch/StyledSwitch.tsx b/src/components/CommonKit/Switch/StyledSwitch.tsx index d8136853ef6452b872454f953f6f3ba6c8db0088..bd890d435fe1ef6051610d1ef4280a411016843b 100644 --- a/src/components/CommonKit/Switch/StyledSwitch.tsx +++ b/src/components/CommonKit/Switch/StyledSwitch.tsx @@ -72,20 +72,19 @@ interface StyledSwitchProps extends SwitchProps { } const StyledSwitch = ({ fluidType, ...props }: StyledSwitchProps) => { - if (fluidType !== undefined) { - switch (fluidType) { - case FluidType.ELECTRICITY: - return <SwitchElec {...props} /> - case FluidType.WATER: - return <SwitchWater {...props} /> - case FluidType.GAS: - return <SwitchGas {...props} /> - default: - return <SwitchBase {...props} /> - } - } else { + if (fluidType === undefined) { return <SwitchBase {...props} /> } + switch (fluidType) { + case FluidType.ELECTRICITY: + return <SwitchElec {...props} /> + case FluidType.WATER: + return <SwitchWater {...props} /> + case FluidType.GAS: + return <SwitchGas {...props} /> + default: + return <SwitchBase {...props} /> + } } export default StyledSwitch diff --git a/src/components/Consumption/ConsumptionView.tsx b/src/components/Consumption/ConsumptionView.tsx index 79784af6e68a92ad15734af988504ea511ba1a5a..ae0db62cbb1ef5a91b59c94e12f208378c5cdaba 100644 --- a/src/components/Consumption/ConsumptionView.tsx +++ b/src/components/Consumption/ConsumptionView.tsx @@ -28,6 +28,7 @@ import { openPartnersModal, setCustomPopup } from 'store/modal/modal.slice' import { isLastDateReached } from 'utils/date' import { getKonnectorUpdateError, + getPartnerKey, getTodayDate, isKonnectorActive, } from 'utils/utils' @@ -38,12 +39,12 @@ const ConsumptionView = ({ fluidType }: { fluidType: FluidType }) => { const navigate = useNavigate() const client = useClient() const dispatch = useAppDispatch() - const isMulti = fluidType === FluidType.MULTIFLUID const { chart: { currentTimeStep, showOfflineData, selectedDate, currentIndex }, global: { fluidStatus, releaseNotes }, modal: { partnersIssueModal, customPopupModal }, } = useAppSelector(state => state.ecolyo) + const isMulti = fluidType === FluidType.MULTIFLUID const dateChartService = new DateChartService() @@ -58,13 +59,13 @@ const ConsumptionView = ({ fluidType }: { fluidType: FluidType }) => { ) const updateKey = - fluidType !== FluidType.MULTIFLUID && fluidStatus[fluidType].lastDataDate + !isMulti && fluidStatus[fluidType].lastDataDate ? `${fluidStatus[fluidType].lastDataDate!.toLocaleString()} + ${ fluidStatus[fluidType].status + fluidType }` : '' const lastDataDateKey = - fluidType !== FluidType.MULTIFLUID && fluidStatus[fluidType].lastDataDate + !isMulti && fluidStatus[fluidType].lastDataDate ? `${fluidStatus[fluidType].lastDataDate!.toLocaleString() + fluidType}` : '' @@ -82,19 +83,6 @@ const ConsumptionView = ({ fluidType }: { fluidType: FluidType }) => { } }, [dispatch, navigate, releaseNotes.notes, releaseNotes.redirectLink]) - const getPartnerKey = (fluidType: FluidType): 'enedis' | 'egl' | 'grdf' => { - switch (fluidType) { - case FluidType.ELECTRICITY: - return 'enedis' - case FluidType.WATER: - return 'egl' - case FluidType.GAS: - return 'grdf' - default: - throw new Error('unknown fluidtype') - } - } - const handleClosePartnerIssueModal = useCallback(async () => { const profileService = new ProfileService(client) const profileValues = await profileService.getProfile() diff --git a/src/components/Consumption/FluidButtons/FluidButton.spec.tsx b/src/components/Consumption/FluidButtons/FluidButton.spec.tsx index 1c8fa5ea6e1821077906d7488b060d1a10013548..09d06751951cf026faba5835fd1c3c13ad34b78f 100644 --- a/src/components/Consumption/FluidButtons/FluidButton.spec.tsx +++ b/src/components/Consumption/FluidButtons/FluidButton.spec.tsx @@ -1,4 +1,4 @@ -import { render } from '@testing-library/react' +import { render, screen } from '@testing-library/react' import { FluidState, FluidType } from 'enums' import { GlobalState } from 'models' import React from 'react' @@ -19,15 +19,14 @@ describe('FluidButton component', () => { }) it('should render multifluidButton', () => { - const { container } = render( + render( <Provider store={store}> <FluidButton fluidType={FluidType.MULTIFLUID} isActive={false} /> </Provider> ) - const element = container.getElementsByClassName('multifluid').item(0) - expect(element).toBeInTheDocument() + expect(screen.getByText('FLUID.MULTIFLUID.LABEL')).toBeInTheDocument() }) - it('should render active button', () => { + it('should render active gas button', () => { const { container } = render( <Provider store={store}> <FluidButton fluidType={FluidType.GAS} isActive={true} /> diff --git a/src/components/Consumption/FluidButtons/FluidButton.tsx b/src/components/Consumption/FluidButtons/FluidButton.tsx index f68eaa2d10542bfcbe93bfa8351ea37d049ce2a5..3d71f623fa2b67a7c1a949a3e19dcf22123ef9b3 100644 --- a/src/components/Consumption/FluidButtons/FluidButton.tsx +++ b/src/components/Consumption/FluidButtons/FluidButton.tsx @@ -1,6 +1,7 @@ import { IconButton } from '@material-ui/core' import ErrorNotif from 'assets/icons/ico/notif_error.svg' import PartnerIssueNotif from 'assets/icons/ico/notif_maintenance.svg' +import classNames from 'classnames' import StyledIcon from 'components/CommonKit/Icon/StyledIcon' import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { FluidState, FluidType } from 'enums' @@ -20,50 +21,42 @@ const FluidButton = ({ fluidType, isActive }: FluidButtonProps) => { const navigate = useNavigate() const { fluidStatus } = useAppSelector(state => state.ecolyo.global) const [showError, setShowError] = useState<boolean>(false) + const isMulti = fluidType === FluidType.MULTIFLUID + const fluidName = getFluidName(fluidType) const isConnected = useCallback(() => { - if (fluidType === FluidType.MULTIFLUID) { - return true - } else return isKonnectorActive(fluidStatus, fluidType) - }, [fluidStatus, fluidType]) + if (isMulti) return true + return isKonnectorActive(fluidStatus, fluidType) + }, [fluidStatus, fluidType, isMulti]) const isErrored = useCallback(() => { if ( - (fluidType !== FluidType.MULTIFLUID && - fluidStatus[fluidType].status === FluidState.ERROR) || + (!isMulti && fluidStatus[fluidType].status === FluidState.ERROR) || (fluidType !== FluidType.WATER && fluidStatus[fluidType].status === FluidState.ERROR_LOGIN_FAILED) ) { return true } return false - }, [fluidStatus, fluidType]) + }, [fluidStatus, fluidType, isMulti]) const iconType = getNavPicto(fluidType, isActive, isConnected()) const goToFluid = useCallback(async () => { - navigate( - fluidType === FluidType.MULTIFLUID - ? '/consumption' - : `/consumption/${getFluidName(fluidType)}` - ) - }, [navigate, fluidType]) + navigate(isMulti ? '/consumption' : `/consumption/${fluidName}`) + }, [navigate, isMulti, fluidName]) const isFluidMaintenance = () => fluidStatus[fluidType]?.maintenance useEffect(() => { // Show errors only on connected konnectors that are in error, outdated, with no data (specific case), and not in multifluid - if (fluidType !== FluidType.MULTIFLUID && isConnected() && isErrored()) { + if (!isMulti && isConnected() && isErrored()) { setShowError(true) } - }, [fluidStatus, fluidType, isConnected, isErrored]) + }, [fluidStatus, fluidType, isConnected, isErrored, isMulti]) + return ( - <IconButton - className={`fluid-title fluid-button ${FluidType[ - fluidType - ].toLowerCase()}`} - onClick={goToFluid} - > + <IconButton className="fluid-title fluid-button" onClick={goToFluid}> <StyledIcon className="fluid-icon" icon={iconType} @@ -81,11 +74,11 @@ const FluidButton = ({ fluidType, isActive }: FluidButtonProps) => { ) )} <div - className={`fluid-title ${getFluidName(fluidType)} ${ - isActive && 'active' - } text-14-normal`} + className={classNames('fluid-title text-14-normal', { + active: isActive, + })} > - {t(`FLUID.${FluidType[fluidType]}.LABEL`)} + {t(`FLUID.${fluidName.toLocaleUpperCase()}.LABEL`)} </div> </IconButton> ) diff --git a/src/components/Consumption/FluidButtons/__snapshots__/FluidButton.spec.tsx.snap b/src/components/Consumption/FluidButtons/__snapshots__/FluidButton.spec.tsx.snap index fe1b616b62680d6c6b7ee1b248b93117710d356b..8c24c5c5e4a9ee60a15420631cef7af09d6dfdd7 100644 --- a/src/components/Consumption/FluidButtons/__snapshots__/FluidButton.spec.tsx.snap +++ b/src/components/Consumption/FluidButtons/__snapshots__/FluidButton.spec.tsx.snap @@ -3,7 +3,7 @@ exports[`FluidButton component should be rendered correctly 1`] = ` <div> <button - class="MuiButtonBase-root MuiIconButton-root fluid-title fluid-button electricity" + class="MuiButtonBase-root MuiIconButton-root fluid-title fluid-button" tabindex="0" type="button" > @@ -21,7 +21,7 @@ exports[`FluidButton component should be rendered correctly 1`] = ` /> </svg> <div - class="fluid-title electricity false text-14-normal" + class="fluid-title text-14-normal" > FLUID.ELECTRICITY.LABEL </div> diff --git a/src/components/Consumption/FluidButtons/__snapshots__/FluidButtons.spec.tsx.snap b/src/components/Consumption/FluidButtons/__snapshots__/FluidButtons.spec.tsx.snap index d7c42349c2df0fcf66d258cf58ac289aee11f4da..271a057e4ab171d41a738c46816f606037038603 100644 --- a/src/components/Consumption/FluidButtons/__snapshots__/FluidButtons.spec.tsx.snap +++ b/src/components/Consumption/FluidButtons/__snapshots__/FluidButtons.spec.tsx.snap @@ -9,7 +9,7 @@ exports[`FluidButtons component should be rendered correctly 1`] = ` class="content" > <button - class="MuiButtonBase-root MuiIconButton-root fluid-title fluid-button multifluid" + class="MuiButtonBase-root MuiIconButton-root fluid-title fluid-button" tabindex="0" type="button" > @@ -27,7 +27,7 @@ exports[`FluidButtons component should be rendered correctly 1`] = ` /> </svg> <div - class="fluid-title multifluid false text-14-normal" + class="fluid-title text-14-normal" > FLUID.MULTIFLUID.LABEL </div> @@ -37,7 +37,7 @@ exports[`FluidButtons component should be rendered correctly 1`] = ` /> </button> <button - class="MuiButtonBase-root MuiIconButton-root fluid-title fluid-button electricity" + class="MuiButtonBase-root MuiIconButton-root fluid-title fluid-button" tabindex="0" type="button" > @@ -55,7 +55,7 @@ exports[`FluidButtons component should be rendered correctly 1`] = ` /> </svg> <div - class="fluid-title electricity active text-14-normal" + class="fluid-title text-14-normal active" > FLUID.ELECTRICITY.LABEL </div> @@ -65,7 +65,7 @@ exports[`FluidButtons component should be rendered correctly 1`] = ` /> </button> <button - class="MuiButtonBase-root MuiIconButton-root fluid-title fluid-button water" + class="MuiButtonBase-root MuiIconButton-root fluid-title fluid-button" tabindex="0" type="button" > @@ -83,7 +83,7 @@ exports[`FluidButtons component should be rendered correctly 1`] = ` /> </svg> <div - class="fluid-title water false text-14-normal" + class="fluid-title text-14-normal" > FLUID.WATER.LABEL </div> @@ -93,7 +93,7 @@ exports[`FluidButtons component should be rendered correctly 1`] = ` /> </button> <button - class="MuiButtonBase-root MuiIconButton-root fluid-title fluid-button gas" + class="MuiButtonBase-root MuiIconButton-root fluid-title fluid-button" tabindex="0" type="button" > @@ -111,7 +111,7 @@ exports[`FluidButtons component should be rendered correctly 1`] = ` /> </svg> <div - class="fluid-title gas false text-14-normal" + class="fluid-title text-14-normal" > FLUID.GAS.LABEL </div> diff --git a/src/components/ConsumptionVisualizer/DataloadNoValue.tsx b/src/components/ConsumptionVisualizer/DataloadNoValue.tsx index 77b90b3d47af8f457f0e0166c17c9c1256fe0bc9..7598813152c06aaa5ab6fc6d841cc15c10b2af0f 100644 --- a/src/components/ConsumptionVisualizer/DataloadNoValue.tsx +++ b/src/components/ConsumptionVisualizer/DataloadNoValue.tsx @@ -5,6 +5,7 @@ import { Dataload } from 'models' import React, { useCallback } from 'react' import { setShowConnectionDetails } from 'store/chart/chart.slice' import { useAppDispatch } from 'store/hooks' +import { getFluidName } from 'utils/utils' import './consumptionVisualizer.scss' interface DataloadNoValueProps { @@ -15,6 +16,7 @@ interface DataloadNoValueProps { const DataloadNoValue = ({ dataload, fluidType }: DataloadNoValueProps) => { const { t } = useI18n() const dispatch = useAppDispatch() + const fluidName = getFluidName(fluidType) const handleToggleKonnectorCard = useCallback(() => { dispatch(setShowConnectionDetails(true)) @@ -45,11 +47,7 @@ const DataloadNoValue = ({ dataload, fluidType }: DataloadNoValueProps) => { return ( <div className="dataloadvisualizer-content text-22-normal"> <div className="dataloadvisualizer-section"> - <div - className={`dataloadvisualizer-value ${FluidType[ - fluidType - ].toLowerCase()} upper`} - > + <div className={`dataloadvisualizer-value ${fluidName} upper`}> {t('consumption_visualizer.no_data')} </div> </div> @@ -74,11 +72,7 @@ const DataloadNoValue = ({ dataload, fluidType }: DataloadNoValueProps) => { return ( <div className="dataloadvisualizer-content text-22-normal"> <div className="dataloadvisualizer-section"> - <div - className={`dataloadvisualizer-value ${FluidType[ - fluidType - ].toLowerCase()} upper to-come`} - > + <div className={`dataloadvisualizer-value ${fluidName} upper to-come`}> {t('consumption_visualizer.data_to_come')} </div> </div> diff --git a/src/components/ConsumptionVisualizer/DataloadSection.tsx b/src/components/ConsumptionVisualizer/DataloadSection.tsx index 16d52ce901cad4382a9606699a12cc0853b53ba8..84a6185eefcd99189f94671696fb370539330759 100644 --- a/src/components/ConsumptionVisualizer/DataloadSection.tsx +++ b/src/components/ConsumptionVisualizer/DataloadSection.tsx @@ -21,17 +21,17 @@ const DataloadSection = ({ toggleEstimationModal, }: DataloadSectionProps) => { const { t } = useI18n() + const isLeft = dataloadSectionType === DataloadSectionType.LEFT + const isRight = dataloadSectionType === DataloadSectionType.RIGHT + const noCompare = dataloadSectionType === DataloadSectionType.NO_COMPARE + const isMulti = fluidType === FluidType.MULTIFLUID + const fluidName = getFluidName(fluidType) - if ( - dataload.value === -1 && - dataloadSectionType === DataloadSectionType.LEFT - ) { + if (dataload.value === -1 && isLeft) { return ( <div className="dataloadvisualizer-section dataloadvisualizer-section-left-novalue"> <div - className={`dataloadvisualizer-novalue ${FluidType[ - fluidType - ].toLowerCase()}-compare text-20-normal`} + className={`dataloadvisualizer-novalue ${fluidName}-compare text-20-normal`} > {t('consumption_visualizer.no_data')} </div> @@ -39,12 +39,6 @@ const DataloadSection = ({ ) } - const isLeft = dataloadSectionType === DataloadSectionType.LEFT - const isRight = dataloadSectionType === DataloadSectionType.RIGHT - const noCompare = dataloadSectionType === DataloadSectionType.NO_COMPARE - const isMulti = fluidType === FluidType.MULTIFLUID - const fluidName = getFluidName(fluidType) - return ( <div className={classNames('dataloadvisualizer-section', { diff --git a/src/components/ConsumptionVisualizer/DataloadSectionValue.tsx b/src/components/ConsumptionVisualizer/DataloadSectionValue.tsx index cfb77c138b854bcbd7d459aea4ffd44d84351c1a..77e227da2ad89bcde169a42729c620e712c8955a 100644 --- a/src/components/ConsumptionVisualizer/DataloadSectionValue.tsx +++ b/src/components/ConsumptionVisualizer/DataloadSectionValue.tsx @@ -3,7 +3,7 @@ import { useI18n } from 'cozy-ui/transpiled/react/I18n' import { DataloadSectionType, FluidType } from 'enums' import { Dataload } from 'models' import React from 'react' -import { formatNumberValues } from 'utils/utils' +import { formatNumberValues, getFluidName } from 'utils/utils' interface DataloadSectionValueProps { dataload: Dataload @@ -19,13 +19,14 @@ const DataloadSectionValue = ({ toggleEstimationModal, }: DataloadSectionValueProps) => { const { t } = useI18n() + const FLUIDNAME = getFluidName(fluidType).toUpperCase() if (fluidType === FluidType.MULTIFLUID) { return ( <> {formatNumberValues(dataload.value)} <div className="text-18-normal euroUnit"> - {t(`FLUID.${FluidType[fluidType]}.UNIT`)} + {t(`FLUID.${FLUIDNAME}.UNIT`)} </div> {dataloadSectionType === DataloadSectionType.NO_COMPARE && ( <Button @@ -43,27 +44,21 @@ const DataloadSectionValue = ({ ) } - const formattedValue = formatNumberValues( - dataload.value, - FluidType[fluidType], - true - ) + const formattedValue = formatNumberValues(dataload.value, FLUIDNAME, true) return ( <> {Number(formattedValue) >= 1000 ? ( <> - {formatNumberValues(dataload.value, FluidType[fluidType])} + {formatNumberValues(dataload.value, FLUIDNAME)} <span className="text-18-normal"> - {t(`FLUID.${FluidType[fluidType]}.MEGAUNIT`)} + {t(`FLUID.${FLUIDNAME}.MEGAUNIT`)} </span> </> ) : ( <> {formatNumberValues(dataload.value)} - <span className="text-18-normal"> - {t(`FLUID.${FluidType[fluidType]}.UNIT`)} - </span> + <span className="text-18-normal">{t(`FLUID.${FLUIDNAME}.UNIT`)}</span> </> )} </> diff --git a/src/components/FluidChart/FluidChartSlide.tsx b/src/components/FluidChart/FluidChartSlide.tsx index f63e06da3887d8f4d91be24460c304c3f3d22c76..9a66f31ed68559e22efadc6a80a795e3a7ef0fc0 100644 --- a/src/components/FluidChart/FluidChartSlide.tsx +++ b/src/components/FluidChart/FluidChartSlide.tsx @@ -70,15 +70,15 @@ const FluidChartSlide = ({ ), ]) const consumptionService = new ConsumptionService(client) - const fluidTypeArray: FluidType[] = - fluidType === FluidType.MULTIFLUID ? fluidTypes : [fluidType] + const isMulti = fluidType === FluidType.MULTIFLUID + const fluidTypeArray: FluidType[] = isMulti ? fluidTypes : [fluidType] const graphData = await consumptionService.getGraphData( timePeriod, currentTimeStep, fluidTypeArray, fluidStatus, compareTimePeriod, - fluidType === FluidType.MULTIFLUID + isMulti ) if (subscribed && graphData && graphData?.actualData.length > 0) { setChartData(graphData) diff --git a/src/components/Konnector/ConnectionResult/ConnectionResult.tsx b/src/components/Konnector/ConnectionResult/ConnectionResult.tsx index 32ea312b459584e6dac4e0414ebfd0f218cf3b60..70062c45959becfca96f82deadef36025ff72f50 100644 --- a/src/components/Konnector/ConnectionResult/ConnectionResult.tsx +++ b/src/components/Konnector/ConnectionResult/ConnectionResult.tsx @@ -18,7 +18,7 @@ import { updateSgeStore, } from 'store/global/global.slice' import { useAppDispatch, useAppSelector } from 'store/hooks' -import { getKonnectorUpdateError } from 'utils/utils' +import { getFluidTypeTranslation, getKonnectorUpdateError } from 'utils/utils' import './connectionResult.scss' interface ConnectionResultProps { @@ -165,17 +165,6 @@ const ConnectionResult = ({ } }, [currentFluidStatus.connection.triggerState, isOutdated]) - const getFluidTypeTranslation = (fluidType: FluidType) => { - switch (fluidType) { - case FluidType.GAS: - return 'de gaz' - case FluidType.ELECTRICITY: - return "d'électricité" - default: - return "d'eau" - } - } - const consentError = konnectorError === KonnectorUpdate.ERROR_CONSENT_FORM_GAS || konnectorError === KonnectorUpdate.ERROR_UPDATE_OAUTH diff --git a/src/components/Konnector/KonnectorModal.tsx b/src/components/Konnector/KonnectorModal.tsx index c5ebc3ba8a5bd98feda2f6cb770acbd2018b23c0..800693207f6d84c1f4eb4f8cac10fc97a8f5cd08 100644 --- a/src/components/Konnector/KonnectorModal.tsx +++ b/src/components/Konnector/KonnectorModal.tsx @@ -17,6 +17,7 @@ import { FluidType, KonnectorError } from 'enums' import { shuffle } from 'lodash' import { Account } from 'models' import React, { useCallback, useEffect, useMemo, useState } from 'react' +import { getFluidName } from 'utils/utils' import KonnectorModalFooter from './KonnectorModalFooter' import './konnectorModal.scss' @@ -45,7 +46,7 @@ const KonnectorModal = ({ account, }: KonnectorModalProps) => { const { t } = useI18n() - const fluidName: string = FluidType[fluidType] + const fluidName = getFluidName(fluidType) const [index, setIndex] = useState<number>(0) const shuffledWaitingTexts = useMemo(() => { if (fluidType) { @@ -110,7 +111,7 @@ const KonnectorModal = ({ {t( `konnector_modal.success_data_${ isUpdating ? 'update_' : '' - }${fluidName.toLowerCase()}` + }${fluidName}` )} </b> <p @@ -119,7 +120,7 @@ const KonnectorModal = ({ __html: t( `konnector_modal.success_data_additional_${ isUpdating ? 'update_' : '' - }${fluidName.toLowerCase()}` + }${fluidName}` ), }} /> @@ -187,13 +188,13 @@ const KonnectorModal = ({ {t( `konnector_modal.error_credentials_${ isUpdating ? 'update_' : '' - }${fluidName.toLowerCase()}` + }${fluidName}` )} </div> {fluidType === FluidType.ELECTRICITY && !isUpdating && ( <div className="elec-fail"> {t( - `konnector_modal.error_credentials_${fluidName.toLowerCase()}_2` + `konnector_modal.error_credentials_${fluidName}_2` )} </div> )} @@ -276,7 +277,7 @@ const KonnectorModal = ({ {t( `konnector_modal.error_data_${ isUpdating ? 'update_' : '' - }${fluidName.toLowerCase()}` + }${fluidName}` )} </div> <div className="err-data-2"> diff --git a/src/components/Konnector/KonnectorViewerList.tsx b/src/components/Konnector/KonnectorViewerList.tsx index c3688d78d6423c24ced94d55a2b082395fea3ce7..c5d4eac40cb6cf9acbb05181c9efe44d0fad12e8 100644 --- a/src/components/Konnector/KonnectorViewerList.tsx +++ b/src/components/Konnector/KonnectorViewerList.tsx @@ -29,14 +29,14 @@ const KonnectorViewerList = () => { > <Icon icon={getAddPicto(fluidStatusItem.fluidType)} size={36} /> <div - className={`konnector-title text-18-bold ${FluidType[ + className={`konnector-title text-18-bold ${getFluidName( fluidStatusItem.fluidType - ].toLowerCase()}`} + )}`} > {t( - `konnector_options.label_connect_to_${FluidType[ + `konnector_options.label_connect_to_${getFluidName( fluidStatusItem.fluidType - ].toLowerCase()}` + )}` )} </div> </StyledCard> diff --git a/src/components/Options/ExportData/Modals/exportLoadingModal.tsx b/src/components/Options/ExportData/Modals/exportLoadingModal.tsx index f6058bed9c22a9a093ed02e7d276bbccecadb78e..151eb496891745a81bf0736db48775fe320b7e74 100644 --- a/src/components/Options/ExportData/Modals/exportLoadingModal.tsx +++ b/src/components/Options/ExportData/Modals/exportLoadingModal.tsx @@ -12,7 +12,7 @@ import { Datachart, Dataload, TimePeriod } from 'models' import React, { useCallback, useEffect } from 'react' import ConsumptionDataManager from 'services/consumption.service' import EnedisMonthlyAnalysisDataService from 'services/enedisMonthlyAnalysisData.service' -import { formatTwoDigits } from 'utils/utils' +import { formatTwoDigits, getFluidName } from 'utils/utils' import * as XLSX from 'xlsx' import './exportLoadingModal.scss' @@ -65,13 +65,11 @@ const ExportLoadingModal = ({ fluidType: FluidType ): Promise<ExportDataRow> => { const dataRow: ExportDataRow = {} + const fluidName = getFluidName(fluidType) dataRow[t('export.month')] = formatTwoDigits(dataload.date.month) dataRow[t('export.year')] = dataload.date.year - dataRow[ - `${t('export.consumption')} (${t( - `FLUID.${FluidType[fluidType]}.UNIT` - )})` - ] = dataload.value + dataRow[`${t('export.consumption')} (${t(`FLUID.${fluidName}.UNIT`)})`] = + dataload.value if (fluidType === FluidType.ELECTRICITY) { const emas = new EnedisMonthlyAnalysisDataService(client) const maxPowerEntities = await emas.getMaxPowerByDate( diff --git a/src/models/relation.model.ts b/src/models/relation.model.ts index 8cb5ea239e444cae73f19cc36c3e00fdab5f00ed..be75b5665bac3b963e9c97587dc9dbca286b931a 100644 --- a/src/models/relation.model.ts +++ b/src/models/relation.model.ts @@ -9,7 +9,3 @@ export interface RelationEntitiesObject { quizEntityRelation: Relation explorationEntityRelation: Relation[] } - -export interface GetRelationshipsReturn { - [relName: string]: Array<Relation> -} diff --git a/src/targets/services/aggregatorUsageEvents.ts b/src/targets/services/aggregatorUsageEvents.ts index f54542bdd4b6ab97fbc94bc198e6fcafc696c819..841b3f7842883c54d03261fdccbac1e74c84f63a 100644 --- a/src/targets/services/aggregatorUsageEvents.ts +++ b/src/targets/services/aggregatorUsageEvents.ts @@ -19,7 +19,7 @@ import ProfileService from 'services/profile.service' import ProfileTypeEntityService from 'services/profileTypeEntity.service' import TermsService from 'services/terms.service' import UsageEventService from 'services/usageEvent.service' -import { getFluidType } from 'utils/utils' +import { getFluidName } from 'utils/utils' import { runService } from './service' const logStack = logger.namespace('aggregatorUsageEvents') @@ -266,7 +266,7 @@ const calculateConsumptionVariation = async (client: Client) => { FluidType.GAS, FluidType.WATER, ]) - for (const fluidType in [ + for (const fluidType of [ FluidType.ELECTRICITY, FluidType.GAS, FluidType.WATER, @@ -287,14 +287,11 @@ const calculateConsumptionVariation = async (client: Client) => { ? consumptionData[fluidType].percentageVariation : 0, // in percent // eslint-disable-next-line camelcase - group1: { fluid_type: FluidType[fluidType].toLowerCase() }, + group1: { fluid_type: getFluidName(fluidType) }, group2: { seniority: Math.round(seniority).toString() }, group3: { // eslint-disable-next-line camelcase - fluid_usage: await buildProfileWithFluidType( - client, - getFluidType(FluidType[fluidType]) - ), + fluid_usage: await buildProfileWithFluidType(client, fluidType), }, } diff --git a/src/utils/utils.spec.ts b/src/utils/utils.spec.ts index 3fd5c09ab54600a8af02d745bd5cde7390449d59..79318b817fa9c770e4ea8f1cdf3c5361d21ee3da 100644 --- a/src/utils/utils.spec.ts +++ b/src/utils/utils.spec.ts @@ -14,12 +14,13 @@ import { formatTwoDigits, getChallengeTitleWithLineReturn, getFluidName, - getFluidType, + getFluidTypeTranslation, getKonnectorSlug, getKonnectorUpdateError, getMonthFullName, getMonthName, getMonthNameWithPrep, + getPartnerKey, getSeason, isKonnectorActive, isValidOffPeakHours, @@ -29,22 +30,6 @@ import { } from './utils' describe('utils test', () => { - describe('getFluidType test', () => { - it('should the electricity fluid type', () => { - const result = getFluidType('eLectRicity') - expect(result).toBe(FluidType.ELECTRICITY) - }) - - it('should the water fluid type', () => { - const result = getFluidType('WatER') - expect(result).toBe(FluidType.WATER) - }) - - it('should the gas fluid type', () => { - const result = getFluidType('gas') - expect(result).toBe(FluidType.GAS) - }) - }) describe('getKonnectorSlug', () => { it('should return correct slug for elec', () => { const slug = getKonnectorSlug(FluidType.ELECTRICITY) @@ -58,6 +43,11 @@ describe('utils test', () => { const slug = getKonnectorSlug(FluidType.GAS) expect(slug).toBe(FluidSlugType.GAS) }) + it('should throw error for invalid fluid type', () => { + expect(() => getKonnectorSlug(99 as FluidType.GAS)).toThrow( + 'unknown fluidtype' + ) + }) }) describe('getKonnectorUpdateError', () => { it('should return KonnectorUpdate.ERROR_UPDATE_OAUTH for USER_ACTION_NEEDED.OAUTH_OUTDATED', () => { @@ -235,6 +225,42 @@ describe('utils test', () => { }) }) + describe('getFluidTypeTranslation', () => { + it('should return electricity', () => { + expect(getFluidTypeTranslation(FluidType.ELECTRICITY)).toBe( + "d'électricité" + ) + }) + it('should return water', () => { + expect(getFluidTypeTranslation(FluidType.WATER)).toBe("d'eau") + }) + it('should return gas', () => { + expect(getFluidTypeTranslation(FluidType.GAS)).toBe('de gaz') + }) + it('should throw error for invalid fluid type', () => { + expect(() => getFluidTypeTranslation(99 as FluidType.GAS)).toThrow( + 'unexpected fluidtype' + ) + }) + }) + + describe('getPartnerKey', () => { + it('should return enedis', () => { + expect(getPartnerKey(FluidType.ELECTRICITY)).toBe('enedis') + }) + it('should return egl', () => { + expect(getPartnerKey(FluidType.WATER)).toBe('egl') + }) + it('should return grdf', () => { + expect(getPartnerKey(FluidType.GAS)).toBe('grdf') + }) + it('should throw error for invalid fluid type', () => { + expect(() => getPartnerKey(99 as FluidType.GAS)).toThrow( + 'unknown fluidtype' + ) + }) + }) + describe('formatListWithAnd', () => { it('should return empty string', () => { expect(formatListWithAnd([])).toBe('') diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 834c7463d74b9489b3aa142199de9e224d1d05d7..ddf4b505afcad81173d45db52fcf9134df9137de 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -8,25 +8,15 @@ import { } from 'enums' import get from 'lodash/get' import { DateTime, Interval } from 'luxon' -import { FluidStatus, GetRelationshipsReturn, Relation } from 'models' +import { FluidStatus, Relation } from 'models' import challengeData from '../db/challengeEntity.json' /** Array of elec, water & gas */ export const allFluids = [FluidType.ELECTRICITY, FluidType.WATER, FluidType.GAS] -export function getFluidType(type: string) { - switch (type.toUpperCase()) { - case 'ELECTRICITY': - return FluidType.ELECTRICITY - case 'WATER': - return FluidType.WATER - case 'GAS': - return FluidType.GAS - default: - return FluidType.ELECTRICITY - } -} -export function getKonnectorSlug(fluidType: FluidType) { +export function getKonnectorSlug( + fluidType: Exclude<FluidType, FluidType.MULTIFLUID> +) { switch (fluidType) { case FluidType.ELECTRICITY: return FluidSlugType.ELECTRICITY @@ -46,6 +36,34 @@ export function getFluidName(fluidType: FluidType) { return FluidType[fluidType].toLowerCase() } +export const getFluidTypeTranslation = ( + fluidType: Exclude<FluidType, FluidType.MULTIFLUID> +) => { + switch (fluidType) { + case FluidType.GAS: + return 'de gaz' + case FluidType.ELECTRICITY: + return "d'électricité" + case FluidType.WATER: + return "d'eau" + default: + throw new Error('unexpected fluidtype') + } +} + +export const getPartnerKey = (fluidType: FluidType) => { + switch (fluidType) { + case FluidType.ELECTRICITY: + return 'enedis' + case FluidType.WATER: + return 'egl' + case FluidType.GAS: + return 'grdf' + default: + throw new Error('unknown fluidtype') + } +} + export function getKonnectorUpdateError(type: string) { switch (type.toUpperCase()) { case 'USER_ACTION_NEEDED.OAUTH_OUTDATED': @@ -121,20 +139,6 @@ export function getRelationshipHasMany<D>(doc: D, relName: string): Relation[] { return get(doc, `relationships.${relName}.data`, []) } -/** - * Get many relations in doc - * @param {object} doc - DocumentEntity - * @param relNameList - Array of name of the relations - */ -export function getRelationships<D>( - doc: D, - relNameList: Array<string> -): GetRelationshipsReturn { - return relNameList.map(relName => ({ - [relName]: get(doc, `relationships.${relName}.data`, []), - }))[0] -} - /** * Import a svg file with format : id.svg */