debian-mirror-gitlab/app/assets/javascripts/jobs/components/trigger_block.vue

95 lines
2.3 KiB
Vue
Raw Normal View History

2018-11-20 20:47:30 +05:30
<script>
2021-03-11 19:13:27 +05:30
import { GlButton, GlTable } from '@gitlab/ui';
2020-01-01 13:55:28 +05:30
import { __ } from '~/locale';
2019-02-15 15:39:39 +05:30
2021-03-11 19:13:27 +05:30
const DEFAULT_TD_CLASSES = 'gl-w-half gl-font-sm! gl-border-gray-200!';
const DEFAULT_TH_CLASSES =
'gl-bg-transparent! gl-border-b-solid! gl-border-b-gray-200! gl-border-b-1!';
2019-02-15 15:39:39 +05:30
2018-12-13 13:39:08 +05:30
export default {
2021-03-11 19:13:27 +05:30
fields: [
{
key: 'key',
label: __('Key'),
tdAttr: { 'data-testid': 'trigger-build-key' },
tdClass: DEFAULT_TD_CLASSES,
thClass: DEFAULT_TH_CLASSES,
},
{
key: 'value',
label: __('Value'),
tdAttr: { 'data-testid': 'trigger-build-value' },
tdClass: DEFAULT_TD_CLASSES,
thClass: DEFAULT_TH_CLASSES,
},
],
2019-02-15 15:39:39 +05:30
components: {
2021-01-03 14:25:43 +05:30
GlButton,
2021-03-11 19:13:27 +05:30
GlTable,
2019-02-15 15:39:39 +05:30
},
2018-12-13 13:39:08 +05:30
props: {
trigger: {
type: Object,
required: true,
2018-11-20 20:47:30 +05:30
},
2018-12-13 13:39:08 +05:30
},
data() {
return {
2019-02-15 15:39:39 +05:30
showVariableValues: false,
2018-12-13 13:39:08 +05:30
};
},
computed: {
hasVariables() {
2021-03-11 19:13:27 +05:30
return this.trigger.variables.length > 0;
2018-11-20 20:47:30 +05:30
},
2019-02-15 15:39:39 +05:30
getToggleButtonText() {
return this.showVariableValues ? __('Hide values') : __('Reveal values');
},
hasValues() {
2021-03-08 18:12:59 +05:30
return this.trigger.variables.some((v) => v.value);
2019-02-15 15:39:39 +05:30
},
2018-12-13 13:39:08 +05:30
},
methods: {
2019-02-15 15:39:39 +05:30
toggleValues() {
this.showVariableValues = !this.showVariableValues;
},
getDisplayValue(value) {
2021-03-11 19:13:27 +05:30
return this.showVariableValues ? value : '••••••';
2018-11-20 20:47:30 +05:30
},
2018-12-13 13:39:08 +05:30
},
};
2018-11-20 20:47:30 +05:30
</script>
<template>
2021-04-17 20:07:23 +05:30
<div>
2018-11-20 20:47:30 +05:30
<p
2018-12-05 23:21:45 +05:30
v-if="trigger.short_token"
2020-07-28 23:09:34 +05:30
:class="{ 'gl-mb-2': hasVariables, 'gl-mb-0': !hasVariables }"
2021-03-11 19:13:27 +05:30
data-testid="trigger-short-token"
2018-11-20 20:47:30 +05:30
>
2021-03-11 19:13:27 +05:30
<span class="gl-font-weight-bold">{{ __('Trigger token:') }}</span> {{ trigger.short_token }}
2018-11-20 20:47:30 +05:30
</p>
2019-02-15 15:39:39 +05:30
<template v-if="hasVariables">
2021-03-11 19:13:27 +05:30
<p class="gl-display-flex gl-justify-content-space-between gl-align-items-center">
<span class="gl-font-weight-bold">{{ __('Trigger variables:') }}</span>
2018-11-20 20:47:30 +05:30
2021-01-03 14:25:43 +05:30
<gl-button
2019-02-15 15:39:39 +05:30
v-if="hasValues"
2021-03-11 19:13:27 +05:30
class="gl-mt-2"
2021-01-03 14:25:43 +05:30
size="small"
2021-03-11 19:13:27 +05:30
data-testid="trigger-reveal-values-button"
2019-02-15 15:39:39 +05:30
@click="toggleValues"
2021-01-03 14:25:43 +05:30
>{{ getToggleButtonText }}</gl-button
2019-01-03 12:48:30 +05:30
>
2019-02-15 15:39:39 +05:30
</p>
2018-11-20 20:47:30 +05:30
2021-03-11 19:13:27 +05:30
<gl-table :items="trigger.variables" :fields="$options.fields" small bordered>
<template #cell(value)="data">
{{ getDisplayValue(data.value) }}
</template>
</gl-table>
2019-02-15 15:39:39 +05:30
</template>
2018-11-20 20:47:30 +05:30
</div>
</template>