Merged PR 2234: refactor(newappeal): extract payload cleanup helpers (Slice 2a)
refactor(newappeal): extract payload cleanup helpers (Slice 2a) - extracted boolean normalization - extracted null key removal - extracted internal key stripping - no behaviour change Related work items: #22576
This commit is contained in:
@@ -6,6 +6,11 @@ import { connect } from "react-redux";
|
|||||||
import { formValueSelector, reduxForm } from "redux-form";
|
import { formValueSelector, reduxForm } from "redux-form";
|
||||||
import { uploadFiles } from "../../actions/services/documentService";
|
import { uploadFiles } from "../../actions/services/documentService";
|
||||||
import { sendEmail } from "../../actions/services/notifyService";
|
import { sendEmail } from "../../actions/services/notifyService";
|
||||||
|
import {
|
||||||
|
normalizeYesNoBooleans,
|
||||||
|
removeNullKeys,
|
||||||
|
stripInternalKeys
|
||||||
|
} from "../../lib/newappeal/payloadCleanup";
|
||||||
import {
|
import {
|
||||||
setCurrentSection,
|
setCurrentSection,
|
||||||
setDocumentsList,
|
setDocumentsList,
|
||||||
@@ -218,19 +223,9 @@ let BuildSection = (props) => {
|
|||||||
"/incidents(" + incidentId + ")"
|
"/incidents(" + incidentId + ")"
|
||||||
});
|
});
|
||||||
|
|
||||||
updateBody = JSON.stringify(updateBody);
|
updateBody = normalizeYesNoBooleans(updateBody);
|
||||||
updateBody = updateBody.replace(/:"Yes"/gm, `:true`);
|
updateBody = removeNullKeys(updateBody);
|
||||||
updateBody = updateBody.replace(/:"No"/gm, `:false`);
|
updateBody = stripInternalKeys(updateBody);
|
||||||
updateBody = JSON.parse(updateBody);
|
|
||||||
|
|
||||||
Object.keys(updateBody).forEach((key) => {
|
|
||||||
if (updateBody[key] === null) {
|
|
||||||
delete updateBody[key];
|
|
||||||
}
|
|
||||||
if (key.indexOf("_") == 0) {
|
|
||||||
delete updateBody[key];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//console.log(updateBody);
|
//console.log(updateBody);
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { useEffect } from "react";
|
|||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { formValueSelector } from "redux-form";
|
import { formValueSelector } from "redux-form";
|
||||||
import { sendEmail } from "../../actions/services/notifyService";
|
import { sendEmail } from "../../actions/services/notifyService";
|
||||||
|
import { normalizeYesNoBooleans } from "../../lib/newappeal/payloadCleanup";
|
||||||
import { setCurrentSection } from "../../store/appealType/action";
|
import { setCurrentSection } from "../../store/appealType/action";
|
||||||
import { getFormCollectionByID } from "../utils";
|
import { getFormCollectionByID } from "../utils";
|
||||||
|
|
||||||
@@ -31,10 +32,7 @@ let CompleteAppeal = (props) => {
|
|||||||
"/incidents(" + incidentId + ")"
|
"/incidents(" + incidentId + ")"
|
||||||
});
|
});
|
||||||
|
|
||||||
updateBody = JSON.stringify(updateBody);
|
updateBody = normalizeYesNoBooleans(updateBody);
|
||||||
updateBody = updateBody.replace(/:"Yes"/gm, `:true`);
|
|
||||||
updateBody = updateBody.replace(/:"No"/gm, `:false`);
|
|
||||||
updateBody = JSON.parse(updateBody);
|
|
||||||
|
|
||||||
let updateFormCollection = appTypeCollection.LogicalCollectionName;
|
let updateFormCollection = appTypeCollection.LogicalCollectionName;
|
||||||
let primaryAttribute = appTypeCollection.PrimaryIdAttribute;
|
let primaryAttribute = appTypeCollection.PrimaryIdAttribute;
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ Base branch for this tracker: `refactor`
|
|||||||
|
|
||||||
## Status
|
## Status
|
||||||
|
|
||||||
Current slice: Slice 1 — XML/Form Derivation Extraction
|
Current slice: Slice 2b — File Merge/Dedupe Helpers
|
||||||
Status: NOT STARTED
|
Status: READY TO START
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ Status: NOT STARTED
|
|||||||
|
|
||||||
### Slice 1 — XML/Form Derivation Extraction
|
### Slice 1 — XML/Form Derivation Extraction
|
||||||
|
|
||||||
Status: NOT STARTED
|
Status: COMPLETE
|
||||||
|
|
||||||
- Extract XML parsing helpers into lib
|
- Extract XML parsing helpers into lib
|
||||||
- Keep selectors identical
|
- Keep selectors identical
|
||||||
@@ -23,7 +23,7 @@ Status: NOT STARTED
|
|||||||
|
|
||||||
### Slice 2a — Payload Cleanup Helpers
|
### Slice 2a — Payload Cleanup Helpers
|
||||||
|
|
||||||
Status: NOT STARTED
|
Status: COMPLETE
|
||||||
|
|
||||||
- Extract boolean normalization
|
- Extract boolean normalization
|
||||||
- Extract null/internal key stripping
|
- Extract null/internal key stripping
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
export const normalizeYesNoBooleans = (updateBody) => {
|
||||||
|
updateBody = JSON.stringify(updateBody);
|
||||||
|
updateBody = updateBody.replace(/:\"Yes\"/gm, `:true`);
|
||||||
|
updateBody = updateBody.replace(/:\"No\"/gm, `:false`);
|
||||||
|
updateBody = JSON.parse(updateBody);
|
||||||
|
|
||||||
|
return updateBody;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const removeNullKeys = (updateBody) => {
|
||||||
|
Object.keys(updateBody).forEach((key) => {
|
||||||
|
if (updateBody[key] === null) {
|
||||||
|
delete updateBody[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return updateBody;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const stripInternalKeys = (updateBody) => {
|
||||||
|
Object.keys(updateBody).forEach((key) => {
|
||||||
|
if (key.indexOf("_") == 0) {
|
||||||
|
delete updateBody[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return updateBody;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user