@@ -175,7 +175,7 @@ export default class Entries {
175175
176176 const localKey = this . locales . map ( ( locale : any ) => locale . code ) ;
177177
178- if ( this . entries [ entryUid ] ?. publish_details && ! Array . isArray ( this . entries [ entryUid ] . publish_details ) ) {
178+ if ( this . entries [ entryUid ] ?. publish_details && ! Array . isArray ( this . entries [ entryUid ] . publish_details ) ) {
179179 this . log ( $t ( auditMsg . ENTRY_PUBLISH_DETAILS_NOT_EXIST , { uid : entryUid } ) , { color : 'red' } ) ;
180180 }
181181
@@ -194,11 +194,23 @@ export default class Entries {
194194 { color : 'red' } ,
195195 ) ;
196196 if ( ! Object . keys ( this . missingEnvLocale ) . includes ( entryUid ) ) {
197- this . missingEnvLocale [ entryUid ] = [ { entry_uid : entryUid , publish_locale : pd . locale , publish_environment : pd . environment , ctUid : ctSchema . uid , ctLocale : code } ] ;
197+ this . missingEnvLocale [ entryUid ] = [
198+ {
199+ entry_uid : entryUid ,
200+ publish_locale : pd . locale ,
201+ publish_environment : pd . environment ,
202+ ctUid : ctSchema . uid ,
203+ ctLocale : code ,
204+ } ,
205+ ] ;
198206 } else {
199- this . missingEnvLocale [ entryUid ] . push (
200- { entry_uid : entryUid , publish_locale : pd . locale , publish_environment : pd . environment , ctUid : ctSchema . uid , ctLocale : code } ,
201- ) ;
207+ this . missingEnvLocale [ entryUid ] . push ( {
208+ entry_uid : entryUid ,
209+ publish_locale : pd . locale ,
210+ publish_environment : pd . environment ,
211+ ctUid : ctSchema . uid ,
212+ ctLocale : code ,
213+ } ) ;
202214 }
203215 return false ;
204216 }
@@ -630,18 +642,29 @@ export default class Entries {
630642 if ( this . fix ) return [ ] ;
631643
632644 const missingRefs : Record < string , any > [ ] = [ ] ;
633- const { uid : data_type , display_name } = fieldStructure ;
645+ const { uid : data_type , display_name, reference_to } = fieldStructure ;
634646
635647 for ( const index in field ?? [ ] ) {
636- const reference = field [ index ] ;
648+ const reference : any = field [ index ] ;
637649 const { uid } = reference ;
650+ if ( ! uid && reference . startsWith ( 'blt' ) ) {
651+ const refExist = find ( this . entryMetaData , { uid : reference } ) ;
652+ if ( ! refExist ) {
653+ if ( Array . isArray ( reference_to ) && reference_to . length === 1 ) {
654+ missingRefs . push ( { uid : reference , _content_type_uid : reference_to [ 0 ] } ) ;
655+ } else {
656+ missingRefs . push ( reference ) ;
657+ }
658+ }
659+ }
638660 // NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
639661 // if (this.config.skipRefs.includes(reference)) continue;
662+ else {
663+ const refExist = find ( this . entryMetaData , { uid } ) ;
640664
641- const refExist = find ( this . entryMetaData , { uid } ) ;
642-
643- if ( ! refExist ) {
644- missingRefs . push ( reference ) ;
665+ if ( ! refExist ) {
666+ missingRefs . push ( reference ) ;
667+ }
645668 }
646669 }
647670
@@ -846,11 +869,14 @@ export default class Entries {
846869 * @returns
847870 */
848871 fixSelectField ( tree : Record < string , unknown > [ ] , field : SelectFeildStruct , entry : any ) {
872+ if ( ! this . config . fixSelectField ) {
873+ return entry ;
874+ }
849875 const { enum : selectOptions , multiple, min_instance, display_type, display_name, uid } = field ;
850876
851877 let missingCTSelectFieldValues ;
852878 let isMissingValuePresent = false ;
853-
879+ let selectedValue : unknown = '' ;
854880 if ( multiple ) {
855881 let obj = this . findNotPresentSelectField ( entry , selectOptions ) ;
856882 let { notPresent, filteredFeild } = obj ;
@@ -868,13 +894,15 @@ export default class Entries {
868894 . slice ( 0 , missingInstances )
869895 . map ( ( choice ) => choice . value ) ;
870896 entry . push ( ...newValues ) ;
897+ selectedValue = newValues ;
871898 this . log ( $t ( auditFixMsg . ENTRY_SELECT_FIELD_FIX , { value : newValues . join ( ' ' ) , uid } ) , 'error' ) ;
872899 }
873900 } else {
874901 if ( entry . length === 0 ) {
875902 isMissingValuePresent = true ;
876903 const defaultValue = selectOptions . choices . length > 0 ? selectOptions . choices [ 0 ] . value : null ;
877904 entry . push ( defaultValue ) ;
905+ selectedValue = defaultValue ;
878906 this . log ( $t ( auditFixMsg . ENTRY_SELECT_FIELD_FIX , { value : defaultValue as string , uid } ) , 'error' ) ;
879907 }
880908 }
@@ -885,6 +913,7 @@ export default class Entries {
885913 isMissingValuePresent = true ;
886914 let defaultValue = selectOptions . choices . length > 0 ? selectOptions . choices [ 0 ] . value : null ;
887915 entry = defaultValue ;
916+ selectedValue = defaultValue ;
888917 this . log ( $t ( auditFixMsg . ENTRY_SELECT_FIELD_FIX , { value : defaultValue as string , uid } ) , 'error' ) ;
889918 }
890919 }
@@ -895,6 +924,7 @@ export default class Entries {
895924 display_name,
896925 display_type,
897926 missingCTSelectFieldValues,
927+ selectedValue,
898928 min_instance : min_instance ?? 'NA' ,
899929 tree,
900930 treeStr : tree
@@ -909,7 +939,7 @@ export default class Entries {
909939
910940 validateMandatoryFields ( tree : Record < string , unknown > [ ] , fieldStructure : any , entry : any ) {
911941 const { display_name, multiple, data_type, mandatory, field_metadata, uid } = fieldStructure ;
912-
942+
913943 const isJsonRteEmpty = ( ) => {
914944 const jsonNode = multiple
915945 ? entry [ uid ] ?. [ 0 ] ?. children ?. [ 0 ] ?. children ?. [ 0 ] ?. text
@@ -922,6 +952,9 @@ export default class Entries {
922952 if ( data_type === 'number' && ! multiple ) {
923953 fieldValue = entry [ uid ] || entry [ uid ] === 0 ? true : false ;
924954 }
955+ if ( data_type === 'text' && ! multiple ) {
956+ fieldValue = entry [ uid ] || entry [ uid ] === 0 ? true : false ;
957+ }
925958 if ( Array . isArray ( entry [ uid ] ) && data_type === 'reference' ) {
926959 fieldValue = entry [ uid ] ?. length ? true : false ;
927960 }
@@ -1186,16 +1219,29 @@ export default class Entries {
11861219 entry = JSON . parse ( stringReference ) ;
11871220 }
11881221 entry = entry
1189- ?. map ( ( reference ) => {
1222+ ?. map ( ( reference : any ) => {
11901223 const { uid } = reference ;
1191- const refExist = find ( this . entryMetaData , { uid } ) ;
1192-
1193- if ( ! refExist ) {
1194- missingRefs . push ( reference ) ;
1195- return null ;
1224+ const { reference_to } = field ;
1225+ if ( ! uid && reference . startsWith ( 'blt' ) ) {
1226+ const refExist = find ( this . entryMetaData , { uid : reference } ) ;
1227+ if ( ! refExist ) {
1228+ if ( Array . isArray ( reference_to ) && reference_to . length === 1 ) {
1229+ missingRefs . push ( { uid : reference , _content_type_uid : reference_to [ 0 ] } ) ;
1230+ } else {
1231+ missingRefs . push ( reference ) ;
1232+ }
1233+ } else {
1234+ return { uid : reference , _content_type_uid : refExist . ctUid } ;
1235+ }
1236+ } else {
1237+ const refExist = find ( this . entryMetaData , { uid } ) ;
1238+ if ( ! refExist ) {
1239+ missingRefs . push ( reference ) ;
1240+ return null ;
1241+ } else {
1242+ return reference ;
1243+ }
11961244 }
1197-
1198- return reference ;
11991245 } )
12001246 . filter ( ( val ) => val ) as EntryReferenceFieldDataType [ ] ;
12011247
@@ -1353,7 +1399,7 @@ export default class Entries {
13531399 `error` ,
13541400 ) ;
13551401 }
1356- this . entryMetaData . push ( { uid : entryUid , title } ) ;
1402+ this . entryMetaData . push ( { uid : entryUid , title, ctUid : uid } ) ;
13571403 }
13581404 }
13591405 }
0 commit comments