Commit 27f92275 authored by Miguel Rincon's avatar Miguel Rincon

Merge branch 'cngo-refactor-sortable' into 'master'

Refactor sortablejs related constants and utils

See merge request gitlab-org/gitlab!84497
parents 22c01277 73931379
...@@ -4,7 +4,7 @@ import { sortBy } from 'lodash'; ...@@ -4,7 +4,7 @@ import { sortBy } from 'lodash';
import Draggable from 'vuedraggable'; import Draggable from 'vuedraggable';
import { mapState, mapGetters, mapActions } from 'vuex'; import { mapState, mapGetters, mapActions } from 'vuex';
import BoardAddNewColumn from 'ee_else_ce/boards/components/board_add_new_column.vue'; import BoardAddNewColumn from 'ee_else_ce/boards/components/board_add_new_column.vue';
import defaultSortableConfig from '~/sortable/sortable_config'; import { defaultSortableOptions } from '~/sortable/constants';
import { DraggableItemTypes } from '../constants'; import { DraggableItemTypes } from '../constants';
import BoardColumn from './board_column.vue'; import BoardColumn from './board_column.vue';
...@@ -43,7 +43,7 @@ export default { ...@@ -43,7 +43,7 @@ export default {
}, },
draggableOptions() { draggableOptions() {
const options = { const options = {
...defaultSortableConfig, ...defaultSortableOptions,
disabled: this.disabled, disabled: this.disabled,
draggable: '.is-draggable', draggable: '.is-draggable',
fallbackOnBody: false, fallbackOnBody: false,
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
import { GlLoadingIcon, GlIntersectionObserver } from '@gitlab/ui'; import { GlLoadingIcon, GlIntersectionObserver } from '@gitlab/ui';
import Draggable from 'vuedraggable'; import Draggable from 'vuedraggable';
import { mapActions, mapGetters, mapState } from 'vuex'; import { mapActions, mapGetters, mapState } from 'vuex';
import { sortableStart, sortableEnd } from '~/boards/mixins/sortable_default_options';
import { sprintf, __ } from '~/locale'; import { sprintf, __ } from '~/locale';
import defaultSortableConfig from '~/sortable/sortable_config'; import { defaultSortableOptions } from '~/sortable/constants';
import { sortableStart, sortableEnd } from '~/sortable/utils';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
import listQuery from 'ee_else_ce/boards/graphql/board_lists_deferred.query.graphql'; import listQuery from 'ee_else_ce/boards/graphql/board_lists_deferred.query.graphql';
import { toggleFormEventPrefix, DraggableItemTypes } from '../constants'; import { toggleFormEventPrefix, DraggableItemTypes } from '../constants';
...@@ -121,7 +121,7 @@ export default { ...@@ -121,7 +121,7 @@ export default {
}, },
treeRootOptions() { treeRootOptions() {
const options = { const options = {
...defaultSortableConfig, ...defaultSortableOptions,
fallbackOnBody: false, fallbackOnBody: false,
group: 'board-list', group: 'board-list',
tag: 'ul', tag: 'ul',
......
<script>
export default {
props: {
title: {
type: String,
required: true,
},
refPath: {
type: String,
required: true,
},
},
};
</script>
<template>
<div data-testid="issue-title">
<p class="gl-font-weight-bold">{{ title }}</p>
<p class="gl-mb-0">{{ refPath }}</p>
</div>
</template>
import Sortable from 'sortablejs'; import Sortable from 'sortablejs';
import {
getBoardSortableDefaultOptions,
sortableStart,
} from '~/boards/mixins/sortable_default_options';
import createFlash from '~/flash'; import createFlash from '~/flash';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { getSortableDefaultOptions, sortableStart } from '~/sortable/utils';
const updateIssue = (url, { move_before_id, move_after_id }) => const updateIssue = (url, { move_before_id, move_after_id }) =>
axios axios
...@@ -28,7 +25,7 @@ const initManualOrdering = () => { ...@@ -28,7 +25,7 @@ const initManualOrdering = () => {
Sortable.create( Sortable.create(
issueList, issueList,
getBoardSortableDefaultOptions({ getSortableDefaultOptions({
scroll: true, scroll: true,
fallbackTolerance: 1, fallbackTolerance: 1,
dataIdAttr: 'data-id', dataIdAttr: 'data-id',
......
<script> <script>
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon } from '@gitlab/ui';
import Sortable from 'sortablejs'; import Sortable from 'sortablejs';
import sortableConfig from '~/sortable/sortable_config';
import RelatedIssuableItem from '~/issuable/components/related_issuable_item.vue'; import RelatedIssuableItem from '~/issuable/components/related_issuable_item.vue';
import { defaultSortableOptions } from '~/sortable/constants';
export default { export default {
name: 'RelatedIssuesList', name: 'RelatedIssuesList',
...@@ -53,7 +53,7 @@ export default { ...@@ -53,7 +53,7 @@ export default {
mounted() { mounted() {
if (this.canReorder) { if (this.canReorder) {
this.sortable = Sortable.create(this.$refs.list, { this.sortable = Sortable.create(this.$refs.list, {
...sortableConfig, ...defaultSortableOptions,
onStart: this.addDraggingCursor, onStart: this.addDraggingCursor,
onEnd: this.reordered, onEnd: this.reordered,
}); });
......
export default { /**
* Default config options for sortablejs.
* @type {object}
*
* @example
* import Sortable from 'sortablejs';
*
* const sortable = Sortable.create(el, {
* ...defaultSortableOptions,
* });
*/
export const defaultSortableOptions = {
animation: 200, animation: 200,
forceFallback: true, forceFallback: true,
fallbackClass: 'is-dragging', fallbackClass: 'is-dragging',
......
/* global DocumentTouch */ /* global DocumentTouch */
import sortableConfig from '~/sortable/sortable_config'; import { defaultSortableOptions } from './constants';
export function sortableStart() { export function sortableStart() {
document.body.classList.add('is-dragging'); document.body.classList.add('is-dragging');
...@@ -10,12 +10,12 @@ export function sortableEnd() { ...@@ -10,12 +10,12 @@ export function sortableEnd() {
document.body.classList.remove('is-dragging'); document.body.classList.remove('is-dragging');
} }
export function getBoardSortableDefaultOptions(obj) { export function getSortableDefaultOptions(options) {
const touchEnabled = const touchEnabled =
'ontouchstart' in window || (window.DocumentTouch && document instanceof DocumentTouch); 'ontouchstart' in window || (window.DocumentTouch && document instanceof DocumentTouch);
const defaultSortOptions = { const defaultSortOptions = {
...sortableConfig, ...defaultSortableOptions,
filter: '.no-drag', filter: '.no-drag',
delay: touchEnabled ? 100 : 0, delay: touchEnabled ? 100 : 0,
scrollSensitivity: touchEnabled ? 60 : 100, scrollSensitivity: touchEnabled ? 60 : 100,
...@@ -24,8 +24,8 @@ export function getBoardSortableDefaultOptions(obj) { ...@@ -24,8 +24,8 @@ export function getBoardSortableDefaultOptions(obj) {
onEnd: sortableEnd, onEnd: sortableEnd,
}; };
Object.keys(obj).forEach((key) => { return {
defaultSortOptions[key] = obj[key]; ...defaultSortOptions,
}); ...options,
return defaultSortOptions; };
} }
...@@ -8,7 +8,7 @@ import BoardListHeader from 'ee_else_ce/boards/components/board_list_header.vue' ...@@ -8,7 +8,7 @@ import BoardListHeader from 'ee_else_ce/boards/components/board_list_header.vue'
import { isListDraggable } from '~/boards/boards_util'; import { isListDraggable } from '~/boards/boards_util';
import eventHub from '~/boards/eventhub'; import eventHub from '~/boards/eventhub';
import { s__, n__, __ } from '~/locale'; import { s__, n__, __ } from '~/locale';
import defaultSortableConfig from '~/sortable/sortable_config'; import { defaultSortableOptions } from '~/sortable/constants';
import { calculateSwimlanesBufferSize } from '../boards_util'; import { calculateSwimlanesBufferSize } from '../boards_util';
import { DRAGGABLE_TAG, EPIC_LANE_BASE_HEIGHT, DraggableItemTypes } from '../constants'; import { DRAGGABLE_TAG, EPIC_LANE_BASE_HEIGHT, DraggableItemTypes } from '../constants';
import EpicLane from './epic_lane.vue'; import EpicLane from './epic_lane.vue';
...@@ -83,7 +83,7 @@ export default { ...@@ -83,7 +83,7 @@ export default {
}, },
treeRootOptions() { treeRootOptions() {
const options = { const options = {
...defaultSortableConfig, ...defaultSortableOptions,
fallbackOnBody: false, fallbackOnBody: false,
group: 'board-swimlanes', group: 'board-swimlanes',
tag: DRAGGABLE_TAG, tag: DRAGGABLE_TAG,
......
...@@ -5,7 +5,7 @@ import { mapState, mapActions } from 'vuex'; ...@@ -5,7 +5,7 @@ import { mapState, mapActions } from 'vuex';
import BoardCard from '~/boards/components/board_card.vue'; import BoardCard from '~/boards/components/board_card.vue';
import BoardNewIssue from '~/boards/components/board_new_issue.vue'; import BoardNewIssue from '~/boards/components/board_new_issue.vue';
import eventHub from '~/boards/eventhub'; import eventHub from '~/boards/eventhub';
import defaultSortableConfig from '~/sortable/sortable_config'; import { defaultSortableOptions } from '~/sortable/constants';
export default { export default {
components: { components: {
...@@ -57,7 +57,7 @@ export default { ...@@ -57,7 +57,7 @@ export default {
}, },
treeRootOptions() { treeRootOptions() {
const options = { const options = {
...defaultSortableConfig, ...defaultSortableOptions,
fallbackOnBody: false, fallbackOnBody: false,
group: 'board-epics-swimlanes', group: 'board-epics-swimlanes',
tag: 'ul', tag: 'ul',
......
import Draggable from 'vuedraggable'; import Draggable from 'vuedraggable';
import defaultSortableConfig from '~/sortable/sortable_config'; import { defaultSortableOptions } from '~/sortable/constants';
import { idProp, relativePositions, treeItemChevronBtnClassName } from '../constants'; import { idProp, relativePositions, treeItemChevronBtnClassName } from '../constants';
export default { export default {
...@@ -10,7 +10,7 @@ export default { ...@@ -10,7 +10,7 @@ export default {
}, },
treeRootOptions() { treeRootOptions() {
const options = { const options = {
...defaultSortableConfig, ...defaultSortableOptions,
fallbackOnBody: false, fallbackOnBody: false,
group: 'sortable-container', group: 'sortable-container',
tag: 'ul', tag: 'ul',
......
...@@ -104,7 +104,7 @@ describe('RelatedItemsTree', () => { ...@@ -104,7 +104,7 @@ describe('RelatedItemsTree', () => {
}); });
describe('treeRootOptions', () => { describe('treeRootOptions', () => {
it('should return object containing Vue.Draggable config extended from `defaultSortableConfig` when userSignedIn prop is true', () => { it('should return object containing Vue.Draggable config extended from `defaultSortableOptions` when userSignedIn prop is true', () => {
expect(wrapper.vm.treeRootOptions).toEqual( expect(wrapper.vm.treeRootOptions).toEqual(
expect.objectContaining({ expect.objectContaining({
animation: 200, animation: 200,
......
import { shallowMount } from '@vue/test-utils';
import IssuableTitle from '~/boards/components/issuable_title.vue';
describe('IssuableTitle', () => {
let wrapper;
const defaultProps = {
title: 'One',
refPath: 'path',
};
const createComponent = () => {
wrapper = shallowMount(IssuableTitle, {
propsData: { ...defaultProps },
});
};
const findIssueContent = () => wrapper.find('[data-testid="issue-title"]');
beforeEach(() => {
createComponent();
});
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
it('renders a title of an issue in the sidebar', () => {
expect(findIssueContent().text()).toContain('One');
});
it('renders a referencePath of an issue in the sidebar', () => {
expect(findIssueContent().text()).toContain('path');
});
});
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