Commit 6c881698 authored by Denys Mishunov's avatar Denys Mishunov

Merge branch 'better-design-overlay-commenting-wrt-click-drag' into 'master'

Design View: Add small buffer to click-drag action

See merge request gitlab-org/gitlab!29469
parents d0ccf9f2 5ccdf0ee
...@@ -203,6 +203,11 @@ export default { ...@@ -203,6 +203,11 @@ export default {
this.movingNoteStartPosition = null; this.movingNoteStartPosition = null;
this.movingNoteNewPosition = null; this.movingNoteNewPosition = null;
}, },
onAddCommentMouseup({ offsetX, offsetY }) {
if (this.disableCommenting) return;
this.setNewNoteCoordinates({ x: offsetX, y: offsetY });
},
}, },
}; };
</script> </script>
...@@ -219,7 +224,7 @@ export default { ...@@ -219,7 +224,7 @@ export default {
type="button" type="button"
class="btn-transparent position-absolute image-diff-overlay-add-comment w-100 h-100 js-add-image-diff-note-button" class="btn-transparent position-absolute image-diff-overlay-add-comment w-100 h-100 js-add-image-diff-note-button"
data-qa-selector="design_image_button" data-qa-selector="design_image_button"
@mouseup="setNewNoteCoordinates({ x: $event.offsetX, y: $event.offsetY })" @mouseup="onAddCommentMouseup"
></button> ></button>
<design-note-pin <design-note-pin
v-for="(note, index) in notes" v-for="(note, index) in notes"
......
...@@ -3,6 +3,8 @@ import { throttle } from 'lodash'; ...@@ -3,6 +3,8 @@ import { throttle } from 'lodash';
import DesignImage from './image.vue'; import DesignImage from './image.vue';
import DesignOverlay from './design_overlay.vue'; import DesignOverlay from './design_overlay.vue';
const CLICK_DRAG_BUFFER_PX = 2;
export default { export default {
components: { components: {
DesignImage, DesignImage,
...@@ -221,16 +223,31 @@ export default { ...@@ -221,16 +223,31 @@ export default {
y: clientY, y: clientY,
}; };
}, },
onPresentationMousemove({ clientX, clientY }) { getDragDelta(clientX, clientY) {
if (!this.lastDragPosition) return; return {
this.isDraggingDesign = true; deltaX: this.lastDragPosition.x - clientX,
deltaY: this.lastDragPosition.y - clientY,
};
},
exceedsDragThreshold(clientX, clientY) {
const { deltaX, deltaY } = this.getDragDelta(clientX, clientY);
return Math.abs(deltaX) > CLICK_DRAG_BUFFER_PX || Math.abs(deltaY) > CLICK_DRAG_BUFFER_PX;
},
shouldDragDesign(clientX, clientY) {
return (
this.lastDragPosition &&
(this.isDraggingDesign || this.exceedsDragThreshold(clientX, clientY))
);
},
onPresentationMousemove({ clientX, clientY }) {
const { presentationViewport } = this.$refs; const { presentationViewport } = this.$refs;
if (!presentationViewport) return; if (!presentationViewport || !this.shouldDragDesign(clientX, clientY)) return;
this.isDraggingDesign = true;
const { scrollLeft, scrollTop } = presentationViewport; const { scrollLeft, scrollTop } = presentationViewport;
const deltaX = this.lastDragPosition.x - clientX; const { deltaX, deltaY } = this.getDragDelta(clientX, clientY);
const deltaY = this.lastDragPosition.y - clientY;
presentationViewport.scrollTo(scrollLeft + deltaX, scrollTop + deltaY); presentationViewport.scrollTo(scrollLeft + deltaX, scrollTop + deltaY);
this.lastDragPosition = { this.lastDragPosition = {
......
...@@ -63,7 +63,7 @@ describe('Design management design presentation component', () => { ...@@ -63,7 +63,7 @@ describe('Design management design presentation component', () => {
.mockReturnValue((childDimensions.height - viewportDimensions.height) * scrollTopPerc); .mockReturnValue((childDimensions.height - viewportDimensions.height) * scrollTopPerc);
} }
function clickDragExplore(startCoords, endCoords, { useTouchEvents } = {}) { function clickDragExplore(startCoords, endCoords, { useTouchEvents, mouseup } = {}) {
const event = useTouchEvents const event = useTouchEvents
? { ? {
mousedown: 'touchstart', mousedown: 'touchstart',
...@@ -85,13 +85,24 @@ describe('Design management design presentation component', () => { ...@@ -85,13 +85,24 @@ describe('Design management design presentation component', () => {
clientX: startCoords.clientX, clientX: startCoords.clientX,
clientY: startCoords.clientY, clientY: startCoords.clientY,
}); });
return wrapper.vm.$nextTick().then(() => { return wrapper.vm
addCommentOverlay.trigger(event.mousemove, { .$nextTick()
clientX: endCoords.clientX, .then(() => {
clientY: endCoords.clientY, addCommentOverlay.trigger(event.mousemove, {
clientX: endCoords.clientX,
clientY: endCoords.clientY,
});
return wrapper.vm.$nextTick();
})
.then(() => {
if (mouseup) {
addCommentOverlay.trigger(event.mouseup);
return wrapper.vm.$nextTick();
}
return undefined;
}); });
return wrapper.vm.$nextTick();
});
} }
afterEach(() => { afterEach(() => {
...@@ -494,12 +505,24 @@ describe('Design management design presentation component', () => { ...@@ -494,12 +505,24 @@ describe('Design management design presentation component', () => {
}); });
}); });
it('does not open a comment form', () => { it('does not open a comment form when drag position exceeds buffer', () => {
return clickDragExplore({ clientX: 0, clientY: 0 }, { clientX: 10, clientY: 10 }).then( return clickDragExplore(
() => { { clientX: 0, clientY: 0 },
expect(wrapper.emitted('openCommentForm')).toBeFalsy(); { clientX: 10, clientY: 10 },
}, { mouseup: true },
); ).then(() => {
expect(wrapper.emitted('openCommentForm')).toBeFalsy();
});
});
it('opens a comment form when drag position is within buffer', () => {
return clickDragExplore(
{ clientX: 0, clientY: 0 },
{ clientX: 1, clientY: 0 },
{ mouseup: true },
).then(() => {
expect(wrapper.emitted('openCommentForm')).toBeDefined();
});
}); });
}); });
}); });
......
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