From 08fe45d3551e11cfe2157c5c3b11cdf68d69fd91 Mon Sep 17 00:00:00 2001
From: Romain CREY <ext.sopra.rcrey@grandlyon.com>
Date: Thu, 23 Jul 2020 10:22:38 +0200
Subject: [PATCH] fix: comments MR + start of month

---
 .../ViewContainer/HomeViewContainer.tsx       |  9 +++------
 .../ContentComponents/Charts/AxisRight.tsx    |  7 +------
 .../ContentComponents/Charts/BarChart.tsx     | 15 ++++++++------
 .../FluidChart/FluidChartSlide.tsx            | 20 +++++++------------
 .../consumptionDataValidatorService.ts        |  2 +-
 5 files changed, 21 insertions(+), 32 deletions(-)

diff --git a/src/components/ContainerComponents/ViewContainer/HomeViewContainer.tsx b/src/components/ContainerComponents/ViewContainer/HomeViewContainer.tsx
index 7c728dc05..29be4f352 100644
--- a/src/components/ContainerComponents/ViewContainer/HomeViewContainer.tsx
+++ b/src/components/ContainerComponents/ViewContainer/HomeViewContainer.tsx
@@ -12,12 +12,9 @@ import ChallengeCardContainer from 'components/ContainerComponents/ChallengeCard
 import KonnectorViewerContainer from 'components/ContainerComponents/KonnectorViewerContainer/KonnectorViewerContainer'
 
 const HomeViewContainer: React.FC = () => {
-  const {
-    fluidTypes,
-    previousTimeStep,
-    setPreviousTimeStep,
-    chartIsLoaded,
-  } = useContext(AppContext)
+  const { fluidTypes, previousTimeStep, setPreviousTimeStep } = useContext(
+    AppContext
+  )
   const [timeStep, setTimeStep] = useState<TimeStep>(
     previousTimeStep && previousTimeStep !== TimeStep.HALF_AN_HOUR
       ? previousTimeStep
diff --git a/src/components/ContentComponents/Charts/AxisRight.tsx b/src/components/ContentComponents/Charts/AxisRight.tsx
index c41678d74..ac48b6a18 100644
--- a/src/components/ContentComponents/Charts/AxisRight.tsx
+++ b/src/components/ContentComponents/Charts/AxisRight.tsx
@@ -16,12 +16,7 @@ interface AxisRightProps {
 
 const AxisRight = (props: AxisRightProps) => {
   const { yScale, fluidTypes, width, marginRight, marginTop, t } = props
-  let isHome
-  if (!window.location.hash.split('/')[2]) {
-    isHome = true
-  } else {
-    isHome = false
-  }
+  const isHome: boolean = !window.location.hash.split('/')[2] ? true : false
   const fluidStyle =
     fluidTypes.length > 1 || isHome ? 'MULTIFLUID' : FluidType[fluidTypes[0]]
   const yAxisRef = useRef<SVGGElement>(null)
diff --git a/src/components/ContentComponents/Charts/BarChart.tsx b/src/components/ContentComponents/Charts/BarChart.tsx
index 7ef7a9109..d2b518640 100644
--- a/src/components/ContentComponents/Charts/BarChart.tsx
+++ b/src/components/ContentComponents/Charts/BarChart.tsx
@@ -1,4 +1,4 @@
-import React, { useContext, useEffect, useState } from 'react'
+import React, { useContext, useEffect } from 'react'
 import { scaleBand, ScaleBand, scaleLinear, ScaleLinear } from 'd3-scale'
 import {
   IDataload,
@@ -78,14 +78,18 @@ const BarChart: React.FC<BarChartProps> = (props: BarChartProps) => {
 
   const getMaxLoad = () => {
     if (
-      (timeStep === TimeStep.DAY || timeStep === TimeStep.HALF_AN_HOUR) &&
-      !showCompare
+      (timeStep === TimeStep.DAY && !showCompare) ||
+      timeStep === TimeStep.HALF_AN_HOUR
     ) {
       const actualMonth = selectedDate.startOf('week').month
       const actualYear = selectedDate.startOf('week').year
       const key = `${actualMonth}/${actualYear}-${isHome}-${fluidTypes
         .sort()
         .join('-')}-${timeStep}`
+      if (DateTime.local() < selectedDate && !maxLoads[key]) {
+        maxLoads[key] = 15
+      }
+
       return maxLoads[key] > 0 ? maxLoads[key] : 15
     } else {
       let max = chartData.actualData
@@ -119,13 +123,12 @@ const BarChart: React.FC<BarChartProps> = (props: BarChartProps) => {
   const yScale: ScaleLinear<number, number> = scaleLinear()
     .domain([0, getMaxLoad()])
     .range([getContentHeight(), 0])
-  const size = Object.keys(maxLoads).length
 
   useEffect(() => {
-    if (size > 0) {
+    if (Object.keys(maxLoads).length > 0) {
       setChartIsLoaded(true)
     }
-  }, [size, maxLoads])
+  }, [maxLoads])
   useEffect(() => {
     setChartIsLoaded(true)
   }, [])
diff --git a/src/components/ContentComponents/FluidChart/FluidChartSlide.tsx b/src/components/ContentComponents/FluidChart/FluidChartSlide.tsx
index a8cdc9574..97a60a5be 100644
--- a/src/components/ContentComponents/FluidChart/FluidChartSlide.tsx
+++ b/src/components/ContentComponents/FluidChart/FluidChartSlide.tsx
@@ -54,12 +54,8 @@ const FluidChartSlide: React.FC<FluidChartSlideProps> = ({
 
   const { setChartIsLoaded, maxLoads, chartIsLoaded } = useContext(AppContext)
 
-  let isHome: boolean
-  if (!window.location.hash.split('/')[2]) {
-    isHome = true
-  } else {
-    isHome = false
-  }
+  const isHome: boolean = !window.location.hash.split('/')[2] ? true : false
+
   useEffect(() => {
     let subscribed = true
     async function loadData() {
@@ -99,14 +95,14 @@ const FluidChartSlide: React.FC<FluidChartSlideProps> = ({
       startDate:
         timeStep === TimeStep.HALF_AN_HOUR
           ? selectedDate.startOf('month')
-          : selectedDate.startOf('month').startOf('week').month !==
-            selectedDate.startOf('month').endOf('week').month
-          ? selectedDate
+          : selectedDate.startOf('week').startOf('month').weekdayLong ===
+            'lundi'
+          ? selectedDate.startOf('week').startOf('month')
+          : selectedDate
               .startOf('week')
               .startOf('month')
               .plus({ days: +7 })
-              .startOf('week')
-          : selectedDate.startOf('week').startOf('month'),
+              .startOf('week'),
       endDate:
         timeStep === TimeStep.HALF_AN_HOUR
           ? selectedDate.endOf('month')
@@ -133,8 +129,6 @@ const FluidChartSlide: React.FC<FluidChartSlideProps> = ({
 
       maxLoads[key] = graphMaxLoad
 
-      key in maxLoads ? (maxLoads[key] = graphMaxLoad) : null
-
       if (subscribed && graphMaxLoad) {
         setIsLoaded(true)
         setChartIsLoaded(true)
diff --git a/src/services/consumptionDataValidatorService.ts b/src/services/consumptionDataValidatorService.ts
index f861b87f6..b5e9b8088 100644
--- a/src/services/consumptionDataValidatorService.ts
+++ b/src/services/consumptionDataValidatorService.ts
@@ -43,7 +43,7 @@ export default class ConsumptionDataValidator {
     )
     if (timeStep == TimeStep.HALF_AN_HOUR && interval.length('hour') > 24)
       return false
-    if (timeStep == TimeStep.DAY && interval.length('day') > 40) return false
+    if (timeStep == TimeStep.DAY && interval.length('day') > 36) return false
     if (timeStep == TimeStep.MONTH && interval.length('month') > 12)
       return false
     if (timeStep == TimeStep.YEAR && interval.length('year') > 10) return false
-- 
GitLab