alerts.vue 1.49 KB
Newer Older
1
<script>
2
import { GlIcon } from '@gitlab/ui';
3
import { escape } from 'lodash';
4 5 6 7
import { __, n__, sprintf } from '~/locale';

export default {
  components: {
8
    GlIcon,
9 10 11 12 13 14 15
  },
  props: {
    count: {
      type: Number,
      required: false,
      default: 0,
    },
16 17 18 19 20
    lastAlert: {
      type: Object,
      required: false,
      default: null,
    },
21 22 23 24 25 26 27 28 29
  },
  computed: {
    alertClasses() {
      return {
        'text-tertiary': this.count <= 0,
        'text-warning': this.count > 0,
      };
    },
    alertCount() {
30 31
      const text = this.lastAlert ? '%{count} %{alerts}:' : '%{count} %{alerts}';
      return sprintf(__(text), {
32 33 34 35 36 37 38
        count: this.count,
        alerts: this.pluralizedAlerts,
      });
    },
    pluralizedAlerts() {
      return n__('Alert', 'Alerts', this.count);
    },
39 40 41 42
    alertText() {
      return sprintf(
        __('%{title} %{operator} %{threshold}'),
        {
43 44
          title: escape(this.lastAlert.title),
          threshold: `${escape(this.lastAlert.threshold)}%`,
45 46 47 48 49
          operator: this.lastAlert.operator,
        },
        false,
      );
    },
50 51 52 53 54 55 56
  },
};
</script>

<template>
  <div class="dashboard-card-alert row">
    <div class="col-12">
57
      <gl-icon
58 59 60 61
        :class="alertClasses"
        class="align-text-bottom js-dashboard-alerts-icon"
        name="warning"
      />
62
      <span class="js-alert-count text-secondary gl-ml-2"> {{ alertCount }} </span>
63
      <span v-if="lastAlert" class="text-secondary">{{ alertText }}</span>
64 65 66
    </div>
  </div>
</template>