gitlab-org--gitlab-foss/app/assets/javascripts/jobs/components/trigger_block.vue

79 lines
2 KiB
Vue
Raw Normal View History

<script>
2018-11-16 14:29:11 -05:00
import { GlButton } from '@gitlab/ui';
import { __ } from '~/locale';
2018-11-09 17:42:24 -05:00
const HIDDEN_VALUE = '••••••';
2018-10-10 02:23:54 -04:00
export default {
2018-11-09 17:42:24 -05:00
components: {
GlButton,
},
2018-10-10 02:23:54 -04:00
props: {
trigger: {
type: Object,
required: true,
},
2018-10-10 02:23:54 -04:00
},
data() {
return {
showVariableValues: false,
2018-10-10 02:23:54 -04:00
};
},
computed: {
hasVariables() {
return this.trigger.variables && this.trigger.variables.length > 0;
},
getToggleButtonText() {
return this.showVariableValues ? __('Hide values') : __('Reveal values');
},
hasValues() {
return this.trigger.variables.some(v => v.value);
},
2018-10-10 02:23:54 -04:00
},
methods: {
toggleValues() {
this.showVariableValues = !this.showVariableValues;
},
getDisplayValue(value) {
return this.showVariableValues ? value : HIDDEN_VALUE;
},
2018-10-10 02:23:54 -04:00
},
};
</script>
<template>
<div class="build-widget block">
<p
v-if="trigger.short_token"
class="js-short-token"
:class="{ 'append-bottom-5': hasVariables, 'append-bottom-0': !hasVariables }"
>
<span class="font-weight-bold">{{ __('Trigger token:') }}</span> {{ trigger.short_token }}
</p>
<template v-if="hasVariables">
<p class="trigger-variables-btn-container d-flex">
<span class="font-weight-bold">{{ __('Trigger variables:') }}</span>
<gl-button
v-if="hasValues"
class="btn-sm group js-reveal-variables trigger-variables-btn"
@click="toggleValues"
>{{ getToggleButtonText }}</gl-button
>
</p>
<table class="js-build-variables trigger-build-variables">
<tr v-for="(variable, index) in trigger.variables" :key="`${variable.key}-${index}`">
<td class="js-build-variable trigger-build-variable trigger-variables-table-cell">
{{ variable.key }}
</td>
<td class="js-build-value trigger-build-value trigger-variables-table-cell">
{{ getDisplayValue(variable.value) }}
</td>
</tr>
</table>
</template>
</div>
</template>