Commit 64239221 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'dj-dast-site-form-serializer' into 'master'

Refactor DAST Site Profile Form

See merge request gitlab-org/gitlab!44997
parents 84a46808 604e7ca3
...@@ -13,6 +13,7 @@ import { ...@@ -13,6 +13,7 @@ import {
import * as Sentry from '~/sentry/wrapper'; import * as Sentry from '~/sentry/wrapper';
import { __, s__ } from '~/locale'; import { __, s__ } from '~/locale';
import { isAbsolute, redirectTo } from '~/lib/utils/url_utility'; import { isAbsolute, redirectTo } from '~/lib/utils/url_utility';
import { serializeFormObject, isEmptyValue } from '~/lib/utils/forms';
import { fetchPolicies } from '~/lib/graphql'; import { fetchPolicies } from '~/lib/graphql';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import DastSiteValidation from './dast_site_validation.vue'; import DastSiteValidation from './dast_site_validation.vue';
...@@ -30,9 +31,6 @@ const initField = value => ({ ...@@ -30,9 +31,6 @@ const initField = value => ({
feedback: null, feedback: null,
}); });
const extractFormValues = form =>
Object.fromEntries(Object.entries(form).map(([key, { value }]) => [key, value]));
export default { export default {
name: 'DastSiteProfileForm', name: 'DastSiteProfileForm',
components: { components: {
...@@ -73,7 +71,7 @@ export default { ...@@ -73,7 +71,7 @@ export default {
return { return {
fetchValidationTimeout: null, fetchValidationTimeout: null,
form, form,
initialFormValues: extractFormValues(form), initialFormValues: serializeFormObject(form),
isFetchingValidationStatus: false, isFetchingValidationStatus: false,
isValidatingSite: false, isValidatingSite: false,
isLoading: false, isLoading: false,
...@@ -121,13 +119,13 @@ export default { ...@@ -121,13 +119,13 @@ export default {
}; };
}, },
formTouched() { formTouched() {
return !isEqual(extractFormValues(this.form), this.initialFormValues); return !isEqual(serializeFormObject(this.form), this.initialFormValues);
}, },
formHasErrors() { formHasErrors() {
return Object.values(this.form).some(({ state }) => state === false); return Object.values(this.form).some(({ state }) => state === false);
}, },
someFieldEmpty() { someFieldEmpty() {
return Object.values(this.form).some(({ value }) => !value); return Object.values(this.form).some(({ value }) => isEmptyValue(value));
}, },
isSubmitDisabled() { isSubmitDisabled() {
return ( return (
...@@ -295,7 +293,7 @@ export default { ...@@ -295,7 +293,7 @@ export default {
const variables = { const variables = {
fullPath: this.fullPath, fullPath: this.fullPath,
...(this.isEdit ? { id: this.siteProfile.id } : {}), ...(this.isEdit ? { id: this.siteProfile.id } : {}),
...extractFormValues(this.form), ...serializeFormObject(this.form),
}; };
this.$apollo this.$apollo
......
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