debian-mirror-gitlab/app/assets/javascripts/monitoring/components/variables_section.vue

59 lines
1.8 KiB
Vue
Raw Normal View History

2020-05-24 23:13:21 +05:30
<script>
import { mapState, mapActions } from 'vuex';
2020-07-28 23:09:34 +05:30
import DropdownField from './variables/dropdown_field.vue';
import TextField from './variables/text_field.vue';
2020-06-23 00:09:42 +05:30
import { setCustomVariablesFromUrl } from '../utils';
2020-07-28 23:09:34 +05:30
import { VARIABLE_TYPES } from '../constants';
2020-05-24 23:13:21 +05:30
export default {
components: {
2020-07-28 23:09:34 +05:30
DropdownField,
TextField,
2020-05-24 23:13:21 +05:30
},
computed: {
2020-06-23 00:09:42 +05:30
...mapState('monitoringDashboard', ['variables']),
2020-05-24 23:13:21 +05:30
},
methods: {
2020-06-23 00:09:42 +05:30
...mapActions('monitoringDashboard', ['updateVariablesAndFetchData']),
2020-05-24 23:13:21 +05:30
refreshDashboard(variable, value) {
2020-07-28 23:09:34 +05:30
if (variable.value !== value) {
this.updateVariablesAndFetchData({ name: variable.name, value });
2020-05-24 23:13:21 +05:30
// 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-06-23 00:09:42 +05:30
setCustomVariablesFromUrl(this.variables);
2020-05-24 23:13:21 +05:30
}
},
2020-07-28 23:09:34 +05:30
variableField(type) {
if (type === VARIABLE_TYPES.custom || type === VARIABLE_TYPES.metric_label_values) {
return DropdownField;
}
return TextField;
2020-05-24 23:13:21 +05:30
},
},
};
</script>
<template>
2020-11-24 15:15:51 +05:30
<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-28 23:09:34 +05:30
<div v-for="variable in variables" :key="variable.name" class="mb-1 pr-2 d-flex d-sm-block">
2020-05-24 23:13:21 +05:30
<component
2020-07-28 23:09:34 +05:30
:is="variableField(variable.type)"
2020-05-24 23:13:21 +05:30
class="mb-0 flex-grow-1"
:label="variable.label"
:value="variable.value"
2020-07-28 23:09:34 +05:30
:name="variable.name"
2020-05-24 23:13:21 +05:30
:options="variable.options"
2020-11-24 15:15:51 +05:30
data-qa-selector="variable_item"
2020-07-28 23:09:34 +05:30
@input="refreshDashboard(variable, $event)"
2020-05-24 23:13:21 +05:30
/>
</div>
</div>
</template>