Welcome to mirror list, hosted at ThFree Co, Russian Federation.

multiline_comment_form.vue « components « notes « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bb13eb87af729b5d8c4cd196432872b00f7d7c9b (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
<script>
import { mapActions } from 'vuex';
import { GlFormSelect, GlSprintf } from '@gitlab/ui';
import { getSymbol, getLineClasses } from './multiline_comment_utils';

export default {
  components: { GlFormSelect, GlSprintf },
  props: {
    lineRange: {
      type: Object,
      required: false,
      default: null,
    },
    line: {
      type: Object,
      required: true,
    },
    commentLineOptions: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      commentLineStart: {},
      commentLineEndType: this.lineRange?.end?.line_type || this.line.type,
    };
  },
  computed: {
    lineNumber() {
      return this.commentLineOptions[this.commentLineOptions.length - 1].text;
    },
  },
  created() {
    const line = this.lineRange?.start || this.line;

    this.commentLineStart = {
      line_code: line.line_code,
      type: line.type,
      old_line: line.old_line,
      new_line: line.new_line,
    };
    this.highlightSelection();
  },
  destroyed() {
    this.setSelectedCommentPosition();
  },
  methods: {
    ...mapActions(['setSelectedCommentPosition']),
    getSymbol({ type }) {
      return getSymbol(type);
    },
    getLineClasses(line) {
      return getLineClasses(line);
    },
    updateCommentLineStart(value) {
      this.commentLineStart = value;
      this.$emit('input', value);
      this.highlightSelection();
    },
    highlightSelection() {
      const { line_code, new_line, old_line, type } = this.line;
      const updatedLineRange = {
        start: { ...this.commentLineStart },
        end: { line_code, new_line, old_line, type },
      };

      this.setSelectedCommentPosition(updatedLineRange);
    },
  },
};
</script>

<template>
  <div>
    <gl-sprintf
      :message="
        s__('MergeRequestDiffs|Commenting on lines %{selectStart}start%{selectEnd} to %{end}')
      "
    >
      <template #select>
        <label for="comment-line-start" class="sr-only">{{
          s__('MergeRequestDiffs|Select comment starting line')
        }}</label>
        <gl-form-select
          id="comment-line-start"
          :value="commentLineStart"
          :options="commentLineOptions"
          size="sm"
          class="gl-w-auto gl-vertical-align-baseline"
          @change="updateCommentLineStart"
        />
      </template>
      <template #end>
        <span :class="getLineClasses(line)">
          {{ lineNumber }}
        </span>
      </template>
    </gl-sprintf>
  </div>
</template>