summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ci_lint/components/ci_lint_warnings.vue
blob: ac0332cb0bd5619d3cfc0ac2a2a7f8350a92db9e (plain)
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
66
67
68
69
<script>
import { GlAlert, GlSprintf } from '@gitlab/ui';
import { __, n__ } from '~/locale';

export default {
  maxWarningsSummary: __('%{total} warnings found: showing first %{warningsDisplayed}'),
  components: {
    GlAlert,
    GlSprintf,
  },
  props: {
    warnings: {
      type: Array,
      required: true,
    },
    maxWarnings: {
      type: Number,
      required: false,
      default: 25,
    },
    title: {
      type: String,
      required: false,
      default: __('The form contains the following warning:'),
    },
  },
  computed: {
    totalWarnings() {
      return this.warnings.length;
    },
    overMaxWarningsLimit() {
      return this.totalWarnings > this.maxWarnings;
    },
    warningsSummary() {
      return n__('%d warning found:', '%d warnings found:', this.totalWarnings);
    },
    summaryMessage() {
      return this.overMaxWarningsLimit ? this.$options.maxWarningsSummary : this.warningsSummary;
    },
    limitWarnings() {
      return this.warnings.slice(0, this.maxWarnings);
    },
  },
};
</script>

<template>
  <gl-alert class="gl-mb-4" :title="title" variant="warning" @dismiss="$emit('dismiss')">
    <details>
      <summary>
        <gl-sprintf :message="summaryMessage">
          <template #total>
            {{ totalWarnings }}
          </template>
          <template #warningsDisplayed>
            {{ maxWarnings }}
          </template>
        </gl-sprintf>
      </summary>
      <p
        v-for="(warning, index) in limitWarnings"
        :key="`warning-${index}`"
        data-testid="ci-lint-warning"
      >
        {{ warning }}
      </p>
    </details>
  </gl-alert>
</template>