Commit aaf22b66 authored by jhampton's avatar jhampton

Conditionally display variable values

We want to hide trigger varialbes values in the UI by default. A toggle
button will be available to maintainers.
parent 9a14844e
<script> <script>
import { GlButton } from '@gitlab/ui'; import { GlButton } from '@gitlab/ui';
const HIDDEN_VALUE = '••••••';
const TOGGLE_BUTTON_TEXT = {
HIDE: 'Hide',
REVEAL: 'Reveal',
};
export default { export default {
components: { components: {
GlButton, GlButton,
...@@ -13,17 +19,27 @@ export default { ...@@ -13,17 +19,27 @@ export default {
}, },
data() { data() {
return { return {
areVariablesVisible: false, showVariableValues: false,
}; };
}, },
computed: { computed: {
hasVariables() { hasVariables() {
return this.trigger.variables && this.trigger.variables.length > 0; return Array.isArray(this.trigger.variables) && this.trigger.variables.length > 0;
},
getToggleButtonText() {
const { HIDE, REVEAL } = TOGGLE_BUTTON_TEXT;
return `${this.showVariableValues ? HIDE : REVEAL} Values`;
},
hasValues() {
return (this.trigger.variables || []).some(v => v.value);
}, },
}, },
methods: { methods: {
revealVariables() { toggleValues() {
this.areVariablesVisible = true; this.showVariableValues = !this.showVariableValues;
},
getDisplayValue(value) {
return this.showVariableValues ? value : HIDDEN_VALUE;
}, },
}, },
}; };
...@@ -33,31 +49,41 @@ export default { ...@@ -33,31 +49,41 @@ export default {
<div class="build-widget block"> <div class="build-widget block">
<h4 class="title">{{ __('Trigger') }}</h4> <h4 class="title">{{ __('Trigger') }}</h4>
<p v-if="trigger.short_token" class="js-short-token"> <p
v-if="trigger.short_token"
class="js-short-token"
:class="{ 'append-bottom-0': !hasVariables }"
>
<span class="build-light-text"> {{ __('Token') }} </span> {{ trigger.short_token }} <span class="build-light-text"> {{ __('Token') }} </span> {{ trigger.short_token }}
</p> </p>
<p v-if="hasVariables"> <template v-if="hasVariables">
<gl-button <p class="trigger-variables-btn-container">
v-if="!areVariablesVisible" <span class="build-light-text"> {{ __('Variables:') }} </span>
type="button"
class="btn btn-default group js-reveal-variables"
@click="revealVariables"
>
{{ __('Reveal Variables') }}
</gl-button>
</p>
<dl v-if="areVariablesVisible" class="js-build-variables trigger-build-variables"> <gl-button
<template v-for="variable in trigger.variables"> v-if="hasValues"
<dt :key="`${variable.key}-variable`" class="js-build-variable trigger-build-variable"> type="button"
{{ variable.key }} class="btn btn-default group js-reveal-variables"
</dt> @click="toggleValues"
>
{{ __(getToggleButtonText) }}
</gl-button>
</p>
<dd :key="`${variable.key}-value`" class="js-build-value trigger-build-value"> <table class="js-build-variables trigger-variables-table trigger-build-variables">
{{ variable.value }} <tr v-for="variable in trigger.variables">
</dd> <td
</template> v-bind:key="`${variable.key}-variable`"
</dl> class="js-build-variable trigger-build-variable"
>
{{ variable.key }}
</td>
<td v-bind:key="`${variable.key}-value`" class="js-build-value trigger-build-value">
{{ getDisplayValue(variable.value) }}
</td>
</tr>
</table>
</template>
</div> </div>
</template> </template>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment