Commit b13ecdd6 authored by Phil Hughes's avatar Phil Hughes

CE backport of image-comment-reviews

parent 0276b868
<script> <script>
import { mapActions, mapGetters, mapState } from 'vuex'; import { mapActions, mapGetters, mapState } from 'vuex';
import diffLineNoteFormMixin from 'ee_else_ce/notes/mixins/diff_line_note_form';
import draftCommentsMixin from 'ee_else_ce/diffs/mixins/draft_comments';
import DiffViewer from '~/vue_shared/components/diff_viewer/diff_viewer.vue'; import DiffViewer from '~/vue_shared/components/diff_viewer/diff_viewer.vue';
import NotDiffableViewer from '~/vue_shared/components/diff_viewer/viewers/not_diffable.vue'; import NotDiffableViewer from '~/vue_shared/components/diff_viewer/viewers/not_diffable.vue';
import NoPreviewViewer from '~/vue_shared/components/diff_viewer/viewers/no_preview.vue'; import NoPreviewViewer from '~/vue_shared/components/diff_viewer/viewers/no_preview.vue';
...@@ -22,7 +24,9 @@ export default { ...@@ -22,7 +24,9 @@ export default {
ImageDiffOverlay, ImageDiffOverlay,
NotDiffableViewer, NotDiffableViewer,
NoPreviewViewer, NoPreviewViewer,
DiffFileDrafts: () => import('ee_component/batch_comments/components/diff_file_drafts.vue'),
}, },
mixins: [diffLineNoteFormMixin, draftCommentsMixin],
props: { props: {
diffFile: { diffFile: {
type: Object, type: Object,
...@@ -58,10 +62,13 @@ export default { ...@@ -58,10 +62,13 @@ export default {
return this.diffViewerMode === diffViewerModes.not_diffable; return this.diffViewerMode === diffViewerModes.not_diffable;
}, },
diffFileCommentForm() { diffFileCommentForm() {
return this.getCommentFormForDiffFile(this.diffFile.file_hash); return this.getCommentFormForDiffFile(this.diffFileHash);
}, },
showNotesContainer() { showNotesContainer() {
return this.diffFile.discussions.length || this.diffFileCommentForm; return this.imageDiscussions.length || this.diffFileCommentForm;
},
diffFileHash() {
return this.diffFile.file_hash;
}, },
}, },
methods: { methods: {
...@@ -112,15 +119,15 @@ export default { ...@@ -112,15 +119,15 @@ export default {
:new-sha="diffFile.diff_refs.head_sha" :new-sha="diffFile.diff_refs.head_sha"
:old-path="diffFile.old_path" :old-path="diffFile.old_path"
:old-sha="diffFile.diff_refs.base_sha" :old-sha="diffFile.diff_refs.base_sha"
:file-hash="diffFile.file_hash" :file-hash="diffFileHash"
:project-path="projectPath" :project-path="projectPath"
:a-mode="diffFile.a_mode" :a-mode="diffFile.a_mode"
:b-mode="diffFile.b_mode" :b-mode="diffFile.b_mode"
> >
<image-diff-overlay <image-diff-overlay
slot="image-overlay" slot="image-overlay"
:discussions="diffFile.discussions" :discussions="imageDiscussions"
:file-hash="diffFile.file_hash" :file-hash="diffFileHash"
:can-comment="getNoteableData.current_user.can_create_note" :can-comment="getNoteableData.current_user.can_create_note"
/> />
<div v-if="showNotesContainer" class="note-container"> <div v-if="showNotesContainer" class="note-container">
...@@ -131,14 +138,16 @@ export default { ...@@ -131,14 +138,16 @@ export default {
:should-collapse-discussions="true" :should-collapse-discussions="true"
:render-avatar-badge="true" :render-avatar-badge="true"
/> />
<diff-file-drafts :file-hash="diffFileHash" class="diff-file-discussions" />
<note-form <note-form
v-if="diffFileCommentForm" v-if="diffFileCommentForm"
ref="noteForm" ref="noteForm"
:is-editing="false" :is-editing="false"
:save-button-title="__('Comment')" :save-button-title="__('Comment')"
class="diff-comment-form new-note discussion-form discussion-form-container" class="diff-comment-form new-note discussion-form discussion-form-container"
@handleFormUpdateAddToReview="addToReview"
@handleFormUpdate="handleSaveNote" @handleFormUpdate="handleSaveNote"
@cancelForm="closeDiffFileCommentForm(diffFile.file_hash)" @cancelForm="closeDiffFileCommentForm(diffFileHash)"
/> />
</div> </div>
</diff-viewer> </diff-viewer>
......
<script> <script>
import { mapActions, mapGetters } from 'vuex'; import { mapActions, mapGetters } from 'vuex';
import _ from 'underscore'; import _ from 'underscore';
import imageDiffMixin from 'ee_else_ce/diffs/mixins/image_diff';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
export default { export default {
...@@ -8,6 +9,7 @@ export default { ...@@ -8,6 +9,7 @@ export default {
components: { components: {
Icon, Icon,
}, },
mixins: [imageDiffMixin],
props: { props: {
discussions: { discussions: {
type: [Array, Object], type: [Array, Object],
...@@ -48,7 +50,6 @@ export default { ...@@ -48,7 +50,6 @@ export default {
}, },
}, },
methods: { methods: {
...mapActions(['toggleDiscussion']),
...mapActions('diffs', ['openDiffFileCommentForm']), ...mapActions('diffs', ['openDiffFileCommentForm']),
getImageDimensions() { getImageDimensions() {
return { return {
...@@ -105,15 +106,15 @@ export default { ...@@ -105,15 +106,15 @@ export default {
v-for="(discussion, index) in allDiscussions" v-for="(discussion, index) in allDiscussions"
:key="discussion.id" :key="discussion.id"
:style="getPosition(discussion)" :style="getPosition(discussion)"
:class="badgeClass" :class="[badgeClass, { 'is-draft': discussion.isDraft }]"
:disabled="!shouldToggleDiscussion" :disabled="!shouldToggleDiscussion"
class="js-image-badge" class="js-image-badge"
type="button" type="button"
@click="toggleDiscussion({ discussionId: discussion.id })" @click="clickedToggle(discussion)"
> >
<icon v-if="showCommentIcon" name="image-comment-dark" /> <icon v-if="showCommentIcon" name="image-comment-dark" />
<template v-else> <template v-else>
{{ index + 1 }} {{ toggleText(discussion, index) }}
</template> </template>
</button> </button>
<button <button
......
...@@ -3,5 +3,8 @@ export default { ...@@ -3,5 +3,8 @@ export default {
shouldRenderDraftRow: () => () => false, shouldRenderDraftRow: () => () => false,
shouldRenderParallelDraftRow: () => () => false, shouldRenderParallelDraftRow: () => () => false,
draftForLine: () => () => ({}), draftForLine: () => () => ({}),
imageDiscussions() {
return this.diffFile.discussions;
},
}, },
}; };
import { mapActions } from 'vuex';
export default {
methods: {
...mapActions(['toggleDiscussion']),
clickedToggle(discussion) {
this.toggleDiscussion({ discussionId: discussion.id });
},
toggleText(discussion, index) {
return index + 1;
},
},
};
...@@ -160,7 +160,9 @@ export default { ...@@ -160,7 +160,9 @@ export default {
} }
if (!file.parallel_diff_lines || !file.highlighted_diff_lines) { if (!file.parallel_diff_lines || !file.highlighted_diff_lines) {
file.discussions = (file.discussions || []).concat(discussion); file.discussions = (file.discussions || [])
.filter(d => d.id !== discussion.id)
.concat(discussion);
} }
return file; return file;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment