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 = [
'endEventLabelId',
];
export const editableFormFieldKeys = [
...formFieldKeys,
'hidden',
'description',
'title',
'legend',
'custom',
];
export const defaultFields = formFieldKeys.reduce((acc, field) => ({ ...acc, [field]: null }), {});
export const defaultErrors = formFieldKeys.reduce((acc, field) => ({ ...acc, [field]: [] }), {});
......
......@@ -8,6 +8,7 @@ import {
defaultFields,
NAME_MAX_LENGTH,
formFieldKeys,
editableFormFieldKeys,
} from './constants';
/**
......@@ -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
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
return custom
? convertObjectPropsToSnakeCase({ ...rest, ...editProps, name })
? convertObjectPropsToSnakeCase({ ...editableFields, ...editProps, name })
: convertObjectPropsToSnakeCase({ ...editProps, name, custom: false });
});
};
......
import {
ERRORS,
NAME_MAX_LENGTH,
editableFormFieldKeys,
} from 'ee/analytics/cycle_analytics/components/create_value_stream_form/constants';
import {
initializeFormData,
......@@ -177,14 +178,9 @@ describe('formatStageDataForSubmission', () => {
expect(Object.keys(res).includes('id')).toBe(false);
});
it('will not include the event fields', () => {
[
'start_event_identifier',
'start_event_label_id',
'end_event_identifier',
'end_event_label_id',
].forEach((field) => {
expect(Object.keys(res).includes(field)).toBe(false);
it('will only include editable fields', () => {
Object.keys(res).forEach((field) => {
expect(editableFormFieldKeys.includes(field)).toBe(true);
});
});
......
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