IssueNotesRefactor: Implement ESC to cancel note form.
This commit is contained in:
parent
15f3362d34
commit
91f4906901
6 changed files with 43 additions and 16 deletions
|
@ -61,7 +61,15 @@ export default {
|
||||||
showReplyForm() {
|
showReplyForm() {
|
||||||
this.isReplying = true;
|
this.isReplying = true;
|
||||||
},
|
},
|
||||||
cancelReplyForm() {
|
cancelReplyForm(shouldConfirm) {
|
||||||
|
if (shouldConfirm && this.$refs.noteForm.isDirty) {
|
||||||
|
const msg = 'Are you sure you want to cancel creating this comment?';
|
||||||
|
const isConfirmed = confirm(msg); // eslint-disable-line
|
||||||
|
if (!isConfirmed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.isReplying = false;
|
this.isReplying = false;
|
||||||
},
|
},
|
||||||
saveReply({ note }) {
|
saveReply({ note }) {
|
||||||
|
@ -139,7 +147,8 @@ export default {
|
||||||
v-if="isReplying"
|
v-if="isReplying"
|
||||||
saveButtonTitle="Comment"
|
saveButtonTitle="Comment"
|
||||||
:updateHandler="saveReply"
|
:updateHandler="saveReply"
|
||||||
:cancelHandler="cancelReplyForm" />
|
:cancelHandler="cancelReplyForm"
|
||||||
|
ref="noteForm" />
|
||||||
<div
|
<div
|
||||||
v-if="!canReply"
|
v-if="!canReply"
|
||||||
class="disabled-comment text-center">
|
class="disabled-comment text-center">
|
||||||
|
|
|
@ -76,7 +76,15 @@ export default {
|
||||||
new Flash('Something went wrong while editing your comment. Please try again.'); // eslint-disable-line
|
new Flash('Something went wrong while editing your comment. Please try again.'); // eslint-disable-line
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
formCancelHandler() {
|
formCancelHandler(shouldConfirm) {
|
||||||
|
if (shouldConfirm && this.$refs.noteBody.$refs.noteForm.isDirty) {
|
||||||
|
const msg = 'Are you sure you want to cancel editing this comment?';
|
||||||
|
const isConfirmed = confirm(msg); // eslint-disable-line
|
||||||
|
if (!isConfirmed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.isEditing = false;
|
this.isEditing = false;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -115,7 +123,8 @@ export default {
|
||||||
:note="note"
|
:note="note"
|
||||||
:isEditing="isEditing"
|
:isEditing="isEditing"
|
||||||
:formUpdateHandler="formUpdateHandler"
|
:formUpdateHandler="formUpdateHandler"
|
||||||
:formCancelHandler="formCancelHandler" />
|
:formCancelHandler="formCancelHandler"
|
||||||
|
ref="noteBody" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -24,6 +24,7 @@ export default {
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
initialNote: this.noteBody,
|
||||||
note: this.noteBody,
|
note: this.noteBody,
|
||||||
markdownPreviewUrl: '',
|
markdownPreviewUrl: '',
|
||||||
markdownDocsUrl: '',
|
markdownDocsUrl: '',
|
||||||
|
@ -39,6 +40,11 @@ export default {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
isDirty() {
|
||||||
|
return this.initialNote !== this.note;
|
||||||
|
},
|
||||||
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
const issuableDataEl = document.getElementById('js-issuable-app-initial-data');
|
const issuableDataEl = document.getElementById('js-issuable-app-initial-data');
|
||||||
const issueData = JSON.parse(issuableDataEl.innerHTML.replace(/"/g, '"'));
|
const issueData = JSON.parse(issuableDataEl.innerHTML.replace(/"/g, '"'));
|
||||||
|
@ -68,7 +74,8 @@ export default {
|
||||||
ref="textarea"
|
ref="textarea"
|
||||||
slot="textarea"
|
slot="textarea"
|
||||||
placeholder="Write a comment or drag your files here..."
|
placeholder="Write a comment or drag your files here..."
|
||||||
@keydown.meta.enter="handleUpdate">
|
@keydown.meta.enter="handleUpdate"
|
||||||
|
@keydown.esc="cancelHandler(true)">
|
||||||
</textarea>
|
</textarea>
|
||||||
</markdown-field>
|
</markdown-field>
|
||||||
<div class="note-form-actions clearfix">
|
<div class="note-form-actions clearfix">
|
||||||
|
@ -79,7 +86,7 @@ export default {
|
||||||
{{saveButtonTitle}}
|
{{saveButtonTitle}}
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
@click="cancelHandler"
|
@click="cancelHandler()"
|
||||||
class="btn btn-nr btn-cancel"
|
class="btn btn-nr btn-cancel"
|
||||||
type="button">
|
type="button">
|
||||||
Cancel
|
Cancel
|
||||||
|
|
|
@ -40,6 +40,7 @@ export default {
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
const { discussionsPath, notesPath, lastFetchedAt } = this.$el.parentNode.dataset;
|
const { discussionsPath, notesPath, lastFetchedAt } = this.$el.parentNode.dataset;
|
||||||
|
|
||||||
this.$store.dispatch('fetchNotes', discussionsPath)
|
this.$store.dispatch('fetchNotes', discussionsPath)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
|
@ -58,6 +59,9 @@ export default {
|
||||||
this.$store.dispatch('poll', options)
|
this.$store.dispatch('poll', options)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
options.lastFetchedAt = res.last_fetched_at;
|
options.lastFetchedAt = res.last_fetched_at;
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
new Flash('Something went wrong while fetching latest comments.'); // eslint-disable-line
|
||||||
});
|
});
|
||||||
}, 6000);
|
}, 6000);
|
||||||
},
|
},
|
||||||
|
|
|
@ -23,7 +23,7 @@ export default {
|
||||||
const options = {
|
const options = {
|
||||||
headers: {
|
headers: {
|
||||||
'X-Last-Fetched-At': lastFetchedAt,
|
'X-Last-Fetched-At': lastFetchedAt,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return Vue.http.get(endpoint, options);
|
return Vue.http.get(endpoint, options);
|
||||||
|
|
|
@ -136,8 +136,7 @@ const actions = {
|
||||||
res.notes.forEach((note) => {
|
res.notes.forEach((note) => {
|
||||||
if (notesById[note.id]) {
|
if (notesById[note.id]) {
|
||||||
context.commit('updateNote', note);
|
context.commit('updateNote', note);
|
||||||
} else {
|
} else if (note.type === 'DiscussionNote') {
|
||||||
if (note.type === 'DiscussionNote') {
|
|
||||||
const discussion = findNoteObjectById(context.state.notes, note.discussion_id);
|
const discussion = findNoteObjectById(context.state.notes, note.discussion_id);
|
||||||
|
|
||||||
if (discussion) {
|
if (discussion) {
|
||||||
|
@ -148,7 +147,6 @@ const actions = {
|
||||||
} else {
|
} else {
|
||||||
context.commit('addNewNote', note);
|
context.commit('addNewNote', note);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue