Commit 7a16c502 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '340073-fix-vsa-form-persistence' into 'master'

Ensure VSA form submits only required fields

See merge request gitlab-org/gitlab!69630
parents 0879cdf6 9e8a7800
...@@ -70,6 +70,15 @@ export const formFieldKeys = [ ...@@ -70,6 +70,15 @@ export const formFieldKeys = [
'endEventLabelId', 'endEventLabelId',
]; ];
export const editableFormFieldKeys = [
...formFieldKeys,
'hidden',
'description',
'title',
'legend',
'custom',
];
export const defaultFields = formFieldKeys.reduce((acc, field) => ({ ...acc, [field]: null }), {}); export const defaultFields = formFieldKeys.reduce((acc, field) => ({ ...acc, [field]: null }), {});
export const defaultErrors = formFieldKeys.reduce((acc, field) => ({ ...acc, [field]: [] }), {}); export const defaultErrors = formFieldKeys.reduce((acc, field) => ({ ...acc, [field]: [] }), {});
......
...@@ -8,6 +8,7 @@ import { ...@@ -8,6 +8,7 @@ import {
defaultFields, defaultFields,
NAME_MAX_LENGTH, NAME_MAX_LENGTH,
formFieldKeys, formFieldKeys,
editableFormFieldKeys,
} from './constants'; } from './constants';
/** /**
...@@ -151,9 +152,10 @@ export const formatStageDataForSubmission = (stages, isEditing = false) => { ...@@ -151,9 +152,10 @@ export const formatStageDataForSubmission = (stages, isEditing = false) => {
// The new stage is still `custom` but wont have an id until the form submits and its persisted to the DB // The new stage is still `custom` but wont have an id until the form submits and its persisted to the DB
editProps = id ? { id, custom: true } : { custom: true }; editProps = id ? { id, custom: true } : { custom: true };
} }
const editableFields = pick(rest, editableFormFieldKeys);
// While we work on https://gitlab.com/gitlab-org/gitlab/-/issues/321959 we should not allow editing default // While we work on https://gitlab.com/gitlab-org/gitlab/-/issues/321959 we should not allow editing default
return custom return custom
? convertObjectPropsToSnakeCase({ ...rest, ...editProps, name }) ? convertObjectPropsToSnakeCase({ ...editableFields, ...editProps, name })
: convertObjectPropsToSnakeCase({ ...editProps, name, custom: false }); : convertObjectPropsToSnakeCase({ ...editProps, name, custom: false });
}); });
}; };
......
import { import {
ERRORS, ERRORS,
NAME_MAX_LENGTH, NAME_MAX_LENGTH,
editableFormFieldKeys,
} from 'ee/analytics/cycle_analytics/components/create_value_stream_form/constants'; } from 'ee/analytics/cycle_analytics/components/create_value_stream_form/constants';
import { import {
initializeFormData, initializeFormData,
...@@ -177,14 +178,9 @@ describe('formatStageDataForSubmission', () => { ...@@ -177,14 +178,9 @@ describe('formatStageDataForSubmission', () => {
expect(Object.keys(res).includes('id')).toBe(false); expect(Object.keys(res).includes('id')).toBe(false);
}); });
it('will not include the event fields', () => { it('will only include editable fields', () => {
[ Object.keys(res).forEach((field) => {
'start_event_identifier', expect(editableFormFieldKeys.includes(field)).toBe(true);
'start_event_label_id',
'end_event_identifier',
'end_event_label_id',
].forEach((field) => {
expect(Object.keys(res).includes(field)).toBe(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