refactor metadata conversion function to use reduce

This commit is contained in:
Jake McDermott
2019-03-18 07:44:54 -04:00
parent 05226333ff
commit ea9ed31f9d

View File

@@ -269,10 +269,12 @@ function AddEditCredentialsController (
* metadata object that can be sent to the api later or reloaded when re-opening the form. * metadata object that can be sent to the api later or reloaded when re-opening the form.
*/ */
function getMetadataFormSubmitData ({ inputs }) { function getMetadataFormSubmitData ({ inputs }) {
const metadata = Object.assign({}, ...inputs._group return inputs._group.reduce((metadata, { id, _value }) => {
.filter(({ _value }) => _value !== undefined) if (_value !== undefined) {
.map(({ id, _value }) => ({ [id]: _value }))); metadata[id] = _value;
return metadata; }
return metadata;
}, {});
} }
vm.onInputSourceNext = () => { vm.onInputSourceNext = () => {
@@ -287,7 +289,7 @@ function AddEditCredentialsController (
// field_name->source_credential link already exists. This occurs one of two ways: // field_name->source_credential link already exists. This occurs one of two ways:
// //
// 1. This field->source_credential link already exists in the API and so we're // 1. This field->source_credential link already exists in the API and so we're
// reflecting the current state as it exists on the backend. // showing the current state as it exists on the backend.
// 2. The metadata form for this specific field->source_credential combination was // 2. The metadata form for this specific field->source_credential combination was
// set during a prior visit to this lookup and so we're reflecting the most // set during a prior visit to this lookup and so we're reflecting the most
// recent set of (unsaved) metadata values provided by the user for this field. // recent set of (unsaved) metadata values provided by the user for this field.
@@ -312,7 +314,7 @@ function AddEditCredentialsController (
const { field, credentialId, credentialName, credentialTypeId } = vm.inputSources; const { field, credentialId, credentialName, credentialTypeId } = vm.inputSources;
const metadata = getMetadataFormSubmitData(vm.inputSources.form); const metadata = getMetadataFormSubmitData(vm.inputSources.form);
// Remove any input source objects already stored for this field then store the metadata // Remove any input source objects already stored for this field then store the metadata
// and currently selected source credential as a valid credential input source object that // and currently selected source credential as a credential input source object that
// can be sent to the api later or reloaded into the form if it is reopened. // can be sent to the api later or reloaded into the form if it is reopened.
vm.inputSources.items = vm.inputSources.items vm.inputSources.items = vm.inputSources.items
.filter(({ input_field_name }) => input_field_name !== field) .filter(({ input_field_name }) => input_field_name !== field)