diff options
author | Tim Zallmann <tzallmann@gitlab.com> | 2018-09-02 00:24:29 +0300 |
---|---|---|
committer | Tim Zallmann <tzallmann@gitlab.com> | 2018-09-07 13:25:50 +0300 |
commit | b8b2cb3675a38fa0460add7a1cab03abbaeb56fd (patch) | |
tree | 2af2939435bff5af4d0f88e12cb13d3dbb8f6bca /app/assets/javascripts/diffs/store/getters.js | |
parent | d7a5d5b6945f63e6a69aa17cf9b652daaa2fe7da (diff) |
Fixed Problems with Inline View + Specs
Diffstat (limited to 'app/assets/javascripts/diffs/store/getters.js')
-rw-r--r-- | app/assets/javascripts/diffs/store/getters.js | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/app/assets/javascripts/diffs/store/getters.js b/app/assets/javascripts/diffs/store/getters.js index f56b0ac695e..2a9191cde8a 100644 --- a/app/assets/javascripts/diffs/store/getters.js +++ b/app/assets/javascripts/diffs/store/getters.js @@ -17,7 +17,10 @@ export const commitId = state => (state.commit && state.commit.id ? state.commit export const diffHasAllExpandedDiscussions = (state, getters) => diff => { const discussions = getters.getDiffFileDiscussions(diff); - return (discussions.length && discussions.every(discussion => discussion.expanded)) || false; + return ( + (discussions && discussions.length && discussions.every(discussion => discussion.expanded)) || + false + ); }; /** @@ -28,7 +31,10 @@ export const diffHasAllExpandedDiscussions = (state, getters) => diff => { export const diffHasAllCollpasedDiscussions = (state, getters) => diff => { const discussions = getters.getDiffFileDiscussions(diff); - return (discussions.length && discussions.every(discussion => !discussion.expanded)) || false; + return ( + (discussions && discussions.length && discussions.every(discussion => !discussion.expanded)) || + false + ); }; /** @@ -40,7 +46,9 @@ export const diffHasExpandedDiscussions = (state, getters) => diff => { const discussions = getters.getDiffFileDiscussions(diff); return ( - (discussions.length && discussions.find(discussion => discussion.expanded) !== undefined) || + (discussions && + discussions.length && + discussions.find(discussion => discussion.expanded) !== undefined) || false ); }; @@ -64,17 +72,6 @@ export const getDiffFileDiscussions = (state, getters, rootState, rootGetters) = discussion.diff_discussion && _.isEqual(discussion.diff_file.file_hash, diff.fileHash), ) || []; -export const singleDiscussionByLineCodeOld = ( - state, - getters, - rootState, - rootGetters, -) => lineCode => { - if (!lineCode || lineCode === undefined) return []; - const discussions = rootGetters.discussionsByLineCode; - return discussions[lineCode] || []; -}; - /** * Returns an Object with discussions by their diff line code * To avoid rendering outdated discussions on the Changes tab we should do a bunch of SHA @@ -113,16 +110,17 @@ export const discussionsByLineCode = (state, getters, rootState, rootGetters) => }, {}); }; -export const shouldRenderParallelCommentRow = (state, getters) => line => { +export const shouldRenderParallelCommentRow = state => line => { const hasDiscussion = - (line.left && line.left.discussions.length) || (line.right && line.right.discussions.length); + (line.left && line.left.discussions && line.left.discussions.length) || + (line.right && line.right.discussions && line.right.discussions.length); const hasExpandedDiscussionOnLeft = - line.left && line.left.discussions.length + line.left && line.left.discussions && line.left.discussions.length ? line.left.discussions.every(discussion => discussion.expanded) : false; const hasExpandedDiscussionOnRight = - line.right && line.right.discussions.length + line.right && line.right.discussions && line.right.discussions.length ? line.right.discussions.every(discussion => discussion.expanded) : false; @@ -136,15 +134,14 @@ export const shouldRenderParallelCommentRow = (state, getters) => line => { return hasCommentFormOnLeft || hasCommentFormOnRight; }; -export const shouldRenderInlineCommentRow = (state, getters) => line => { +export const shouldRenderInlineCommentRow = state => line => { if (state.diffLineCommentForms[line.lineCode]) return true; - const lineDiscussions = getters.singleDiscussionByLineCode(line.lineCode); - if (lineDiscussions.length === 0) { + if (!line.discussions && line.discussions.length === 0) { return false; } - return lineDiscussions.every(discussion => discussion.expanded); + return line.discussions.every(discussion => discussion.expanded); }; // prevent babel-plugin-rewire from generating an invalid default during karma∂ tests |