Commit 9e8a7800 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Ensure the VSA form submits only required fields

With https://gitlab.com/gitlab-org/gitlab/-/merge_requests/64273 we
introduced changes to locally store labels in vuex, this added some
additional fields to VSA form, which are not needed when persisting
changes.

This MR adds an allow list for fields that should be submitted
for the Value stream.
parent 6596a65d
...@@ -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