2020-05-11 15:09:37 +00:00
|
|
|
<script>
|
|
|
|
import { mapState, mapActions } from 'vuex';
|
2020-06-24 03:08:44 +00:00
|
|
|
import DropdownField from './variables/dropdown_field.vue';
|
|
|
|
import TextField from './variables/text_field.vue';
|
2020-05-21 21:08:31 +00:00
|
|
|
import { setCustomVariablesFromUrl } from '../utils';
|
2020-06-24 03:08:44 +00:00
|
|
|
import { VARIABLE_TYPES } from '../constants';
|
2020-05-11 15:09:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
2020-06-24 03:08:44 +00:00
|
|
|
DropdownField,
|
|
|
|
TextField,
|
2020-05-11 15:09:37 +00:00
|
|
|
},
|
|
|
|
computed: {
|
2020-05-21 21:08:31 +00:00
|
|
|
...mapState('monitoringDashboard', ['variables']),
|
2020-05-11 15:09:37 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2020-05-22 21:08:22 +00:00
|
|
|
...mapActions('monitoringDashboard', ['updateVariablesAndFetchData']),
|
2020-05-16 00:08:12 +00:00
|
|
|
refreshDashboard(variable, value) {
|
2020-05-21 21:08:31 +00:00
|
|
|
if (this.variables[variable].value !== value) {
|
2020-05-16 00:08:12 +00:00
|
|
|
const changedVariable = { key: variable, value };
|
|
|
|
// update the Vuex store
|
2020-05-22 21:08:22 +00:00
|
|
|
this.updateVariablesAndFetchData(changedVariable);
|
2020-05-16 00:08:12 +00:00
|
|
|
// the below calls can ideally be moved out of the
|
|
|
|
// component and into the actions and let the
|
|
|
|
// mutation respond directly.
|
|
|
|
// This can be further investigate in
|
|
|
|
// https://gitlab.com/gitlab-org/gitlab/-/issues/217713
|
2020-05-21 21:08:31 +00:00
|
|
|
setCustomVariablesFromUrl(this.variables);
|
2020-05-11 15:09:37 +00:00
|
|
|
}
|
|
|
|
},
|
2020-06-24 03:08:44 +00:00
|
|
|
variableField(type) {
|
|
|
|
if (type === VARIABLE_TYPES.custom || type === VARIABLE_TYPES.metric_label_values) {
|
|
|
|
return DropdownField;
|
|
|
|
}
|
|
|
|
return TextField;
|
2020-05-16 00:08:12 +00:00
|
|
|
},
|
2020-05-11 15:09:37 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<template>
|
|
|
|
<div ref="variablesSection" class="d-sm-flex flex-sm-wrap pt-2 pr-1 pb-0 pl-2 variables-section">
|
2020-05-21 21:08:31 +00:00
|
|
|
<div v-for="(variable, key) in variables" :key="key" class="mb-1 pr-2 d-flex d-sm-block">
|
2020-05-16 00:08:12 +00:00
|
|
|
<component
|
2020-06-24 03:08:44 +00:00
|
|
|
:is="variableField(variable.type)"
|
2020-05-16 00:08:12 +00:00
|
|
|
class="mb-0 flex-grow-1"
|
|
|
|
:label="variable.label"
|
|
|
|
:value="variable.value"
|
|
|
|
:name="key"
|
|
|
|
:options="variable.options"
|
|
|
|
@onUpdate="refreshDashboard"
|
|
|
|
/>
|
2020-05-11 15:09:37 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|