All files / app/assets/javascripts/ide/components error_message.vue

91.67% Statements 11/12
100% Branches 2/2
85.71% Functions 6/7
91.67% Lines 11/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65  2x 2x                                 9x           9x         5x 6x   4x   4x     4x             1x           57x                          
<script>
import { GlAlert, GlLoadingIcon, GlSafeHtmlDirective } from '@gitlab/ui';
import { mapActions } from 'vuex';
 
export default {
  components: {
    GlAlert,
    GlLoadingIcon,
  },
  directives: {
    SafeHtml: GlSafeHtmlDirective,
  },
  props: {
    message: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      isLoading: false,
    };
  },
  computed: {
    canDismiss() {
      return !this.message.action;
    },
  },
  methods: {
    ...mapActions(['setErrorMessage']),
    doAction() {
      if (this.isLoading) return;
 
      this.isLoading = true;
 
      this.message
        .action(this.message.actionPayload)
        .then(() => {
          this.isLoading = false;
        })
        .catch(() => {
          this.isLoading = false;
        });
    },
    dismiss() {
      this.setErrorMessage(null);
    },
  },
};
</script>
 
<template>
  <gl-alert
    data-qa-selector="flash_alert"
    variant="danger"
    :dismissible="canDismiss"
    :primary-button-text="message.actionText"
    @dismiss="dismiss"
    @primaryAction="doAction"
  >
    <span v-safe-html="message.text"></span>
    <gl-loading-icon v-show="isLoading" size="sm" inline class="vertical-align-middle ml-1" />
  </gl-alert>
</template>