debian-mirror-gitlab/app/assets/javascripts/integrations/edit/components/override_dropdown.vue

87 lines
2 KiB
Vue
Raw Normal View History

2020-07-28 23:09:34 +05:30
<script>
2020-11-24 15:15:51 +05:30
import { mapState } from 'vuex';
import { GlDropdown, GlDropdownItem, GlLink } from '@gitlab/ui';
2020-10-24 23:57:45 +05:30
import { s__ } from '~/locale';
2020-11-24 15:15:51 +05:30
import { defaultIntegrationLevel, overrideDropdownDescriptions } from '../constants';
2020-07-28 23:09:34 +05:30
const dropdownOptions = [
{
value: false,
2020-10-24 23:57:45 +05:30
text: s__('Integrations|Use default settings'),
2020-07-28 23:09:34 +05:30
},
{
value: true,
text: s__('Integrations|Use custom settings'),
},
];
export default {
dropdownOptions,
name: 'OverrideDropdown',
components: {
2020-11-24 15:15:51 +05:30
GlDropdown,
GlDropdownItem,
GlLink,
2020-07-28 23:09:34 +05:30
},
props: {
inheritFromId: {
type: Number,
required: true,
},
2020-11-24 15:15:51 +05:30
learnMorePath: {
type: String,
required: false,
default: null,
},
2020-07-28 23:09:34 +05:30
override: {
type: Boolean,
required: true,
},
},
data() {
return {
selected: dropdownOptions.find(x => x.value === this.override),
};
},
2020-11-24 15:15:51 +05:30
computed: {
...mapState(['defaultState']),
description() {
const level = this.defaultState.integrationLevel;
return (
overrideDropdownDescriptions[level] || overrideDropdownDescriptions[defaultIntegrationLevel]
);
},
},
2020-07-28 23:09:34 +05:30
methods: {
onClick(option) {
this.selected = option;
this.$emit('change', option.value);
},
},
};
</script>
<template>
<div
class="gl-display-flex gl-justify-content-space-between gl-align-items-baseline gl-py-4 gl-mt-5 gl-mb-6 gl-border-t-1 gl-border-t-solid gl-border-b-1 gl-border-b-solid gl-border-gray-100"
>
2020-11-24 15:15:51 +05:30
<span
>{{ description }}
<gl-link v-if="learnMorePath" :href="learnMorePath" target="_blank">{{
__('Learn more')
}}</gl-link>
</span>
2020-07-28 23:09:34 +05:30
<input name="service[inherit_from_id]" :value="override ? '' : inheritFromId" type="hidden" />
2020-11-24 15:15:51 +05:30
<gl-dropdown :text="selected.text">
<gl-dropdown-item
2020-07-28 23:09:34 +05:30
v-for="option in $options.dropdownOptions"
:key="option.value"
@click="onClick(option)"
>
{{ option.text }}
2020-11-24 15:15:51 +05:30
</gl-dropdown-item>
</gl-dropdown>
2020-07-28 23:09:34 +05:30
</div>
</template>