Commit e108a9a7 authored by Natalia Tepluhina's avatar Natalia Tepluhina Committed by Phil Hughes

Resolve "Error when quickly reordering designs"

parent 58f318e0
...@@ -71,6 +71,7 @@ export default { ...@@ -71,6 +71,7 @@ export default {
selectedDesigns: [], selectedDesigns: [],
isDraggingDesign: false, isDraggingDesign: false,
reorderedDesigns: null, reorderedDesigns: null,
isReorderingInProgress: false,
}; };
}, },
computed: { computed: {
...@@ -277,6 +278,7 @@ export default { ...@@ -277,6 +278,7 @@ export default {
return variables; return variables;
}, },
reorderDesigns({ moved: { newIndex, element } }) { reorderDesigns({ moved: { newIndex, element } }) {
this.isReorderingInProgress = true;
this.$apollo this.$apollo
.mutate({ .mutate({
mutation: moveDesignMutation, mutation: moveDesignMutation,
...@@ -287,6 +289,9 @@ export default { ...@@ -287,6 +289,9 @@ export default {
}) })
.catch(() => { .catch(() => {
createFlash(MOVE_DESIGN_ERROR); createFlash(MOVE_DESIGN_ERROR);
})
.finally(() => {
this.isReorderingInProgress = false;
}); });
}, },
onDesignMove(designs) { onDesignMove(designs) {
...@@ -358,7 +363,7 @@ export default { ...@@ -358,7 +363,7 @@ export default {
<vue-draggable <vue-draggable
v-else v-else
:value="designs" :value="designs"
:disabled="!isLatestVersion" :disabled="!isLatestVersion || isReorderingInProgress"
v-bind="$options.dragOptions" v-bind="$options.dragOptions"
tag="ol" tag="ol"
draggable=".js-design-tile" draggable=".js-design-tile"
......
---
title: Resolve Error when quickly reordering designs
merge_request: 42818
author:
type: fixed
...@@ -99,6 +99,7 @@ describe('Design management index page', () => { ...@@ -99,6 +99,7 @@ describe('Design management index page', () => {
const findFirstDropzoneWithDesign = () => wrapper.findAll(DesignDropzone).at(1); const findFirstDropzoneWithDesign = () => wrapper.findAll(DesignDropzone).at(1);
const findDesignsWrapper = () => wrapper.find('[data-testid="designs-root"]'); const findDesignsWrapper = () => wrapper.find('[data-testid="designs-root"]');
const findDesigns = () => wrapper.findAll(Design); const findDesigns = () => wrapper.findAll(Design);
const draggableAttributes = () => wrapper.find(VueDraggable).vm.$attrs;
async function moveDesigns(localWrapper) { async function moveDesigns(localWrapper) {
await jest.runOnlyPendingTimers(); await jest.runOnlyPendingTimers();
...@@ -676,6 +677,20 @@ describe('Design management index page', () => { ...@@ -676,6 +677,20 @@ describe('Design management index page', () => {
).toBe('2'); ).toBe('2');
}); });
it('prevents reordering when reorderDesigns mutation is in progress', async () => {
createComponentWithApollo({});
await moveDesigns(wrapper);
expect(draggableAttributes().disabled).toBe(true);
await jest.runOnlyPendingTimers(); // kick off the mocked GQL stuff (promises)
await wrapper.vm.$nextTick(); // kick off the DOM update
await wrapper.vm.$nextTick(); // kick off the DOM update for finally block
expect(draggableAttributes().disabled).toBe(false);
});
it('displays flash if mutation had a recoverable error', async () => { it('displays flash if mutation had a recoverable error', async () => {
createComponentWithApollo({ createComponentWithApollo({
moveHandler: jest.fn().mockResolvedValue(moveDesignMutationResponseWithErrors), moveHandler: jest.fn().mockResolvedValue(moveDesignMutationResponseWithErrors),
......
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