@@ -97,10 +97,25 @@ interface AfterExecuteQueryAction {
97
97
result : QueryResult ;
98
98
}
99
99
100
- const TriggerTypeOptions = [
100
+ const CommonTriggerOptions = [
101
+ { label : trans ( "query.triggerTypeInputChange" ) , value : "onInputChange" } ,
102
+ { label : trans ( "query.triggerTypeQueryExec" ) , value : "onQueryExecution" } ,
103
+ { label : trans ( "query.triggerTypeTimeout" ) , value : "onTimeout" } ,
104
+ ]
105
+
106
+ export const TriggerTypeOptions = [
107
+ { label : trans ( "query.triggerTypePageLoad" ) , value : "onPageLoad" } ,
108
+ ...CommonTriggerOptions ,
101
109
{ label : trans ( "query.triggerTypeAuto" ) , value : "automatic" } ,
102
110
{ label : trans ( "query.triggerTypeManual" ) , value : "manual" } ,
103
111
] as const ;
112
+
113
+ export const JSTriggerTypeOptions = [
114
+ ...CommonTriggerOptions ,
115
+ { label : trans ( "query.triggerTypePageLoad" ) , value : "automatic" } ,
116
+ { label : trans ( "query.triggerTypeManual" ) , value : "manual" } ,
117
+ ] ;
118
+
104
119
export type TriggerType = ValueFromOption < typeof TriggerTypeOptions > ;
105
120
106
121
const EventOptions = [
@@ -151,6 +166,13 @@ const childrenMap = {
151
166
} ,
152
167
} ) ,
153
168
cancelPrevious : withDefault ( BoolPureControl , false ) ,
169
+ // use only for onQueryExecution trigger
170
+ depQueryName : SimpleNameComp ,
171
+ // use only for onTimeout trigger, triggers query after x time passed on page load
172
+ delayTime : millisecondsControl ( {
173
+ left : 0 ,
174
+ defaultValue : 5 * 1000 ,
175
+ } )
154
176
} ;
155
177
156
178
let QueryCompTmp = withTypeAndChildren < typeof QueryMap , ToInstanceType < typeof childrenMap > > (
@@ -174,6 +196,7 @@ export type QueryChildrenType = InstanceType<typeof QueryCompTmp> extends MultiB
174
196
? X
175
197
: never ;
176
198
199
+ let blockInputChangeQueries = true ;
177
200
/**
178
201
* Logic to automatically trigger execution
179
202
*/
@@ -222,11 +245,17 @@ QueryCompTmp = class extends QueryCompTmp {
222
245
const isJsQuery = this . children . compType . getView ( ) === "js" ;
223
246
const notExecuted = this . children . lastQueryStartTime . getView ( ) === - 1 ;
224
247
const isAutomatic = getTriggerType ( this ) === "automatic" ;
248
+ const isPageLoadTrigger = getTriggerType ( this ) === "onPageLoad" ;
249
+ const isInputChangeTrigger = getTriggerType ( this ) === "onInputChange" ;
225
250
226
251
if (
227
- action . type === CompActionTypes . UPDATE_NODES_V2 &&
228
- isAutomatic &&
229
- ( ! isJsQuery || ( isJsQuery && notExecuted ) ) // query which has deps can be executed on page load(first time)
252
+ action . type === CompActionTypes . UPDATE_NODES_V2
253
+ && (
254
+ isAutomatic
255
+ || isInputChangeTrigger
256
+ || ( isPageLoadTrigger && notExecuted )
257
+ )
258
+ // && (!isJsQuery || (isJsQuery && notExecuted)) // query which has deps can be executed on page load(first time)
230
259
) {
231
260
const next = super . reduce ( action ) ;
232
261
const depends = this . children . comp . node ( ) ?. dependValues ( ) ;
@@ -250,6 +279,18 @@ QueryCompTmp = class extends QueryCompTmp {
250
279
const dependsChanged = ! _ . isEqual ( preDepends , depends ) ;
251
280
const dslNotChanged = _ . isEqual ( preDsl , dsl ) ;
252
281
282
+ if ( isInputChangeTrigger && blockInputChangeQueries && dependsChanged ) {
283
+ // block executing input change queries initially on page refresh
284
+ setTimeout ( ( ) => {
285
+ blockInputChangeQueries = false ;
286
+ } , 500 )
287
+
288
+ return setFieldsNoTypeCheck ( next , {
289
+ [ lastDependsKey ] : depends ,
290
+ [ lastDslKey ] : dsl ,
291
+ } ) ;
292
+ }
293
+
253
294
// If the dsl has not changed, but the dependent node value has changed, then trigger the query execution
254
295
// FIXME, this should be changed to a reference judgement, but for unknown reasons if the reference is modified once, it will change twice.
255
296
if ( dependsChanged ) {
@@ -277,24 +318,33 @@ function QueryView(props: QueryViewProps) {
277
318
useEffect ( ( ) => {
278
319
// Automatically load when page load
279
320
if (
280
- getTriggerType ( comp ) === "automatic" &&
321
+ (
322
+ getTriggerType ( comp ) === "automatic"
323
+ || getTriggerType ( comp ) === "onPageLoad"
324
+ ) &&
281
325
( comp as any ) . isDepReady &&
282
326
! comp . children . isNewCreate . value
283
327
) {
284
328
setTimeout ( ( ) => {
285
329
comp . dispatch ( deferAction ( executeQueryAction ( { } ) ) ) ;
286
330
} , 300 ) ;
287
331
}
332
+
333
+ if ( getTriggerType ( comp ) === "onTimeout" ) {
334
+ setTimeout ( ( ) => {
335
+ comp . dispatch ( deferAction ( executeQueryAction ( { } ) ) ) ;
336
+ } , comp . children . delayTime . getView ( ) ) ;
337
+ }
288
338
} , [ ] ) ;
289
339
290
340
useFixedDelay (
291
341
( ) =>
292
342
getPromiseAfterDispatch ( comp . dispatch , executeQueryAction ( { } ) , {
293
343
notHandledError : trans ( "query.fixedDelayError" ) ,
294
344
} ) ,
295
- getTriggerType ( comp ) === "automatic" && comp . children . periodic . getView ( )
296
- ? comp . children . periodicTime . getView ( )
297
- : null
345
+ getTriggerType ( comp ) === "automatic" && comp . children . periodic . getView ( )
346
+ ? comp . children . periodicTime . getView ( )
347
+ : null
298
348
) ;
299
349
300
350
return null ;
@@ -609,6 +659,29 @@ export const QueryComp = withExposingConfigs(QueryCompTmp, [
609
659
const QueryListTmpComp = list ( QueryComp ) ;
610
660
611
661
class QueryListComp extends QueryListTmpComp implements BottomResListComp {
662
+ override reduce ( action : CompAction ) : this {
663
+ if ( isCustomAction < AfterExecuteQueryAction > ( action , "afterExecQuery" ) ) {
664
+ if ( action . path ?. length === 1 && ! isNaN ( parseInt ( action . path [ 0 ] ) ) ) {
665
+ const queryIdx = parseInt ( action . path [ 0 ] ) ;
666
+ const queryComps = this . getView ( ) ;
667
+ const queryName = queryComps ?. [ queryIdx ] ?. children . name . getView ( ) ;
668
+ const dependentQueries = queryComps . filter ( ( query , idx ) => {
669
+ if ( queryIdx === idx ) return false ;
670
+ if (
671
+ getTriggerType ( query ) === 'onQueryExecution'
672
+ && query . children . depQueryName . getView ( ) === queryName
673
+ ) {
674
+ return true ;
675
+ }
676
+ } )
677
+ dependentQueries ?. forEach ( ( query ) => {
678
+ query . dispatch ( deferAction ( executeQueryAction ( { } ) ) ) ;
679
+ } )
680
+ }
681
+ }
682
+ return super . reduce ( action ) ;
683
+ }
684
+
612
685
nameAndExposingInfo ( ) : NameAndExposingInfo {
613
686
const result : NameAndExposingInfo = { } ;
614
687
Object . values ( this . children ) . forEach ( ( comp ) => {
0 commit comments