Skip to content
代码片段 群组 项目
feature_card.vue 4.8 KB
更新 更旧
Mark Florian's avatar
Mark Florian 已提交
<script>
import { GlButton, GlCard, GlIcon, GlLink } from '@gitlab/ui';
import { __, s__, sprintf } from '~/locale';
import ManageViaMr from '~/vue_shared/security_configuration/components/manage_via_mr.vue';
import { REPORT_TYPE_SAST_IAC } from '~/vue_shared/security_reports/constants';
Mark Florian's avatar
Mark Florian 已提交

export default {
  components: {
    GlButton,
    GlCard,
    GlIcon,
    GlLink,
    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 = 'secondary';
Mark Florian's avatar
Mark Florian 已提交
      button.text = sprintf(button.text, { feature: this.shortName });

      return button;
    },
    showManageViaMr() {
      return ManageViaMr.canRender(this.feature);
Mark Florian's avatar
Mark Florian 已提交
    },
    cardClasses() {
      return { 'gl-bg-gray-10': !this.available };
    },
    statusClasses() {
      const { enabled } = this;

      return {
        'gl-ml-auto': true,
        'gl-flex-shrink-0': true,
        'gl-text-gray-500': !enabled,
        'gl-text-green-500': enabled,
      };
    },
    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;
    },
  methods: {
    onError(message) {
      this.$emit('error', message);
    },
  },
Mark Florian's avatar
Mark Florian 已提交
  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">
      <h3 class="gl-font-lg gl-m-0 gl-mr-3">{{ feature.name }}</h3>

        v-if="isNotSastIACTemporaryHack"
        :class="statusClasses"
        data-testid="feature-status"
        :data-qa-selector="`${feature.type}_status`"
      >
        <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">
          {{ $options.i18n.notEnabled }}
        </template>
        <template v-else>
          {{ $options.i18n.availableWith }}
Mark Florian's avatar
Mark Florian 已提交
        </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">
Mark Florian's avatar
Mark Florian 已提交
      <gl-button
        v-if="feature.configurationPath"
        :href="feature.configurationPath"
        variant="confirm"
        :category="configurationButton.category"
        :data-qa-selector="`${feature.type}_enable_button`"
Mark Florian's avatar
Mark Florian 已提交
        class="gl-mt-5"
      >
        {{ configurationButton.text }}
      </gl-button>

      <manage-via-mr
        v-else-if="showManageViaMr"
        :feature="feature"
        variant="confirm"
Mark Florian's avatar
Mark Florian 已提交
        class="gl-mt-5"
        :data-qa-selector="`${feature.type}_mr_button`"
      <gl-button
        v-else-if="feature.configurationHelpPath"
        icon="external-link"
        :href="feature.configurationHelpPath"
        class="gl-mt-5"
      >
Mark Florian's avatar
Mark Florian 已提交
        {{ $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>