@@ -290,6 +290,7 @@ export default function RecordProvider({
290
290
if ( m . hasWaitFor ) {
291
291
m . waitForDataLoaded = false ;
292
292
}
293
+ m . tableMarkdownContentProcessed = false ;
293
294
} ) ;
294
295
295
296
// related table
@@ -300,6 +301,7 @@ export default function RecordProvider({
300
301
if ( m . hasWaitFor ) {
301
302
m . waitForDataLoaded = false ;
302
303
}
304
+ m . tableMarkdownContentProcessed = false ;
303
305
} ) ;
304
306
305
307
// update the cause list
@@ -369,9 +371,14 @@ export default function RecordProvider({
369
371
}
370
372
371
373
// -------------------------- flow control function ---------------------- //
372
- const printDebugMessage = ( message : string , counter ?: number ) : void => {
374
+ const printDebugMessage = ( message : string , relatedModel ?: RecordRelatedModel , counter ?: number ) : void => {
373
375
counter = typeof counter !== 'number' ? flowControl . current . queue . counter : counter ;
374
- $log . debug ( `${ Date . now ( ) } , ${ counter } : ${ message } ` ) ;
376
+ let dm = `${ Date . now ( ) } , ${ counter } : ` ;
377
+ if ( relatedModel ) {
378
+ dm += `${ relatedModel . isInline ? 'inline' : 'related' } (index=${ relatedModel . index } ), ` ;
379
+ }
380
+ dm += `${ message } ` ;
381
+ $log . debug ( dm ) ;
375
382
} ;
376
383
377
384
/**
@@ -652,6 +659,7 @@ export default function RecordProvider({
652
659
// this indicates that we got the waitfor data:
653
660
// only if w got the waitfor data, and the main data we can popuplate the tableMarkdownContent value
654
661
waitForDataLoaded : ! col . hasWaitFor ,
662
+ tableMarkdownContentProcessed : false ,
655
663
updateMainEntity : ( ) => { throw new Error ( 'function not registered' ) } ,
656
664
fetchSecondaryRequests : ( ) => { throw new Error ( 'function not registered' ) } ,
657
665
addUpdateCauses : ( ) => { throw new Error ( 'function not registered' ) } ,
@@ -679,6 +687,7 @@ export default function RecordProvider({
679
687
index,
680
688
hasWaitFor : ref . display . sourceHasWaitFor ,
681
689
waitForDataLoaded : false ,
690
+ tableMarkdownContentProcessed : false ,
682
691
updateMainEntity : ( ) => { throw new Error ( 'function not registered' ) } ,
683
692
fetchSecondaryRequests : ( ) => { throw new Error ( 'function not registered' ) } ,
684
693
addUpdateCauses : ( ) => { throw new Error ( 'function not registered' ) } ,
@@ -708,10 +717,30 @@ export default function RecordProvider({
708
717
* @param values the updated values
709
718
*/
710
719
const updateRelatedRecordsetState = ( index : number , isInline : boolean , values : RecordRelatedModelRecordsetProps ) => {
720
+ printDebugMessage ( `${ isInline ? 'inline' : 'related' } (index=${ index } ), updating recordset state isLoading: ${ values . isLoading } ` ) ;
721
+ const updatedValues : { [ key : string ] : any } = { recordsetState : values } ;
722
+
723
+ /**
724
+ * There might be a delay between recieving the data and updating the state. If the delay is long enough that the
725
+ * waitForDataLoaded is set to true but the recordsetState still is not updated, the attachPseudoColumnValue might not
726
+ * be able to process the markdown content. So the following checks if that the case and if so, it would compute the
727
+ * markdown content.
728
+ */
729
+ const rm = isInline ? flowControl . current . inlineRelatedRequestModels [ index ] : flowControl . current . relatedRequestModels [ index ] ;
730
+ const m = isInline ? columnModels [ index ] . relatedModel : relatedModels [ index ] ;
731
+ const hasMainData = values . page && ! values . isLoading ;
732
+ const hasWaitForData = ! rm . hasWaitFor || rm . waitForDataLoaded ;
733
+ if ( ! rm . tableMarkdownContentProcessed && hasMainData && hasWaitForData ) {
734
+ printDebugMessage ( 'updating markdown content in updateRelatedRecordsetState' , m ) ;
735
+ rm . tableMarkdownContentProcessed = true ;
736
+ updatedValues . tableMarkdownContentInitialized = true ;
737
+ updatedValues . tableMarkdownContent = values . page . getContent ( flowControl . current . templateVariables ) ;
738
+ }
739
+
711
740
if ( isInline ) {
712
- setColumnModelsRelatedModelByIndex ( index , { recordsetState : values } ) ;
741
+ setColumnModelsRelatedModelByIndex ( index , updatedValues ) ;
713
742
} else {
714
- setRelatedModelsByIndex ( index , { recordsetState : values } ) ;
743
+ setRelatedModelsByIndex ( index , updatedValues ) ;
715
744
}
716
745
} ;
717
746
@@ -754,13 +783,19 @@ export default function RecordProvider({
754
783
reqModel . processed = ! res . success ;
755
784
756
785
const rm = isInline ? flowControl . current . inlineRelatedRequestModels [ index ] : flowControl . current . relatedRequestModels [ index ] ;
786
+ const m = isInline ? columnModels [ index ] . relatedModel : relatedModels [ index ] ;
757
787
758
788
/*
759
789
* the returned `res` boolean indicates whether we should consider this response final or not.
760
790
* it doesn't necessarily mean that the response was successful, so we should not use the page blindly.
761
791
* If the request errored out (timeout or other types of error) page will be undefined.
762
792
*/
763
- if ( res . success && res . page && ( ! rm . hasWaitFor || rm . waitForDataLoaded ) ) {
793
+ const hasMainData = res . success && res . page ;
794
+ const hasWaitForData = ! rm . hasWaitFor || rm . waitForDataLoaded ;
795
+ if ( hasMainData && hasWaitForData ) {
796
+ printDebugMessage ( 'updating markdown content in afterUpdateRelatedEntity' , m ) ;
797
+
798
+ rm . tableMarkdownContentProcessed = true ;
764
799
const updatedValues = {
765
800
tableMarkdownContentInitialized : true ,
766
801
tableMarkdownContent : res . page . getContent ( flowControl . current . templateVariables )
@@ -770,6 +805,8 @@ export default function RecordProvider({
770
805
} else {
771
806
setRelatedModelsByIndex ( index , updatedValues ) ;
772
807
}
808
+ } else { ;
809
+ printDebugMessage ( `unable to update markdown content, main:${ hasMainData } , waitFor: ${ hasWaitForData } ` , m ) ;
773
810
}
774
811
} ;
775
812
} ;
@@ -810,12 +847,28 @@ export default function RecordProvider({
810
847
cb = activeListModel . column . getAggregatedValue ( pageRef . current , logObj ) ;
811
848
}
812
849
850
+ const dependentSummary = activeListModel . objects . map ( ( obj : any ) => {
851
+ let objType ;
852
+ if ( obj . column ) {
853
+ objType = 'column' ;
854
+ } else if ( obj . inline ) {
855
+ objType = 'inline' ;
856
+ } else {
857
+ objType = 'related' ;
858
+ }
859
+ return `${ objType } (index=${ obj . index } )` ;
860
+ } ) ;
861
+
862
+ const description = `(${ activeListModel . entityset ? 'entityset' : 'aggregate' } ) for: ${ dependentSummary . join ( ', ' ) } ` ;
863
+ printDebugMessage ( `fetching 2nd req ${ description } ` ) ;
813
864
cb . then ( function ( values : any ) {
814
865
if ( flowControl . current . queue . counter !== current ) {
815
866
resolve ( false ) ;
816
867
return ;
817
868
}
818
869
870
+ printDebugMessage ( `successful 2nd req fetch ${ description } ` ) ;
871
+
819
872
// remove the column error (they might retry)
820
873
const errroIndexes : any = { } ;
821
874
activeListModel . objects . forEach ( function ( obj : any ) {
@@ -876,6 +929,8 @@ export default function RecordProvider({
876
929
return ;
877
930
}
878
931
932
+ printDebugMessage ( `failed 2nd req ${ description } ` ) ;
933
+
879
934
const errorIndexes : any = { } ;
880
935
activeListModel . objects . forEach ( function ( obj : any ) {
881
936
if ( obj . column || obj . inline ) {
@@ -959,6 +1014,7 @@ export default function RecordProvider({
959
1014
reqModel = flowControl . current . inlineRelatedRequestModels [ obj . index ] ;
960
1015
}
961
1016
const hasAll = ref . display . sourceWaitFor . every ( hasColumnData ) ;
1017
+ printDebugMessage ( `hasAll: ${ hasAll } ` , obj . related ? relatedModelsRef . current [ obj . index ] : columnModelsRef . current [ obj . index ] . relatedModel ) ;
962
1018
if ( ! hasAll ) return ;
963
1019
964
1020
// in case the main request was slower, this will just signal so the other
@@ -974,6 +1030,8 @@ export default function RecordProvider({
974
1030
}
975
1031
} ) ;
976
1032
1033
+ printDebugMessage ( `attachPseudoColumnValue, doneInlines: ${ Object . keys ( doneInlines ) } , doneRelated: ${ Object . keys ( doneRelated ) } ` ) ;
1034
+
977
1035
// set the values
978
1036
setRecordValues ( ( prevValues : any ) => (
979
1037
prevValues . map ( ( val : any , index : number ) => {
@@ -995,10 +1053,15 @@ export default function RecordProvider({
995
1053
// otherwise we should just wait for the related/inline table data to get back to popuplate the tableMarkdownContent
996
1054
let mdProps : { tableMarkdownContentInitialized : boolean , tableMarkdownContent : string | null } | object = { } ;
997
1055
if ( val . relatedModel . recordsetState . page && ! val . relatedModel . recordsetState . isLoading ) {
1056
+ printDebugMessage ( 'updating markdown content in attachPseudoColumnValue' , val . relatedModel ) ;
1057
+ const rm = flowControl . current . inlineRelatedRequestModels [ index ] ;
1058
+ rm . tableMarkdownContentProcessed = true ;
998
1059
mdProps = {
999
1060
tableMarkdownContentInitialized : true ,
1000
1061
tableMarkdownContent : val . relatedModel . recordsetState . page . getContent ( flowControl . current . templateVariables ) ,
1001
1062
}
1063
+ } else {
1064
+ printDebugMessage ( 'unable to update markdown content since main page is still not loaded' , val . relatedModel ) ;
1002
1065
}
1003
1066
return { ...val , isLoading : false , relatedModel : { ...val . relatedModel , ...mdProps } } ;
1004
1067
}
@@ -1013,11 +1076,16 @@ export default function RecordProvider({
1013
1076
// if the page data is already fetched, we can just popuplate the tableMarkdownContent value.
1014
1077
// otherwise we should just wait for the related/inline table data to get back to popuplate the tableMarkdownContent
1015
1078
if ( val . recordsetState . page && ! val . recordsetState . isLoading ) {
1079
+ printDebugMessage ( 'updating markdown content in attachPseudoColumnValue' , val ) ;
1080
+ const rm = flowControl . current . relatedRequestModels [ index ] ;
1081
+ rm . tableMarkdownContentProcessed = true ;
1016
1082
return {
1017
1083
...val ,
1018
1084
tableMarkdownContentInitialized : true ,
1019
1085
tableMarkdownContent : val . recordsetState . page . getContent ( flowControl . current . templateVariables ) ,
1020
1086
}
1087
+ } else {
1088
+ printDebugMessage ( 'unable to update markdown content since main page is still not loaded' , val ) ;
1021
1089
}
1022
1090
}
1023
1091
return val ;
0 commit comments