@@ -70,6 +70,7 @@ export class RunsWithQcModel extends RunsOverviewModel {
7070 constructor ( model ) {
7171 super ( model ) ;
7272
73+ this . _observablesQcFlagsSummaryDependsOn$ = null ;
7374 this . _mcReproducibleAsNotBad = false ;
7475
7576 this . _runDetectorsSelectionModel = new RunDetectorsSelectionModel ( ) ;
@@ -131,57 +132,73 @@ export class RunsWithQcModel extends RunsOverviewModel {
131132 */
132133 async load ( ) {
133134 this . _runDetectorsSelectionModel . reset ( ) ;
134- this . _fetchQcSummary ( ) ;
135+ // Only fetch QC summary manually if no observer is registered
136+ if ( ! this . _observablesQcFlagsSummaryDependsOn$ ) {
137+ this . _fetchQcSummary ( ) ;
138+ }
135139 super . load ( ) ;
136140 }
137141
138142 /**
139- * Register not-bad fraction detectors filtering model
143+ * Register not-bad fraction detectors filtering model and update it when detectors are loaded
144+ * Also, trigger an immediate update if detectors are already loaded at the moment of registration
140145 *
141146 * @param {ObservableData<RemoteData<Detector>> } detectors$ detectors remote data observable
142147 */
143148 registerDetectorsNotBadFractionFilterModels ( detectors$ ) {
144- detectors$ . observe ( ( observableData ) => observableData . getCurrent ( ) . apply ( {
145- Success : ( detectors ) => detectors . forEach ( ( { id } ) => {
146- this . _filteringModel . put ( `detectorsQc[_${ id } ][notBadFraction]` , new NumericalComparisonFilterModel ( {
147- scale : 0.01 ,
148- integer : false ,
149- } ) ) ;
150- } ) ,
151- } ) ) ;
149+ const callback = ( observableData ) => {
150+ const current = observableData . getCurrent ( ) ;
151+ current ?. apply ( {
152+ Success : ( detectors ) => detectors . forEach ( ( { id } ) => {
153+ this . _filteringModel . put ( `detectorsQc[_${ id } ][notBadFraction]` , new NumericalComparisonFilterModel ( {
154+ scale : 0.01 ,
155+ integer : false ,
156+ } ) ) ;
157+ } ) ,
158+ } ) ;
159+ } ;
160+ detectors$ . observe ( callback ) ;
161+ callback ( detectors$ ) ;
152162 }
153163
154164 /**
155- * Register detectors for QC flags data export
165+ * Register detectors for QC flags data export and update export configuration when detectors are loaded
166+ * Also, trigger an immediate update if detectors are already loaded at the moment of registration
156167 *
157168 * @param {ObservableData<RemoteData<Detector>> } detectors$ detectors remote data observable
158169 */
159170 registerDetectorsForQcFlagsDataExport ( detectors$ ) {
160- detectors$ . observe ( ( observableData ) => observableData . getCurrent ( ) . apply ( {
161- Success : ( detectors ) => {
162- this . _exportModel . setDataExportConfiguration ( {
163- ...baseDataExportConfiguration ,
164- ...qcFlagsExportConfigurationFactory ( detectors ) ,
165- } ) ;
166- } ,
167- Other : ( ) => null ,
168- } ) ) ;
171+ const callback = ( observableData ) => {
172+ const current = observableData . getCurrent ( ) ;
173+ current ?. apply ( {
174+ Success : ( detectors ) => {
175+ this . _exportModel . setDataExportConfiguration ( {
176+ ...baseDataExportConfiguration ,
177+ ...qcFlagsExportConfigurationFactory ( detectors ) ,
178+ } ) ;
179+ } ,
180+ Other : ( ) => null ,
181+ } ) ;
182+ } ;
183+ detectors$ . observe ( callback ) ;
184+ // Also trigger immediately if detectors are already loaded
185+ callback ( detectors$ ) ;
169186 }
170187
171188 /**
172- * Register obervables data, which QC flags fetching operation success dependes on
189+ * Register observables data, which QC flags fetching operation success depends on
173190 *
174- * @param {ObservableData<RemoteData>[] } observables obervable data list
191+ * @param {ObservableData<RemoteData<Detector>> } detectors$ observable data which QC flags fetching operation success depends on
175192 */
176- registerObervablesQcSummaryDependesOn ( observables ) {
177- this . _observablesQcFlagsSummaryDepndsOn $ = ObservableData
178- . builder ( )
179- . sources ( observables )
180- . apply ( ( remoteDataList ) => mergeRemoteData ( remoteDataList ) )
181- . build ( ) ;
182-
183- this . _observablesQcFlagsSummaryDepndsOn$
184- . observe ( ( observableData ) => observableData . getCurrent ( ) . apply ( { Success : ( ) => this . _fetchQcSummary ( ) } ) ) ;
193+ registerObservablesQcSummaryDependsOn ( detectors$ ) {
194+ this . _observablesQcFlagsSummaryDependsOn $ = detectors$ ;
195+ const callback = ( observableData ) => {
196+ const current = observableData . getCurrent ( ) ;
197+ current ? .apply ( { Success : ( ) => this . _fetchQcSummary ( ) } ) ;
198+ } ;
199+ this . _observablesQcFlagsSummaryDependsOn$ . observe ( callback ) ;
200+ // Also trigger immediately if detectors are already loaded
201+ callback ( this . _observablesQcFlagsSummaryDependsOn$ ) ;
185202 }
186203
187204 /**
@@ -208,8 +225,8 @@ export class RunsWithQcModel extends RunsOverviewModel {
208225 async _fetchQcSummary ( ) {
209226 const qcSummaryScopeValid = Object . entries ( this . qcSummaryScope ) . filter ( ( [ , id ] ) => id ) . length == 1 ;
210227
211- if ( qcSummaryScopeValid && this . detectors && this . _observablesQcFlagsSummaryDepndsOn$ . getCurrent ( ) ) {
212- mergeRemoteData ( [ this . detectors , this . _observablesQcFlagsSummaryDepndsOn $. getCurrent ( ) ] ) . match ( {
228+ if ( qcSummaryScopeValid && this . detectors && this . _observablesQcFlagsSummaryDependsOn$ ? .getCurrent ( ) ) {
229+ mergeRemoteData ( [ this . detectors , this . _observablesQcFlagsSummaryDependsOn $. getCurrent ( ) ] ) . match ( {
213230 Success : async ( [ detectors ] ) => {
214231 this . _qcSummary$ . setCurrent ( RemoteData . loading ( ) ) ;
215232 try {
0 commit comments