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-07-03 09:08:53 +00:00
|
|
|
if (variable.value !== value) {
|
|
|
|
this.updateVariablesAndFetchData({ name: variable.name, value });
|
2020-05-16 00:08:12 +00:00
|
|
|
// update the Vuex store
|
|
|
|
// 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>
|
2020-08-24 12:10:17 +00:00
|
|
|
<div
|
|
|
|
ref="variablesSection"
|
|
|
|
class="d-sm-flex flex-sm-wrap pt-2 pr-1 pb-0 pl-2 variables-section"
|
|
|
|
data-qa-selector="variables_content"
|
|
|
|
>
|
2020-07-03 09:08:53 +00:00
|
|
|
<div v-for="variable in variables" :key="variable.name" 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"
|
2020-07-03 09:08:53 +00:00
|
|
|
:name="variable.name"
|
2020-05-16 00:08:12 +00:00
|
|
|
:options="variable.options"
|
2020-08-24 12:10:17 +00:00
|
|
|
data-qa-selector="variable_item"
|
2020-07-03 09:08:53 +00:00
|
|
|
@input="refreshDashboard(variable, $event)"
|
2020-05-16 00:08:12 +00:00
|
|
|
/>
|
2020-05-11 15:09:37 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|