2020-01-16 13:08:46 -05:00
|
|
|
<script>
|
|
|
|
import {
|
2020-05-11 14:09:55 -04:00
|
|
|
GlIcon,
|
2020-09-14 08:09:34 -04:00
|
|
|
GlDropdown,
|
2020-09-14 14:09:48 -04:00
|
|
|
GlDropdownItem,
|
2020-09-14 20:09:47 -04:00
|
|
|
GlDropdownSectionHeader,
|
2020-09-14 14:09:48 -04:00
|
|
|
GlDropdownDivider,
|
2020-01-30 13:08:57 -05:00
|
|
|
GlSearchBoxByType,
|
2020-01-16 13:08:46 -05:00
|
|
|
GlModalDirective,
|
|
|
|
} from '@gitlab/ui';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { mapState, mapGetters } from 'vuex';
|
2020-01-16 13:08:46 -05:00
|
|
|
|
|
|
|
const events = {
|
|
|
|
selectDashboard: 'selectDashboard',
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
2020-05-11 14:09:55 -04:00
|
|
|
GlIcon,
|
2020-09-14 08:09:34 -04:00
|
|
|
GlDropdown,
|
2020-09-14 14:09:48 -04:00
|
|
|
GlDropdownItem,
|
2020-09-14 20:09:47 -04:00
|
|
|
GlDropdownSectionHeader,
|
2020-09-14 14:09:48 -04:00
|
|
|
GlDropdownDivider,
|
2020-01-30 13:08:57 -05:00
|
|
|
GlSearchBoxByType,
|
2020-01-16 13:08:46 -05:00
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
GlModal: GlModalDirective,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
defaultBranch: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2020-01-30 13:08:57 -05:00
|
|
|
searchTerm: '',
|
2020-01-16 13:08:46 -05:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapState('monitoringDashboard', ['allDashboards']),
|
2020-05-12 11:10:33 -04:00
|
|
|
...mapGetters('monitoringDashboard', ['selectedDashboard']),
|
2020-01-16 13:08:46 -05:00
|
|
|
selectedDashboardText() {
|
2020-05-12 11:10:33 -04:00
|
|
|
return this.selectedDashboard?.display_name;
|
|
|
|
},
|
|
|
|
selectedDashboardPath() {
|
|
|
|
return this.selectedDashboard?.path;
|
2020-01-16 13:08:46 -05:00
|
|
|
},
|
2020-05-11 14:09:55 -04:00
|
|
|
|
2020-01-30 13:08:57 -05:00
|
|
|
filteredDashboards() {
|
2022-03-31 08:08:17 -04:00
|
|
|
return this.allDashboards.filter(({ display_name: displayName = '' }) =>
|
|
|
|
displayName.toLowerCase().includes(this.searchTerm.toLowerCase()),
|
2020-01-30 13:08:57 -05:00
|
|
|
);
|
|
|
|
},
|
|
|
|
shouldShowNoMsgContainer() {
|
|
|
|
return this.filteredDashboards.length === 0;
|
|
|
|
},
|
2020-05-11 14:09:55 -04:00
|
|
|
starredDashboards() {
|
|
|
|
return this.filteredDashboards.filter(({ starred }) => starred);
|
|
|
|
},
|
|
|
|
nonStarredDashboards() {
|
|
|
|
return this.filteredDashboards.filter(({ starred }) => !starred);
|
|
|
|
},
|
2020-01-16 13:08:46 -05:00
|
|
|
},
|
|
|
|
methods: {
|
2020-05-11 14:09:55 -04:00
|
|
|
dashboardDisplayName(dashboard) {
|
|
|
|
return dashboard.display_name || dashboard.path || '';
|
|
|
|
},
|
2020-01-16 13:08:46 -05:00
|
|
|
selectDashboard(dashboard) {
|
|
|
|
this.$emit(events.selectDashboard, dashboard);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<template>
|
2020-09-14 08:09:34 -04:00
|
|
|
<gl-dropdown
|
2020-01-30 13:08:57 -05:00
|
|
|
toggle-class="dropdown-menu-toggle"
|
|
|
|
menu-class="monitor-dashboard-dropdown-menu"
|
|
|
|
:text="selectedDashboardText"
|
|
|
|
>
|
|
|
|
<div class="d-flex flex-column overflow-hidden">
|
2020-09-14 20:09:47 -04:00
|
|
|
<gl-dropdown-section-header>{{ __('Dashboard') }}</gl-dropdown-section-header>
|
2020-10-15 14:08:43 -04:00
|
|
|
<gl-search-box-by-type ref="monitorDashboardsDropdownSearch" v-model="searchTerm" />
|
2020-05-11 14:09:55 -04:00
|
|
|
|
2020-01-30 13:08:57 -05:00
|
|
|
<div class="flex-fill overflow-auto">
|
2020-09-14 14:09:48 -04:00
|
|
|
<gl-dropdown-item
|
2020-05-11 14:09:55 -04:00
|
|
|
v-for="dashboard in starredDashboards"
|
|
|
|
:key="dashboard.path"
|
2022-08-26 11:11:58 -04:00
|
|
|
is-check-item
|
2020-08-06 05:09:42 -04:00
|
|
|
:is-checked="dashboard.path === selectedDashboardPath"
|
2020-05-11 14:09:55 -04:00
|
|
|
@click="selectDashboard(dashboard)"
|
|
|
|
>
|
2020-08-06 05:09:42 -04:00
|
|
|
<div class="gl-display-flex">
|
2020-08-26 14:11:43 -04:00
|
|
|
<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-11 14:09:55 -04:00
|
|
|
</div>
|
2020-09-14 14:09:48 -04:00
|
|
|
</gl-dropdown-item>
|
|
|
|
<gl-dropdown-divider
|
2020-05-11 14:09:55 -04:00
|
|
|
v-if="starredDashboards.length && nonStarredDashboards.length"
|
|
|
|
ref="starredListDivider"
|
|
|
|
/>
|
|
|
|
|
2020-09-14 14:09:48 -04:00
|
|
|
<gl-dropdown-item
|
2020-05-11 14:09:55 -04:00
|
|
|
v-for="dashboard in nonStarredDashboards"
|
2020-01-30 13:08:57 -05:00
|
|
|
:key="dashboard.path"
|
2022-08-26 11:11:58 -04:00
|
|
|
is-check-item
|
2020-08-06 05:09:42 -04:00
|
|
|
:is-checked="dashboard.path === selectedDashboardPath"
|
2020-01-30 13:08:57 -05:00
|
|
|
@click="selectDashboard(dashboard)"
|
|
|
|
>
|
2020-08-26 14:11:43 -04:00
|
|
|
<span class="gl-overflow-hidden gl-overflow-wrap-break">
|
|
|
|
{{ dashboardDisplayName(dashboard) }}
|
|
|
|
</span>
|
2020-09-14 14:09:48 -04:00
|
|
|
</gl-dropdown-item>
|
2020-01-30 13:08:57 -05:00
|
|
|
</div>
|
2020-01-16 13:08:46 -05:00
|
|
|
|
2020-01-30 13:08:57 -05:00
|
|
|
<div
|
|
|
|
v-show="shouldShowNoMsgContainer"
|
|
|
|
ref="monitorDashboardsDropdownMsg"
|
|
|
|
class="text-secondary no-matches-message"
|
2020-01-16 13:08:46 -05:00
|
|
|
>
|
2020-01-30 13:08:57 -05:00
|
|
|
{{ __('No matching results') }}
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-09-14 08:09:34 -04:00
|
|
|
</gl-dropdown>
|
2020-01-16 13:08:46 -05:00
|
|
|
</template>
|