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 = [
'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