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

Delete Discussions fix

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