Commit 998299e2 authored by Fatih Acet's avatar Fatih Acet

IssueNotesRefactor: Implement note edit.

parent 092d4ca6
......@@ -57,8 +57,23 @@ export default {
});
}
},
formUpdateHandler() {
// console.log('update requested', data);
formUpdateHandler(note) {
const data = {
endpoint: `${this.note.path}?full_data=1`,
note: {
target_type: 'issue',
target_id: this.note.noteable_id,
note,
},
};
this.$store.dispatch('updateNote', data)
.then(() => {
this.isEditing = false;
})
.catch(() => {
new Flash('Something went wrong while editing your comment. Please try again.'); // eslint-disable-line
});
},
formCancelHandler() {
this.isEditing = false;
......
......@@ -32,6 +32,11 @@ export default {
renderGFM() {
$(this.$refs['note-body']).renderGFM();
},
handleFormUpdate() {
this.formUpdateHandler({
note: this.$refs.noteForm.note,
});
},
},
mounted() {
this.renderGFM();
......@@ -48,7 +53,8 @@ export default {
class="note-text md"></div>
<issue-note-form
v-if="isEditing"
:updateHandler="formUpdateHandler"
ref="noteForm"
:updateHandler="handleFormUpdate"
:cancelHandler="formCancelHandler"
:noteBody="note.note" />
<issue-note-edited-text
......
......@@ -13,4 +13,7 @@ export default {
replyToDiscussion(endpoint, data) {
return Vue.http.post(endpoint, data, { emulateJSON: true });
},
updateNote(endpoint, data) {
return Vue.http.put(endpoint, data, { emulateJSON: true });
},
};
......@@ -42,6 +42,16 @@ const mutations = {
noteObj.notes.push(note);
},
updateNote(storeState, note) {
const noteObj = findNoteObjectById(storeState.notes, note.discussion_id);
if (noteObj.individual_note) {
noteObj.notes.splice(0, 1, note);
} else {
const comment = findNoteObjectById(noteObj.notes, note.id);
noteObj.notes.splice(noteObj.notes.indexOf(comment), 1, note);
}
},
};
const actions = {
......@@ -70,6 +80,16 @@ const actions = {
context.commit('addNewReplyToDiscussion', res);
});
},
updateNote(context, data) {
const { endpoint, note } = data;
return service
.updateNote(endpoint, note)
.then(res => res.json())
.then((res) => {
context.commit('updateNote', res);
});
},
};
export default {
......
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