summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/diffs/components/parallel_diff_comment_row.vue
blob: 26417c350cb463e73a54fee3b4f5bbc29a53c204 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<script>
import { mapState } from 'vuex';
import diffDiscussions from './diff_discussions.vue';
import diffLineNoteForm from './diff_line_note_form.vue';

export default {
  components: {
    diffDiscussions,
    diffLineNoteForm,
  },
  props: {
    line: {
      type: Object,
      required: true,
    },
    diffFileHash: {
      type: String,
      required: true,
    },
    lineIndex: {
      type: Number,
      required: true,
    },
  },
  computed: {
    ...mapState({
      diffLineCommentForms: state => state.diffs.diffLineCommentForms,
    }),
    leftLineCode() {
      return this.line.left && this.line.left.lineCode;
    },
    rightLineCode() {
      return this.line.right && this.line.right.lineCode;
    },
    hasExpandedDiscussionOnLeft() {
      return this.line.left && this.line.left.discussions
        ? this.line.left.discussions.every(discussion => discussion.expanded)
        : false;
    },
    hasExpandedDiscussionOnRight() {
      return this.line.right && this.line.right.discussions
        ? this.line.right.discussions.every(discussion => discussion.expanded)
        : false;
    },
    hasAnyExpandedDiscussion() {
      return this.hasExpandedDiscussionOnLeft || this.hasExpandedDiscussionOnRight;
    },
    shouldRenderDiscussionsOnLeft() {
      return this.line.left && this.line.left.discussions && this.hasExpandedDiscussionOnLeft;
    },
    shouldRenderDiscussionsOnRight() {
      return (
        this.line.right &&
        this.line.right.discussions &&
        this.hasExpandedDiscussionOnRight &&
        this.line.right.type
      );
    },
    showRightSideCommentForm() {
      return (
        this.line.right && this.line.right.type && this.diffLineCommentForms[this.rightLineCode]
      );
    },
    className() {
      return (this.left && this.line.left.discussions.length > 0) ||
        (this.right && this.line.right.discussions.length > 0)
        ? ''
        : 'js-temp-notes-holder';
    },
  },
};
</script>

<template>
  <tr
    :class="className"
    class="notes_holder"
  >
    <td class="notes_line old"></td>
    <td class="notes_content parallel old">
      <div
        v-if="shouldRenderDiscussionsOnLeft"
        class="content"
      >
        <diff-discussions
          v-if="line.left.discussions.length"
          :discussions="line.left.discussions"
        />
      </div>
      <diff-line-note-form
        v-if="diffLineCommentForms[leftLineCode]"
        :diff-file-hash="diffFileHash"
        :line="line.left"
        :note-target-line="line.left"
        position="left"
      />
    </td>
    <td class="notes_line new"></td>
    <td class="notes_content parallel new">
      <div
        v-if="shouldRenderDiscussionsOnRight"
        class="content"
      >
        <diff-discussions
          v-if="line.right.discussions.length"
          :discussions="line.right.discussions"
        />
      </div>
      <diff-line-note-form
        v-if="showRightSideCommentForm"
        :diff-file-hash="diffFileHash"
        :line="line.right"
        :note-target-line="line.right"
        position="right"
      />
    </td>
  </tr>
</template>