debian-mirror-gitlab/app/assets/javascripts/security_configuration/components/feature_card.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

192 lines
5.5 KiB
Vue
Raw Normal View History

2021-06-08 01:23:25 +05:30
<script>
import { GlButton, GlCard, GlIcon, GlLink } from '@gitlab/ui';
import { __, s__, sprintf } from '~/locale';
2022-06-21 17:19:12 +05:30
import { REPORT_TYPE_SAST_IAC } from '~/vue_shared/security_reports/constants';
2021-06-08 01:23:25 +05:30
import ManageViaMr from '~/vue_shared/security_configuration/components/manage_via_mr.vue';
2022-06-21 17:19:12 +05:30
import FeatureCardBadge from './feature_card_badge.vue';
2021-06-08 01:23:25 +05:30
export default {
components: {
GlButton,
GlCard,
GlIcon,
GlLink,
2022-06-21 17:19:12 +05:30
FeatureCardBadge,
2021-06-08 01:23:25 +05:30
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,
};
2022-06-21 17:19:12 +05:30
button.category = this.feature.category || 'secondary';
2021-06-08 01:23:25 +05:30
button.text = sprintf(button.text, { feature: this.shortName });
return button;
},
2022-06-21 17:19:12 +05:30
manageViaMrButtonCategory() {
return this.feature.category || 'secondary';
},
2021-06-08 01:23:25 +05:30
showManageViaMr() {
2021-09-30 23:02:18 +05:30
return ManageViaMr.canRender(this.feature);
2021-06-08 01:23:25 +05:30
},
cardClasses() {
return { 'gl-bg-gray-10': !this.available };
},
statusClasses() {
2022-06-21 17:19:12 +05:30
const { enabled, hasBadge } = this;
2021-06-08 01:23:25 +05:30
return {
'gl-ml-auto': true,
'gl-flex-shrink-0': true,
'gl-text-gray-500': !enabled,
'gl-text-green-500': enabled,
2022-06-21 17:19:12 +05:30
'gl-w-full': hasBadge,
'gl-justify-content-space-between': hasBadge,
'gl-display-flex': hasBadge,
'gl-mb-4': hasBadge,
2021-06-08 01:23:25 +05:30
};
},
hasSecondary() {
const { name, description, configurationText } = this.feature.secondary ?? {};
return Boolean(name && description && configurationText);
},
2022-06-21 17:19:12 +05:30
// 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);
},
2021-06-08 01:23:25 +05:30
},
2021-12-11 22:18:48 +05:30
methods: {
onError(message) {
this.$emit('error', message);
},
},
2021-06-08 01:23:25 +05:30
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">
2022-06-21 17:19:12 +05:30
<div
class="gl-display-flex gl-align-items-baseline"
:class="{ 'gl-flex-direction-column-reverse': hasBadge }"
>
2021-06-08 01:23:25 +05:30
<h3 class="gl-font-lg gl-m-0 gl-mr-3">{{ feature.name }}</h3>
2021-10-27 15:23:28 +05:30
<div
2022-06-21 17:19:12 +05:30
v-if="isNotSastIACTemporaryHack"
2021-10-27 15:23:28 +05:30
:class="statusClasses"
data-testid="feature-status"
:data-qa-selector="`${feature.type}_status`"
>
2022-06-21 17:19:12 +05:30
<feature-card-badge
v-if="hasBadge"
:badge="feature.badge"
:badge-href="feature.badge.badgeHref"
/>
2022-04-04 11:22:00 +05:30
<template v-if="enabled">
2022-07-16 23:28:13 +05:30
<span>
<gl-icon name="check-circle-filled" />
<span class="gl-text-green-700">{{ $options.i18n.enabled }}</span>
</span>
2022-04-04 11:22:00 +05:30
</template>
2021-06-08 01:23:25 +05:30
2022-04-04 11:22:00 +05:30
<template v-else-if="available">
2022-06-21 17:19:12 +05:30
<span>{{ $options.i18n.notEnabled }}</span>
2022-04-04 11:22:00 +05:30
</template>
2021-06-08 01:23:25 +05:30
2022-04-04 11:22:00 +05:30
<template v-else>
{{ $options.i18n.availableWith }}
2021-06-08 01:23:25 +05:30
</template>
</div>
</div>
<p class="gl-mb-0 gl-mt-5">
{{ feature.description }}
<gl-link :href="feature.helpPath">{{ $options.i18n.learnMore }}</gl-link>
</p>
2022-06-21 17:19:12 +05:30
<template v-if="available && isNotSastIACTemporaryHack">
2021-06-08 01:23:25 +05:30
<gl-button
v-if="feature.configurationPath"
:href="feature.configurationPath"
variant="confirm"
:category="configurationButton.category"
2021-10-27 15:23:28 +05:30
:data-qa-selector="`${feature.type}_enable_button`"
2021-06-08 01:23:25 +05:30
class="gl-mt-5"
>
{{ configurationButton.text }}
</gl-button>
<manage-via-mr
v-else-if="showManageViaMr"
:feature="feature"
variant="confirm"
2022-06-21 17:19:12 +05:30
:category="manageViaMrButtonCategory"
2021-06-08 01:23:25 +05:30
class="gl-mt-5"
2021-11-18 22:05:49 +05:30
:data-qa-selector="`${feature.type}_mr_button`"
2021-12-11 22:18:48 +05:30
@error="onError"
2021-06-08 01:23:25 +05:30
/>
2021-10-27 15:23:28 +05:30
<gl-button
v-else-if="feature.configurationHelpPath"
icon="external-link"
:href="feature.configurationHelpPath"
class="gl-mt-5"
>
2021-06-08 01:23:25 +05:30
{{ $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>