Commit 173ecfc4 authored by Tim Zallmann's avatar Tim Zallmann

Delete Discussions fix

parent 958cf02e
<script> <script>
import { mapActions } from 'vuex';
import noteableDiscussion from '../../notes/components/noteable_discussion.vue'; import noteableDiscussion from '../../notes/components/noteable_discussion.vue';
export default { export default {
...@@ -11,6 +12,14 @@ export default { ...@@ -11,6 +12,14 @@ export default {
required: true, required: true,
}, },
}, },
methods: {
...mapActions('diffs', ['removeDiscussionsFromDiff']),
deleteNoteHandler(discussion) {
if (discussion.notes.length <= 1) {
this.removeDiscussionsFromDiff(discussion);
}
},
},
}; };
</script> </script>
...@@ -31,6 +40,7 @@ export default { ...@@ -31,6 +40,7 @@ export default {
:render-diff-file="false" :render-diff-file="false"
:always-expanded="true" :always-expanded="true"
:discussions-by-diff-order="true" :discussions-by-diff-order="true"
@handleNoteDelete="deleteNoteHandler"
/> />
</ul> </ul>
</div> </div>
......
...@@ -57,6 +57,30 @@ export const assignDiscussionsToDiff = ({ state }, allLineDiscussions) => { ...@@ -57,6 +57,30 @@ export const assignDiscussionsToDiff = ({ state }, allLineDiscussions) => {
}); });
}; };
export const removeDiscussionsFromDiff = ({ state }, removeDiscussion) => {
const { fileHash } = removeDiscussion;
const selectedFile = state.diffFiles.find(file => file.fileHash === fileHash);
if (selectedFile) {
const targetLine = selectedFile.parallelDiffLines.find(
line =>
(line.left && line.left.lineCode === removeDiscussion.line_code) ||
(line.right && line.right.lineCode === removeDiscussion.line_code),
);
if (targetLine) {
Object.assign(targetLine.right, { discussions: [] });
}
const targetInlineLine = selectedFile.highlightedDiffLines.find(
line => line.lineCode === removeDiscussion.line_code,
);
if (targetInlineLine) {
Object.assign(targetInlineLine, { discussions: [] });
}
}
};
export const startRenderDiffsQueue = ({ state, commit }) => { export const startRenderDiffsQueue = ({ state, commit }) => {
const checkItem = () => const checkItem = () =>
new Promise(resolve => { new Promise(resolve => {
......
...@@ -137,8 +137,10 @@ export default { ...@@ -137,8 +137,10 @@ export default {
return this.unresolvedDiscussions.length > 1; return this.unresolvedDiscussions.length > 1;
}, },
showJumpToNextDiscussion() { showJumpToNextDiscussion() {
return this.hasMultipleUnresolvedDiscussions && return (
!this.isLastUnresolvedDiscussion(this.discussion.id, this.discussionsByDiffOrder); this.hasMultipleUnresolvedDiscussions &&
!this.isLastUnresolvedDiscussion(this.discussion.id, this.discussionsByDiffOrder)
);
}, },
shouldRenderDiffs() { shouldRenderDiffs() {
const { diffDiscussion, diffFile } = this.transformedDiscussion; const { diffDiscussion, diffFile } = this.transformedDiscussion;
...@@ -256,11 +258,16 @@ Please check your network connection and try again.`; ...@@ -256,11 +258,16 @@ Please check your network connection and try again.`;
}); });
}, },
jumpToNextDiscussion() { jumpToNextDiscussion() {
const nextId = const nextId = this.nextUnresolvedDiscussionId(
this.nextUnresolvedDiscussionId(this.discussion.id, this.discussionsByDiffOrder); this.discussion.id,
this.discussionsByDiffOrder,
);
this.jumpToDiscussion(nextId); this.jumpToDiscussion(nextId);
}, },
deleteNoteHandler(note) {
this.$emit('handleNoteDelete', this.discussion, note);
},
}, },
}; };
</script> </script>
...@@ -270,6 +277,7 @@ Please check your network connection and try again.`; ...@@ -270,6 +277,7 @@ Please check your network connection and try again.`;
<div class="timeline-entry-inner"> <div class="timeline-entry-inner">
<div class="timeline-icon"> <div class="timeline-icon">
<user-avatar-link <user-avatar-link
v-if="author"
:link-href="author.path" :link-href="author.path"
:img-src="author.avatar_url" :img-src="author.avatar_url"
:img-alt="author.name" :img-alt="author.name"
...@@ -344,6 +352,7 @@ Please check your network connection and try again.`; ...@@ -344,6 +352,7 @@ Please check your network connection and try again.`;
:is="componentName(note)" :is="componentName(note)"
:note="componentData(note)" :note="componentData(note)"
:key="note.id" :key="note.id"
@handleDeleteNote="deleteNoteHandler"
/> />
</ul> </ul>
<div <div
......
...@@ -86,6 +86,7 @@ export default { ...@@ -86,6 +86,7 @@ export default {
// eslint-disable-next-line no-alert // eslint-disable-next-line no-alert
if (window.confirm('Are you sure you want to delete this comment?')) { if (window.confirm('Are you sure you want to delete this comment?')) {
this.isDeleting = true; this.isDeleting = true;
this.$emit('handleDeleteNote', this.note);
this.deleteNote(this.note) this.deleteNote(this.note)
.then(() => { .then(() => {
......
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