@@ -75,8 +75,8 @@ const arrangGroups = ({ schema, newStack }: any) => {
7575 if ( item ?. contentstackFieldType === 'group' ) {
7676 const groupSchema : any = { ...item , schema : [ ] }
7777 if ( item ?. contentstackFieldUid ?. includes ( '.' ) ) {
78- const parts = item . contentstackFieldUid . split ( '.' ) ;
79- groupSchema . contentstackFieldUid = parts [ parts . length - 1 ] ;
78+ const parts = item ? .contentstackFieldUid ? .split ( '.' ) ;
79+ groupSchema . contentstackFieldUid = parts ?. [ parts ? .length - 1 ] ;
8080 }
8181 schema ?. forEach ( ( et : any ) => {
8282 if ( et ?. contentstackFieldUid ?. includes ( `${ item ?. contentstackFieldUid } .` ) ||
@@ -668,12 +668,12 @@ const mergeArrays = (a: any[], b: any[]): any[] => {
668668 const result = [ ...a ] ;
669669
670670 for ( const field of b ) {
671- const exists = result . some ( f =>
671+ const exists = result ? .some ( f =>
672672 f ?. uid === field ?. uid &&
673673 f ?. data_type === field ?. data_type
674674 ) ;
675675 if ( ! exists ) {
676- result . push ( field ) ;
676+ result ? .push ( field ) ;
677677 }
678678 }
679679
@@ -684,27 +684,27 @@ const mergeFields = async (schema1: any[], schema2: any[]): Promise<any[]> => {
684684 const result : any [ ] = [ ] ;
685685
686686 for ( const field2 of schema2 ) {
687- if ( field2 . data_type === 'group' ) {
687+ if ( field2 ? .data_type === 'group' ) {
688688 const machingGroup = findGroupByUid ( schema1 , field2 ?. uid ) ;
689689 if ( machingGroup ) {
690690 const schema = await mergeArrays ( machingGroup ?. schema ?? [ ] , field2 ?. schema ?? [ ] ) ;
691- result . push ( {
691+ result ? .push ( {
692692 ...field2 ,
693693 schema : schema
694694 } ) ;
695695 }
696696 else {
697- result . push ( {
697+ result ? .push ( {
698698 ...field2 ,
699699 schema : await mergeFields ( schema1 , field2 ?. schema )
700700 } )
701701 }
702702 }
703703 else {
704- const exists = schema1 . find (
704+ const exists = schema1 ? .find (
705705 ( fld ) =>
706- fld . uid === field2 . uid &&
707- fld . data_type === field2 . data_type
706+ fld ? .uid === field2 ? .uid &&
707+ fld ? .data_type === field2 ? .data_type
708708 ) ;
709709 result ?. push ( {
710710 ...field2
@@ -715,14 +715,14 @@ const mergeFields = async (schema1: any[], schema2: any[]): Promise<any[]> => {
715715 }
716716
717717 for ( const field1 of schema1 ) {
718- const isMatched = schema2 . some (
718+ const isMatched = schema2 ? .some (
719719 ( field2 ) =>
720- field1 . uid === field2 . uid &&
721- field1 . data_type === field2 . data_type
720+ field1 ? .uid === field2 ? .uid &&
721+ field1 ? .data_type === field2 ? .data_type
722722 ) ;
723723
724724 if ( ! isMatched ) {
725- result . push ( field1 ) ;
725+ result ? .push ( field1 ) ;
726726 }
727727 }
728728
@@ -736,9 +736,9 @@ const findGroupByUid = (
736736 excludeRef : any = null
737737) : any | undefined => {
738738 for ( const field of schema ) {
739- if ( field . data_type === 'group' ) {
740- if ( field . uid === uid && field !== excludeRef ) return field ;
741- const nested = findGroupByUid ( field . schema ?? [ ] , uid , excludeRef ) ;
739+ if ( field ? .data_type === 'group' ) {
740+ if ( field ? .uid === uid && field !== excludeRef ) return field ;
741+ const nested = findGroupByUid ( field ? .schema ?? [ ] , uid , excludeRef ) ;
742742 if ( nested ) return nested ;
743743 }
744744 }
0 commit comments