Skip to content

Commit 8af0aa2

Browse files
committed
Make helper functions for chained container keys
1 parent 0045e58 commit 8af0aa2

File tree

1 file changed

+10
-5
lines changed
  • packages/shared-components/src/context/sendInn/utils

1 file changed

+10
-5
lines changed

packages/shared-components/src/context/sendInn/utils/utils.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,23 @@ const findComponent = (formSummaryComponents, key: string) => {
1919
});
2020
return result;
2121
};
22+
23+
const isChainedKey = (key: string) => key.split('.').length > 1;
24+
25+
const removeConainerPrefixFromKey = (component) => {
26+
const [_containerKey, ...newKey] = component.key.split('.');
27+
return { ...component, key: newKey.join('.') };
28+
};
29+
2230
const filterOutIfNotInSummary = (originalData: SubmissionData, formSummaryComponents) => {
2331
const filteredSubmissionEntries = Object.entries(originalData)
2432
.map(([key, value]) => {
2533
const matchingComponents = findComponent(formSummaryComponents, key);
2634
// Remove value from submission
2735
if (matchingComponents.length === 0) return undefined;
2836
// Container
29-
if (matchingComponents[0].key.split('.').length > 1) {
30-
const containerComponents = matchingComponents.map((component) => {
31-
const [_containerKey, ...newKey] = component.key.split('.');
32-
return { ...component, key: newKey.join('.') };
33-
});
37+
if (isChainedKey(matchingComponents[0].key)) {
38+
const containerComponents = matchingComponents.map(removeConainerPrefixFromKey);
3439
const nestedData = filterOutIfNotInSummary(value as SubmissionData, containerComponents);
3540
return nestedData ? [key, nestedData] : undefined;
3641
}

0 commit comments

Comments
 (0)