From fee064be01e6e37076b9af4028ade12a2ce0180a Mon Sep 17 00:00:00 2001
From: Phil Hughes <me@iamphill.com>
Date: Fri, 3 Feb 2017 14:48:31 +0000
Subject: [PATCH] Fixed modal lists dropdown not updating when list is deleted

---
 .../javascripts/boards/boards_bundle.js.es6   |  4 ----
 .../components/modal/lists_dropdown.js.es6    |  5 ++++-
 .../boards/stores/modal_store.js.es6          |  2 +-
 spec/features/boards/add_issues_modal_spec.rb | 21 +++++++++++++++++++
 4 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/app/assets/javascripts/boards/boards_bundle.js.es6 b/app/assets/javascripts/boards/boards_bundle.js.es6
index 4ac91786762..529ea9aec5b 100644
--- a/app/assets/javascripts/boards/boards_bundle.js.es6
+++ b/app/assets/javascripts/boards/boards_bundle.js.es6
@@ -71,10 +71,6 @@ $(() => {
 
           Store.addBlankState();
           this.loading = false;
-
-          if (this.state.lists.length > 0) {
-            ModalStore.store.selectedList = this.state.lists[0];
-          }
         });
     }
   });
diff --git a/app/assets/javascripts/boards/components/modal/lists_dropdown.js.es6 b/app/assets/javascripts/boards/components/modal/lists_dropdown.js.es6
index 96f12da3753..3c05120a2da 100644
--- a/app/assets/javascripts/boards/components/modal/lists_dropdown.js.es6
+++ b/app/assets/javascripts/boards/components/modal/lists_dropdown.js.es6
@@ -11,9 +11,12 @@
     },
     computed: {
       selected() {
-        return this.modal.selectedList;
+        return this.modal.selectedList || this.state.lists[0];
       },
     },
+    destroyed() {
+      this.modal.selectedList = null;
+    },
     template: `
       <div class="dropdown inline">
         <button
diff --git a/app/assets/javascripts/boards/stores/modal_store.js.es6 b/app/assets/javascripts/boards/stores/modal_store.js.es6
index fa46b6135e0..73518b42b84 100644
--- a/app/assets/javascripts/boards/stores/modal_store.js.es6
+++ b/app/assets/javascripts/boards/stores/modal_store.js.es6
@@ -11,7 +11,7 @@
         selectedIssues: [],
         showAddIssuesModal: false,
         activeTab: 'all',
-        selectedList: {},
+        selectedList: null,
         searchTerm: '',
         loading: false,
         loadingNewPage: false,
diff --git a/spec/features/boards/add_issues_modal_spec.rb b/spec/features/boards/add_issues_modal_spec.rb
index b953480cec2..2875fc1e533 100644
--- a/spec/features/boards/add_issues_modal_spec.rb
+++ b/spec/features/boards/add_issues_modal_spec.rb
@@ -76,6 +76,27 @@ describe 'Issue Boards add issue modal', :feature, :js do
       end
     end
 
+    context 'list dropdown' do
+      it 'resets after deleting list' do
+        page.within('.add-issues-modal') do
+          expect(find('.add-issues-footer')).to have_button(planning.title)
+
+          click_button 'Cancel'
+        end
+
+        first('.board-delete').click
+
+        click_button('Add issues')
+
+        wait_for_vue_resource
+
+        page.within('.add-issues-modal') do
+          expect(find('.add-issues-footer')).not_to have_button(planning.title)
+          expect(find('.add-issues-footer')).to have_button(label.title)
+        end
+      end
+    end
+
     context 'search' do
       it 'returns issues' do
         page.within('.add-issues-modal') do
-- 
GitLab