summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/batch_comments/utils.js
blob: cf4f7af0ebbe8ceeb3c9fc16ebc8a09f06f5e96d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { getFormData } from '~/diffs/store/utils';

export const getDraftReplyFormData = data => ({
  endpoint: data.notesData.draftsPath,
  data,
});

export const getDraftFormData = params => ({
  endpoint: params.notesData.draftsPath,
  data: getFormData(params),
});

export const parallelLineKey = (line, side) => (line[side] ? line[side].line_code : '');

export const showDraftOnSide = (line, side) => {
  // inline mode
  if (side === null) {
    return true;
  }

  // parallel
  if (side === 'left' || side === 'right') {
    const otherSide = side === 'left' ? 'right' : 'left';
    const thisCode = (line[side] && line[side].line_code) || '';
    const otherCode = (line[otherSide] && line[otherSide].line_code) || '';

    // either the lineCodes are different
    // or if they're the same, only show on the left side
    if (thisCode !== otherCode || (side === 'left' && thisCode === otherCode)) {
      return true;
    }
  }

  return false;
};