Commit 89fd4113 authored by Jarka Košanová's avatar Jarka Košanová Committed by Kushal Pandya

Fix moving items up in the epic tree

Fixes item swapping in Epics Tree.
Adding new issues always adds them to top.
parent 3dbb2de4
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
import { mapState, mapActions } from 'vuex'; import { mapState, mapActions } from 'vuex';
import { GlButton, GlLoadingIcon } from '@gitlab/ui'; import { GlButton, GlLoadingIcon } from '@gitlab/ui';
import { ChildType } from '../constants';
import TreeDragAndDropMixin from '../mixins/tree_dd_mixin'; import TreeDragAndDropMixin from '../mixins/tree_dd_mixin';
export default { export default {
...@@ -28,9 +27,6 @@ export default { ...@@ -28,9 +27,6 @@ export default {
}, },
computed: { computed: {
...mapState(['childrenFlags', 'userSignedIn']), ...mapState(['childrenFlags', 'userSignedIn']),
currentItemIssuesBeginAtIndex() {
return this.children.findIndex(item => item.type === ChildType.Issue);
},
hasMoreChildren() { hasMoreChildren() {
const flags = this.childrenFlags[this.parentItem.reference]; const flags = this.childrenFlags[this.parentItem.reference];
......
...@@ -48,7 +48,7 @@ export default { ...@@ -48,7 +48,7 @@ export default {
* @param {number} object.newIndex new position of target item * @param {number} object.newIndex new position of target item
* @param {object} object.targetItem target item object * @param {object} object.targetItem target item object
*/ */
getTreeReorderMutation({ newIndex, targetItem }) { getTreeReorderMutation({ oldIndex, newIndex, targetItem }) {
let relativePosition; let relativePosition;
// adjacentReference is always the item that's at the position // adjacentReference is always the item that's at the position
...@@ -65,10 +65,14 @@ export default { ...@@ -65,10 +65,14 @@ export default {
// Adjacent reference will be the one which is currently at the bottom, // Adjacent reference will be the one which is currently at the bottom,
// and it's relative position with respect to target's new position is `before`. // and it's relative position with respect to target's new position is `before`.
relativePosition = relativePositions.Before; relativePosition = relativePositions.Before;
} else { } else if (oldIndex < newIndex) {
// If newIndex is neither top nor bottom, it was moved somewhere in the middle. // If newIndex is neither top nor bottom, it was moved somewhere in the middle.
// Adjacent reference will be the one which currently at that position, // Adjacent reference will be the one which currently at that position,
// and it's relative postion with respect to target's new position is `after`.
// when the item is moved down, the newIndex is before the adjacent reference.
relativePosition = relativePositions.Before;
} else {
// when the item is moved up, the newIndex is after the adjacent reference.
relativePosition = relativePositions.After; relativePosition = relativePositions.After;
} }
...@@ -106,7 +110,7 @@ export default { ...@@ -106,7 +110,7 @@ export default {
const targetItem = this.children[oldIndex]; const targetItem = this.children[oldIndex];
this.reorderItem({ this.reorderItem({
treeReorderMutation: this.getTreeReorderMutation({ newIndex, targetItem }), treeReorderMutation: this.getTreeReorderMutation({ oldIndex, newIndex, targetItem }),
parentItem: this.parentItem, parentItem: this.parentItem,
targetItem, targetItem,
oldIndex, oldIndex,
......
...@@ -286,7 +286,7 @@ export const receiveAddItemSuccess = ({ dispatch, commit, getters }, { rawItems ...@@ -286,7 +286,7 @@ export const receiveAddItemSuccess = ({ dispatch, commit, getters }, { rawItems
}); });
commit(types.RECEIVE_ADD_ITEM_SUCCESS, { commit(types.RECEIVE_ADD_ITEM_SUCCESS, {
insertAt: getters.isEpic ? 0 : getters.issuesBeginAtIndex, insertAt: 0,
items, items,
}); });
...@@ -342,7 +342,7 @@ export const receiveCreateItemSuccess = ({ state, commit, dispatch, getters }, { ...@@ -342,7 +342,7 @@ export const receiveCreateItemSuccess = ({ state, commit, dispatch, getters }, {
}); });
commit(types.RECEIVE_CREATE_ITEM_SUCCESS, { commit(types.RECEIVE_CREATE_ITEM_SUCCESS, {
insertAt: getters.issuesBeginAtIndex > 0 ? getters.issuesBeginAtIndex - 1 : 0, insertAt: 0,
item, item,
}); });
......
...@@ -23,9 +23,6 @@ export const headerItems = state => [ ...@@ -23,9 +23,6 @@ export const headerItems = state => [
}, },
]; ];
export const issuesBeginAtIndex = (state, getters) =>
getters.directChildren.findIndex(item => item.type === ChildType.Issue);
export const itemAutoCompleteSources = (state, getters) => { export const itemAutoCompleteSources = (state, getters) => {
if (getters.isEpic) { if (getters.isEpic) {
return state.autoCompleteEpics ? getters.autoCompleteSources : {}; return state.autoCompleteEpics ? getters.autoCompleteSources : {};
......
...@@ -5,12 +5,7 @@ import createDefaultState from 'ee/related_items_tree/store/state'; ...@@ -5,12 +5,7 @@ import createDefaultState from 'ee/related_items_tree/store/state';
import { issuableTypesMap } from 'ee/related_issues/constants'; import { issuableTypesMap } from 'ee/related_issues/constants';
import { ChildType } from 'ee/related_items_tree/constants'; import { ChildType } from 'ee/related_items_tree/constants';
import { import { mockEpic1, mockEpic2 } from '../../../javascripts/related_items_tree/mock_data';
mockEpic1,
mockEpic2,
mockIssue1,
mockIssue2,
} from '../../../javascripts/related_items_tree/mock_data';
window.gl = window.gl || {}; window.gl = window.gl || {};
...@@ -19,19 +14,11 @@ describe('RelatedItemsTree', () => { ...@@ -19,19 +14,11 @@ describe('RelatedItemsTree', () => {
describe('getters', () => { describe('getters', () => {
const { GfmAutoComplete } = gl; const { GfmAutoComplete } = gl;
let state; let state;
let mockGetters;
beforeAll(() => { beforeAll(() => {
gl.GfmAutoComplete = { gl.GfmAutoComplete = {
dataSources: 'foo/bar', dataSources: 'foo/bar',
}; };
mockGetters = {
directChildren: [mockEpic1, mockEpic2, mockIssue1, mockIssue2].map(item => ({
...item,
type: item.reference.indexOf('&') > -1 ? ChildType.Epic : ChildType.Issue,
})),
};
}); });
beforeEach(() => { beforeEach(() => {
...@@ -103,12 +90,6 @@ describe('RelatedItemsTree', () => { ...@@ -103,12 +90,6 @@ describe('RelatedItemsTree', () => {
}); });
}); });
describe('issuesBeginAtIndex', () => {
it('returns number representing index at which Issues begin in direct children array', () => {
expect(getters.issuesBeginAtIndex(state, mockGetters)).toBe(2);
});
});
describe('itemAutoCompleteSources', () => { describe('itemAutoCompleteSources', () => {
it('returns autoCompleteSources value when `issuableType` is set to `Epic` and `autoCompleteEpics` is true', () => { it('returns autoCompleteSources value when `issuableType` is set to `Epic` and `autoCompleteEpics` is true', () => {
const mockGetter = { const mockGetter = {
......
...@@ -801,7 +801,6 @@ describe('RelatedItemTree', () => { ...@@ -801,7 +801,6 @@ describe('RelatedItemTree', () => {
describe('receiveAddItemSuccess', () => { describe('receiveAddItemSuccess', () => {
it('should set `state.itemAddInProgress` to false and dispatches actions `setPendingReferences`, `setItemInputValue` and `toggleAddItemForm`', done => { it('should set `state.itemAddInProgress` to false and dispatches actions `setPendingReferences`, `setItemInputValue` and `toggleAddItemForm`', done => {
state.epicsBeginAtIndex = 0;
state.issuableType = issuableTypesMap.EPIC; state.issuableType = issuableTypesMap.EPIC;
state.isEpic = true; state.isEpic = true;
...@@ -972,7 +971,6 @@ describe('RelatedItemTree', () => { ...@@ -972,7 +971,6 @@ describe('RelatedItemTree', () => {
reference: `${mockEpics[0].group.fullPath}${mockEpics[0].reference}`, reference: `${mockEpics[0].group.fullPath}${mockEpics[0].reference}`,
pathIdSeparator: PathIdSeparator.Epic, pathIdSeparator: PathIdSeparator.Epic,
}); });
state.epicsBeginAtIndex = 0;
state.parentItem = { state.parentItem = {
fullPath: createdEpic.group.fullPath, fullPath: createdEpic.group.fullPath,
}; };
......
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