Commit 3f996024 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'issue-edit-inline-locked-warning' into 'issue-edit-inline'

Show warning if realtime data has changed since the form has opened

See merge request !11495
parents 3c3b17a5 95efe5b3
...@@ -90,12 +90,12 @@ export default { ...@@ -90,12 +90,12 @@ export default {
openForm() { openForm() {
if (!this.showForm) { if (!this.showForm) {
this.showForm = true; this.showForm = true;
this.store.formState = { this.store.formState = Object.assign(this.store.formState, {
title: this.state.titleText, title: this.state.titleText,
confidential: this.isConfidential, confidential: this.isConfidential,
description: this.state.descriptionText, description: this.state.descriptionText,
move_to_project_id: 0, move_to_project_id: 0,
}; });
} }
}, },
closeForm() { closeForm() {
...@@ -139,7 +139,14 @@ export default { ...@@ -139,7 +139,14 @@ export default {
resource: this.service, resource: this.service,
method: 'getData', method: 'getData',
successCallback: (res) => { successCallback: (res) => {
this.store.updateState(res.json()); const data = res.json();
const shouldUpdate = this.store.stateShouldUpdate(data);
this.store.updateState(data);
if (this.showForm && (shouldUpdate.title || shouldUpdate.description)) {
this.store.formState.lockedWarningVisible = true;
}
}, },
errorCallback(err) { errorCallback(err) {
throw new Error(err); throw new Error(err);
......
<script> <script>
import lockedWarning from './locked_warning.vue';
import titleField from './fields/title.vue'; import titleField from './fields/title.vue';
import descriptionField from './fields/description.vue'; import descriptionField from './fields/description.vue';
import editActions from './edit_actions.vue'; import editActions from './edit_actions.vue';
...@@ -33,6 +34,7 @@ ...@@ -33,6 +34,7 @@
}, },
}, },
components: { components: {
lockedWarning,
titleField, titleField,
descriptionField, descriptionField,
editActions, editActions,
...@@ -44,6 +46,7 @@ ...@@ -44,6 +46,7 @@
<template> <template>
<form> <form>
<locked-warning v-if="formState.lockedWarningVisible" />
<title-field <title-field
:form-state="formState" /> :form-state="formState" />
<confidential-checkbox <confidential-checkbox
......
<script>
export default {
computed: {
currentPath() {
return location.pathname;
},
},
};
</script>
<template>
<div class="alert alert-danger">
Someone edited the issue at the same time you did. Please check out
<a
:href="currentPath"
target="_blank"
rel="nofollow">the issue</a>
and make sure your changes will not unintentionally remove theirs.
</div>
</template>
...@@ -16,6 +16,7 @@ export default class Store { ...@@ -16,6 +16,7 @@ export default class Store {
title: '', title: '',
confidential: false, confidential: false,
description: '', description: '',
lockedWarningVisible: false,
move_to_project_id: 0, move_to_project_id: 0,
}; };
} }
...@@ -28,4 +29,11 @@ export default class Store { ...@@ -28,4 +29,11 @@ export default class Store {
this.state.taskStatus = data.task_status; this.state.taskStatus = data.task_status;
this.state.updatedAt = data.updated_at; this.state.updatedAt = data.updated_at;
} }
stateShouldUpdate(data) {
return {
title: this.state.titleText !== data.title_text,
description: this.state.descriptionText !== data.description_text,
};
}
} }
...@@ -285,4 +285,36 @@ describe('Issuable output', () => { ...@@ -285,4 +285,36 @@ describe('Issuable output', () => {
}); });
}); });
}); });
describe('open form', () => {
it('shows locked warning if form is open & data is different', (done) => {
Vue.http.interceptors.push(issueShowInterceptor(issueShowData.initialRequest));
Vue.nextTick()
.then(() => new Promise((resolve) => {
setTimeout(resolve);
}))
.then(() => {
vm.openForm();
Vue.http.interceptors.push(issueShowInterceptor(issueShowData.secondRequest));
return new Promise((resolve) => {
setTimeout(resolve);
});
})
.then(() => {
expect(
vm.formState.lockedWarningVisible,
).toBeTruthy();
expect(
vm.$el.querySelector('.alert'),
).not.toBeNull();
done();
})
.catch(done.fail);
});
});
}); });
import Vue from 'vue';
import formComponent from '~/issue_show/components/form.vue';
describe('Inline edit form component', () => {
let vm;
beforeEach((done) => {
const Component = Vue.extend(formComponent);
vm = new Component({
propsData: {
canDestroy: true,
canMove: true,
formState: {
title: 'b',
description: 'a',
lockedWarningVisible: false,
},
markdownPreviewUrl: '/',
markdownDocs: '/',
projectsAutocompleteUrl: '/',
},
}).$mount();
Vue.nextTick(done);
});
it('hides locked warning by default', () => {
expect(
vm.$el.querySelector('.alert'),
).toBeNull();
});
it('shows locked warning if formState is different', (done) => {
vm.formState.lockedWarningVisible = true;
Vue.nextTick(() => {
expect(
vm.$el.querySelector('.alert'),
).not.toBeNull();
done();
});
});
});
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