Commit ae6729c6 authored by Miguel Rincon's avatar Miguel Rincon

Update dashboard deprecated environment dropdowns

As part of our efforts to keep our components up to date,
update environment dropdowns to the GlNewDropdown component.
parent 1c45c9e2
...@@ -3,11 +3,10 @@ import { debounce } from 'lodash'; ...@@ -3,11 +3,10 @@ import { debounce } from 'lodash';
import { mapActions, mapState, mapGetters } from 'vuex'; import { mapActions, mapState, mapGetters } from 'vuex';
import { import {
GlButton, GlButton,
GlDeprecatedDropdown, GlNewDropdown,
GlDeprecatedDropdownItem,
GlDeprecatedDropdownHeader,
GlDeprecatedDropdownDivider,
GlLoadingIcon, GlLoadingIcon,
GlNewDropdownItem,
GlNewDropdownHeader,
GlSearchBoxByType, GlSearchBoxByType,
GlModalDirective, GlModalDirective,
GlTooltipDirective, GlTooltipDirective,
...@@ -29,11 +28,11 @@ export default { ...@@ -29,11 +28,11 @@ export default {
components: { components: {
Icon, Icon,
GlButton, GlButton,
GlDeprecatedDropdown, GlNewDropdown,
GlLoadingIcon, GlLoadingIcon,
GlDeprecatedDropdownItem, GlNewDropdownItem,
GlDeprecatedDropdownHeader, GlNewDropdownHeader,
GlDeprecatedDropdownDivider,
GlSearchBoxByType, GlSearchBoxByType,
DateTimePicker, DateTimePicker,
...@@ -112,6 +111,9 @@ export default { ...@@ -112,6 +111,9 @@ export default {
showRearrangePanelsBtn() { showRearrangePanelsBtn() {
return !this.shouldShowEmptyState && this.rearrangePanelsAvailable; return !this.shouldShowEmptyState && this.rearrangePanelsAvailable;
}, },
environmentDropdownText() {
return this.currentEnvironmentName ?? '';
},
displayUtc() { displayUtc() {
return this.dashboardTimezone === timezones.UTC; return this.dashboardTimezone === timezones.UTC;
}, },
...@@ -176,31 +178,30 @@ export default { ...@@ -176,31 +178,30 @@ export default {
<span aria-hidden="true" class="gl-pl-3 border-left gl-mb-3 d-none d-sm-block"></span> <span aria-hidden="true" class="gl-pl-3 border-left gl-mb-3 d-none d-sm-block"></span>
<div class="mb-2 pr-2 d-flex d-sm-block"> <div class="mb-2 pr-2 d-flex d-sm-block">
<gl-deprecated-dropdown <gl-new-dropdown
id="monitor-environments-dropdown" id="monitor-environments-dropdown"
ref="monitorEnvironmentsDropdown" ref="monitorEnvironmentsDropdown"
class="flex-grow-1" class="flex-grow-1"
data-qa-selector="environments_dropdown" data-qa-selector="environments_dropdown"
toggle-class="dropdown-menu-toggle" toggle-class="dropdown-menu-toggle"
menu-class="monitor-environment-dropdown-menu" menu-class="monitor-environment-dropdown-menu"
:text="currentEnvironmentName" :text="environmentDropdownText"
> >
<div class="d-flex flex-column overflow-hidden"> <div class="d-flex flex-column overflow-hidden">
<gl-deprecated-dropdown-header class="monitor-environment-dropdown-header text-center"> <gl-new-dropdown-header>{{ __('Environment') }}</gl-new-dropdown-header>
{{ __('Environment') }}
</gl-deprecated-dropdown-header>
<gl-deprecated-dropdown-divider />
<gl-search-box-by-type class="m-2" @input="debouncedEnvironmentsSearch" /> <gl-search-box-by-type class="m-2" @input="debouncedEnvironmentsSearch" />
<gl-loading-icon v-if="environmentsLoading" :inline="true" /> <gl-loading-icon v-if="environmentsLoading" :inline="true" />
<div v-else class="flex-fill overflow-auto"> <div v-else class="flex-fill overflow-auto">
<gl-deprecated-dropdown-item <gl-new-dropdown-item
v-for="environment in filteredEnvironments" v-for="environment in filteredEnvironments"
:key="environment.id" :key="environment.id"
:active="environment.name === currentEnvironmentName" :is-check-item="true"
active-class="is-active" :is-checked="environment.name === currentEnvironmentName"
:href="getEnvironmentPath(environment.id)" :href="getEnvironmentPath(environment.id)"
>{{ environment.name }}</gl-deprecated-dropdown-item
> >
{{ environment.name }}
</gl-new-dropdown-item>
</div> </div>
<div <div
v-show="shouldShowEnvironmentsDropdownNoMatchedMsg" v-show="shouldShowEnvironmentsDropdownNoMatchedMsg"
...@@ -210,7 +211,7 @@ export default { ...@@ -210,7 +211,7 @@ export default {
{{ __('No matching results') }} {{ __('No matching results') }}
</div> </div>
</div> </div>
</gl-deprecated-dropdown> </gl-new-dropdown>
</div> </div>
<div class="mb-2 pr-2 d-flex d-sm-block"> <div class="mb-2 pr-2 d-flex d-sm-block">
......
...@@ -63,10 +63,6 @@ ...@@ -63,10 +63,6 @@
} }
.prometheus-graphs-header { .prometheus-graphs-header {
.monitor-environment-dropdown-header header {
font-size: $gl-font-size;
}
.monitor-environment-dropdown-menu, .monitor-environment-dropdown-menu,
.monitor-dashboard-dropdown-menu { .monitor-dashboard-dropdown-menu {
&.show { &.show {
......
---
title: Improve environment dropdowns in operations metrics dashboard and highlight
selected environment
merge_request: 39303
author:
type: changed
...@@ -32,26 +32,24 @@ exports[`Dashboard template matches the default snapshot 1`] = ` ...@@ -32,26 +32,24 @@ exports[`Dashboard template matches the default snapshot 1`] = `
<div <div
class="mb-2 pr-2 d-flex d-sm-block" class="mb-2 pr-2 d-flex d-sm-block"
> >
<gl-deprecated-dropdown-stub <gl-new-dropdown-stub
category="tertiary"
class="flex-grow-1" class="flex-grow-1"
data-qa-selector="environments_dropdown" data-qa-selector="environments_dropdown"
headertext=""
id="monitor-environments-dropdown" id="monitor-environments-dropdown"
menu-class="monitor-environment-dropdown-menu" menu-class="monitor-environment-dropdown-menu"
size="medium"
text="production" text="production"
toggle-class="dropdown-menu-toggle" toggleclass="dropdown-menu-toggle"
variant="default"
> >
<div <div
class="d-flex flex-column overflow-hidden" class="d-flex flex-column overflow-hidden"
> >
<gl-deprecated-dropdown-header-stub <gl-new-dropdown-header-stub>
class="monitor-environment-dropdown-header text-center" Environment
> </gl-new-dropdown-header-stub>
Environment
</gl-deprecated-dropdown-header-stub>
<gl-deprecated-dropdown-divider-stub />
<gl-search-box-by-type-stub <gl-search-box-by-type-stub
class="m-2" class="m-2"
...@@ -71,7 +69,7 @@ exports[`Dashboard template matches the default snapshot 1`] = ` ...@@ -71,7 +69,7 @@ exports[`Dashboard template matches the default snapshot 1`] = `
</div> </div>
</div> </div>
</gl-deprecated-dropdown-stub> </gl-new-dropdown-stub>
</div> </div>
<div <div
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { createStore } from '~/monitoring/stores'; import { createStore } from '~/monitoring/stores';
import * as types from '~/monitoring/stores/mutation_types'; import * as types from '~/monitoring/stores/mutation_types';
import { GlDeprecatedDropdownItem, GlSearchBoxByType, GlLoadingIcon, GlButton } from '@gitlab/ui'; import { GlNewDropdownItem, GlSearchBoxByType, GlLoadingIcon, GlButton } from '@gitlab/ui';
import DateTimePicker from '~/vue_shared/components/date_time_picker/date_time_picker.vue'; import DateTimePicker from '~/vue_shared/components/date_time_picker/date_time_picker.vue';
import RefreshButton from '~/monitoring/components/refresh_button.vue'; import RefreshButton from '~/monitoring/components/refresh_button.vue';
import DashboardHeader from '~/monitoring/components/dashboard_header.vue'; import DashboardHeader from '~/monitoring/components/dashboard_header.vue';
...@@ -31,7 +31,7 @@ describe('Dashboard header', () => { ...@@ -31,7 +31,7 @@ describe('Dashboard header', () => {
const findDashboardDropdown = () => wrapper.find(DashboardsDropdown); const findDashboardDropdown = () => wrapper.find(DashboardsDropdown);
const findEnvsDropdown = () => wrapper.find({ ref: 'monitorEnvironmentsDropdown' }); const findEnvsDropdown = () => wrapper.find({ ref: 'monitorEnvironmentsDropdown' });
const findEnvsDropdownItems = () => findEnvsDropdown().findAll(GlDeprecatedDropdownItem); const findEnvsDropdownItems = () => findEnvsDropdown().findAll(GlNewDropdownItem);
const findEnvsDropdownSearch = () => findEnvsDropdown().find(GlSearchBoxByType); const findEnvsDropdownSearch = () => findEnvsDropdown().find(GlSearchBoxByType);
const findEnvsDropdownSearchMsg = () => wrapper.find({ ref: 'monitorEnvironmentsDropdownMsg' }); const findEnvsDropdownSearchMsg = () => wrapper.find({ ref: 'monitorEnvironmentsDropdownMsg' });
const findEnvsDropdownLoadingIcon = () => findEnvsDropdown().find(GlLoadingIcon); const findEnvsDropdownLoadingIcon = () => findEnvsDropdown().find(GlLoadingIcon);
...@@ -116,7 +116,7 @@ describe('Dashboard header', () => { ...@@ -116,7 +116,7 @@ describe('Dashboard header', () => {
}); });
it('there are no environments listed', () => { it('there are no environments listed', () => {
expect(findEnvsDropdownItems().length).toBe(0); expect(findEnvsDropdownItems()).toHaveLength(0);
}); });
}); });
...@@ -145,12 +145,17 @@ describe('Dashboard header', () => { ...@@ -145,12 +145,17 @@ describe('Dashboard header', () => {
}); });
}); });
it('renders the environments dropdown with an active element', () => { it('environments dropdown items can be checked', () => {
const selectedItems = findEnvsDropdownItems().filter( const items = findEnvsDropdownItems();
item => item.attributes('active') === 'true', const checkItems = findEnvsDropdownItems().filter(item => item.props('isCheckItem'));
);
expect(selectedItems.length).toBe(1); expect(items).toHaveLength(checkItems.length);
});
it('checks the currently selected environment', () => {
const selectedItems = findEnvsDropdownItems().filter(item => item.props('isChecked'));
expect(selectedItems).toHaveLength(1);
expect(selectedItems.at(0).text()).toBe(currentEnvironmentName); expect(selectedItems.at(0).text()).toBe(currentEnvironmentName);
}); });
...@@ -160,7 +165,7 @@ describe('Dashboard header', () => { ...@@ -160,7 +165,7 @@ describe('Dashboard header', () => {
setSearchTerm(searchTerm); setSearchTerm(searchTerm);
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(findEnvsDropdownItems().length).toBe(resultEnvs.length); expect(findEnvsDropdownItems()).toHaveLength(resultEnvs.length);
}); });
}); });
...@@ -169,7 +174,7 @@ describe('Dashboard header', () => { ...@@ -169,7 +174,7 @@ describe('Dashboard header', () => {
setSearchTerm(searchTerm); setSearchTerm(searchTerm);
return wrapper.vm.$nextTick(() => { return wrapper.vm.$nextTick(() => {
expect(findEnvsDropdownItems().length).toBe(environmentData.length); expect(findEnvsDropdownItems()).toHaveLength(environmentData.length);
}); });
}); });
......
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