Skip to content

Commit

Permalink
Refactor from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Kainic authored and Kainic committed Jul 13, 2018
1 parent b4f7814 commit 2b5f1a9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export function getActiveProperties(activePages) {
});

return allProperties;

// return new Set([].concat(
// ...activePages.map(page => Object.keys(page.schema.properties))
// ));
}

export function getInactivePages(pages, data) {
Expand Down Expand Up @@ -227,15 +231,16 @@ export function filterViewFields(data) {
}, {});
}

export function filterInactivePages(inactivePages, activePages, form) {
export function filterInactivePageData(inactivePages, activePages, form) {
const activeProperties = getActiveProperties(activePages);
let newData;

return inactivePages.reduce((formData, page) => {
return Object.keys(page.schema.properties)
.reduce((currentData, prop) => {
newData = currentData;
if (!activeProperties.includes(prop)) {
newData = _.unset(prop, currentData);
delete newData[prop];
}
return newData;
}, formData);
Expand Down Expand Up @@ -293,7 +298,7 @@ export function isInProgress(pathName) {
export function transformForSubmit(formConfig, form, replacer = stringifyFormReplacer) {
const activePages = getActivePages(createFormPageList(formConfig), form.data);
const inactivePages = getInactivePages(createFormPageList(formConfig), form.data);
const withoutInactivePages = filterInactivePages(inactivePages, activePages, form);
const withoutInactivePages = filterInactivePageData(inactivePages, activePages, form);
const withoutViewFields = filterViewFields(withoutInactivePages);

return JSON.stringify(withoutViewFields, replacer) || '{}';
Expand Down

0 comments on commit 2b5f1a9

Please sign in to comment.