File tree 1 file changed +10
-5
lines changed
packages/shared-components/src/context/sendInn/utils
1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -19,18 +19,23 @@ const findComponent = (formSummaryComponents, key: string) => {
19
19
} ) ;
20
20
return result ;
21
21
} ;
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
+
22
30
const filterOutIfNotInSummary = ( originalData : SubmissionData , formSummaryComponents ) => {
23
31
const filteredSubmissionEntries = Object . entries ( originalData )
24
32
. map ( ( [ key , value ] ) => {
25
33
const matchingComponents = findComponent ( formSummaryComponents , key ) ;
26
34
// Remove value from submission
27
35
if ( matchingComponents . length === 0 ) return undefined ;
28
36
// 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 ) ;
34
39
const nestedData = filterOutIfNotInSummary ( value as SubmissionData , containerComponents ) ;
35
40
return nestedData ? [ key , nestedData ] : undefined ;
36
41
}
You can’t perform that action at this time.
0 commit comments