From 4c27da2749bc8fdf40e8f879fb9726b42c98f6bb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timoth=C3=A9e=20Poussard?= <tpoussard@neogeo.fr>
Date: Tue, 14 Sep 2021 12:15:26 +0200
Subject: [PATCH] display file import status only for the feature_type related

---
 src/store/modules/feature_type.js             |  2 ++
 .../feature_type/Feature_type_detail.vue      | 25 +++++++++++--------
 src/views/feature_type/Feature_type_edit.vue  |  4 +--
 3 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/src/store/modules/feature_type.js b/src/store/modules/feature_type.js
index a8c4e34d..7d2f2a67 100644
--- a/src/store/modules/feature_type.js
+++ b/src/store/modules/feature_type.js
@@ -20,6 +20,8 @@ const feature_type = {
       state.feature_types = feature_types;
     },
     SET_CURRENT_FEATURE_TYPE_SLUG(state, payload) {
+      //* reset import status of features for a specific feature_type when changing
+      state.importFeatureTypeData = null;
       state.current_feature_type_slug = payload;
     },
     UPDATE_FORM(state, payload) {
diff --git a/src/views/feature_type/Feature_type_detail.vue b/src/views/feature_type/Feature_type_detail.vue
index 594d19bc..be60179f 100644
--- a/src/views/feature_type/Feature_type_detail.vue
+++ b/src/views/feature_type/Feature_type_detail.vue
@@ -57,13 +57,13 @@
         <!-- <div v-if="permissions.can_create_feature" class="ui styled accordion"> -->
         <div class="ui styled accordion">
           <div
-            @click="showImport = !showImport"
-            :class="['title', { active: !showImport }]"
+            @click="toggleShowImport"
+            :class="['title', { active: showImport }]"
           >
             <i class="dropdown icon"></i>
             Importer des signalements
           </div>
-          <div :class="['content', { active: !showImport }]">
+          <div :class="['content', { active: showImport }]">
             <div id="form-import-features" class="ui form">
               <div class="field">
                 <label class="ui icon button" for="json_file">
@@ -93,13 +93,13 @@
             </div>
           </div>
           <div
-            @click="showImport = !showImport"
-            :class="['title', { active: showImport }]"
+            @click="toggleShowImport"
+            :class="['title', { active: !showImport }]"
           >
             <i class="dropdown icon"></i>
             Exporter les signalements
           </div>
-          <div :class="['content', { active: showImport }]">
+          <div :class="['content', { active: !showImport }]">
             <p>
               Vous pouvez télécharger l'ensemble des signalements ayant le
               statut publiés pour ce type.
@@ -227,15 +227,20 @@ export default {
     },
   },
 
-  watch: {
+  /*   watch: {
     structure(newVal, oldVal) {
       if (newVal !== oldVal) {
-        this.$store.dispatch("feature_type/GET_IMPORTS", this.structure.slug);
-      }
+        }
     },
-  },
+  }, */
 
   methods: {
+    toggleShowImport() {
+      this.showImport = !this.showImport;
+      if (this.showImport) {
+        this.$store.dispatch("feature_type/GET_IMPORTS", this.structure.slug);
+      }
+    },
     onFileChange(e) {
       const files = e.target.files || e.dataTransfer.files;
       if (!files.length) return;
diff --git a/src/views/feature_type/Feature_type_edit.vue b/src/views/feature_type/Feature_type_edit.vue
index ce8b04bb..1c6744c0 100644
--- a/src/views/feature_type/Feature_type_edit.vue
+++ b/src/views/feature_type/Feature_type_edit.vue
@@ -443,7 +443,7 @@ export default {
       return "char"; //* string by default, most accepted type in database
     },
 
-    importGeoJson() {
+    importGeoJsonFeatureType() {
       if (this.geojson.features && this.geojson.features.length) {
         //* in order to get feature_type properties, the first feature is enough
         const { properties, geometry } = this.geojson.features[0];
@@ -499,7 +499,7 @@ export default {
     }
     //* when creation from a geojson
     if (this.geojson) {
-      this.importGeoJson();
+      this.importGeoJsonFeatureType();
       if (this.$store.state.feature_type.fileToImport.name) {
         this.form.title.value = // * use the filename as title by default
           this.$store.state.feature_type.fileToImport.name.split(".")[0];
-- 
GitLab