Welcome to mirror list, hosted at ThFree Co, Russian Federation.

validation_segment.vue « header « components « pipeline_editor « ci « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8553256f13a925a3db1dfcd5cf017186112eae25 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<script>
import { GlIcon, GlLink, GlLoadingIcon, GlSprintf } from '@gitlab/ui';
import { s__, sprintf } from '~/locale';
import getAppStatus from '~/ci/pipeline_editor/graphql/queries/client/app_status.query.graphql';
import {
  EDITOR_APP_STATUS_EMPTY,
  EDITOR_APP_STATUS_LINT_UNAVAILABLE,
  EDITOR_APP_STATUS_LOADING,
  EDITOR_APP_STATUS_VALID,
} from '../../constants';

export const i18n = {
  empty: s__(
    "Pipelines|We'll continuously validate your pipeline configuration. The validation results will appear here.",
  ),
  loading: s__('Pipelines|Validating GitLab CI configuration…'),
  invalid: s__(
    'Pipelines|This GitLab CI configuration is invalid. %{linkStart}Learn more%{linkEnd}',
  ),
  invalidWithReason: s__(
    'Pipelines|This GitLab CI configuration is invalid: %{reason}. %{linkStart}Learn more%{linkEnd}',
  ),
  unavailableValidation: s__(
    'Pipelines|Unable to validate CI/CD configuration. See the %{linkStart}GitLab CI/CD troubleshooting guide%{linkEnd} for more details.',
  ),
  valid: s__('Pipelines|Pipeline syntax is correct. %{linkStart}Learn more%{linkEnd}'),
};

export default {
  i18n,
  components: {
    GlIcon,
    GlLink,
    GlLoadingIcon,
    GlSprintf,
  },
  inject: {
    ciTroubleshootingPath: {
      default: '',
    },
    ymlHelpPagePath: {
      default: '',
    },
  },
  props: {
    ciConfig: {
      type: Object,
      required: false,
      default: () => ({}),
    },
  },
  apollo: {
    appStatus: {
      query: getAppStatus,
      update(data) {
        return data.app.status;
      },
    },
  },
  computed: {
    APP_STATUS_CONFIG() {
      return {
        [EDITOR_APP_STATUS_EMPTY]: {
          icon: 'check',
          message: this.$options.i18n.empty,
        },
        [EDITOR_APP_STATUS_LINT_UNAVAILABLE]: {
          icon: 'time-out',
          link: this.ciTroubleshootingPath,
          message: this.$options.i18n.unavailableValidation,
        },
        [EDITOR_APP_STATUS_VALID]: {
          icon: 'check',
          message: this.$options.i18n.valid,
        },
      };
    },
    currentAppStatusConfig() {
      return this.APP_STATUS_CONFIG[this.appStatus] || {};
    },
    hasLink() {
      return this.appStatus !== EDITOR_APP_STATUS_EMPTY;
    },
    helpPath() {
      return this.currentAppStatusConfig.link || this.ymlHelpPagePath;
    },
    isLoading() {
      return this.appStatus === EDITOR_APP_STATUS_LOADING;
    },
    icon() {
      return this.currentAppStatusConfig.icon || 'warning-solid';
    },
    message() {
      const [reason] = this.ciConfig?.errors || [];

      return (
        this.currentAppStatusConfig.message ||
        // Only display first error as a reason
        (reason
          ? sprintf(this.$options.i18n.invalidWithReason, { reason }, false)
          : this.$options.i18n.invalid)
      );
    },
  },
};
</script>

<template>
  <div>
    <template v-if="isLoading">
      <gl-loading-icon size="sm" inline />
      {{ $options.i18n.loading }}
    </template>
    <span v-else data-testid="validation-segment">
      <span class="gl-max-w-full" data-qa-selector="validation_message_content">
        <gl-icon :name="icon" />
        <gl-sprintf :message="message">
          <template v-if="hasLink" #link="{ content }">
            <gl-link :href="helpPath">{{ content }}</gl-link>
          </template>
        </gl-sprintf>
      </span>
    </span>
  </div>
</template>