summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/diffs/store/getters.js
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2018-07-09 18:13:41 +0100
committerFilipa Lacerda <filipa@gitlab.com>2018-07-10 12:03:00 +0100
commitac71675d3096ac9317ea230a408d69029bdadc73 (patch)
tree25ac9376545ed94915f38cd05c4ec5d0b6af2e42 /app/assets/javascripts/diffs/store/getters.js
parentcb6bc902ed1f89e7f94caa86b75e756b9163af51 (diff)
downloadgitlab-ce-ac71675d3096ac9317ea230a408d69029bdadc73.tar.gz
Fixes toggle discussion button not expanding collapsed discussions
Discussions were being toggled by jquery DOM querying them and toggling visibility but in vue, only the open discussions will be in the DOM Fix includes: - Adds a getter to the store to get the expanded discussions - Adds an action to collapse a discussion - When the user clicks the button, all data needed is now accessible through a getter and we can dispatch an action to toggle the discussion within the state, instead of showing/hiding with jQuery - Removes hardcoded properties Resolves #48237
Diffstat (limited to 'app/assets/javascripts/diffs/store/getters.js')
-rw-r--r--app/assets/javascripts/diffs/store/getters.js36
1 files changed, 35 insertions, 1 deletions
diff --git a/app/assets/javascripts/diffs/store/getters.js b/app/assets/javascripts/diffs/store/getters.js
index f3c2d7427e7..9a8d27d0b04 100644
--- a/app/assets/javascripts/diffs/store/getters.js
+++ b/app/assets/javascripts/diffs/store/getters.js
@@ -1,3 +1,4 @@
+import _ from 'underscore';
import { PARALLEL_DIFF_VIEW_TYPE, INLINE_DIFF_VIEW_TYPE } from '../constants';
export const isParallelView = state => state.diffViewType === PARALLEL_DIFF_VIEW_TYPE;
@@ -8,5 +9,38 @@ export const areAllFilesCollapsed = state => state.diffFiles.every(file => file.
export const commitId = state => (state.commit && state.commit.id ? state.commit.id : null);
-// prevent babel-plugin-rewire from generating an invalid default during karma tests
+/**
+ * Checks if the diff has all discussions expanded
+ * @param {Object} diff
+ * @returns {Boolean}
+ */
+export const diffHasAllExpandedDiscussions = (state, getters) => diff => {
+ const discussions = getters.getDiffFileDiscussions(diff);
+
+ return (discussions.length && discussions.every(discussion => discussion.expanded)) || false;
+};
+
+/**
+ * Checks if the diff has all discussions collpased
+ * @param {Object} diff
+ * @returns {Boolean}
+ */
+export const diffHasAllCollpasedDiscussions = (state, getters) => diff => {
+ const discussions = getters.getDiffFileDiscussions(diff);
+
+ return (discussions.length && discussions.every(discussion => !discussion.expanded)) || false;
+};
+
+/**
+ * Returns an array with the discussions of the given diff
+ * @param {Object} diff
+ * @returns {Array}
+ */
+export const getDiffFileDiscussions = (state, getters, rootState, rootGetters) => diff =>
+ rootGetters.discussions.filter(
+ discussion =>
+ discussion.diff_discussion && _.isEqual(discussion.diff_file.file_hash, diff.fileHash),
+ ) || [];
+
+// prevent babel-plugin-rewire from generating an invalid default during karma∂ tests
export default () => {};