debian-mirror-gitlab/app/assets/javascripts/diffs/components/diff_content.vue

185 lines
6 KiB
Vue
Raw Normal View History

2018-11-08 19:23:39 +05:30
<script>
2019-07-31 22:56:46 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { mapActions, mapGetters, mapState } from 'vuex';
2021-09-30 23:02:18 +05:30
import { mapParallel } from 'ee_else_ce/diffs/components/diff_row_utils';
2021-03-11 19:13:27 +05:30
import DiffFileDrafts from '~/batch_comments/components/diff_file_drafts.vue';
2020-06-23 00:09:42 +05:30
import draftCommentsMixin from '~/diffs/mixins/draft_comments';
2021-03-11 19:13:27 +05:30
import { diffViewerModes } from '~/ide/constants';
import diffLineNoteFormMixin from '~/notes/mixins/diff_line_note_form';
2018-11-08 19:23:39 +05:30
import DiffViewer from '~/vue_shared/components/diff_viewer/diff_viewer.vue';
2019-07-07 11:18:12 +05:30
import NoPreviewViewer from '~/vue_shared/components/diff_viewer/viewers/no_preview.vue';
2021-03-11 19:13:27 +05:30
import NotDiffableViewer from '~/vue_shared/components/diff_viewer/viewers/not_diffable.vue';
2018-12-13 13:39:08 +05:30
import NoteForm from '../../notes/components/note_form.vue';
2020-04-22 19:07:51 +05:30
import eventHub from '../../notes/event_hub';
2021-03-11 19:13:27 +05:30
import userAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue';
2018-12-13 13:39:08 +05:30
import { IMAGE_DIFF_POSITION_TYPE } from '../constants';
import { getDiffMode } from '../store/utils';
2021-03-11 19:13:27 +05:30
import DiffDiscussions from './diff_discussions.vue';
import DiffView from './diff_view.vue';
import ImageDiffOverlay from './image_diff_overlay.vue';
2018-11-08 19:23:39 +05:30
export default {
components: {
2019-07-31 22:56:46 +05:30
GlLoadingIcon,
2021-01-29 00:20:46 +05:30
DiffView,
2018-11-08 19:23:39 +05:30
DiffViewer,
2018-12-13 13:39:08 +05:30
NoteForm,
DiffDiscussions,
ImageDiffOverlay,
2019-07-07 11:18:12 +05:30
NotDiffableViewer,
NoPreviewViewer,
2019-09-04 21:01:54 +05:30
userAvatarLink,
2020-06-23 00:09:42 +05:30
DiffFileDrafts,
2018-11-08 19:23:39 +05:30
},
2021-09-30 23:02:18 +05:30
mixins: [diffLineNoteFormMixin, draftCommentsMixin],
2018-11-08 19:23:39 +05:30
props: {
diffFile: {
type: Object,
required: true,
},
2019-02-15 15:39:39 +05:30
helpPagePath: {
type: String,
required: false,
default: '',
},
2018-11-08 19:23:39 +05:30
},
computed: {
2021-06-08 01:23:25 +05:30
...mapState('diffs', ['projectPath']),
2020-11-24 15:15:51 +05:30
...mapGetters('diffs', [
'isInlineView',
'getCommentFormForDiffFile',
'diffLines',
2021-09-04 01:27:46 +05:30
'fileLineCodequality',
2020-11-24 15:15:51 +05:30
]),
2019-09-04 21:01:54 +05:30
...mapGetters(['getNoteableData', 'noteableType', 'getUserData']),
2018-11-08 19:23:39 +05:30
diffMode() {
2018-12-13 13:39:08 +05:30
return getDiffMode(this.diffFile);
2018-11-08 19:23:39 +05:30
},
2019-07-07 11:18:12 +05:30
diffViewerMode() {
return this.diffFile.viewer.name;
},
2018-11-08 19:23:39 +05:30
isTextFile() {
2019-07-07 11:18:12 +05:30
return this.diffViewerMode === diffViewerModes.text;
},
noPreview() {
return this.diffViewerMode === diffViewerModes.no_preview;
2018-11-08 19:23:39 +05:30
},
2019-07-07 11:18:12 +05:30
notDiffable() {
return this.diffViewerMode === diffViewerModes.not_diffable;
2019-02-15 15:39:39 +05:30
},
2018-12-13 13:39:08 +05:30
diffFileCommentForm() {
2019-07-31 22:56:46 +05:30
return this.getCommentFormForDiffFile(this.diffFileHash);
2018-12-13 13:39:08 +05:30
},
showNotesContainer() {
2019-07-31 22:56:46 +05:30
return this.imageDiscussions.length || this.diffFileCommentForm;
},
diffFileHash() {
return this.diffFile.file_hash;
2018-12-13 13:39:08 +05:30
},
2019-09-04 21:01:54 +05:30
author() {
return this.getUserData;
},
2021-01-29 00:20:46 +05:30
mappedLines() {
2021-09-30 23:02:18 +05:30
// TODO: Do this data generation when we recieve a response to save a computed property being created
return this.diffLines(this.diffFile).map(mapParallel(this)) || [];
2021-01-29 00:20:46 +05:30
},
2018-12-13 13:39:08 +05:30
},
2020-04-22 19:07:51 +05:30
updated() {
2021-01-03 14:25:43 +05:30
this.$nextTick(() => {
eventHub.$emit('showBlobInteractionZones', this.diffFile.new_path);
});
2020-04-22 19:07:51 +05:30
},
2018-12-13 13:39:08 +05:30
methods: {
...mapActions('diffs', ['saveDiffDiscussion', 'closeDiffFileCommentForm']),
handleSaveNote(note) {
this.saveDiffDiscussion({
note,
formData: {
noteableData: this.getNoteableData,
noteableType: this.noteableType,
diffFile: this.diffFile,
positionType: IMAGE_DIFF_POSITION_TYPE,
x: this.diffFileCommentForm.x,
y: this.diffFileCommentForm.y,
width: this.diffFileCommentForm.width,
height: this.diffFileCommentForm.height,
},
});
},
2018-11-08 19:23:39 +05:30
},
};
</script>
<template>
<div class="diff-content">
2019-07-07 11:18:12 +05:30
<div class="diff-viewer">
2021-09-30 23:02:18 +05:30
<template v-if="isTextFile">
2021-01-29 00:20:46 +05:30
<diff-view
:diff-file="diffFile"
:diff-lines="mappedLines"
:help-page-path="helpPagePath"
:inline="isInlineView"
/>
<gl-loading-icon v-if="diffFile.renderingLines" size="md" class="mt-3" />
</template>
2019-07-07 11:18:12 +05:30
<not-diffable-viewer v-else-if="notDiffable" />
<no-preview-viewer v-else-if="noPreview" />
2018-11-08 19:23:39 +05:30
<diff-viewer
v-else
2020-06-23 00:09:42 +05:30
:diff-file="diffFile"
2018-11-08 19:23:39 +05:30
:diff-mode="diffMode"
2019-07-07 11:18:12 +05:30
:diff-viewer-mode="diffViewerMode"
2019-02-15 15:39:39 +05:30
:new-path="diffFile.new_path"
:new-sha="diffFile.diff_refs.head_sha"
2019-12-26 22:10:19 +05:30
:new-size="diffFile.new_size"
2019-02-15 15:39:39 +05:30
:old-path="diffFile.old_path"
:old-sha="diffFile.diff_refs.base_sha"
2019-12-26 22:10:19 +05:30
:old-size="diffFile.old_size"
2019-07-31 22:56:46 +05:30
:file-hash="diffFileHash"
2018-12-13 13:39:08 +05:30
:project-path="projectPath"
2019-02-15 15:39:39 +05:30
:a-mode="diffFile.a_mode"
:b-mode="diffFile.b_mode"
2018-12-13 13:39:08 +05:30
>
2021-02-22 17:27:13 +05:30
<template #image-overlay="{ renderedWidth, renderedHeight }">
<image-diff-overlay
v-if="renderedWidth"
:rendered-width="renderedWidth"
:rendered-height="renderedHeight"
:discussions="imageDiscussions"
:file-hash="diffFileHash"
:can-comment="getNoteableData.current_user.can_create_note && !diffFile.brokenSymlink"
/>
</template>
2019-02-15 15:39:39 +05:30
<div v-if="showNotesContainer" class="note-container">
2019-09-04 21:01:54 +05:30
<user-avatar-link
v-if="diffFileCommentForm && author"
:link-href="author.path"
:img-src="author.avatar_url"
:img-alt="author.name"
:img-size="40"
class="d-none d-sm-block new-comment"
/>
2018-12-13 13:39:08 +05:30
<diff-discussions
v-if="diffFile.discussions.length"
class="diff-file-discussions"
:discussions="diffFile.discussions"
2022-05-07 20:08:51 +05:30
should-collapse-discussions
render-avatar-badge
2018-12-13 13:39:08 +05:30
/>
2019-07-31 22:56:46 +05:30
<diff-file-drafts :file-hash="diffFileHash" class="diff-file-discussions" />
2018-12-13 13:39:08 +05:30
<note-form
v-if="diffFileCommentForm"
ref="noteForm"
:is-editing="false"
:save-button-title="__('Comment')"
class="diff-comment-form new-note discussion-form discussion-form-container"
2019-07-31 22:56:46 +05:30
@handleFormUpdateAddToReview="addToReview"
2018-12-13 13:39:08 +05:30
@handleFormUpdate="handleSaveNote"
2019-07-31 22:56:46 +05:30
@cancelForm="closeDiffFileCommentForm(diffFileHash)"
2019-02-15 15:39:39 +05:30
/>
2018-12-13 13:39:08 +05:30
</div>
</diff-viewer>
2018-11-08 19:23:39 +05:30
</div>
</div>
</template>