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">
<p class="trigger-variables-btn-container">
<span class="build-light-text"> {{ __('Variables:') }} </span>
<gl-button <gl-button
v-if="!areVariablesVisible" v-if="hasValues"
type="button" type="button"
class="btn btn-default group js-reveal-variables" class="btn btn-default group js-reveal-variables"
@click="revealVariables" @click="toggleValues"
> >
{{ __('Reveal Variables') }} {{ __(getToggleButtonText) }}
</gl-button> </gl-button>
</p> </p>
<dl v-if="areVariablesVisible" class="js-build-variables trigger-build-variables"> <table class="js-build-variables trigger-variables-table trigger-build-variables">
<template v-for="variable in trigger.variables"> <tr v-for="variable in trigger.variables">
<dt :key="`${variable.key}-variable`" class="js-build-variable trigger-build-variable"> <td
v-bind:key="`${variable.key}-variable`"
class="js-build-variable trigger-build-variable"
>
{{ variable.key }} {{ variable.key }}
</dt> </td>
<td v-bind:key="`${variable.key}-value`" class="js-build-value trigger-build-value">
<dd :key="`${variable.key}-value`" class="js-build-value trigger-build-value"> {{ getDisplayValue(variable.value) }}
{{ variable.value }} </td>
</dd> </tr>
</table>
</template> </template>
</dl>
</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