Commit 2ab61b39 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'user-can-enable-alert-management' into 'master'

User can enable alert management

See merge request gitlab-org/gitlab!30024
parents c5daf89f d4e0e99c
<script> <script>
import { GlEmptyState, GlButton, GlLoadingIcon, GlTable, GlAlert } from '@gitlab/ui'; import { GlEmptyState, GlDeprecatedButton, GlLoadingIcon, GlTable, GlAlert } from '@gitlab/ui';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import getAlerts from '../graphql/queries/getAlerts.query.graphql'; import getAlerts from '../graphql/queries/getAlerts.query.graphql';
...@@ -49,26 +49,28 @@ export default { ...@@ -49,26 +49,28 @@ export default {
], ],
components: { components: {
GlEmptyState, GlEmptyState,
GlButton,
GlLoadingIcon, GlLoadingIcon,
GlTable, GlTable,
GlAlert, GlAlert,
GlDeprecatedButton,
}, },
props: { props: {
indexPath: { indexPath: {
type: String, type: String,
required: true, required: true,
}, },
// TODO: Handle alertManagementEnabled depending on resolution - https://gitlab.com/gitlab-org/gitlab/-/merge_requests/30024.
alertManagementEnabled: { alertManagementEnabled: {
type: Boolean, type: Boolean,
required: false, required: true,
default: true,
}, },
enableAlertManagementPath: { enableAlertManagementPath: {
type: String, type: String,
required: true, required: true,
}, },
userCanEnableAlertManagement: {
type: Boolean,
required: true,
},
emptyAlertSvgPath: { emptyAlertSvgPath: {
type: String, type: String,
required: true, required: true,
...@@ -137,29 +139,28 @@ export default { ...@@ -137,29 +139,28 @@ export default {
</template> </template>
</gl-table> </gl-table>
</div> </div>
<template v-else> <gl-empty-state v-else :title="__('Surface alerts in GitLab')" :svg-path="emptyAlertSvgPath">
<gl-empty-state <template #description>
:title="s__('AlertManagement|Surface alerts in GitLab')" <div class="d-block">
:svg-path="emptyAlertSvgPath" <span>{{
> s__(
<template #description> 'AlertManagement|Display alerts from all your monitoring tools directly within GitLab. Streamline the investigation of your alerts and the escalation of alerts to incidents.',
<div class="d-block"> )
<span>{{ }}</span>
s__( <a href="/help/user/project/operations/alert_management.html" target="_blank">
'AlertManagement|Display alerts from all your monitoring tools directly within GitLab. Streamline the investigation of your alerts and the escalation of alerts to incidents.', {{ s__('AlertManagement|More information') }}
) </a>
}}</span> </div>
<a href="/help/user/project/operations/alert_management.html"> <div v-if="userCanEnableAlertManagement" class="d-block center pt-4">
{{ s__('AlertManagement|More information') }} <gl-deprecated-button
</a> category="primary"
</div> variant="success"
<div class="d-block center pt-4"> :href="enableAlertManagementPath"
<gl-button category="primary" variant="success" :href="enableAlertManagementPath"> >
{{ s__('AlertManagement|Authorize external service') }} {{ s__('AlertManagement|Authorize external service') }}
</gl-button> </gl-deprecated-button>
</div> </div>
</template> </template>
</gl-empty-state> </gl-empty-state>
</template>
</div> </div>
</template> </template>
import Vue from 'vue'; import Vue from 'vue';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import createDefaultClient from '~/lib/graphql'; import createDefaultClient from '~/lib/graphql';
import { parseBoolean } from '~/lib/utils/common_utils';
import AlertManagementList from './components/alert_management_list.vue'; import AlertManagementList from './components/alert_management_list.vue';
Vue.use(VueApollo); Vue.use(VueApollo);
...@@ -10,6 +11,10 @@ export default () => { ...@@ -10,6 +11,10 @@ export default () => {
const domEl = document.querySelector(selector); const domEl = document.querySelector(selector);
const { indexPath, enableAlertManagementPath, emptyAlertSvgPath } = domEl.dataset; const { indexPath, enableAlertManagementPath, emptyAlertSvgPath } = domEl.dataset;
let { alertManagementEnabled, userCanEnableAlertManagement } = domEl.dataset;
alertManagementEnabled = parseBoolean(alertManagementEnabled);
userCanEnableAlertManagement = parseBoolean(userCanEnableAlertManagement);
const apolloProvider = new VueApollo({ const apolloProvider = new VueApollo({
defaultClient: createDefaultClient(), defaultClient: createDefaultClient(),
...@@ -27,6 +32,8 @@ export default () => { ...@@ -27,6 +32,8 @@ export default () => {
indexPath, indexPath,
enableAlertManagementPath, enableAlertManagementPath,
emptyAlertSvgPath, emptyAlertSvgPath,
alertManagementEnabled,
userCanEnableAlertManagement,
}, },
}); });
}, },
......
# frozen_string_literal: true # frozen_string_literal: true
module Projects::AlertManagementHelper module Projects::AlertManagementHelper
def alert_management_data(project) def alert_management_data(current_user, project)
{ {
'index-path' => project_alert_management_index_path(project, 'index-path' => project_alert_management_index_path(project,
format: :json), format: :json),
'enable-alert-management-path' => project_settings_operations_path(project), 'enable-alert-management-path' => project_settings_operations_path(project),
'empty-alert-svg-path' => image_path('illustrations/alert-management-empty-state.svg') 'empty-alert-svg-path' => image_path('illustrations/alert-management-empty-state.svg'),
'user-can-enable-alert-management' => 'false',
'alert-management-enabled' => Feature.enabled?(:alert_management_minimal, project).to_s
} }
end end
end end
- page_title _('Alerts') - page_title _('Alerts')
#js-alert_management{ data: alert_management_data(@project) } #js-alert_management{ data: alert_management_data(@current_user, @project) }
---
title: Alert management can user enable
merge_request: 30024
author:
type: changed
...@@ -1716,9 +1716,6 @@ msgstr "" ...@@ -1716,9 +1716,6 @@ msgstr ""
msgid "AlertManagement|Status" msgid "AlertManagement|Status"
msgstr "" msgstr ""
msgid "AlertManagement|Surface alerts in GitLab"
msgstr ""
msgid "AlertManagement|There was an error displaying the alerts. Confirm your endpoint's configuration details to ensure alerts appear." msgid "AlertManagement|There was an error displaying the alerts. Confirm your endpoint's configuration details to ensure alerts appear."
msgstr "" msgstr ""
...@@ -20129,6 +20126,9 @@ msgstr "" ...@@ -20129,6 +20126,9 @@ msgstr ""
msgid "Support page URL" msgid "Support page URL"
msgstr "" msgstr ""
msgid "Surface alerts in GitLab"
msgstr ""
msgid "Switch branch/tag" msgid "Switch branch/tag"
msgstr "" msgstr ""
......
...@@ -12,7 +12,10 @@ describe('AlertManagementList', () => { ...@@ -12,7 +12,10 @@ describe('AlertManagementList', () => {
function mountComponent({ function mountComponent({
stubs = {}, stubs = {},
props = { alertManagementEnabled: false }, props = {
alertManagementEnabled: false,
userCanEnableAlertManagement: false,
},
data = {}, data = {},
loading = false, loading = false,
} = {}) { } = {}) {
...@@ -62,7 +65,7 @@ describe('AlertManagementList', () => { ...@@ -62,7 +65,7 @@ describe('AlertManagementList', () => {
it('loading state', () => { it('loading state', () => {
mountComponent({ mountComponent({
stubs: { GlTable }, stubs: { GlTable },
props: { alertManagementEnabled: true }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alerts: null }, data: { alerts: null },
loading: true, loading: true,
}); });
...@@ -73,7 +76,7 @@ describe('AlertManagementList', () => { ...@@ -73,7 +76,7 @@ describe('AlertManagementList', () => {
it('error state', () => { it('error state', () => {
mountComponent({ mountComponent({
stubs: { GlTable }, stubs: { GlTable },
props: { alertManagementEnabled: true }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alerts: null, errored: true }, data: { alerts: null, errored: true },
loading: false, loading: false,
}); });
...@@ -86,7 +89,7 @@ describe('AlertManagementList', () => { ...@@ -86,7 +89,7 @@ describe('AlertManagementList', () => {
it('empty state', () => { it('empty state', () => {
mountComponent({ mountComponent({
stubs: { GlTable }, stubs: { GlTable },
props: { alertManagementEnabled: true }, props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alerts: [], errored: false }, data: { alerts: [], errored: false },
loading: false, loading: false,
}); });
......
...@@ -5,21 +5,32 @@ require 'spec_helper' ...@@ -5,21 +5,32 @@ require 'spec_helper'
describe Projects::AlertManagementHelper do describe Projects::AlertManagementHelper do
include Gitlab::Routing.url_helpers include Gitlab::Routing.url_helpers
let(:project) { create(:project) } let_it_be(:project, reload: true) { create(:project) }
let_it_be(:current_user) { create(:user) }
describe '#alert_management_data' do describe '#alert_management_data' do
let(:user_can_enable_alert_management) { false }
let(:setting_path) { project_settings_operations_path(project) } let(:setting_path) { project_settings_operations_path(project) }
let(:index_path) do let(:index_path) do
project_alert_management_index_path(project, format: :json) project_alert_management_index_path(project, format: :json)
end end
before do
allow(helper)
.to receive(:can?)
.with(current_user, :admin_operations, project)
.and_return(user_can_enable_alert_management)
end
context 'without alert_managements_setting' do context 'without alert_managements_setting' do
it 'returns frontend configuration' do it 'returns frontend configuration' do
expect(alert_management_data(project)).to eq( expect(alert_management_data(current_user, project)).to eq(
'index-path' => index_path, 'index-path' => index_path,
'enable-alert-management-path' => setting_path, 'enable-alert-management-path' => setting_path,
"empty-alert-svg-path" => "/images/illustrations/alert-management-empty-state.svg" "empty-alert-svg-path" => "/images/illustrations/alert-management-empty-state.svg",
'user-can-enable-alert-management' => 'false',
'alert-management-enabled' => 'true'
) )
end end
end end
......
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