Commit da3f6c39 authored by Winnie Hellmann's avatar Winnie Hellmann Committed by Fatih Acet

Remove actionType from RelatedItemsTreeApp component

parent 461f4589
...@@ -10,11 +10,10 @@ import TreeItemRemoveModal from './tree_item_remove_modal.vue'; ...@@ -10,11 +10,10 @@ import TreeItemRemoveModal from './tree_item_remove_modal.vue';
import RelatedItemsTreeHeader from './related_items_tree_header.vue'; import RelatedItemsTreeHeader from './related_items_tree_header.vue';
import RelatedItemsTreeBody from './related_items_tree_body.vue'; import RelatedItemsTreeBody from './related_items_tree_body.vue';
import { PathIdSeparator, ActionType, OVERFLOW_AFTER } from '../constants'; import { PathIdSeparator, OVERFLOW_AFTER } from '../constants';
export default { export default {
PathIdSeparator, PathIdSeparator,
ActionType,
OVERFLOW_AFTER, OVERFLOW_AFTER,
components: { components: {
GlLoadingIcon, GlLoadingIcon,
...@@ -37,7 +36,7 @@ export default { ...@@ -37,7 +36,7 @@ export default {
'autoCompleteIssues', 'autoCompleteIssues',
'pendingReferences', 'pendingReferences',
'itemInputValue', 'itemInputValue',
'actionType', 'issuableType',
'epicsEndpoint', 'epicsEndpoint',
'issuesEndpoint', 'issuesEndpoint',
]), ]),
...@@ -90,12 +89,12 @@ export default { ...@@ -90,12 +89,12 @@ export default {
}); });
}, },
handleAddItemFormCancel() { handleAddItemFormCancel() {
this.toggleAddItemForm({ toggleState: false, actionType: this.actionType }); this.toggleAddItemForm({ toggleState: false });
this.setPendingReferences([]); this.setPendingReferences([]);
this.setItemInputValue(''); this.setItemInputValue('');
}, },
handleCreateEpicFormCancel() { handleCreateEpicFormCancel() {
this.toggleCreateEpicForm({ toggleState: false, actionType: this.actionType }); this.toggleCreateEpicForm({ toggleState: false });
this.setItemInputValue(''); this.setItemInputValue('');
}, },
}, },
...@@ -123,7 +122,7 @@ export default { ...@@ -123,7 +122,7 @@ export default {
> >
<add-item-form <add-item-form
v-if="showAddItemForm" v-if="showAddItemForm"
:issuable-type="actionType" :issuable-type="issuableType"
:input-value="itemInputValue" :input-value="itemInputValue"
:is-submitting="itemAddInProgress" :is-submitting="itemAddInProgress"
:pending-references="pendingReferences" :pending-references="pendingReferences"
......
...@@ -40,10 +40,7 @@ export default { ...@@ -40,10 +40,7 @@ export default {
toggleState: true, toggleState: true,
}); });
} else { } else {
this.toggleCreateEpicForm({ this.toggleCreateEpicForm({ toggleState: true });
actionType,
toggleState: true,
});
} }
}, },
}, },
......
import { issuableTypesMap } from 'ee/related_issues/constants';
import { ChildType, ActionType, PathIdSeparator } from '../constants'; import { ChildType, ActionType, PathIdSeparator } from '../constants';
export const autoCompleteSources = () => gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources; export const autoCompleteSources = () => gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources;
...@@ -32,6 +33,18 @@ export const itemAutoCompleteSources = (state, getters) => { ...@@ -32,6 +33,18 @@ export const itemAutoCompleteSources = (state, getters) => {
return state.autoCompleteIssues ? getters.autoCompleteSources : {}; return state.autoCompleteIssues ? getters.autoCompleteSources : {};
}; };
export const issuableType = state => {
if (state.actionType === ActionType.Epic) {
return issuableTypesMap.EPIC;
}
if (state.actionType === ActionType.Issue) {
return issuableTypesMap.ISSUE;
}
return null;
};
export const itemPathIdSeparator = state => export const itemPathIdSeparator = state =>
state.actionType === ActionType.Epic ? PathIdSeparator.Epic : PathIdSeparator.Issue; state.actionType === ActionType.Epic ? PathIdSeparator.Epic : PathIdSeparator.Issue;
......
...@@ -121,13 +121,14 @@ export default { ...@@ -121,13 +121,14 @@ export default {
}, },
[types.TOGGLE_ADD_ITEM_FORM](state, { actionType, toggleState }) { [types.TOGGLE_ADD_ITEM_FORM](state, { actionType, toggleState }) {
state.actionType = actionType; if (actionType) {
state.actionType = actionType;
}
state.showAddItemForm = toggleState; state.showAddItemForm = toggleState;
state.showCreateEpicForm = false; state.showCreateEpicForm = false;
}, },
[types.TOGGLE_CREATE_EPIC_FORM](state, { actionType, toggleState }) { [types.TOGGLE_CREATE_EPIC_FORM](state, { toggleState }) {
state.actionType = actionType;
state.showCreateEpicForm = toggleState; state.showCreateEpicForm = toggleState;
state.showAddItemForm = false; state.showAddItemForm = false;
}, },
......
...@@ -2,6 +2,7 @@ import * as getters from 'ee/related_items_tree/store/getters'; ...@@ -2,6 +2,7 @@ import * as getters from 'ee/related_items_tree/store/getters';
import createDefaultState from 'ee/related_items_tree/store/state'; import createDefaultState from 'ee/related_items_tree/store/state';
import { issuableTypesMap } from 'ee/related_issues/constants';
import { ChildType, ActionType } from 'ee/related_items_tree/constants'; import { ChildType, ActionType } from 'ee/related_items_tree/constants';
import { import {
...@@ -142,6 +143,17 @@ describe('RelatedItemsTree', () => { ...@@ -142,6 +143,17 @@ describe('RelatedItemsTree', () => {
}); });
}); });
describe('issuableType', () => {
it.each`
actionType | expectedValue
${null} | ${null}
${ActionType.Epic} | ${issuableTypesMap.EPIC}
${ActionType.Issue} | ${issuableTypesMap.ISSUE}
`('for $actionType returns $expectedValue', ({ actionType, expectedValue }) => {
expect(getters.issuableType({ actionType })).toBe(expectedValue);
});
});
describe('itemPathIdSeparator', () => { describe('itemPathIdSeparator', () => {
it('returns string containing pathIdSeparator for `Epic` when `state.actionType` is set to `Epic`', () => { it('returns string containing pathIdSeparator for `Epic` when `state.actionType` is set to `Epic`', () => {
state.actionType = ActionType.Epic; state.actionType = ActionType.Epic;
......
...@@ -379,15 +379,11 @@ describe('RelatedItemsTree', () => { ...@@ -379,15 +379,11 @@ describe('RelatedItemsTree', () => {
}); });
describe(types.TOGGLE_CREATE_EPIC_FORM, () => { describe(types.TOGGLE_CREATE_EPIC_FORM, () => {
it('should set value of `actionType`, `showCreateEpicForm` as it is and `showAddItemForm` as false on state', () => { it('should set value of `showCreateEpicForm` as it is and `showAddItemForm` as false on state', () => {
const data = { const data = { toggleState: true };
actionType: 'Epic',
toggleState: true,
};
mutations[types.TOGGLE_CREATE_EPIC_FORM](state, data); mutations[types.TOGGLE_CREATE_EPIC_FORM](state, data);
expect(state.actionType).toBe(data.actionType);
expect(state.showCreateEpicForm).toBe(data.toggleState); expect(state.showCreateEpicForm).toBe(data.toggleState);
expect(state.showAddItemForm).toBe(false); expect(state.showAddItemForm).toBe(false);
}); });
......
...@@ -124,10 +124,7 @@ describe('RelatedItemsTreeApp', () => { ...@@ -124,10 +124,7 @@ describe('RelatedItemsTreeApp', () => {
wrapper.vm.handleAddItemFormCancel(); wrapper.vm.handleAddItemFormCancel();
expect(wrapper.vm.toggleAddItemForm).toHaveBeenCalledWith({ expect(wrapper.vm.toggleAddItemForm).toHaveBeenCalledWith({ toggleState: false });
toggleState: false,
actionType: '',
});
}); });
it('calls `setPendingReferences` action with empty array', () => { it('calls `setPendingReferences` action with empty array', () => {
...@@ -152,11 +149,6 @@ describe('RelatedItemsTreeApp', () => { ...@@ -152,11 +149,6 @@ describe('RelatedItemsTreeApp', () => {
spyOn(wrapper.vm, 'toggleCreateEpicForm'); spyOn(wrapper.vm, 'toggleCreateEpicForm');
wrapper.vm.handleCreateEpicFormCancel(); wrapper.vm.handleCreateEpicFormCancel();
expect(wrapper.vm.toggleCreateEpicForm).toHaveBeenCalledWith({
toggleState: false,
actionType: '',
});
}); });
it('calls `setItemInputValue` action with empty string', () => { it('calls `setItemInputValue` action with empty string', () => {
......
...@@ -73,15 +73,9 @@ describe('RelatedItemsTree', () => { ...@@ -73,15 +73,9 @@ describe('RelatedItemsTree', () => {
it('calls `toggleCreateEpicForm` action when provided `id` param value is not `0`', () => { it('calls `toggleCreateEpicForm` action when provided `id` param value is not `0`', () => {
spyOn(wrapper.vm, 'toggleCreateEpicForm'); spyOn(wrapper.vm, 'toggleCreateEpicForm');
wrapper.vm.handleActionClick({ wrapper.vm.handleActionClick({ id: 1 });
id: 1,
actionType,
});
expect(wrapper.vm.toggleCreateEpicForm).toHaveBeenCalledWith({ expect(wrapper.vm.toggleCreateEpicForm).toHaveBeenCalledWith({ toggleState: true });
actionType,
toggleState: true,
});
}); });
}); });
}); });
......
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