From d45e4f39e64e181886ebefa92d56f93a4f3fa72e Mon Sep 17 00:00:00 2001
From: Guilhem CARRON <gcarron@grandlyon.com>
Date: Wed, 29 Jun 2022 12:35:58 +0000
Subject: [PATCH] fix(analysis): Fix navigation issue in monthly analysis

---
 .../Analysis/ElecHalfHourMonthlyAnalysis.tsx  | 33 +++++++++++--------
 .../ElecHalfHourMonthlyAnalysis.spec.tsx.snap |  8 +++--
 2 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/src/components/Analysis/ElecHalfHourMonthlyAnalysis.tsx b/src/components/Analysis/ElecHalfHourMonthlyAnalysis.tsx
index e93d9fc31..3103495ad 100644
--- a/src/components/Analysis/ElecHalfHourMonthlyAnalysis.tsx
+++ b/src/components/Analysis/ElecHalfHourMonthlyAnalysis.tsx
@@ -63,6 +63,24 @@ const ElecHalfHourMonthlyAnalysis: React.FC<ElecHalfHourMonthlyAnalysisProps> =
   const toggleOpenModal = useCallback(() => {
     setOpenInfoModal(prev => !prev)
   }, [])
+  const getPowerChart = useCallback((): JSX.Element => {
+    if (
+      monthDataloads &&
+      monthDataloads.weekend &&
+      monthDataloads.week &&
+      monthDataloads.weekend[0] !== null &&
+      monthDataloads.week[0] !== null
+    ) {
+      return (
+        <ElecHalfHourChart
+          dataLoad={isWeekend ? monthDataloads.weekend : monthDataloads.week}
+          isWeekend={isWeekend}
+        />
+      )
+    } else {
+      return <p className={`text-20-bold no_data`}>{t('analysis.no_data')}</p>
+    }
+  }, [isWeekend, monthDataloads, t])
 
   useEffect(() => {
     let subscribed = true
@@ -160,18 +178,7 @@ const ElecHalfHourMonthlyAnalysis: React.FC<ElecHalfHourMonthlyAnalysisProps> =
           </div>
           {!isLoading ? (
             <>
-              {monthDataloads ? (
-                <ElecHalfHourChart
-                  dataLoad={
-                    isWeekend ? monthDataloads.weekend : monthDataloads.week
-                  }
-                  isWeekend={isWeekend}
-                />
-              ) : (
-                <p className={`text-20-bold no_data`}>
-                  {t('analysis.no_data')}
-                </p>
-              )}
+              {getPowerChart()}
               {enedisAnalysisValues && (
                 <div className="min-max">
                   <div className="container">
@@ -215,7 +222,7 @@ const ElecHalfHourMonthlyAnalysis: React.FC<ElecHalfHourMonthlyAnalysisProps> =
                             <span className="text-18-normal"> %</span>
                           </div>
                           <div className="text-18-bold">
-                            {elecPrice
+                            {elecPrice && elecPrice.price
                               ? (
                                   enedisAnalysisValues.minimumLoad *
                                   elecPrice.price
diff --git a/src/components/Analysis/__snapshots__/ElecHalfHourMonthlyAnalysis.spec.tsx.snap b/src/components/Analysis/__snapshots__/ElecHalfHourMonthlyAnalysis.spec.tsx.snap
index 3e66e5b70..d572a4092 100644
--- a/src/components/Analysis/__snapshots__/ElecHalfHourMonthlyAnalysis.spec.tsx.snap
+++ b/src/components/Analysis/__snapshots__/ElecHalfHourMonthlyAnalysis.spec.tsx.snap
@@ -557,9 +557,11 @@ exports[`ElecHalfHourMonthlyAnalysis component should be rendered correctly when
         </ForwardRef(IconButton)>
       </WithStyles(ForwardRef(IconButton))>
     </div>
-    <mock-elechalfhourchart
-      isWeekend={true}
-    />
+    <p
+      className="text-20-bold no_data"
+    >
+      analysis.no_data
+    </p>
     <div
       className="min-max"
     >
-- 
GitLab