debian-mirror-gitlab/app/assets/javascripts/monitoring/components/dashboards_dropdown.vue

128 lines
3.5 KiB
Vue
Raw Normal View History

2020-03-13 15:44:24 +05:30
<script>
2020-10-24 23:57:45 +05:30
import { mapState, mapGetters } from 'vuex';
2020-03-13 15:44:24 +05:30
import {
2020-05-24 23:13:21 +05:30
GlIcon,
2020-11-24 15:15:51 +05:30
GlDropdown,
GlDropdownItem,
GlDropdownSectionHeader,
GlDropdownDivider,
2020-03-13 15:44:24 +05:30
GlSearchBoxByType,
GlModalDirective,
} from '@gitlab/ui';
const events = {
selectDashboard: 'selectDashboard',
};
export default {
components: {
2020-05-24 23:13:21 +05:30
GlIcon,
2020-11-24 15:15:51 +05:30
GlDropdown,
GlDropdownItem,
GlDropdownSectionHeader,
GlDropdownDivider,
2020-03-13 15:44:24 +05:30
GlSearchBoxByType,
},
directives: {
GlModal: GlModalDirective,
},
props: {
defaultBranch: {
type: String,
required: true,
},
},
data() {
return {
searchTerm: '',
};
},
computed: {
...mapState('monitoringDashboard', ['allDashboards']),
2020-05-24 23:13:21 +05:30
...mapGetters('monitoringDashboard', ['selectedDashboard']),
2020-03-13 15:44:24 +05:30
selectedDashboardText() {
2020-05-24 23:13:21 +05:30
return this.selectedDashboard?.display_name;
},
selectedDashboardPath() {
return this.selectedDashboard?.path;
2020-03-13 15:44:24 +05:30
},
2020-05-24 23:13:21 +05:30
2020-03-13 15:44:24 +05:30
filteredDashboards() {
2020-05-24 23:13:21 +05:30
return this.allDashboards.filter(({ display_name = '' }) =>
2020-03-13 15:44:24 +05:30
display_name.toLowerCase().includes(this.searchTerm.toLowerCase()),
);
},
shouldShowNoMsgContainer() {
return this.filteredDashboards.length === 0;
},
2020-05-24 23:13:21 +05:30
starredDashboards() {
return this.filteredDashboards.filter(({ starred }) => starred);
},
nonStarredDashboards() {
return this.filteredDashboards.filter(({ starred }) => !starred);
},
2020-03-13 15:44:24 +05:30
},
methods: {
2020-05-24 23:13:21 +05:30
dashboardDisplayName(dashboard) {
return dashboard.display_name || dashboard.path || '';
},
2020-03-13 15:44:24 +05:30
selectDashboard(dashboard) {
this.$emit(events.selectDashboard, dashboard);
},
},
};
</script>
<template>
2020-11-24 15:15:51 +05:30
<gl-dropdown
2020-03-13 15:44:24 +05:30
toggle-class="dropdown-menu-toggle"
menu-class="monitor-dashboard-dropdown-menu"
:text="selectedDashboardText"
>
<div class="d-flex flex-column overflow-hidden">
2020-11-24 15:15:51 +05:30
<gl-dropdown-section-header>{{ __('Dashboard') }}</gl-dropdown-section-header>
2021-01-03 14:25:43 +05:30
<gl-search-box-by-type ref="monitorDashboardsDropdownSearch" v-model="searchTerm" />
2020-05-24 23:13:21 +05:30
2020-03-13 15:44:24 +05:30
<div class="flex-fill overflow-auto">
2020-11-24 15:15:51 +05:30
<gl-dropdown-item
2020-05-24 23:13:21 +05:30
v-for="dashboard in starredDashboards"
:key="dashboard.path"
2020-10-24 23:57:45 +05:30
:is-check-item="true"
:is-checked="dashboard.path === selectedDashboardPath"
2020-05-24 23:13:21 +05:30
@click="selectDashboard(dashboard)"
>
2020-10-24 23:57:45 +05:30
<div class="gl-display-flex">
2020-11-24 15:15:51 +05:30
<span class="gl-flex-grow-1 gl-min-w-0 gl-overflow-hidden gl-overflow-wrap-break">
{{ dashboardDisplayName(dashboard) }}
</span>
<gl-icon class="text-muted gl-flex-shrink-0 gl-ml-3 gl-align-self-center" name="star" />
2020-05-24 23:13:21 +05:30
</div>
2020-11-24 15:15:51 +05:30
</gl-dropdown-item>
<gl-dropdown-divider
2020-05-24 23:13:21 +05:30
v-if="starredDashboards.length && nonStarredDashboards.length"
ref="starredListDivider"
/>
2020-11-24 15:15:51 +05:30
<gl-dropdown-item
2020-05-24 23:13:21 +05:30
v-for="dashboard in nonStarredDashboards"
2020-03-13 15:44:24 +05:30
:key="dashboard.path"
2020-10-24 23:57:45 +05:30
:is-check-item="true"
:is-checked="dashboard.path === selectedDashboardPath"
2020-03-13 15:44:24 +05:30
@click="selectDashboard(dashboard)"
>
2020-11-24 15:15:51 +05:30
<span class="gl-overflow-hidden gl-overflow-wrap-break">
{{ dashboardDisplayName(dashboard) }}
</span>
</gl-dropdown-item>
2020-03-13 15:44:24 +05:30
</div>
<div
v-show="shouldShowNoMsgContainer"
ref="monitorDashboardsDropdownMsg"
class="text-secondary no-matches-message"
>
{{ __('No matching results') }}
</div>
</div>
2020-11-24 15:15:51 +05:30
</gl-dropdown>
2020-03-13 15:44:24 +05:30
</template>