Revert "Merge branch '_acet-fix-mr-autosave' into 'master'"
This reverts commit5ba542b109
, reversing changes made to32c831ea2b
.
This commit is contained in:
parent
8693aa139d
commit
c7cd9ee97c
|
@ -53,8 +53,4 @@ export default class Autosave {
|
||||||
|
|
||||||
return window.localStorage.removeItem(this.key);
|
return window.localStorage.removeItem(this.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
|
||||||
this.field.off('input');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
<script>
|
<script>
|
||||||
|
import $ from 'jquery';
|
||||||
import { mapState, mapGetters, mapActions } from 'vuex';
|
import { mapState, mapGetters, mapActions } from 'vuex';
|
||||||
import createFlash from '~/flash';
|
import createFlash from '~/flash';
|
||||||
import { s__ } from '~/locale';
|
import { s__ } from '~/locale';
|
||||||
import noteForm from '../../notes/components/note_form.vue';
|
import noteForm from '../../notes/components/note_form.vue';
|
||||||
import { getNoteFormData } from '../store/utils';
|
import { getNoteFormData } from '../store/utils';
|
||||||
import autosave from '../../notes/mixins/autosave';
|
import Autosave from '../../autosave';
|
||||||
import { DIFF_NOTE_TYPE } from '../constants';
|
import { DIFF_NOTE_TYPE, NOTE_TYPE } from '../constants';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
noteForm,
|
noteForm,
|
||||||
},
|
},
|
||||||
mixins: [autosave],
|
|
||||||
props: {
|
props: {
|
||||||
diffFileHash: {
|
diffFileHash: {
|
||||||
type: String,
|
type: String,
|
||||||
|
@ -41,35 +41,28 @@ export default {
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
if (this.isLoggedIn) {
|
if (this.isLoggedIn) {
|
||||||
|
const noteableData = this.getNoteableData;
|
||||||
const keys = [
|
const keys = [
|
||||||
this.noteableData.diff_head_sha,
|
NOTE_TYPE,
|
||||||
|
this.noteableType,
|
||||||
|
noteableData.id,
|
||||||
|
noteableData.diff_head_sha,
|
||||||
DIFF_NOTE_TYPE,
|
DIFF_NOTE_TYPE,
|
||||||
this.noteableData.source_project_id,
|
noteableData.source_project_id,
|
||||||
this.line.lineCode,
|
this.line.lineCode,
|
||||||
];
|
];
|
||||||
|
|
||||||
this.initAutoSave(this.noteableData, keys);
|
this.autosave = new Autosave($(this.$refs.noteForm.$refs.textarea), keys);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions('diffs', ['cancelCommentForm']),
|
...mapActions('diffs', ['cancelCommentForm']),
|
||||||
...mapActions(['saveNote', 'refetchDiscussionById']),
|
...mapActions(['saveNote', 'refetchDiscussionById']),
|
||||||
handleCancelCommentForm(shouldConfirm, isDirty) {
|
handleCancelCommentForm() {
|
||||||
if (shouldConfirm && isDirty) {
|
this.autosave.reset();
|
||||||
const msg = s__('Notes|Are you sure you want to cancel creating this comment?');
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-alert
|
|
||||||
if (!window.confirm(msg)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.cancelCommentForm({
|
this.cancelCommentForm({
|
||||||
lineCode: this.line.lineCode,
|
lineCode: this.line.lineCode,
|
||||||
});
|
});
|
||||||
this.$nextTick(() => {
|
|
||||||
this.resetAutoSave();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
handleSaveNote(note) {
|
handleSaveNote(note) {
|
||||||
const selectedDiffFile = this.getDiffFileByHash(this.diffFileHash);
|
const selectedDiffFile = this.getDiffFileByHash(this.diffFileHash);
|
||||||
|
|
|
@ -7,7 +7,7 @@ import issuableStateMixin from '../mixins/issuable_state';
|
||||||
import resolvable from '../mixins/resolvable';
|
import resolvable from '../mixins/resolvable';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'NoteForm',
|
name: 'IssueNoteForm',
|
||||||
components: {
|
components: {
|
||||||
issueWarning,
|
issueWarning,
|
||||||
markdownField,
|
markdownField,
|
||||||
|
|
|
@ -6,7 +6,6 @@ import nextDiscussionsSvg from 'icons/_next_discussion.svg';
|
||||||
import { convertObjectPropsToCamelCase, scrollToElement } from '~/lib/utils/common_utils';
|
import { convertObjectPropsToCamelCase, scrollToElement } from '~/lib/utils/common_utils';
|
||||||
import { truncateSha } from '~/lib/utils/text_utility';
|
import { truncateSha } from '~/lib/utils/text_utility';
|
||||||
import systemNote from '~/vue_shared/components/notes/system_note.vue';
|
import systemNote from '~/vue_shared/components/notes/system_note.vue';
|
||||||
import { s__ } from '~/locale';
|
|
||||||
import Flash from '../../flash';
|
import Flash from '../../flash';
|
||||||
import { SYSTEM_NOTE } from '../constants';
|
import { SYSTEM_NOTE } from '../constants';
|
||||||
import userAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue';
|
import userAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue';
|
||||||
|
@ -145,17 +144,19 @@ export default {
|
||||||
return this.isDiffDiscussion ? '' : 'card discussion-wrapper';
|
return this.isDiffDiscussion ? '' : 'card discussion-wrapper';
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
mounted() {
|
||||||
isReplying() {
|
if (this.isReplying) {
|
||||||
if (this.isReplying) {
|
this.initAutoSave(this.transformedDiscussion);
|
||||||
this.$nextTick(() => {
|
}
|
||||||
// Pass an extra key to separate reply and note edit forms
|
},
|
||||||
this.initAutoSave(this.transformedDiscussion, ['Reply']);
|
updated() {
|
||||||
});
|
if (this.isReplying) {
|
||||||
|
if (!this.autosave) {
|
||||||
|
this.initAutoSave(this.transformedDiscussion);
|
||||||
} else {
|
} else {
|
||||||
this.disposeAutoSave();
|
this.setAutoSave();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.resolveDiscussionsSvg = resolveDiscussionsSvg;
|
this.resolveDiscussionsSvg = resolveDiscussionsSvg;
|
||||||
|
@ -193,18 +194,16 @@ export default {
|
||||||
showReplyForm() {
|
showReplyForm() {
|
||||||
this.isReplying = true;
|
this.isReplying = true;
|
||||||
},
|
},
|
||||||
cancelReplyForm(shouldConfirm, isDirty) {
|
cancelReplyForm(shouldConfirm) {
|
||||||
if (shouldConfirm && isDirty) {
|
if (shouldConfirm && this.$refs.noteForm.isDirty) {
|
||||||
const msg = s__('Notes|Are you sure you want to cancel creating this comment?');
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-alert
|
// eslint-disable-next-line no-alert
|
||||||
if (!window.confirm(msg)) {
|
if (!window.confirm('Are you sure you want to cancel creating this comment?')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isReplying = false;
|
|
||||||
this.resetAutoSave();
|
this.resetAutoSave();
|
||||||
|
this.isReplying = false;
|
||||||
},
|
},
|
||||||
saveReply(noteText, form, callback) {
|
saveReply(noteText, form, callback) {
|
||||||
const postData = {
|
const postData = {
|
||||||
|
@ -421,8 +420,7 @@ Please check your network connection and try again.`;
|
||||||
:is-editing="false"
|
:is-editing="false"
|
||||||
save-button-title="Comment"
|
save-button-title="Comment"
|
||||||
@handleFormUpdate="saveReply"
|
@handleFormUpdate="saveReply"
|
||||||
@cancelForm="cancelReplyForm"
|
@cancelForm="cancelReplyForm" />
|
||||||
/>
|
|
||||||
<note-signed-out-widget v-if="!canReply" />
|
<note-signed-out-widget v-if="!canReply" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -4,18 +4,12 @@ import { capitalizeFirstCharacter } from '../../lib/utils/text_utility';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
methods: {
|
methods: {
|
||||||
initAutoSave(noteable, extraKeys = []) {
|
initAutoSave(noteable) {
|
||||||
let keys = [
|
this.autosave = new Autosave($(this.$refs.noteForm.$refs.textarea), [
|
||||||
'Note',
|
'Note',
|
||||||
capitalizeFirstCharacter(noteable.noteable_type || noteable.noteableType),
|
capitalizeFirstCharacter(noteable.noteable_type),
|
||||||
noteable.id,
|
noteable.id,
|
||||||
];
|
]);
|
||||||
|
|
||||||
if (extraKeys) {
|
|
||||||
keys = keys.concat(extraKeys);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.autosave = new Autosave($(this.$refs.noteForm.$refs.textarea), keys);
|
|
||||||
},
|
},
|
||||||
resetAutoSave() {
|
resetAutoSave() {
|
||||||
this.autosave.reset();
|
this.autosave.reset();
|
||||||
|
@ -23,8 +17,5 @@ export default {
|
||||||
setAutoSave() {
|
setAutoSave() {
|
||||||
this.autosave.save();
|
this.autosave.save();
|
||||||
},
|
},
|
||||||
disposeAutoSave() {
|
|
||||||
this.autosave.dispose();
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -3610,9 +3610,6 @@ msgstr ""
|
||||||
msgid "Note: Consider asking your GitLab administrator to configure %{github_integration_link}, which will allow login via GitHub and allow importing repositories without generating a Personal Access Token."
|
msgid "Note: Consider asking your GitLab administrator to configure %{github_integration_link}, which will allow login via GitHub and allow importing repositories without generating a Personal Access Token."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
msgid "Notes|Are you sure you want to cancel creating this comment?"
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
msgid "Notification events"
|
msgid "Notification events"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|
|
@ -59,10 +59,12 @@ describe('Autosave', () => {
|
||||||
|
|
||||||
Autosave.prototype.restore.call(autosave);
|
Autosave.prototype.restore.call(autosave);
|
||||||
|
|
||||||
expect(field.trigger).toHaveBeenCalled();
|
expect(
|
||||||
|
field.trigger,
|
||||||
|
).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers native event', done => {
|
it('triggers native event', (done) => {
|
||||||
autosave.field.get(0).addEventListener('change', () => {
|
autosave.field.get(0).addEventListener('change', () => {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@ -79,7 +81,9 @@ describe('Autosave', () => {
|
||||||
it('does not trigger event', () => {
|
it('does not trigger event', () => {
|
||||||
spyOn(field, 'trigger').and.callThrough();
|
spyOn(field, 'trigger').and.callThrough();
|
||||||
|
|
||||||
expect(field.trigger).not.toHaveBeenCalled();
|
expect(
|
||||||
|
field.trigger,
|
||||||
|
).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,7 +3,6 @@ import DiffLineNoteForm from '~/diffs/components/diff_line_note_form.vue';
|
||||||
import store from '~/mr_notes/stores';
|
import store from '~/mr_notes/stores';
|
||||||
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
|
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
|
||||||
import diffFileMockData from '../mock_data/diff_file';
|
import diffFileMockData from '../mock_data/diff_file';
|
||||||
import { noteableDataMock } from '../../notes/mock_data';
|
|
||||||
|
|
||||||
describe('DiffLineNoteForm', () => {
|
describe('DiffLineNoteForm', () => {
|
||||||
let component;
|
let component;
|
||||||
|
@ -22,9 +21,10 @@ describe('DiffLineNoteForm', () => {
|
||||||
noteTargetLine: diffLines[0],
|
noteTargetLine: diffLines[0],
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.defineProperties(component, {
|
Object.defineProperty(component, 'isLoggedIn', {
|
||||||
noteableData: { value: noteableDataMock },
|
get() {
|
||||||
isLoggedIn: { value: true },
|
return true;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
component.$mount();
|
component.$mount();
|
||||||
|
@ -32,37 +32,12 @@ describe('DiffLineNoteForm', () => {
|
||||||
|
|
||||||
describe('methods', () => {
|
describe('methods', () => {
|
||||||
describe('handleCancelCommentForm', () => {
|
describe('handleCancelCommentForm', () => {
|
||||||
it('should ask for confirmation when shouldConfirm and isDirty passed as truthy', () => {
|
it('should call cancelCommentForm with lineCode', () => {
|
||||||
spyOn(window, 'confirm').and.returnValue(false);
|
|
||||||
|
|
||||||
component.handleCancelCommentForm(true, true);
|
|
||||||
expect(window.confirm).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should ask for confirmation when one of the params false', () => {
|
|
||||||
spyOn(window, 'confirm').and.returnValue(false);
|
|
||||||
|
|
||||||
component.handleCancelCommentForm(true, false);
|
|
||||||
expect(window.confirm).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
component.handleCancelCommentForm(false, true);
|
|
||||||
expect(window.confirm).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call cancelCommentForm with lineCode', done => {
|
|
||||||
spyOn(window, 'confirm');
|
|
||||||
spyOn(component, 'cancelCommentForm');
|
spyOn(component, 'cancelCommentForm');
|
||||||
spyOn(component, 'resetAutoSave');
|
|
||||||
component.handleCancelCommentForm();
|
component.handleCancelCommentForm();
|
||||||
|
|
||||||
expect(window.confirm).not.toHaveBeenCalled();
|
expect(component.cancelCommentForm).toHaveBeenCalledWith({
|
||||||
component.$nextTick(() => {
|
lineCode: diffLines[0].lineCode,
|
||||||
expect(component.cancelCommentForm).toHaveBeenCalledWith({
|
|
||||||
lineCode: diffLines[0].lineCode,
|
|
||||||
});
|
|
||||||
expect(component.resetAutoSave).toHaveBeenCalled();
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -91,7 +66,7 @@ describe('DiffLineNoteForm', () => {
|
||||||
|
|
||||||
describe('mounted', () => {
|
describe('mounted', () => {
|
||||||
it('should init autosave', () => {
|
it('should init autosave', () => {
|
||||||
const key = 'autosave/Note/Issue/98//DiffNote//1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_1';
|
const key = 'autosave/Note/issue///DiffNote//1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_1';
|
||||||
|
|
||||||
expect(component.autosave).toBeDefined();
|
expect(component.autosave).toBeDefined();
|
||||||
expect(component.autosave.key).toEqual(key);
|
expect(component.autosave.key).toEqual(key);
|
||||||
|
|
|
@ -46,15 +46,10 @@ describe('noteable_discussion component', () => {
|
||||||
|
|
||||||
it('should toggle reply form', done => {
|
it('should toggle reply form', done => {
|
||||||
vm.$el.querySelector('.js-vue-discussion-reply').click();
|
vm.$el.querySelector('.js-vue-discussion-reply').click();
|
||||||
|
|
||||||
Vue.nextTick(() => {
|
Vue.nextTick(() => {
|
||||||
|
expect(vm.$refs.noteForm).not.toBeNull();
|
||||||
expect(vm.isReplying).toEqual(true);
|
expect(vm.isReplying).toEqual(true);
|
||||||
|
done();
|
||||||
// There is a watcher for `isReplying` which will init autosave in the next tick
|
|
||||||
Vue.nextTick(() => {
|
|
||||||
expect(vm.$refs.noteForm).not.toBeNull();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue