2018-06-21 08:22:40 -04:00
|
|
|
import { PARALLEL_DIFF_VIEW_TYPE, INLINE_DIFF_VIEW_TYPE } from '../constants';
|
|
|
|
|
2018-07-06 08:13:33 -04:00
|
|
|
export const isParallelView = state => state.diffViewType === PARALLEL_DIFF_VIEW_TYPE;
|
|
|
|
|
|
|
|
export const isInlineView = state => state.diffViewType === INLINE_DIFF_VIEW_TYPE;
|
|
|
|
|
2018-11-07 08:03:13 -05:00
|
|
|
export const hasCollapsedFile = state => state.diffFiles.some(file => file.collapsed);
|
2018-07-06 08:13:33 -04:00
|
|
|
|
|
|
|
export const commitId = state => (state.commit && state.commit.id ? state.commit.id : null);
|
|
|
|
|
2018-07-09 13:13:41 -04:00
|
|
|
/**
|
|
|
|
* Checks if the diff has all discussions expanded
|
|
|
|
* @param {Object} diff
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
export const diffHasAllExpandedDiscussions = (state, getters) => diff => {
|
|
|
|
const discussions = getters.getDiffFileDiscussions(diff);
|
|
|
|
|
2018-09-01 17:24:29 -04:00
|
|
|
return (
|
|
|
|
(discussions && discussions.length && discussions.every(discussion => discussion.expanded)) ||
|
|
|
|
false
|
|
|
|
);
|
2018-07-09 13:13:41 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the diff has all discussions collpased
|
|
|
|
* @param {Object} diff
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
export const diffHasAllCollpasedDiscussions = (state, getters) => diff => {
|
|
|
|
const discussions = getters.getDiffFileDiscussions(diff);
|
|
|
|
|
2018-09-01 17:24:29 -04:00
|
|
|
return (
|
|
|
|
(discussions && discussions.length && discussions.every(discussion => !discussion.expanded)) ||
|
|
|
|
false
|
|
|
|
);
|
2018-07-09 13:13:41 -04:00
|
|
|
};
|
|
|
|
|
2018-07-10 07:05:06 -04:00
|
|
|
/**
|
|
|
|
* Checks if the diff has any open discussions
|
|
|
|
* @param {Object} diff
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
export const diffHasExpandedDiscussions = (state, getters) => diff => {
|
|
|
|
const discussions = getters.getDiffFileDiscussions(diff);
|
|
|
|
|
|
|
|
return (
|
2018-09-01 17:24:29 -04:00
|
|
|
(discussions &&
|
|
|
|
discussions.length &&
|
|
|
|
discussions.find(discussion => discussion.expanded) !== undefined) ||
|
2018-07-10 07:05:06 -04:00
|
|
|
false
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2018-07-17 07:54:33 -04:00
|
|
|
/**
|
|
|
|
* Checks if the diff has any discussion
|
|
|
|
* @param {Boolean} diff
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
export const diffHasDiscussions = (state, getters) => diff =>
|
|
|
|
getters.getDiffFileDiscussions(diff).length > 0;
|
|
|
|
|
2018-07-09 13:13:41 -04:00
|
|
|
/**
|
|
|
|
* 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(
|
2018-11-09 14:48:41 -05:00
|
|
|
discussion => discussion.diff_discussion && discussion.diff_file.file_hash === diff.file_hash,
|
2018-07-09 13:13:41 -04:00
|
|
|
) || [];
|
|
|
|
|
2018-09-01 17:24:29 -04:00
|
|
|
export const shouldRenderParallelCommentRow = state => line => {
|
2018-08-13 04:47:54 -04:00
|
|
|
const hasDiscussion =
|
2018-09-01 17:24:29 -04:00
|
|
|
(line.left && line.left.discussions && line.left.discussions.length) ||
|
|
|
|
(line.right && line.right.discussions && line.right.discussions.length);
|
2018-08-13 04:47:54 -04:00
|
|
|
|
|
|
|
const hasExpandedDiscussionOnLeft =
|
2018-09-01 17:24:29 -04:00
|
|
|
line.left && line.left.discussions && line.left.discussions.length
|
2018-08-13 04:47:54 -04:00
|
|
|
? line.left.discussions.every(discussion => discussion.expanded)
|
|
|
|
: false;
|
|
|
|
const hasExpandedDiscussionOnRight =
|
2018-09-01 17:24:29 -04:00
|
|
|
line.right && line.right.discussions && line.right.discussions.length
|
2018-08-13 04:47:54 -04:00
|
|
|
? line.right.discussions.every(discussion => discussion.expanded)
|
|
|
|
: false;
|
2018-08-07 22:50:01 -04:00
|
|
|
|
|
|
|
if (hasDiscussion && (hasExpandedDiscussionOnLeft || hasExpandedDiscussionOnRight)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-11-09 14:48:41 -05:00
|
|
|
const hasCommentFormOnLeft = line.left && state.diffLineCommentForms[line.left.line_code];
|
|
|
|
const hasCommentFormOnRight = line.right && state.diffLineCommentForms[line.right.line_code];
|
2018-08-07 22:50:01 -04:00
|
|
|
|
|
|
|
return hasCommentFormOnLeft || hasCommentFormOnRight;
|
|
|
|
};
|
|
|
|
|
2018-09-01 17:24:29 -04:00
|
|
|
export const shouldRenderInlineCommentRow = state => line => {
|
2018-11-09 14:48:41 -05:00
|
|
|
if (state.diffLineCommentForms[line.line_code]) return true;
|
2018-08-07 22:50:01 -04:00
|
|
|
|
2018-09-02 17:26:25 -04:00
|
|
|
if (!line.discussions || line.discussions.length === 0) {
|
2018-08-07 22:50:01 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-01 17:24:29 -04:00
|
|
|
return line.discussions.every(discussion => discussion.expanded);
|
2018-08-07 22:50:01 -04:00
|
|
|
};
|
|
|
|
|
2018-07-09 13:13:41 -04:00
|
|
|
// prevent babel-plugin-rewire from generating an invalid default during karma∂ tests
|
2018-07-17 11:47:02 -04:00
|
|
|
export const getDiffFileByHash = state => fileHash =>
|
2018-11-09 14:48:41 -05:00
|
|
|
state.diffFiles.find(file => file.file_hash === fileHash);
|
2018-07-17 11:47:02 -04:00
|
|
|
|
2018-10-03 05:05:43 -04:00
|
|
|
export const allBlobs = state => Object.values(state.treeEntries).filter(f => f.type === 'blob');
|
|
|
|
|
|
|
|
export const diffFilesLength = state => state.diffFiles.length;
|
|
|
|
|
2018-10-18 03:50:38 -04:00
|
|
|
export const getCommentFormForDiffFile = state => fileHash =>
|
|
|
|
state.commentForms.find(form => form.fileHash === fileHash);
|
|
|
|
|
2018-07-17 11:47:02 -04:00
|
|
|
// prevent babel-plugin-rewire from generating an invalid default during karma tests
|
2018-07-06 08:13:33 -04:00
|
|
|
export default () => {};
|