From 9421e926bca19cbe09c45d6566ec65ceeaf771cc Mon Sep 17 00:00:00 2001 From: Raffael Sahli Date: Thu, 2 Apr 2020 11:14:40 +0200 Subject: [PATCH 1/2] wait for all actions and fullfil reload at the end once --- src/App.vue | 30 ++++++++++++++++++++---------- src/components/AlertList.vue | 16 ++++++++++++---- src/store/modules/alerts.store.ts | 22 ++++++---------------- 3 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/App.vue b/src/App.vue index 92dc6461..2e68ef56 100644 --- a/src/App.vue +++ b/src/App.vue @@ -692,11 +692,13 @@ export default { this.$store.dispatch('alerts/updateSelected', []) }, takeBulkAction(action) { - this.selected.map(a => this.$store.dispatch('alerts/takeAction', [a.id, action, ''])) - .reduce(() => this.clearSelected()) + Promise.all(this.selected.map(a => this.$store.dispatch('alerts/takeAction', [a.id, action, '']))).then(() => { + this.clearSelected() + this.$store.dispatch('alerts/getAlerts') + }) }, bulkShelveAlert() { - this.selected.map(a => { + Promise.All(this.selected.map(a => { this.$store .dispatch('alerts/takeAction', [ a.id, @@ -704,21 +706,27 @@ export default { '', this.shelveTimeout ]) + })).then(() => { + this.clearSelected() + this.$store.dispatch('alerts/getAlerts') }) - .reduce(() => this.clearSelected()) }, isWatched(tags) { const tag = `watch:${this.username}` return tags ? tags.indexOf(tag) > -1 : false }, toggleWatch() { + var map if (this.selected.some(x => !this.isWatched(x.tags))) { - this.selected.map(a => this.watchAlert(a.id)) - .reduce(() => this.clearSelected()) + map = this.selected.map(a => this.watchAlert(a.id)) } else { - this.selected.map(a => this.unwatchAlert(a.id)) - .reduce(() => this.clearSelected()) + map = this.selected.map(a => this.unwatchAlert(a.id)) } + + Promise.All(map).then(() => { + this.clearSelected() + this.$store.dispatch('alerts/getAlerts') + }) }, watchAlert(id) { this.$store.dispatch('alerts/watchAlert', id) @@ -728,8 +736,10 @@ export default { }, bulkDeleteAlert() { confirm(i18n.t('ConfirmDelete')) && - this.selected.map(a => this.$store.dispatch('alerts/deleteAlert', a.id)) - .reduce(() => this.clearSelected()) + Promise.all(this.selected.map(a => this.$store.dispatch('alerts/deleteAlert', a.id, false))).then(() => { + this.clearSelected() + this.$store.dispatch('alerts/getAlerts') + }) }, toggle(sw, value) { this.$store.dispatch('alerts/toggle', [sw, value]) diff --git a/src/components/AlertList.vue b/src/components/AlertList.vue index e87d277d..e8cf0d79 100644 --- a/src/components/AlertList.vue +++ b/src/components/AlertList.vue @@ -609,7 +609,9 @@ export default { }, takeAction: debounce(function(id, action) { this.$store - .dispatch('alerts/takeAction', [id, action, '']) + .dispatch('alerts/takeAction', [id, action, '']).then(() => { + this.$store.dispatch('alerts/getAlerts') + }) }, 200, {leading: true, trailing: false}), shelveAlert: debounce(function(id) { this.$store @@ -622,15 +624,21 @@ export default { }, 200, {leading: true, trailing: false}), watchAlert: debounce(function(id) { this.$store - .dispatch('alerts/watchAlert', id) + .dispatch('alerts/watchAlert', id).then(() => { + this.$store.dispatch('alerts/getAlerts') + }) }, 200, {leading: true, trailing: false}), unwatchAlert: debounce(function(id) { this.$store - .dispatch('alerts/unwatchAlert', id) + .dispatch('alerts/unwatchAlert', id).then(() => { + this.$store.dispatch('alerts/getAlerts') + }) }, 200, {leading: true, trailing: false}), deleteAlert: debounce(function(id) { confirm(i18n.t('ConfirmDelete')) && - this.$store.dispatch('alerts/deleteAlert', id) + this.$store.dispatch('alerts/deleteAlert', id).then(() => { + this.$store.dispatch('alerts/getAlerts') + }) }, 200, {leading: true, trailing: false}), } } diff --git a/src/store/modules/alerts.store.ts b/src/store/modules/alerts.store.ts index d945a525..5e0c5df4 100644 --- a/src/store/modules/alerts.store.ts +++ b/src/store/modules/alerts.store.ts @@ -170,33 +170,25 @@ const actions = { watchAlert({ commit, dispatch, rootState}, alertId) { const username = rootState.auth.payload.preferred_username const tag = `watch:${username}` - return AlertsApi.tagAlert(alertId, {tags: [tag]}).then(response => - dispatch('getAlerts') - ) + return AlertsApi.tagAlert(alertId, {tags: [tag]}) }, unwatchAlert({ commit, dispatch, rootState}, alertId) { const username = rootState.auth.payload.preferred_username const tag = `watch:${username}` - return AlertsApi.untagAlert(alertId, {tags: [tag]}).then(response => - dispatch('getAlerts') - ) + return AlertsApi.untagAlert(alertId, {tags: [tag]}) }, takeAction({ commit, dispatch }, [alertId, action, text, timeout]) { return AlertsApi.actionAlert(alertId, { action: action, text: text, timeout: timeout - }).then(response => dispatch('getAlerts')) + }) }, tagAlert({ commit, dispatch }, [alertId, tags]) { - return AlertsApi.tagAlert(alertId, tags).then(response => - dispatch('getAlerts') - ) + return AlertsApi.tagAlert(alertId, tags) }, untagAlert({ commit, dispatch }, [alertId, tags]) { - return AlertsApi.untagAlert(alertId, tags).then(response => - dispatch('getAlerts') - ) + return AlertsApi.untagAlert(alertId, tags) }, addNote({ commit, dispatch }, [alertId, note]) { return AlertsApi.addNote(alertId, { @@ -204,9 +196,7 @@ const actions = { }).then(response => dispatch('getAlerts')) }, deleteAlert({ commit, dispatch }, alertId) { - return AlertsApi.deleteAlert(alertId).then(response => - dispatch('getAlerts') - ) + return AlertsApi.deleteAlert(alertId) }, getEnvironments({ commit }) { From 02b0787f6ed530d5c93b59e0445670d35ee3dc80 Mon Sep 17 00:00:00 2001 From: Raffael Sahli Date: Thu, 2 Apr 2020 11:27:34 +0200 Subject: [PATCH 2/2] fixes typo --- src/App.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/App.vue b/src/App.vue index 2e68ef56..8a8179f7 100644 --- a/src/App.vue +++ b/src/App.vue @@ -698,7 +698,7 @@ export default { }) }, bulkShelveAlert() { - Promise.All(this.selected.map(a => { + Promise.all(this.selected.map(a => { this.$store .dispatch('alerts/takeAction', [ a.id, @@ -723,7 +723,7 @@ export default { map = this.selected.map(a => this.unwatchAlert(a.id)) } - Promise.All(map).then(() => { + Promise.all(map).then(() => { this.clearSelected() this.$store.dispatch('alerts/getAlerts') })