Commit 397686df authored by Fatih Acet's avatar Fatih Acet

IssueNotesRefactor: Implement note edit conflict warning.

parent 3c946b93
...@@ -111,7 +111,7 @@ export default { ...@@ -111,7 +111,7 @@ export default {
<button <button
@click="editHandler" @click="editHandler"
type="button" type="button"
class="btn btn-transparent"> class="btn btn-transparent js-note-edit">
Edit comment Edit comment
</button> </button>
</li> </li>
...@@ -126,7 +126,7 @@ export default { ...@@ -126,7 +126,7 @@ export default {
<a <a
v-if="canEdit" v-if="canEdit"
@click.prevent="deleteHandler" @click.prevent="deleteHandler"
class="js-note-delete" class="js-note-delete js-note-delete"
href="#"> href="#">
<span class="text-danger"> <span class="text-danger">
Delete comment Delete comment
......
...@@ -28,6 +28,11 @@ export default { ...@@ -28,6 +28,11 @@ export default {
required: true, required: true,
}, },
}, },
computed: {
noteBody() {
return this.note.note;
},
},
components: { components: {
IssueNoteEditedText, IssueNoteEditedText,
IssueNoteAwardsList, IssueNoteAwardsList,
...@@ -75,7 +80,8 @@ export default { ...@@ -75,7 +80,8 @@ export default {
ref="noteForm" ref="noteForm"
:updateHandler="handleFormUpdate" :updateHandler="handleFormUpdate"
:cancelHandler="formCancelHandler" :cancelHandler="formCancelHandler"
:noteBody="note.note" /> :noteBody="noteBody"
:noteId="note.id" />
<textarea <textarea
v-if="canEdit" v-if="canEdit"
v-model="note.note" v-model="note.note"
......
...@@ -9,6 +9,10 @@ export default { ...@@ -9,6 +9,10 @@ export default {
required: false, required: false,
default: '', default: '',
}, },
noteId: {
type: Number,
required: false,
},
updateHandler: { updateHandler: {
type: Function, type: Function,
required: true, required: true,
...@@ -29,8 +33,18 @@ export default { ...@@ -29,8 +33,18 @@ export default {
note: this.noteBody, note: this.noteBody,
markdownPreviewUrl: '', markdownPreviewUrl: '',
markdownDocsUrl: '', markdownDocsUrl: '',
conflictWhileEditing: false,
}; };
}, },
watch: {
noteBody() {
if (this.note === this.initialNote) {
this.note = this.noteBody;
} else {
this.conflictWhileEditing = true;
}
},
},
components: { components: {
MarkdownField, MarkdownField,
}, },
...@@ -57,6 +71,9 @@ export default { ...@@ -57,6 +71,9 @@ export default {
isDirty() { isDirty() {
return this.initialNote !== this.note; return this.initialNote !== this.note;
}, },
noteHash() {
return `#note_${this.noteId}`;
},
}, },
mounted() { mounted() {
const issuableDataEl = document.getElementById('js-issuable-app-initial-data'); const issuableDataEl = document.getElementById('js-issuable-app-initial-data');
...@@ -72,6 +89,16 @@ export default { ...@@ -72,6 +89,16 @@ export default {
<template> <template>
<div class="note-edit-form"> <div class="note-edit-form">
<div
v-if="conflictWhileEditing"
class="js-conflict-edit-warning alert alert-danger">
This comment has changed since you started editing, please review the
<a
:href="noteHash"
target="_blank"
rel="noopener noreferrer">updated comment</a>
to ensure information is not lost.
</div>
<form class="edit-note common-note-form"> <form class="edit-note common-note-form">
<markdown-field <markdown-field
:markdown-preview-url="markdownPreviewUrl" :markdown-preview-url="markdownPreviewUrl"
...@@ -79,7 +106,7 @@ export default { ...@@ -79,7 +106,7 @@ export default {
:addSpacingClasses="false"> :addSpacingClasses="false">
<textarea <textarea
id="note-body" id="note-body"
class="note-textarea js-gfm-input js-autosize markdown-area" class="note-textarea js-gfm-input js-autosize markdown-area js-note-text"
data-supports-slash-commands="true" data-supports-slash-commands="true"
data-supports-quick-actions="true" data-supports-quick-actions="true"
aria-label="Description" aria-label="Description"
...@@ -101,7 +128,7 @@ export default { ...@@ -101,7 +128,7 @@ export default {
</button> </button>
<button <button
@click="cancelHandler()" @click="cancelHandler()"
class="btn btn-nr btn-cancel" class="btn btn-nr btn-cancel note-edit-cancel"
type="button"> type="button">
Cancel Cancel
</button> </button>
......
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