gitlab-org--gitlab-foss/app/assets/javascripts/monitoring/components/dashboard.vue

208 lines
5.4 KiB
Vue
Raw Normal View History

<script>
import { GlDropdown, GlDropdownItem } from '@gitlab/ui';
import { s__ } from '~/locale';
import Icon from '~/vue_shared/components/icon.vue';
2018-03-27 15:19:20 -04:00
import Flash from '../../flash';
import MonitoringService from '../services/monitoring_service';
import MonitorAreaChart from './charts/area.vue';
2018-03-27 15:19:20 -04:00
import GraphGroup from './graph_group.vue';
import EmptyState from './empty_state.vue';
import MonitoringStore from '../stores/monitoring_store';
const sidebarAnimationDuration = 150;
let sidebarMutationObserver;
2018-03-27 15:19:20 -04:00
export default {
components: {
MonitorAreaChart,
2018-03-27 15:19:20 -04:00
GraphGroup,
EmptyState,
Icon,
GlDropdown,
GlDropdownItem,
2018-03-27 15:19:20 -04:00
},
props: {
hasMetrics: {
type: Boolean,
required: false,
default: true,
2018-01-05 09:31:01 -05:00
},
2018-03-27 15:19:20 -04:00
showPanels: {
type: Boolean,
required: false,
default: true,
},
2018-03-27 15:19:20 -04:00
documentationPath: {
type: String,
required: true,
},
2018-03-27 15:19:20 -04:00
settingsPath: {
type: String,
required: true,
},
clustersPath: {
type: String,
required: true,
},
tagsPath: {
type: String,
required: true,
},
projectPath: {
type: String,
required: true,
},
metricsEndpoint: {
type: String,
required: true,
},
deploymentEndpoint: {
type: String,
required: false,
default: null,
},
emptyGettingStartedSvgPath: {
type: String,
required: true,
},
emptyLoadingSvgPath: {
type: String,
required: true,
},
emptyNoDataSvgPath: {
type: String,
required: true,
},
emptyUnableToConnectSvgPath: {
type: String,
required: true,
},
environmentsEndpoint: {
type: String,
required: true,
},
currentEnvironmentName: {
type: String,
required: true,
},
2018-03-27 15:19:20 -04:00
},
data() {
return {
store: new MonitoringStore(),
state: 'gettingStarted',
showEmptyState: true,
2018-09-25 17:43:43 -04:00
elWidth: 0,
2018-03-27 15:19:20 -04:00
};
},
created() {
this.service = new MonitoringService({
metricsEndpoint: this.metricsEndpoint,
deploymentEndpoint: this.deploymentEndpoint,
environmentsEndpoint: this.environmentsEndpoint,
2018-03-27 15:19:20 -04:00
});
},
beforeDestroy() {
if (sidebarMutationObserver) {
sidebarMutationObserver.disconnect();
}
2018-03-27 15:19:20 -04:00
},
mounted() {
if (!this.hasMetrics) {
this.state = 'gettingStarted';
} else {
this.getGraphsData();
sidebarMutationObserver = new MutationObserver(this.onSidebarMutation);
sidebarMutationObserver.observe(document.querySelector('.layout-page'), {
attributes: true,
childList: false,
subtree: false,
});
2018-03-27 15:19:20 -04:00
}
},
methods: {
2019-01-07 14:07:25 -05:00
getGraphAlerts(graphId) {
return this.alertData ? this.alertData[graphId] || {} : {};
},
2018-03-27 15:19:20 -04:00
getGraphsData() {
this.state = 'loading';
Promise.all([
this.service.getGraphsData().then(data => this.store.storeMetrics(data)),
this.service
.getDeploymentData()
.then(data => this.store.storeDeploymentData(data))
.catch(() => Flash(s__('Metrics|There was an error getting deployment information.'))),
this.service
.getEnvironmentsData()
.then(data => this.store.storeEnvironmentsData(data))
.catch(() => Flash(s__('Metrics|There was an error getting environments information.'))),
2018-03-27 15:19:20 -04:00
])
.then(() => {
if (this.store.groups.length < 1) {
this.state = 'noData';
return;
}
2018-03-27 15:19:20 -04:00
this.showEmptyState = false;
})
.catch(() => {
this.state = 'unableToConnect';
});
},
onSidebarMutation() {
setTimeout(() => {
this.elWidth = this.$el.clientWidth;
}, sidebarAnimationDuration);
2018-01-05 09:31:01 -05:00
},
2018-03-27 15:19:20 -04:00
},
};
</script>
<template>
<div v-if="!showEmptyState" class="prometheus-graphs prepend-top-default">
<div class="environments d-flex align-items-center">
<strong>{{ s__('Metrics|Environment') }}</strong>
<gl-dropdown
class="prepend-left-10 js-environments-dropdown"
toggle-class="dropdown-menu-toggle"
:text="currentEnvironmentName"
:disabled="store.environmentsData.length === 0"
>
<gl-dropdown-item
v-for="environment in store.environmentsData"
:key="environment.id"
:active="environment.name === currentEnvironmentName"
active-class="is-active"
>{{ environment.name }}</gl-dropdown-item
>
</gl-dropdown>
2018-06-27 18:13:21 -04:00
</div>
<graph-group
v-for="(groupData, index) in store.groups"
:key="index"
:name="groupData.group"
:show-panels="showPanels"
>
2019-02-01 03:37:48 -05:00
<monitor-area-chart
v-for="(graphData, graphIndex) in groupData.metrics"
:key="graphIndex"
:graph-data="graphData"
:deployment-data="store.deploymentData"
2019-01-07 14:07:25 -05:00
:alert-data="getGraphAlerts(graphData.id)"
:container-width="elWidth"
2019-01-07 14:07:25 -05:00
group-id="monitor-area-chart"
2019-02-01 03:37:48 -05:00
/>
</graph-group>
</div>
2017-08-30 00:49:29 -04:00
<empty-state
v-else
:selected-state="state"
:documentation-path="documentationPath"
:settings-path="settingsPath"
:clusters-path="clustersPath"
:empty-getting-started-svg-path="emptyGettingStartedSvgPath"
:empty-loading-svg-path="emptyLoadingSvgPath"
:empty-no-data-svg-path="emptyNoDataSvgPath"
:empty-unable-to-connect-svg-path="emptyUnableToConnectSvgPath"
/>
</template>