Commit 5e1148e4 authored by Brandon Labuschagne's avatar Brandon Labuschagne Committed by Mike Greiling

Default cycle analytics duration chart stage filter to all items selected

parent 4dff571a
<script> <script>
import { sprintf, s__, n__ } from '~/locale'; import { sprintf, s__ } from '~/locale';
import $ from 'jquery'; import $ from 'jquery';
import _ from 'underscore'; import _ from 'underscore';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
import { GlButton } from '@gitlab/ui'; import { GlButton } from '@gitlab/ui';
import { capitalizeFirstCharacter } from '~/lib/utils/text_utility';
export default { export default {
name: 'StageDropdownFilter', name: 'StageDropdownFilter',
...@@ -25,21 +24,26 @@ export default { ...@@ -25,21 +24,26 @@ export default {
}, },
data() { data() {
return { return {
selectedStages: [], selectedStages: this.stages,
}; };
}, },
computed: { computed: {
selectedStagesLabel() { selectedStagesLabel() {
return this.selectedStages.length const { stages, selectedStages } = this;
? sprintf(
n__( if (selectedStages.length === stages.length) {
'CycleAnalytics|%{stageName}', return s__('CycleAnalytics|All stages');
'CycleAnalytics|%d stages selected', }
this.selectedStages.length, if (selectedStages.length > 1) {
), return sprintf(s__('CycleAnalytics|%{stageCount} stages selected'), {
{ stageName: capitalizeFirstCharacter(this.selectedStages[0].name) }, stageCount: selectedStages.length,
) });
: s__('CycleAnalytics|All stages'); }
if (selectedStages.length === 1) {
return selectedStages[0].title;
}
return s__('CycleAnalytics|No stages selected');
}, },
}, },
mounted() { mounted() {
...@@ -49,14 +53,14 @@ export default { ...@@ -49,14 +53,14 @@ export default {
clicked: this.onClick.bind(this), clicked: this.onClick.bind(this),
data: this.formatData.bind(this), data: this.formatData.bind(this),
renderRow: group => this.rowTemplate(group), renderRow: group => this.rowTemplate(group),
text: stage => stage.name, text: stage => stage.title,
}); });
}, },
methods: { methods: {
setSelectedStages(selectedObj, isMarking) { setSelectedStages(selectedObj, isMarking) {
this.selectedStages = isMarking this.selectedStages = isMarking
? this.selectedStages.concat([selectedObj]) ? this.selectedStages.concat([selectedObj])
: this.selectedStages.filter(stage => stage.name !== selectedObj.name); : this.selectedStages.filter(stage => stage.title !== selectedObj.title);
}, },
onClick({ selectedObj, e, isMarking }) { onClick({ selectedObj, e, isMarking }) {
e.preventDefault(); e.preventDefault();
...@@ -69,8 +73,8 @@ export default { ...@@ -69,8 +73,8 @@ export default {
rowTemplate(stage) { rowTemplate(stage) {
return ` return `
<li> <li>
<a href='#' class='dropdown-menu-link'> <a href='#' class='dropdown-menu-link is-active'>
${_.escape(capitalizeFirstCharacter(stage.name))} ${_.escape(stage.title)}
</a> </a>
</li> </li>
`; `;
......
...@@ -10,13 +10,13 @@ jest.mock('~/api', () => ({ ...@@ -10,13 +10,13 @@ jest.mock('~/api', () => ({
const stages = [ const stages = [
{ {
name: 'issue', title: 'Issue',
}, },
{ {
name: 'plan', title: 'Plan',
}, },
{ {
name: 'code', title: 'Code',
}, },
]; ];
...@@ -34,10 +34,11 @@ describe('StageDropdownFilter component', () => { ...@@ -34,10 +34,11 @@ describe('StageDropdownFilter component', () => {
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null;
}); });
beforeEach(() => { beforeEach(() => {
createComponent({ multiSelect: false }); createComponent();
}); });
const findDropdown = () => wrapper.find('.dropdown'); const findDropdown = () => wrapper.find('.dropdown');
...@@ -55,43 +56,42 @@ describe('StageDropdownFilter component', () => { ...@@ -55,43 +56,42 @@ describe('StageDropdownFilter component', () => {
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}); });
it('should add to selection when new stage is clicked', () => { describe('clicking a selected stage', () => {
findDropdownItems() it('should remove from selection', () => {
.at(0) const item = findDropdownItems().at(0);
.trigger('click');
findDropdownItems() item.trigger('click');
.at(1)
.trigger('click');
expect(wrapper.emittedByOrder()).toEqual([ expect(wrapper.emittedByOrder()).toEqual([
{ {
name: 'selected', name: 'selected',
args: [[stages[0]]], args: [[stages[1], stages[2]]],
},
{
name: 'selected',
args: [[stages[0], stages[1]]],
}, },
]); ]);
}); });
});
it('should remove from selection when clicked again', () => { describe('clicking a deselected stage', () => {
const item = findDropdownItems().at(0); it('should add to selection', () => {
findDropdownItems()
.at(0)
.trigger('click');
item.trigger('click'); findDropdownItems()
item.trigger('click'); .at(0)
.trigger('click');
expect(wrapper.emittedByOrder()).toEqual([ expect(wrapper.emittedByOrder()).toEqual([
{ {
name: 'selected', name: 'selected',
args: [[stages[0]]], args: [[stages[1], stages[2]]],
}, },
{ {
name: 'selected', name: 'selected',
args: [[]], args: [[stages[1], stages[2], stages[0]]],
}, },
]); ]);
}); });
}); });
});
}); });
...@@ -5257,14 +5257,15 @@ msgid_plural "CycleAnalytics|%d projects selected" ...@@ -5257,14 +5257,15 @@ msgid_plural "CycleAnalytics|%d projects selected"
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
msgid "CycleAnalytics|%{stageName}" msgid "CycleAnalytics|%{stageCount} stages selected"
msgid_plural "CycleAnalytics|%d stages selected" msgstr ""
msgstr[0] ""
msgstr[1] ""
msgid "CycleAnalytics|All stages" msgid "CycleAnalytics|All stages"
msgstr "" msgstr ""
msgid "CycleAnalytics|No stages selected"
msgstr ""
msgid "CycleAnalytics|Stages" msgid "CycleAnalytics|Stages"
msgstr "" msgstr ""
......
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