Commit d1a865d5 authored by Illya Klymov's avatar Illya Klymov

Merge branch '213717-migrate-depreacted-dashboard-dropdown' into 'master'

Migrate dashboard dropdown to the new dropdown component

Closes #213717

See merge request gitlab-org/gitlab!38670
parents 737b0d43 3bb1f411
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
import { mapState, mapGetters } from 'vuex'; import { mapState, mapGetters } from 'vuex';
import { import {
GlIcon, GlIcon,
GlDeprecatedDropdown, GlNewDropdown,
GlDeprecatedDropdownItem, GlNewDropdownItem,
GlDeprecatedDropdownHeader, GlNewDropdownHeader,
GlDeprecatedDropdownDivider, GlNewDropdownDivider,
GlSearchBoxByType, GlSearchBoxByType,
GlModalDirective, GlModalDirective,
} from '@gitlab/ui'; } from '@gitlab/ui';
...@@ -17,10 +17,10 @@ const events = { ...@@ -17,10 +17,10 @@ const events = {
export default { export default {
components: { components: {
GlIcon, GlIcon,
GlDeprecatedDropdown, GlNewDropdown,
GlDeprecatedDropdownItem, GlNewDropdownItem,
GlDeprecatedDropdownHeader, GlNewDropdownHeader,
GlDeprecatedDropdownDivider, GlNewDropdownDivider,
GlSearchBoxByType, GlSearchBoxByType,
}, },
directives: { directives: {
...@@ -73,16 +73,13 @@ export default { ...@@ -73,16 +73,13 @@ export default {
}; };
</script> </script>
<template> <template>
<gl-deprecated-dropdown <gl-new-dropdown
toggle-class="dropdown-menu-toggle" toggle-class="dropdown-menu-toggle"
menu-class="monitor-dashboard-dropdown-menu" menu-class="monitor-dashboard-dropdown-menu"
:text="selectedDashboardText" :text="selectedDashboardText"
> >
<div class="d-flex flex-column overflow-hidden"> <div class="d-flex flex-column overflow-hidden">
<gl-deprecated-dropdown-header class="monitor-dashboard-dropdown-header text-center">{{ <gl-new-dropdown-header>{{ __('Dashboard') }}</gl-new-dropdown-header>
__('Dashboard')
}}</gl-deprecated-dropdown-header>
<gl-deprecated-dropdown-divider />
<gl-search-box-by-type <gl-search-box-by-type
ref="monitorDashboardsDropdownSearch" ref="monitorDashboardsDropdownSearch"
v-model="searchTerm" v-model="searchTerm"
...@@ -90,33 +87,36 @@ export default { ...@@ -90,33 +87,36 @@ export default {
/> />
<div class="flex-fill overflow-auto"> <div class="flex-fill overflow-auto">
<gl-deprecated-dropdown-item <gl-new-dropdown-item
v-for="dashboard in starredDashboards" v-for="dashboard in starredDashboards"
:key="dashboard.path" :key="dashboard.path"
:active="dashboard.path === selectedDashboardPath" :is-check-item="true"
active-class="is-active" :is-checked="dashboard.path === selectedDashboardPath"
@click="selectDashboard(dashboard)" @click="selectDashboard(dashboard)"
> >
<div class="d-flex"> <div class="gl-display-flex">
{{ dashboardDisplayName(dashboard) }} <div class="gl-flex-grow-1 gl-min-w-0">
<gl-icon class="text-muted ml-auto" name="star" /> <div class="gl-word-break-all">
{{ dashboardDisplayName(dashboard) }}
</div>
</div>
<gl-icon class="text-muted gl-flex-shrink-0" name="star" />
</div> </div>
</gl-deprecated-dropdown-item> </gl-new-dropdown-item>
<gl-new-dropdown-divider
<gl-deprecated-dropdown-divider
v-if="starredDashboards.length && nonStarredDashboards.length" v-if="starredDashboards.length && nonStarredDashboards.length"
ref="starredListDivider" ref="starredListDivider"
/> />
<gl-deprecated-dropdown-item <gl-new-dropdown-item
v-for="dashboard in nonStarredDashboards" v-for="dashboard in nonStarredDashboards"
:key="dashboard.path" :key="dashboard.path"
:active="dashboard.path === selectedDashboardPath" :is-check-item="true"
active-class="is-active" :is-checked="dashboard.path === selectedDashboardPath"
@click="selectDashboard(dashboard)" @click="selectDashboard(dashboard)"
> >
{{ dashboardDisplayName(dashboard) }} {{ dashboardDisplayName(dashboard) }}
</gl-deprecated-dropdown-item> </gl-new-dropdown-item>
</div> </div>
<div <div
...@@ -127,5 +127,5 @@ export default { ...@@ -127,5 +127,5 @@ export default {
{{ __('No matching results') }} {{ __('No matching results') }}
</div> </div>
</div> </div>
</gl-deprecated-dropdown> </gl-new-dropdown>
</template> </template>
...@@ -63,8 +63,7 @@ ...@@ -63,8 +63,7 @@
} }
.prometheus-graphs-header { .prometheus-graphs-header {
.monitor-environment-dropdown-header header, .monitor-environment-dropdown-header header {
.monitor-dashboard-dropdown-header header {
font-size: $gl-font-size; font-size: $gl-font-size;
} }
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlDeprecatedDropdownItem, GlIcon } from '@gitlab/ui'; import { GlNewDropdownItem, GlIcon } from '@gitlab/ui';
import DashboardsDropdown from '~/monitoring/components/dashboards_dropdown.vue'; import DashboardsDropdown from '~/monitoring/components/dashboards_dropdown.vue';
...@@ -22,7 +22,7 @@ describe('DashboardsDropdown', () => { ...@@ -22,7 +22,7 @@ describe('DashboardsDropdown', () => {
}, },
}; };
return shallowMount(DashboardsDropdown, { wrapper = shallowMount(DashboardsDropdown, {
propsData: { propsData: {
...props, ...props,
defaultBranch, defaultBranch,
...@@ -33,8 +33,8 @@ describe('DashboardsDropdown', () => { ...@@ -33,8 +33,8 @@ describe('DashboardsDropdown', () => {
}); });
} }
const findItems = () => wrapper.findAll(GlDeprecatedDropdownItem); const findItems = () => wrapper.findAll(GlNewDropdownItem);
const findItemAt = i => wrapper.findAll(GlDeprecatedDropdownItem).at(i); const findItemAt = i => wrapper.findAll(GlNewDropdownItem).at(i);
const findSearchInput = () => wrapper.find({ ref: 'monitorDashboardsDropdownSearch' }); const findSearchInput = () => wrapper.find({ ref: 'monitorDashboardsDropdownSearch' });
const findNoItemsMsg = () => wrapper.find({ ref: 'monitorDashboardsDropdownMsg' }); const findNoItemsMsg = () => wrapper.find({ ref: 'monitorDashboardsDropdownMsg' });
const findStarredListDivider = () => wrapper.find({ ref: 'starredListDivider' }); const findStarredListDivider = () => wrapper.find({ ref: 'starredListDivider' });
...@@ -47,7 +47,7 @@ describe('DashboardsDropdown', () => { ...@@ -47,7 +47,7 @@ describe('DashboardsDropdown', () => {
describe('when it receives dashboards data', () => { describe('when it receives dashboards data', () => {
beforeEach(() => { beforeEach(() => {
wrapper = createComponent(); createComponent();
}); });
it('displays an item for each dashboard', () => { it('displays an item for each dashboard', () => {
...@@ -91,10 +91,22 @@ describe('DashboardsDropdown', () => { ...@@ -91,10 +91,22 @@ describe('DashboardsDropdown', () => {
}); });
}); });
describe('when a dashboard is selected', () => {
beforeEach(() => {
[mockSelectedDashboard] = starredDashboards;
createComponent();
});
it('dashboard item is selected', () => {
expect(findItemAt(0).props('isChecked')).toBe(true);
expect(findItemAt(1).props('isChecked')).toBe(false);
});
});
describe('when the dashboard is missing a display name', () => { describe('when the dashboard is missing a display name', () => {
beforeEach(() => { beforeEach(() => {
mockDashboards = dashboardGitResponse.map(d => ({ ...d, display_name: undefined })); mockDashboards = dashboardGitResponse.map(d => ({ ...d, display_name: undefined }));
wrapper = createComponent(); createComponent();
}); });
it('displays items with the dashboard path, with starred dashboards first', () => { it('displays items with the dashboard path, with starred dashboards first', () => {
...@@ -107,7 +119,7 @@ describe('DashboardsDropdown', () => { ...@@ -107,7 +119,7 @@ describe('DashboardsDropdown', () => {
describe('when it receives starred dashboards', () => { describe('when it receives starred dashboards', () => {
beforeEach(() => { beforeEach(() => {
mockDashboards = starredDashboards; mockDashboards = starredDashboards;
wrapper = createComponent(); createComponent();
}); });
it('displays an item for each dashboard', () => { it('displays an item for each dashboard', () => {
...@@ -128,7 +140,7 @@ describe('DashboardsDropdown', () => { ...@@ -128,7 +140,7 @@ describe('DashboardsDropdown', () => {
describe('when it receives only not-starred dashboards', () => { describe('when it receives only not-starred dashboards', () => {
beforeEach(() => { beforeEach(() => {
mockDashboards = notStarredDashboards; mockDashboards = notStarredDashboards;
wrapper = createComponent(); createComponent();
}); });
it('displays an item for each dashboard', () => { it('displays an item for each dashboard', () => {
...@@ -147,7 +159,7 @@ describe('DashboardsDropdown', () => { ...@@ -147,7 +159,7 @@ describe('DashboardsDropdown', () => {
describe('when a dashboard gets selected by the user', () => { describe('when a dashboard gets selected by the user', () => {
beforeEach(() => { beforeEach(() => {
wrapper = createComponent(); createComponent();
findItemAt(1).vm.$emit('click'); findItemAt(1).vm.$emit('click');
}); });
......
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