Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-07-28 09:11:15 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-07-28 09:11:15 +0300
commitce42a2ec96165f05c4611d012afb22baf75a9686 (patch)
treecf36134035a644c5fd8e2b865049c8e798cf92a4 /app/assets/javascripts/batch_comments
parent7f3beaceb93bb6ce188a1bf7c28b5eeeded8dee2 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/batch_comments')
-rw-r--r--app/assets/javascripts/batch_comments/components/review_bar.vue28
-rw-r--r--app/assets/javascripts/batch_comments/i18n.js3
-rw-r--r--app/assets/javascripts/batch_comments/stores/modules/batch_comments/actions.js5
3 files changed, 36 insertions, 0 deletions
diff --git a/app/assets/javascripts/batch_comments/components/review_bar.vue b/app/assets/javascripts/batch_comments/components/review_bar.vue
index 3cd1a2525e9..111b670596b 100644
--- a/app/assets/javascripts/batch_comments/components/review_bar.vue
+++ b/app/assets/javascripts/batch_comments/components/review_bar.vue
@@ -2,10 +2,20 @@
import { mapActions, mapGetters } from 'vuex';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { REVIEW_BAR_VISIBLE_CLASS_NAME } from '../constants';
+import { PREVENT_LEAVING_PENDING_REVIEW } from '../i18n';
import PreviewDropdown from './preview_dropdown.vue';
import PublishButton from './publish_button.vue';
import SubmitDropdown from './submit_dropdown.vue';
+function closeInterrupt(event) {
+ event.preventDefault();
+
+ // This is the correct way to write backwards-compatible beforeunload listeners
+ // https://developer.chrome.com/blog/page-lifecycle-api/#the-beforeunload-event
+ /* eslint-disable-next-line no-return-assign, no-param-reassign */
+ return (event.returnValue = PREVENT_LEAVING_PENDING_REVIEW);
+}
+
export default {
components: {
PreviewDropdown,
@@ -25,8 +35,26 @@ export default {
},
mounted() {
document.body.classList.add(REVIEW_BAR_VISIBLE_CLASS_NAME);
+ /*
+ * This stuff is a lot trickier than it looks.
+ *
+ * Mandatory reading: https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event
+ * Some notable sentences:
+ * - "[...] browsers may not display prompts created in beforeunload event handlers unless the
+ * page has been interacted with, or may even not display them at all."
+ * - "Especially on mobile, the beforeunload event is not reliably fired."
+ * - "The beforeunload event is not compatible with the back/forward cache (bfcache) [...]
+ * It is recommended that developers listen for beforeunload only in this scenario, and only
+ * when they actually have unsaved changes, so as to minimize the effect on performance."
+ *
+ * Please ensure that this is really not working before you modify it, because there are a LOT
+ * of scenarios where browser behavior will make it _seem_ like it's not working, but it actually
+ * is under the right combination of contexts.
+ */
+ window.addEventListener('beforeunload', closeInterrupt, { capture: true });
},
beforeDestroy() {
+ window.removeEventListener('beforeunload', closeInterrupt, { capture: true });
document.body.classList.remove(REVIEW_BAR_VISIBLE_CLASS_NAME);
},
methods: {
diff --git a/app/assets/javascripts/batch_comments/i18n.js b/app/assets/javascripts/batch_comments/i18n.js
new file mode 100644
index 00000000000..6cdbf00f9ca
--- /dev/null
+++ b/app/assets/javascripts/batch_comments/i18n.js
@@ -0,0 +1,3 @@
+import { __ } from '~/locale';
+
+export const PREVENT_LEAVING_PENDING_REVIEW = __('There are unsubmitted review comments.');
diff --git a/app/assets/javascripts/batch_comments/stores/modules/batch_comments/actions.js b/app/assets/javascripts/batch_comments/stores/modules/batch_comments/actions.js
index a44b9827fe9..863d2a99972 100644
--- a/app/assets/javascripts/batch_comments/stores/modules/batch_comments/actions.js
+++ b/app/assets/javascripts/batch_comments/stores/modules/batch_comments/actions.js
@@ -1,9 +1,12 @@
import { isEmpty } from 'lodash';
+
import createFlash from '~/flash';
import { scrollToElement } from '~/lib/utils/common_utils';
import { __ } from '~/locale';
+
import { CHANGES_TAB, DISCUSSION_TAB, SHOW_TAB } from '../../../constants';
import service from '../../../services/drafts_service';
+
import * as types from './mutation_types';
export const saveDraft = ({ dispatch }, draft) =>
@@ -15,6 +18,7 @@ export const addDraftToDiscussion = ({ commit }, { endpoint, data }) =>
.then((res) => res.data)
.then((res) => {
commit(types.ADD_NEW_DRAFT, res);
+
return res;
})
.catch(() => {
@@ -29,6 +33,7 @@ export const createNewDraft = ({ commit }, { endpoint, data }) =>
.then((res) => res.data)
.then((res) => {
commit(types.ADD_NEW_DRAFT, res);
+
return res;
})
.catch(() => {