Scroll to top of window on error

parent 4db43ced
...@@ -54,7 +54,7 @@ export default { ...@@ -54,7 +54,7 @@ export default {
data() { data() {
return { return {
isLoading: false, isLoading: false,
showError: false, isErrorVisible: false,
targetUrl: { targetUrl: {
field: 'targetUrl', field: 'targetUrl',
label: s__('APIFuzzing|Target URL'), label: s__('APIFuzzing|Target URL'),
...@@ -159,7 +159,7 @@ export default { ...@@ -159,7 +159,7 @@ export default {
methods: { methods: {
async onSubmit() { async onSubmit() {
this.isLoading = true; this.isLoading = true;
this.showError = false; this.dismissError();
try { try {
const input = { const input = {
projectPath: this.fullPath, projectPath: this.fullPath,
...@@ -186,21 +186,25 @@ export default { ...@@ -186,21 +186,25 @@ export default {
variables: { input }, variables: { input },
}); });
if (errors.length) { if (errors.length) {
this.showError = true; this.showError();
} else { } else {
this.ciYamlEditPath = gitlabCiYamlEditPath; this.ciYamlEditPath = gitlabCiYamlEditPath;
this.configurationYaml = configurationYaml; this.configurationYaml = configurationYaml;
this.$refs[CONFIGURATION_SNIPPET_MODAL_ID].show(); this.$refs[CONFIGURATION_SNIPPET_MODAL_ID].show();
} }
} catch (e) { } catch (e) {
this.showError = true; this.showError();
Sentry.captureException(e); Sentry.captureException(e);
} finally { } finally {
this.isLoading = false; this.isLoading = false;
} }
}, },
showError() {
this.isErrorVisible = true;
window.scrollTo({ top: 0 });
},
dismissError() { dismissError() {
this.showError = false; this.isErrorVisible = false;
}, },
}, },
SCAN_MODES, SCAN_MODES,
...@@ -209,7 +213,7 @@ export default { ...@@ -209,7 +213,7 @@ export default {
<template> <template>
<form @submit.prevent="onSubmit"> <form @submit.prevent="onSubmit">
<gl-alert v-if="showError" variant="danger" class="gl-mb-5" @dismiss="dismissError"> <gl-alert v-if="isErrorVisible" variant="danger" class="gl-mb-5" @dismiss="dismissError">
{{ s__('APIFuzzing|The configuration could not be saved, please try again later.') }} {{ s__('APIFuzzing|The configuration could not be saved, please try again later.') }}
</gl-alert> </gl-alert>
......
---
title: Scroll to top of window when API Fuzzing configuration fails
merge_request: 56890
author:
type: changed
...@@ -263,6 +263,7 @@ describe('EE - ApiFuzzingConfigurationForm', () => { ...@@ -263,6 +263,7 @@ describe('EE - ApiFuzzingConfigurationForm', () => {
await waitForPromises(); await waitForPromises();
expect(findAlert().exists()).toBe(true); expect(findAlert().exists()).toBe(true);
expect(window.scrollTo).toHaveBeenCalledWith({ top: 0 });
}); });
it('shows an error on error-as-data', async () => { it('shows an error on error-as-data', async () => {
...@@ -287,6 +288,7 @@ describe('EE - ApiFuzzingConfigurationForm', () => { ...@@ -287,6 +288,7 @@ describe('EE - ApiFuzzingConfigurationForm', () => {
await waitForPromises(); await waitForPromises();
expect(findAlert().exists()).toBe(true); expect(findAlert().exists()).toBe(true);
expect(window.scrollTo).toHaveBeenCalledWith({ top: 0 });
}); });
}); });
}); });
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