diff --git a/.rubocop.yml b/.rubocop.yml index 60808f72e24..807d6ca10d3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -371,10 +371,8 @@ RSpec/LeakyConstantDeclaration: - 'spec/models/concerns/bulk_insertable_associations_spec.rb' - 'spec/models/concerns/triggerable_hooks_spec.rb' - 'spec/models/repository_spec.rb' - - 'spec/serializers/commit_entity_spec.rb' - 'spec/services/clusters/applications/check_installation_progress_service_spec.rb' - 'spec/services/clusters/applications/check_uninstall_progress_service_spec.rb' - - 'spec/support/shared_contexts/spam_constants.rb' - 'spec/support/shared_examples/quick_actions/issuable/issuable_quick_actions_shared_examples.rb' - 'spec/support_specs/matchers/exceed_query_limit_helpers_spec.rb' diff --git a/app/assets/javascripts/alert_management/components/alert_details.vue b/app/assets/javascripts/alert_management/components/alert_details.vue index 89db7db77d5..bb9f092a9ae 100644 --- a/app/assets/javascripts/alert_management/components/alert_details.vue +++ b/app/assets/javascripts/alert_management/components/alert_details.vue @@ -20,6 +20,8 @@ import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import { ALERTS_SEVERITY_LABELS } from '../constants'; import updateAlertStatus from '../graphql/mutations/update_alert_status.graphql'; +import createIssueQuery from '../graphql/mutations/create_issue_from_alert.graphql'; +import { visitUrl, joinPaths } from '~/lib/utils/url_utility'; export default { statuses: { @@ -60,7 +62,7 @@ export default { type: String, required: true, }, - newIssuePath: { + projectIssuesPath: { type: String, required: true, }, @@ -85,7 +87,13 @@ export default { }, }, data() { - return { alert: null, errored: false, isErrorDismissed: false }; + return { + alert: null, + errored: false, + isErrorDismissed: false, + createIssueError: '', + issueCreationInProgress: false, + }; }, computed: { loading() { @@ -122,6 +130,33 @@ export default { ); }); }, + createIssue() { + this.issueCreationInProgress = true; + + this.$apollo + .mutate({ + mutation: createIssueQuery, + variables: { + iid: this.alert.iid, + projectPath: this.projectPath, + }, + }) + .then(({ data: { createAlertIssue: { errors, issue } } }) => { + if (errors?.length) { + [this.createIssueError] = errors; + this.issueCreationInProgress = false; + } else if (issue) { + visitUrl(this.issuePath(issue.iid)); + } + }) + .catch(error => { + this.createIssueError = error; + this.issueCreationInProgress = false; + }); + }, + issuePath(issueId) { + return joinPaths(this.projectIssuesPath, issueId); + }, }, }; @@ -130,6 +165,14 @@ export default { {{ $options.i18n.errorMsg }} + + {{ createIssueError }} +
{{ alert.monitoringTool }}
- - {{ s__('AlertManagement|Create issue') }} - +
+ + {{ s__('AlertManagement|View issue') }} + + + {{ s__('AlertManagement|Create issue') }} + +
{ const domEl = document.querySelector(selector); - const { alertId, projectPath, newIssuePath } = domEl.dataset; + const { alertId, projectPath, projectIssuesPath } = domEl.dataset; const apolloProvider = new VueApollo({ defaultClient: createDefaultClient( @@ -39,7 +39,7 @@ export default selector => { props: { alertId, projectPath, - newIssuePath, + projectIssuesPath, }, }); }, diff --git a/app/assets/javascripts/alert_management/graphql/fragments/listItem.fragment.graphql b/app/assets/javascripts/alert_management/graphql/fragments/listItem.fragment.graphql index fffe07b0cfd..22adfc9800c 100644 --- a/app/assets/javascripts/alert_management/graphql/fragments/listItem.fragment.graphql +++ b/app/assets/javascripts/alert_management/graphql/fragments/listItem.fragment.graphql @@ -6,4 +6,5 @@ fragment AlertListItem on AlertManagementAlert { startedAt endedAt eventCount + issueIid } diff --git a/app/assets/javascripts/alert_management/graphql/mutations/create_issue_from_alert.graphql b/app/assets/javascripts/alert_management/graphql/mutations/create_issue_from_alert.graphql new file mode 100644 index 00000000000..664596ab88f --- /dev/null +++ b/app/assets/javascripts/alert_management/graphql/mutations/create_issue_from_alert.graphql @@ -0,0 +1,8 @@ +mutation ($projectPath: ID!, $iid: String!) { + createAlertIssue(input: { iid: $iid, projectPath: $projectPath }) { + errors + issue { + iid + } + } +} diff --git a/app/assets/javascripts/pages/admin/projects/index/components/delete_project_modal.vue b/app/assets/javascripts/pages/admin/projects/index/components/delete_project_modal.vue index b22fbf6b833..8bb093da771 100644 --- a/app/assets/javascripts/pages/admin/projects/index/components/delete_project_modal.vue +++ b/app/assets/javascripts/pages/admin/projects/index/components/delete_project_modal.vue @@ -92,7 +92,7 @@ export default { @submit="onSubmit" @cancel="onCancel" > -