Commit 02b3b8a5 authored by Mark Florian's avatar Mark Florian

Persist Auto DevOps alert dismissal

Addresses https://gitlab.com/gitlab-org/gitlab/-/issues/239468
parent 8b7b5a53
<script> <script>
import { GlAlert, GlLink, GlSprintf, GlTable } from '@gitlab/ui'; import { GlAlert, GlLink, GlSprintf, GlTable } from '@gitlab/ui';
import { parseBoolean } from '~/lib/utils/common_utils';
import { s__, __ } from '~/locale'; import { s__, __ } from '~/locale';
import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import AutoFixSettings from './auto_fix_settings.vue'; import AutoFixSettings from './auto_fix_settings.vue';
import ManageFeature from './manage_feature.vue'; import ManageFeature from './manage_feature.vue';
...@@ -12,6 +14,7 @@ export default { ...@@ -12,6 +14,7 @@ export default {
GlSprintf, GlSprintf,
GlTable, GlTable,
AutoFixSettings, AutoFixSettings,
LocalStorageSync,
ManageFeature, ManageFeature,
}, },
mixins: [glFeatureFlagsMixin()], mixins: [glFeatureFlagsMixin()],
...@@ -63,6 +66,9 @@ export default { ...@@ -63,6 +66,9 @@ export default {
required: true, required: true,
}, },
}, },
data: () => ({
autoDevopsAlertDismissed: 'false',
}),
computed: { computed: {
devopsMessage() { devopsMessage() {
return this.autoDevopsEnabled return this.autoDevopsEnabled
...@@ -100,7 +106,12 @@ export default { ...@@ -100,7 +106,12 @@ export default {
]; ];
}, },
shouldShowAutoDevopsAlert() { shouldShowAutoDevopsAlert() {
return Boolean(!this.autoDevopsEnabled && !this.gitlabCiPresent && this.canEnableAutoDevops); return Boolean(
!parseBoolean(this.autoDevopsAlertDismissed) &&
!this.autoDevopsEnabled &&
!this.gitlabCiPresent &&
this.canEnableAutoDevops,
);
}, },
}, },
methods: { methods: {
...@@ -113,10 +124,14 @@ export default { ...@@ -113,10 +124,14 @@ export default {
return s__('SecurityConfiguration|Not enabled'); return s__('SecurityConfiguration|Not enabled');
}, },
dismissAutoDevopsAlert() {
this.autoDevopsAlertDismissed = 'true';
},
}, },
autoDevopsAlertMessage: s__(` autoDevopsAlertMessage: s__(`
SecurityConfiguration|You can quickly enable all security scanning tools by SecurityConfiguration|You can quickly enable all security scanning tools by
enabling %{linkStart}Auto DevOps%{linkEnd}.`), enabling %{linkStart}Auto DevOps%{linkEnd}.`),
autoDevopsAlertStorageKey: 'security_configuration_auto_devops_dismissed',
}; };
</script> </script>
...@@ -134,13 +149,18 @@ export default { ...@@ -134,13 +149,18 @@ export default {
</p> </p>
</header> </header>
<local-storage-sync
v-model="autoDevopsAlertDismissed"
:storage-key="$options.autoDevopsAlertStorageKey"
/>
<gl-alert <gl-alert
v-if="shouldShowAutoDevopsAlert" v-if="shouldShowAutoDevopsAlert"
:title="__('Auto DevOps')" :title="__('Auto DevOps')"
:primary-button-text="__('Enable Auto DevOps')" :primary-button-text="__('Enable Auto DevOps')"
:primary-button-link="autoDevopsPath" :primary-button-link="autoDevopsPath"
:dismissible="false"
class="gl-mb-5" class="gl-mb-5"
@dismiss="dismissAutoDevopsAlert"
> >
<gl-sprintf :message="$options.autoDevopsAlertMessage"> <gl-sprintf :message="$options.autoDevopsAlertMessage">
<template #link="{ content }"> <template #link="{ content }">
......
---
title: Make Auto DevOps alert in Security Configuration dismissible
merge_request: 40375
author:
type: added
...@@ -4,6 +4,7 @@ import { GlAlert, GlLink } from '@gitlab/ui'; ...@@ -4,6 +4,7 @@ import { GlAlert, GlLink } from '@gitlab/ui';
import SecurityConfigurationApp from 'ee/security_configuration/components/app.vue'; import SecurityConfigurationApp from 'ee/security_configuration/components/app.vue';
import ManageFeature from 'ee/security_configuration/components/manage_feature.vue'; import ManageFeature from 'ee/security_configuration/components/manage_feature.vue';
import stubChildren from 'helpers/stub_children'; import stubChildren from 'helpers/stub_children';
import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue';
import { generateFeatures } from './helpers'; import { generateFeatures } from './helpers';
const propsData = { const propsData = {
...@@ -38,6 +39,10 @@ describe('Security Configuration App', () => { ...@@ -38,6 +39,10 @@ describe('Security Configuration App', () => {
); );
}; };
beforeEach(() => {
localStorage.clear();
});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null; wrapper = null;
...@@ -70,21 +75,29 @@ describe('Security Configuration App', () => { ...@@ -70,21 +75,29 @@ describe('Security Configuration App', () => {
describe('Auto DevOps alert', () => { describe('Auto DevOps alert', () => {
describe.each` describe.each`
gitlabCiPresent | autoDevopsEnabled | canEnableAutoDevops | shouldShowAlert gitlabCiPresent | autoDevopsEnabled | canEnableAutoDevops | dismissed | shouldShowAlert
${false} | ${false} | ${true} | ${true} ${false} | ${false} | ${true} | ${false} | ${true}
${true} | ${false} | ${true} | ${false} ${false} | ${false} | ${true} | ${true} | ${false}
${false} | ${true} | ${true} | ${false} ${true} | ${false} | ${true} | ${false} | ${false}
${false} | ${false} | ${false} | ${false} ${false} | ${true} | ${true} | ${false} | ${false}
${false} | ${false} | ${false} | ${false} | ${false}
`( `(
'given gitlabCiPresent is $gitlabCiPresent, autoDevopsEnabled is $autoDevopsEnabled, canEnableAutoDevops is $canEnableAutoDevops', 'given gitlabCiPresent is $gitlabCiPresent, autoDevopsEnabled is $autoDevopsEnabled, dismissed is $dismissed, canEnableAutoDevops is $canEnableAutoDevops',
({ gitlabCiPresent, autoDevopsEnabled, canEnableAutoDevops, shouldShowAlert }) => { ({ gitlabCiPresent, autoDevopsEnabled, canEnableAutoDevops, dismissed, shouldShowAlert }) => {
beforeEach(() => { beforeEach(() => {
if (dismissed) {
localStorage.setItem(SecurityConfigurationApp.autoDevopsAlertStorageKey, 'true');
}
createComponent({ createComponent({
propsData: { propsData: {
gitlabCiPresent, gitlabCiPresent,
autoDevopsEnabled, autoDevopsEnabled,
canEnableAutoDevops, canEnableAutoDevops,
}, },
stubs: {
LocalStorageSync,
},
}); });
}); });
...@@ -109,7 +122,6 @@ describe('Security Configuration App', () => { ...@@ -109,7 +122,6 @@ describe('Security Configuration App', () => {
title: 'Auto DevOps', title: 'Auto DevOps',
primaryButtonText: 'Enable Auto DevOps', primaryButtonText: 'Enable Auto DevOps',
primaryButtonLink: propsData.autoDevopsPath, primaryButtonLink: propsData.autoDevopsPath,
dismissible: false,
}); });
}); });
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment