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

55 lines
1.7 KiB
Vue
Raw Normal View History

2020-05-24 23:13:21 +05:30
<script>
import { mapState, mapActions } from 'vuex';
import CustomVariable from './variables/custom_variable.vue';
import TextVariable from './variables/text_variable.vue';
2020-06-23 00:09:42 +05:30
import { setCustomVariablesFromUrl } from '../utils';
2020-05-24 23:13:21 +05:30
export default {
components: {
CustomVariable,
TextVariable,
},
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-06-23 00:09:42 +05:30
if (this.variables[variable].value !== value) {
2020-05-24 23:13:21 +05:30
const changedVariable = { key: variable, value };
// update the Vuex store
2020-06-23 00:09:42 +05:30
this.updateVariablesAndFetchData(changedVariable);
2020-05-24 23:13:21 +05:30
// 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
}
},
variableComponent(type) {
const types = {
text: TextVariable,
custom: CustomVariable,
};
return types[type] || TextVariable;
},
},
};
</script>
<template>
<div ref="variablesSection" class="d-sm-flex flex-sm-wrap pt-2 pr-1 pb-0 pl-2 variables-section">
2020-06-23 00:09:42 +05:30
<div v-for="(variable, key) in variables" :key="key" class="mb-1 pr-2 d-flex d-sm-block">
2020-05-24 23:13:21 +05:30
<component
:is="variableComponent(variable.type)"
class="mb-0 flex-grow-1"
:label="variable.label"
:value="variable.value"
:name="key"
:options="variable.options"
@onUpdate="refreshDashboard"
/>
</div>
</div>
</template>