debian-mirror-gitlab/app/assets/javascripts/notes/components/multiline_comment_form.vue

103 lines
2.4 KiB
Vue
Raw Normal View History

2020-06-23 00:09:42 +05:30
<script>
import { GlFormSelect, GlSprintf } from '@gitlab/ui';
2021-12-11 22:18:48 +05:30
import { mapActions } from 'vuex';
2020-06-23 00:09:42 +05:30
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 {
2020-07-28 23:09:34 +05:30
commentLineStart: {},
commentLineEndType: this.lineRange?.end?.line_type || this.line.type,
2020-06-23 00:09:42 +05:30
};
},
2020-07-28 23:09:34 +05:30
computed: {
lineNumber() {
return this.commentLineOptions[this.commentLineOptions.length - 1].text;
},
},
created() {
2021-12-11 22:18:48 +05:30
const line = this.lineRange?.start || this.line;
2020-07-28 23:09:34 +05:30
this.commentLineStart = {
line_code: line.line_code,
type: line.type,
old_line: line.old_line,
new_line: line.new_line,
};
2021-03-08 18:12:59 +05:30
2020-07-28 23:09:34 +05:30
this.highlightSelection();
},
destroyed() {
this.setSelectedCommentPosition();
},
2020-06-23 00:09:42 +05:30
methods: {
2020-07-28 23:09:34 +05:30
...mapActions(['setSelectedCommentPosition']),
2020-06-23 00:09:42 +05:30
getSymbol({ type }) {
return getSymbol(type);
},
getLineClasses(line) {
return getLineClasses(line);
},
2020-07-28 23:09:34 +05:30
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);
},
2020-06-23 00:09:42 +05:30
},
};
</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"
2020-07-28 23:09:34 +05:30
@change="updateCommentLineStart"
2020-06-23 00:09:42 +05:30
/>
</template>
<template #end>
<span :class="getLineClasses(line)">
2020-07-28 23:09:34 +05:30
{{ lineNumber }}
2020-06-23 00:09:42 +05:30
</span>
</template>
</gl-sprintf>
</div>
</template>