@@ -97,10 +97,18 @@ interface AfterExecuteQueryAction {
97
97
result : QueryResult ;
98
98
}
99
99
100
- const TriggerTypeOptions = [
100
+ export const TriggerTypeOptions = [
101
+ { label : "On Page Load" , value : "onPageLoad" } ,
102
+ { label : "On Input Change" , value : "onInputChange" } ,
101
103
{ label : trans ( "query.triggerTypeAuto" ) , value : "automatic" } ,
102
104
{ label : trans ( "query.triggerTypeManual" ) , value : "manual" } ,
103
105
] as const ;
106
+
107
+ export const JSTriggerTypeOptions = [
108
+ { label : trans ( "query.triggerTypeAuto" ) , value : "automatic" } ,
109
+ { label : trans ( "query.triggerTypeManual" ) , value : "manual" } ,
110
+ ] ;
111
+
104
112
export type TriggerType = ValueFromOption < typeof TriggerTypeOptions > ;
105
113
106
114
const EventOptions = [
@@ -174,6 +182,7 @@ export type QueryChildrenType = InstanceType<typeof QueryCompTmp> extends MultiB
174
182
? X
175
183
: never ;
176
184
185
+ let blockInputChangeQueries = true ;
177
186
/**
178
187
* Logic to automatically trigger execution
179
188
*/
@@ -222,10 +231,16 @@ QueryCompTmp = class extends QueryCompTmp {
222
231
const isJsQuery = this . children . compType . getView ( ) === "js" ;
223
232
const notExecuted = this . children . lastQueryStartTime . getView ( ) === - 1 ;
224
233
const isAutomatic = getTriggerType ( this ) === "automatic" ;
234
+ const isPageLoadTrigger = getTriggerType ( this ) === "onPageLoad" ;
235
+ const isInputChangeTrigger = getTriggerType ( this ) === "onInputChange" ;
225
236
226
237
if (
227
238
action . type === CompActionTypes . UPDATE_NODES_V2 &&
228
- isAutomatic &&
239
+ (
240
+ isAutomatic
241
+ || isInputChangeTrigger
242
+ || ( isPageLoadTrigger && notExecuted )
243
+ ) &&
229
244
( ! isJsQuery || ( isJsQuery && notExecuted ) ) // query which has deps can be executed on page load(first time)
230
245
) {
231
246
const next = super . reduce ( action ) ;
@@ -250,6 +265,18 @@ QueryCompTmp = class extends QueryCompTmp {
250
265
const dependsChanged = ! _ . isEqual ( preDepends , depends ) ;
251
266
const dslNotChanged = _ . isEqual ( preDsl , dsl ) ;
252
267
268
+ if ( isInputChangeTrigger && blockInputChangeQueries && dependsChanged ) {
269
+ // block executing input change queries initially on page refresh
270
+ setTimeout ( ( ) => {
271
+ blockInputChangeQueries = false ;
272
+ } , 500 )
273
+
274
+ return setFieldsNoTypeCheck ( next , {
275
+ [ lastDependsKey ] : depends ,
276
+ [ lastDslKey ] : dsl ,
277
+ } ) ;
278
+ }
279
+
253
280
// If the dsl has not changed, but the dependent node value has changed, then trigger the query execution
254
281
// FIXME, this should be changed to a reference judgement, but for unknown reasons if the reference is modified once, it will change twice.
255
282
if ( dependsChanged ) {
@@ -277,7 +304,10 @@ function QueryView(props: QueryViewProps) {
277
304
useEffect ( ( ) => {
278
305
// Automatically load when page load
279
306
if (
280
- getTriggerType ( comp ) === "automatic" &&
307
+ (
308
+ getTriggerType ( comp ) === "automatic"
309
+ || getTriggerType ( comp ) === "onPageLoad"
310
+ ) &&
281
311
( comp as any ) . isDepReady &&
282
312
! comp . children . isNewCreate . value
283
313
) {
@@ -292,9 +322,9 @@ function QueryView(props: QueryViewProps) {
292
322
getPromiseAfterDispatch ( comp . dispatch , executeQueryAction ( { } ) , {
293
323
notHandledError : trans ( "query.fixedDelayError" ) ,
294
324
} ) ,
295
- getTriggerType ( comp ) === "automatic" && comp . children . periodic . getView ( )
296
- ? comp . children . periodicTime . getView ( )
297
- : null
325
+ getTriggerType ( comp ) === "automatic" && comp . children . periodic . getView ( )
326
+ ? comp . children . periodicTime . getView ( )
327
+ : null
298
328
) ;
299
329
300
330
return null ;
0 commit comments