提交 aed5632c 编写于 作者: F Fatih Acet

IssueNotesRefactor: Fix showing placeholders in discussion wrapper.

上级 eae72cc7
...@@ -8,6 +8,8 @@ import IssueNoteActions from './issue_note_actions.vue'; ...@@ -8,6 +8,8 @@ import IssueNoteActions from './issue_note_actions.vue';
import IssueNoteSignedOutWidget from './issue_note_signed_out_widget.vue'; import IssueNoteSignedOutWidget from './issue_note_signed_out_widget.vue';
import IssueNoteEditedText from './issue_note_edited_text.vue'; import IssueNoteEditedText from './issue_note_edited_text.vue';
import IssueNoteForm from './issue_note_form.vue'; import IssueNoteForm from './issue_note_form.vue';
import PlaceholderNote from './issue_placeholder_note.vue';
import PlaceholderSystemNote from './issue_placeholder_system_note.vue';
export default { export default {
props: { props: {
...@@ -41,8 +43,23 @@ export default { ...@@ -41,8 +43,23 @@ export default {
IssueNoteEditedText, IssueNoteEditedText,
IssueNoteSignedOutWidget, IssueNoteSignedOutWidget,
IssueNoteForm, IssueNoteForm,
PlaceholderNote,
PlaceholderSystemNote,
}, },
methods: { methods: {
component(note) {
if (note.isPlaceholderNote) {
if (note.placeholderType === 'systemNote') {
return PlaceholderSystemNote;
}
return PlaceholderNote;
}
return IssueNote;
},
componentData(note) {
return note.isPlaceholderNote ? note.notes[0] : note;
},
toggleDiscussion() { toggleDiscussion() {
this.$store.commit('toggleDiscussion', { this.$store.commit('toggleDiscussion', {
discussionId: this.note.id, discussionId: this.note.id,
...@@ -65,6 +82,7 @@ export default { ...@@ -65,6 +82,7 @@ export default {
saveReply({ note }) { saveReply({ note }) {
const replyData = { const replyData = {
endpoint: this.newNotePath, endpoint: this.newNotePath,
flashContainer: this.$el,
data: { data: {
in_reply_to_discussion_id: this.note.reply_id, in_reply_to_discussion_id: this.note.reply_id,
target_type: 'issue', target_type: 'issue',
...@@ -120,10 +138,11 @@ export default { ...@@ -120,10 +138,11 @@ export default {
<div class="panel panel-default"> <div class="panel panel-default">
<div class="discussion-notes"> <div class="discussion-notes">
<ul class="notes"> <ul class="notes">
<issue-note <component
v-for="note in note.notes" v-for="note in note.notes"
key="note.id" :is="component(note)"
:note="note" /> :note="componentData(note)"
key="note.id" />
</ul> </ul>
<div class="flash-container"></div> <div class="flash-container"></div>
<div class="discussion-reply-holder"> <div class="discussion-reply-holder">
......
...@@ -110,7 +110,12 @@ const mutations = { ...@@ -110,7 +110,12 @@ const mutations = {
storeState.lastFetchedAt = fetchedAt; storeState.lastFetchedAt = fetchedAt;
}, },
showPlaceholderNote(storeState, data) { showPlaceholderNote(storeState, data) {
storeState.notes.push({ let notesArr = storeState.notes;
if (data.replyId) {
notesArr = findNoteObjectById(notesArr, data.replyId).notes;
}
notesArr.push({
individual_note: true, individual_note: true,
isPlaceholderNote: true, isPlaceholderNote: true,
placeholderType: data.isSystemNote ? 'systemNote' : 'note', placeholderType: data.isSystemNote ? 'systemNote' : 'note',
...@@ -125,7 +130,16 @@ const mutations = { ...@@ -125,7 +130,16 @@ const mutations = {
const { notes } = storeState; const { notes } = storeState;
for (let i = notes.length - 1; i >= 0; i -= 1) { for (let i = notes.length - 1; i >= 0; i -= 1) {
if (notes[i].isPlaceholderNote) { const note = notes[i];
const children = note.notes;
if (children.length && !note.individual_note) { // remove placeholder from discussions
for (let j = children.length - 1; j >= 0; j -= 1) {
if (children[j].isPlaceholderNote) {
children.splice(j, 1);
}
}
} else if (note.isPlaceholderNote) { // remove placeholders from state root
notes.splice(i, 1); notes.splice(i, 1);
} }
} }
...@@ -166,6 +180,8 @@ const actions = { ...@@ -166,6 +180,8 @@ const actions = {
.then(res => res.json()) .then(res => res.json())
.then((res) => { .then((res) => {
context.commit('addNewReplyToDiscussion', res); context.commit('addNewReplyToDiscussion', res);
return res;
}); });
}, },
createNewNote(context, noteData) { createNewNote(context, noteData) {
...@@ -185,6 +201,8 @@ const actions = { ...@@ -185,6 +201,8 @@ const actions = {
const { note } = noteData.data.note; const { note } = noteData.data.note;
let placeholderText = note; let placeholderText = note;
const hasQuickActions = utils.hasQuickActions(placeholderText); const hasQuickActions = utils.hasQuickActions(placeholderText);
const replyId = noteData.data.in_reply_to_discussion_id;
const methodToDispatch = replyId ? 'replyToDiscussion' : 'createNewNote';
if (hasQuickActions) { if (hasQuickActions) {
placeholderText = utils.stripQuickActions(placeholderText); placeholderText = utils.stripQuickActions(placeholderText);
...@@ -193,6 +211,7 @@ const actions = { ...@@ -193,6 +211,7 @@ const actions = {
if (placeholderText.length) { if (placeholderText.length) {
context.commit('showPlaceholderNote', { context.commit('showPlaceholderNote', {
noteBody: placeholderText, noteBody: placeholderText,
replyId,
}); });
} }
...@@ -200,12 +219,10 @@ const actions = { ...@@ -200,12 +219,10 @@ const actions = {
context.commit('showPlaceholderNote', { context.commit('showPlaceholderNote', {
isSystemNote: true, isSystemNote: true,
noteBody: utils.getQuickActionText(note), noteBody: utils.getQuickActionText(note),
replyId,
}); });
} }
const hasReplyId = noteData.data.in_reply_to_discussion_id;
const methodToDispatch = hasReplyId ? 'replyToDiscussion' : 'createNewNote';
return context.dispatch(methodToDispatch, noteData) return context.dispatch(methodToDispatch, noteData)
.then((res) => { .then((res) => {
const { errors } = res; const { errors } = res;
......
...@@ -29,4 +29,4 @@ export default { ...@@ -29,4 +29,4 @@ export default {
stripQuickActions(note) { stripQuickActions(note) {
return note.replace(REGEX_QUICK_ACTIONS, '').trim(); return note.replace(REGEX_QUICK_ACTIONS, '').trim();
}, },
} };
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册