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-10-24 23:57:45 +05:30
|
|
|
GlNewDropdown,
|
|
|
|
GlNewDropdownItem,
|
|
|
|
GlNewDropdownHeader,
|
|
|
|
GlNewDropdownDivider,
|
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-10-24 23:57:45 +05:30
|
|
|
GlNewDropdown,
|
|
|
|
GlNewDropdownItem,
|
|
|
|
GlNewDropdownHeader,
|
|
|
|
GlNewDropdownDivider,
|
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-10-24 23:57:45 +05:30
|
|
|
<gl-new-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-10-24 23:57:45 +05:30
|
|
|
<gl-new-dropdown-header>{{ __('Dashboard') }}</gl-new-dropdown-header>
|
2020-03-13 15:44:24 +05:30
|
|
|
<gl-search-box-by-type
|
|
|
|
ref="monitorDashboardsDropdownSearch"
|
|
|
|
v-model="searchTerm"
|
|
|
|
class="m-2"
|
|
|
|
/>
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
<div class="flex-fill overflow-auto">
|
2020-10-24 23:57:45 +05:30
|
|
|
<gl-new-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">
|
|
|
|
<div class="gl-flex-grow-1 gl-min-w-0">
|
|
|
|
<div class="gl-word-break-all">
|
|
|
|
{{ dashboardDisplayName(dashboard) }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<gl-icon class="text-muted gl-flex-shrink-0" name="star" />
|
2020-05-24 23:13:21 +05:30
|
|
|
</div>
|
2020-10-24 23:57:45 +05:30
|
|
|
</gl-new-dropdown-item>
|
|
|
|
<gl-new-dropdown-divider
|
2020-05-24 23:13:21 +05:30
|
|
|
v-if="starredDashboards.length && nonStarredDashboards.length"
|
|
|
|
ref="starredListDivider"
|
|
|
|
/>
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
<gl-new-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-05-24 23:13:21 +05:30
|
|
|
{{ dashboardDisplayName(dashboard) }}
|
2020-10-24 23:57:45 +05:30
|
|
|
</gl-new-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-10-24 23:57:45 +05:30
|
|
|
</gl-new-dropdown>
|
2020-03-13 15:44:24 +05:30
|
|
|
</template>
|