summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/security_configuration/components/feature_card.vue
blob: 309e5f2144549f63bf83a97853432ab8283efbeb (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<script>
import { GlButton, GlCard, GlIcon, GlLink } from '@gitlab/ui';
import { __, s__, sprintf } from '~/locale';
import { REPORT_TYPE_SAST_IAC } from '~/vue_shared/security_reports/constants';
import ManageViaMr from '~/vue_shared/security_configuration/components/manage_via_mr.vue';
import FeatureCardBadge from './feature_card_badge.vue';

export default {
  components: {
    GlButton,
    GlCard,
    GlIcon,
    GlLink,
    FeatureCardBadge,
    ManageViaMr,
  },
  props: {
    feature: {
      type: Object,
      required: true,
    },
  },
  computed: {
    available() {
      return this.feature.available;
    },
    enabled() {
      return this.available && this.feature.configured;
    },
    shortName() {
      return this.feature.shortName ?? this.feature.name;
    },
    configurationButton() {
      const button = this.enabled
        ? {
            text: this.$options.i18n.configureFeature,
          }
        : {
            text: this.$options.i18n.enableFeature,
          };

      button.category = this.feature.category || 'secondary';
      button.text = sprintf(button.text, { feature: this.shortName });

      return button;
    },
    manageViaMrButtonCategory() {
      return this.feature.category || 'secondary';
    },
    showManageViaMr() {
      return ManageViaMr.canRender(this.feature);
    },
    cardClasses() {
      return { 'gl-bg-gray-10': !this.available };
    },
    statusClasses() {
      const { enabled, hasBadge } = this;

      return {
        'gl-ml-auto': true,
        'gl-flex-shrink-0': true,
        'gl-text-gray-500': !enabled,
        'gl-text-green-500': enabled,
        'gl-w-full': hasBadge,
        'gl-justify-content-space-between': hasBadge,
        'gl-display-flex': hasBadge,
        'gl-mb-4': hasBadge,
      };
    },
    hasSecondary() {
      const { name, description, configurationText } = this.feature.secondary ?? {};
      return Boolean(name && description && configurationText);
    },
    // This condition is a temporary hack to not display any wrong information
    // until this BE Bug is fixed: https://gitlab.com/gitlab-org/gitlab/-/issues/350307.
    // More Information: https://gitlab.com/gitlab-org/gitlab/-/issues/350307#note_825447417
    isNotSastIACTemporaryHack() {
      return this.feature.type !== REPORT_TYPE_SAST_IAC;
    },
    hasBadge() {
      return Boolean(this.available && this.feature.badge?.text);
    },
  },
  methods: {
    onError(message) {
      this.$emit('error', message);
    },
  },
  i18n: {
    enabled: s__('SecurityConfiguration|Enabled'),
    notEnabled: s__('SecurityConfiguration|Not enabled'),
    availableWith: s__('SecurityConfiguration|Available with Ultimate'),
    configurationGuide: s__('SecurityConfiguration|Configuration guide'),
    configureFeature: s__('SecurityConfiguration|Configure %{feature}'),
    enableFeature: s__('SecurityConfiguration|Enable %{feature}'),
    learnMore: __('Learn more'),
  },
};
</script>

<template>
  <gl-card :class="cardClasses">
    <div
      class="gl-display-flex gl-align-items-baseline"
      :class="{ 'gl-flex-direction-column-reverse': hasBadge }"
    >
      <h3 class="gl-font-lg gl-m-0 gl-mr-3">{{ feature.name }}</h3>

      <div
        v-if="isNotSastIACTemporaryHack"
        :class="statusClasses"
        data-testid="feature-status"
        :data-qa-selector="`${feature.type}_status`"
      >
        <feature-card-badge
          v-if="hasBadge"
          :badge="feature.badge"
          :badge-href="feature.badge.badgeHref"
        />

        <template v-if="enabled">
          <gl-icon name="check-circle-filled" />
          <span class="gl-text-green-700">{{ $options.i18n.enabled }}</span>
        </template>

        <template v-else-if="available">
          <span>{{ $options.i18n.notEnabled }}</span>
        </template>

        <template v-else>
          {{ $options.i18n.availableWith }}
        </template>
      </div>
    </div>

    <p class="gl-mb-0 gl-mt-5">
      {{ feature.description }}
      <gl-link :href="feature.helpPath">{{ $options.i18n.learnMore }}</gl-link>
    </p>

    <template v-if="available && isNotSastIACTemporaryHack">
      <gl-button
        v-if="feature.configurationPath"
        :href="feature.configurationPath"
        variant="confirm"
        :category="configurationButton.category"
        :data-qa-selector="`${feature.type}_enable_button`"
        class="gl-mt-5"
      >
        {{ configurationButton.text }}
      </gl-button>

      <manage-via-mr
        v-else-if="showManageViaMr"
        :feature="feature"
        variant="confirm"
        :category="manageViaMrButtonCategory"
        class="gl-mt-5"
        :data-qa-selector="`${feature.type}_mr_button`"
        @error="onError"
      />

      <gl-button
        v-else-if="feature.configurationHelpPath"
        icon="external-link"
        :href="feature.configurationHelpPath"
        class="gl-mt-5"
      >
        {{ $options.i18n.configurationGuide }}
      </gl-button>
    </template>

    <div v-if="hasSecondary" data-testid="secondary-feature">
      <h4 class="gl-font-base gl-m-0 gl-mt-6">{{ feature.secondary.name }}</h4>

      <p class="gl-mb-0 gl-mt-5">{{ feature.secondary.description }}</p>

      <gl-button
        v-if="available && feature.secondary.configurationPath"
        :href="feature.secondary.configurationPath"
        variant="confirm"
        category="secondary"
        class="gl-mt-5"
      >
        {{ feature.secondary.configurationText }}
      </gl-button>
    </div>
  </gl-card>
</template>