From 77396eb297ff398663498d11942204eb81a9f3d5 Mon Sep 17 00:00:00 2001
From: Jonathan Foucher <jfoucher@gmail.com>
Date: Thu, 11 Aug 2022 10:51:58 +0200
Subject: [PATCH] Make sure graphs load when navigating between evaluation
 steps. Fixes https://app.asana.com/0/1202404842967175/1202782140079881

---
 .../Single/Components/Step3/AttackGraph.vue           |  2 +-
 .../Single/Components/Step3/ExpositionGraph.vue       |  2 +-
 .../Single/Components/Step3/MeasuresGraph.vue         | 11 +++++++----
 .../Evaluations/Single/Components/Step3/RiskGraph.vue |  2 +-
 .../Single/Components/Step4/CyberRiskyGraph.vue       |  2 +-
 .../js/components/Evaluations/Single/Steps/Step2.vue  |  2 +-
 resources/js/stores/graphs.js                         |  5 ++---
 7 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/resources/js/components/Evaluations/Single/Components/Step3/AttackGraph.vue b/resources/js/components/Evaluations/Single/Components/Step3/AttackGraph.vue
index 78627422..0bfe9049 100644
--- a/resources/js/components/Evaluations/Single/Components/Step3/AttackGraph.vue
+++ b/resources/js/components/Evaluations/Single/Components/Step3/AttackGraph.vue
@@ -21,7 +21,7 @@ export default {
     props: ['evaluation', 'maxHeight'],
     data() {
         return {
-            loaded: this.$store.state.graphs[this.evaluation.id],
+            loaded: this.$store.state.graphs[this.evaluation.id] && this.$store.state.graphs[this.evaluation.id].attack,
             options: {
                 plugins: {
                     legend: {
diff --git a/resources/js/components/Evaluations/Single/Components/Step3/ExpositionGraph.vue b/resources/js/components/Evaluations/Single/Components/Step3/ExpositionGraph.vue
index 731f33fb..00d44d81 100644
--- a/resources/js/components/Evaluations/Single/Components/Step3/ExpositionGraph.vue
+++ b/resources/js/components/Evaluations/Single/Components/Step3/ExpositionGraph.vue
@@ -19,7 +19,7 @@ export default {
     props: ['evaluation'],
     data() {
         return {
-            loaded: this.$store.state.graphs[this.evaluation.id],
+            loaded: this.$store.state.graphs[this.evaluation.id] && this.$store.state.graphs[this.evaluation.id].exposition,
             options: {
                 plugins: {
                     legend: {
diff --git a/resources/js/components/Evaluations/Single/Components/Step3/MeasuresGraph.vue b/resources/js/components/Evaluations/Single/Components/Step3/MeasuresGraph.vue
index 08e8461e..3287171b 100644
--- a/resources/js/components/Evaluations/Single/Components/Step3/MeasuresGraph.vue
+++ b/resources/js/components/Evaluations/Single/Components/Step3/MeasuresGraph.vue
@@ -1,7 +1,9 @@
 <template>
-    <Radar v-if="loaded && chartData" :chart-data="chartData" :chart-options="options" />
-    <div v-else class=" text-center">
-        <i class="fas fa-spin fa-spinner"></i>
+    <div>
+        <Radar v-if="loaded && chartData" :chart-data="chartData" :chart-options="options" />
+        <div v-else class=" text-center">
+            <i class="fas fa-spin fa-spinner"></i>
+        </div>
     </div>
 </template>
 
@@ -19,7 +21,7 @@ export default {
     props: ['evaluation'],
     data() {
         return {
-            loaded: this.$store.state.graphs[this.evaluation.id],
+            loaded: this.$store.state.graphs[this.evaluation.id] && this.$store.state.graphs[this.evaluation.id].measures,
             options: {
                 plugins: {
                     legend: {
@@ -53,6 +55,7 @@ export default {
             if (!this.$store.state.graphs[this.evaluation.id] || !this.$store.state.graphs[this.evaluation.id].measures) {
                 return null;
             }
+
             const labels = this.$store.state.graphs[this.evaluation.id].measures.labels;
             const data = this.$store.state.graphs[this.evaluation.id].measures.data;
 
diff --git a/resources/js/components/Evaluations/Single/Components/Step3/RiskGraph.vue b/resources/js/components/Evaluations/Single/Components/Step3/RiskGraph.vue
index efd3ab98..34c72a56 100644
--- a/resources/js/components/Evaluations/Single/Components/Step3/RiskGraph.vue
+++ b/resources/js/components/Evaluations/Single/Components/Step3/RiskGraph.vue
@@ -19,7 +19,7 @@ export default {
     props: ['evaluation'],
     data() {
         return {
-            loaded: this.$store.state.graphs[this.evaluation.id],
+            loaded: this.$store.state.graphs[this.evaluation.id] && this.$store.state.graphs[this.evaluation.id].risks,
             options: {
                 plugins: {
                     legend: {
diff --git a/resources/js/components/Evaluations/Single/Components/Step4/CyberRiskyGraph.vue b/resources/js/components/Evaluations/Single/Components/Step4/CyberRiskyGraph.vue
index 2b73b01f..a5bd82dd 100644
--- a/resources/js/components/Evaluations/Single/Components/Step4/CyberRiskyGraph.vue
+++ b/resources/js/components/Evaluations/Single/Components/Step4/CyberRiskyGraph.vue
@@ -32,7 +32,7 @@ export default {
     props: ['evaluation'],
     data() {
         return {
-            loaded: this.$store.state.graphs[this.evaluation.id],
+            loaded: this.$store.state.graphs[this.evaluation.id] && this.$store.state.graphs[this.evaluation.id].risks && this.$store.state.graphs[this.evaluation.id].futurerisks,
         }
     },
     computed: {
diff --git a/resources/js/components/Evaluations/Single/Steps/Step2.vue b/resources/js/components/Evaluations/Single/Steps/Step2.vue
index 12df7651..ae0463ec 100644
--- a/resources/js/components/Evaluations/Single/Steps/Step2.vue
+++ b/resources/js/components/Evaluations/Single/Steps/Step2.vue
@@ -12,8 +12,8 @@
                     <MeasureLevelChooser
                         v-for="(measure, index) in measures"
                         :key="measure.id"
-                        :index="index"
                         :ref="`Measure${measure.id}`"
+                        :index="index"
                         :measure="measure"
                         :evaluation="evaluation"
                         :is-editable="isEditable"
diff --git a/resources/js/stores/graphs.js b/resources/js/stores/graphs.js
index a84be566..4aeb6a45 100755
--- a/resources/js/stores/graphs.js
+++ b/resources/js/stores/graphs.js
@@ -7,7 +7,8 @@ export default {
             if (typeof state[id] === 'undefined') {
                 state[id] = {};
             }
-            state[id][name] = data
+
+            state[id] = {...state[id], [name]: data}
         },
         removeGraphData (state, {id}) {
             if (typeof state[id] !== 'undefined') {
@@ -17,9 +18,7 @@ export default {
     },
     actions: {
         async getGraphForEvaluation ({ commit }, {name, id}) {
-            console.log('getting graph data');
             const req = await axios.get(`/api/evaluations/${id}/graphs/${name}`)
-            console.log('got graph data', req);
             commit('setGraphData', { name, data: req.data, id })
             return req.data
         }
-- 
GitLab