Commit 897a37b8 authored by Winnie Hellmann's avatar Winnie Hellmann Committed by Kushal Pandya

Use EpicActionsSplitButton in RelatedItemsTreeHeader

parent 8a6d7e6b
<script>
import SplitButton from '~/vue_shared/components/split_button.vue';
import { s__ } from '~/locale';
const actionItems = [
{
title: s__('Epics|Add an epic'),
description: s__('Epics|Add an existing epic as a child epic.'),
eventName: 'showAddEpicForm',
},
{
title: s__('Epics|Create new epic'),
description: s__('Epics|Create an epic within this group and add it as a child epic.'),
eventName: 'showCreateEpicForm',
},
];
export default {
actionItems,
components: {
SplitButton,
},
};
</script>
<template>
<split-button
:action-items="$options.actionItems"
class="js-add-epics-button"
menu-class="dropdown-menu-large"
right
size="sm"
v-on="$listeners"
/>
</template>
...@@ -6,16 +6,15 @@ import { GlButton, GlTooltipDirective } from '@gitlab/ui'; ...@@ -6,16 +6,15 @@ import { GlButton, GlTooltipDirective } from '@gitlab/ui';
import { sprintf, s__ } from '~/locale'; import { sprintf, s__ } from '~/locale';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
import DroplabDropdownButton from '~/vue_shared/components/droplab_dropdown_button.vue'; import { issuableTypesMap } from 'ee/related_issues/constants';
import { EpicDropdownActions } from '../constants'; import EpicActionsSplitButton from './epic_actions_split_button.vue';
export default { export default {
EpicDropdownActions,
components: { components: {
Icon, Icon,
GlButton, GlButton,
DroplabDropdownButton, EpicActionsSplitButton,
}, },
directives: { directives: {
GlTooltip: GlTooltipDirective, GlTooltip: GlTooltipDirective,
...@@ -32,15 +31,20 @@ export default { ...@@ -32,15 +31,20 @@ export default {
}, },
methods: { methods: {
...mapActions(['toggleAddItemForm', 'toggleCreateEpicForm']), ...mapActions(['toggleAddItemForm', 'toggleCreateEpicForm']),
handleActionClick({ id, issuableType }) { showAddEpicForm() {
if (id === 0) { this.toggleAddItemForm({
this.toggleAddItemForm({ issuableType: issuableTypesMap.EPIC,
issuableType, toggleState: true,
toggleState: true, });
}); },
} else { showAddIssueForm() {
this.toggleCreateEpicForm({ toggleState: true }); this.toggleAddItemForm({
} issuableType: issuableTypesMap.ISSUE,
toggleState: true,
});
},
showCreateEpicForm() {
this.toggleCreateEpicForm({ toggleState: true });
}, },
}, },
}; };
...@@ -67,13 +71,10 @@ export default { ...@@ -67,13 +71,10 @@ export default {
</div> </div>
<div class="d-inline-flex"> <div class="d-inline-flex">
<template v-if="parentItem.userPermissions.adminEpic"> <template v-if="parentItem.userPermissions.adminEpic">
<droplab-dropdown-button <epic-actions-split-button
:actions="$options.EpicDropdownActions" :class="headerItems[0].qaClass"
:default-action="0" @showAddEpicForm="showAddEpicForm"
:primary-button-class="`${headerItems[0].qaClass} js-add-epics-button`" @showCreateEpicForm="showCreateEpicForm"
class="btn-create-epic"
size="sm"
@onActionClick="handleActionClick"
/> />
<slot name="issueActions"> <slot name="issueActions">
...@@ -81,7 +82,7 @@ export default { ...@@ -81,7 +82,7 @@ export default {
:class="headerItems[1].qaClass" :class="headerItems[1].qaClass"
class="ml-1 js-add-issues-button" class="ml-1 js-add-issues-button"
size="sm" size="sm"
@click="handleActionClick({ id: 0, issuableType: 'issue' })" @click="showAddIssueForm"
>{{ __('Add an issue') }}</gl-button >{{ __('Add an issue') }}</gl-button
> >
</slot> </slot>
......
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { issuableTypesMap } from 'ee/related_issues/constants';
export const ChildType = { export const ChildType = {
// eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings // eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings
...@@ -43,21 +42,6 @@ export const RemoveItemModalProps = { ...@@ -43,21 +42,6 @@ export const RemoveItemModalProps = {
}, },
}; };
export const EpicDropdownActions = [
{
id: 0,
issuableType: issuableTypesMap.EPIC,
title: s__('Epics|Add an epic'),
description: s__('Epics|Add an existing epic as a child epic.'),
},
{
id: 1,
issuableType: issuableTypesMap.EPIC,
title: s__('Epics|Create new epic'),
description: s__('Epics|Create an epic within this group and add it as a child epic.'),
},
];
export const OVERFLOW_AFTER = 5; export const OVERFLOW_AFTER = 5;
export const itemRemoveModalId = 'item-remove-confirmation'; export const itemRemoveModalId = 'item-remove-confirmation';
...@@ -2,15 +2,6 @@ ...@@ -2,15 +2,6 @@
border-top-left-radius: 0; border-top-left-radius: 0;
border-top-right-radius: 0; border-top-right-radius: 0;
.btn-create-epic {
.dropdown-menu {
top: 100%;
right: 0;
bottom: auto;
left: auto;
}
}
.add-item-form-container { .add-item-form-container {
border-bottom: 1px solid $border-color; border-bottom: 1px solid $border-color;
} }
......
...@@ -3,10 +3,10 @@ import { GlButton } from '@gitlab/ui'; ...@@ -3,10 +3,10 @@ import { GlButton } from '@gitlab/ui';
import RelatedItemsTreeHeader from 'ee/related_items_tree/components/related_items_tree_header.vue'; import RelatedItemsTreeHeader from 'ee/related_items_tree/components/related_items_tree_header.vue';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
import DroplabDropdownButton from '~/vue_shared/components/droplab_dropdown_button.vue';
import createDefaultStore from 'ee/related_items_tree/store'; import createDefaultStore from 'ee/related_items_tree/store';
import * as epicUtils from 'ee/related_items_tree/utils/epic_utils'; import * as epicUtils from 'ee/related_items_tree/utils/epic_utils';
import { issuableTypesMap } from 'ee/related_issues/constants'; import { issuableTypesMap } from 'ee/related_issues/constants';
import EpicActionsSplitButton from 'ee/related_items_tree/components/epic_actions_split_button.vue';
import { mockParentItem, mockQueryResponse } from '../mock_data'; import { mockParentItem, mockQueryResponse } from '../mock_data';
...@@ -37,6 +37,9 @@ describe('RelatedItemsTree', () => { ...@@ -37,6 +37,9 @@ describe('RelatedItemsTree', () => {
describe('RelatedItemsTreeHeader', () => { describe('RelatedItemsTreeHeader', () => {
let wrapper; let wrapper;
const findAddIssuesButton = () => wrapper.find(GlButton);
const findEpicsSplitButton = () => wrapper.find(EpicActionsSplitButton);
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
}); });
...@@ -53,34 +56,89 @@ describe('RelatedItemsTree', () => { ...@@ -53,34 +56,89 @@ describe('RelatedItemsTree', () => {
}); });
}); });
describe('methods', () => { describe('epic actions split button', () => {
beforeEach(() => { beforeEach(() => {
wrapper = createComponent(); wrapper = createComponent();
}); });
describe('handleActionClick', () => { describe('showAddEpicForm event', () => {
const issuableType = issuableTypesMap.Epic; let toggleAddItemForm;
it('calls `toggleAddItemForm` action when provided `id` param as value `0`', () => {
spyOn(wrapper.vm, 'toggleAddItemForm');
wrapper.vm.handleActionClick({ beforeEach(() => {
id: 0, toggleAddItemForm = jasmine.createSpy();
issuableType, wrapper.vm.$store.hotUpdate({
actions: {
toggleAddItemForm,
},
}); });
});
expect(wrapper.vm.toggleAddItemForm).toHaveBeenCalledWith({ it('dispatches toggleAddItemForm action', () => {
issuableType, findEpicsSplitButton().vm.$emit('showAddEpicForm');
expect(toggleAddItemForm).toHaveBeenCalled();
const payload = toggleAddItemForm.calls.mostRecent().args[1];
expect(payload).toEqual({
issuableType: issuableTypesMap.EPIC,
toggleState: true, toggleState: true,
}); });
}); });
});
describe('showCreateEpicForm event', () => {
let toggleCreateEpicForm;
beforeEach(() => {
toggleCreateEpicForm = jasmine.createSpy();
wrapper.vm.$store.hotUpdate({
actions: {
toggleCreateEpicForm,
},
});
});
it('dispatches toggleCreateEpicForm action', () => {
findEpicsSplitButton().vm.$emit('showCreateEpicForm');
expect(toggleCreateEpicForm).toHaveBeenCalled();
const payload = toggleCreateEpicForm.calls.mostRecent().args[1];
expect(payload).toEqual({ toggleState: true });
});
});
});
describe('add issues button', () => {
beforeEach(() => {
wrapper = createComponent();
});
describe('click event', () => {
let toggleAddItemForm;
beforeEach(() => {
toggleAddItemForm = jasmine.createSpy();
wrapper.vm.$store.hotUpdate({
actions: {
toggleAddItemForm,
},
});
});
it('dispatches toggleAddItemForm action', () => {
findAddIssuesButton().vm.$emit('click');
it('calls `toggleCreateEpicForm` action when provided `id` param value is not `0`', () => { expect(toggleAddItemForm).toHaveBeenCalled();
spyOn(wrapper.vm, 'toggleCreateEpicForm');
wrapper.vm.handleActionClick({ id: 1 }); const payload = toggleAddItemForm.calls.mostRecent().args[1];
expect(wrapper.vm.toggleCreateEpicForm).toHaveBeenCalledWith({ toggleState: true }); expect(payload).toEqual({
issuableType: issuableTypesMap.ISSUE,
toggleState: true,
});
}); });
}); });
}); });
...@@ -115,11 +173,11 @@ describe('RelatedItemsTree', () => { ...@@ -115,11 +173,11 @@ describe('RelatedItemsTree', () => {
}); });
it('renders `Add an epic` dropdown button', () => { it('renders `Add an epic` dropdown button', () => {
expect(wrapper.find(DroplabDropdownButton).isVisible()).toBe(true); expect(findEpicsSplitButton().isVisible()).toBe(true);
}); });
it('renders `Add an issue` dropdown button', () => { it('renders `Add an issue` dropdown button', () => {
const addIssueBtn = wrapper.find(GlButton); const addIssueBtn = findAddIssuesButton();
expect(addIssueBtn.isVisible()).toBe(true); expect(addIssueBtn.isVisible()).toBe(true);
expect(addIssueBtn.text()).toBe('Add an issue'); expect(addIssueBtn.text()).toBe('Add an issue');
...@@ -131,7 +189,7 @@ describe('RelatedItemsTree', () => { ...@@ -131,7 +189,7 @@ describe('RelatedItemsTree', () => {
it('defaults to button', () => { it('defaults to button', () => {
wrapper = createComponent(); wrapper = createComponent();
expect(wrapper.find(GlButton).exists()).toBe(true); expect(findAddIssuesButton().exists()).toBe(true);
}); });
it('uses provided slot content', () => { it('uses provided slot content', () => {
...@@ -145,7 +203,7 @@ describe('RelatedItemsTree', () => { ...@@ -145,7 +203,7 @@ describe('RelatedItemsTree', () => {
}, },
}); });
expect(wrapper.find(GlButton).exists()).toBe(false); expect(findAddIssuesButton().exists()).toBe(false);
expect(wrapper.find(issueActions).exists()).toBe(true); expect(wrapper.find(issueActions).exists()).toBe(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