gitlab-org--gitlab-foss/app/assets/javascripts/notes/mixins/resolvable.js

56 lines
1.5 KiB
JavaScript
Raw Normal View History

import Flash from '~/flash';
import { __ } from '~/locale';
export default {
computed: {
discussionResolved() {
2018-06-21 08:22:40 -04:00
if (this.discussion) {
const { notes, resolved } = this.discussion;
if (notes) {
// Decide resolved state using store. Only valid for discussions.
return notes.filter(note => !note.system).every(note => note.resolved);
}
2018-06-21 08:22:40 -04:00
return resolved;
}
2018-06-21 08:22:40 -04:00
return this.note.resolved;
},
resolveButtonTitle() {
if (this.updatedNoteBody) {
if (this.discussionResolved) {
return __('Comment & unresolve thread');
}
return __('Comment & resolve thread');
}
2018-06-21 08:22:40 -04:00
return this.discussionResolved ? __('Unresolve thread') : __('Resolve thread');
},
},
methods: {
resolveHandler(resolvedState = false) {
if (this.note && this.note.isDraft) {
return this.$emit('toggleResolveStatus');
}
this.isResolving = true;
const isResolved = this.discussionResolved || resolvedState;
const discussion = this.resolveAsThread;
2018-06-21 08:22:40 -04:00
const endpoint = discussion ? this.discussion.resolve_path : `${this.note.path}/resolve`;
return this.toggleResolveNote({ endpoint, isResolved, discussion })
.then(() => {
this.isResolving = false;
})
.catch(() => {
this.isResolving = false;
2018-06-21 08:22:40 -04:00
const msg = __('Something went wrong while resolving this discussion. Please try again.');
Flash(msg, 'alert', this.$el);
});
},
},
};