@@ -97,10 +97,18 @@ interface AfterExecuteQueryAction {
9797 result : QueryResult ;
9898}
9999
100- const TriggerTypeOptions = [
100+ export const TriggerTypeOptions = [
101+ { label : "On Page Load" , value : "onPageLoad" } ,
102+ { label : "On Input Change" , value : "onInputChange" } ,
101103 { label : trans ( "query.triggerTypeAuto" ) , value : "automatic" } ,
102104 { label : trans ( "query.triggerTypeManual" ) , value : "manual" } ,
103105] as const ;
106+
107+ export const JSTriggerTypeOptions = [
108+ { label : trans ( "query.triggerTypeAuto" ) , value : "automatic" } ,
109+ { label : trans ( "query.triggerTypeManual" ) , value : "manual" } ,
110+ ] ;
111+
104112export type TriggerType = ValueFromOption < typeof TriggerTypeOptions > ;
105113
106114const EventOptions = [
@@ -174,6 +182,7 @@ export type QueryChildrenType = InstanceType<typeof QueryCompTmp> extends MultiB
174182 ? X
175183 : never ;
176184
185+ let blockInputChangeQueries = true ;
177186/**
178187 * Logic to automatically trigger execution
179188 */
@@ -222,10 +231,16 @@ QueryCompTmp = class extends QueryCompTmp {
222231 const isJsQuery = this . children . compType . getView ( ) === "js" ;
223232 const notExecuted = this . children . lastQueryStartTime . getView ( ) === - 1 ;
224233 const isAutomatic = getTriggerType ( this ) === "automatic" ;
234+ const isPageLoadTrigger = getTriggerType ( this ) === "onPageLoad" ;
235+ const isInputChangeTrigger = getTriggerType ( this ) === "onInputChange" ;
225236
226237 if (
227238 action . type === CompActionTypes . UPDATE_NODES_V2 &&
228- isAutomatic &&
239+ (
240+ isAutomatic
241+ || isInputChangeTrigger
242+ || ( isPageLoadTrigger && notExecuted )
243+ ) &&
229244 ( ! isJsQuery || ( isJsQuery && notExecuted ) ) // query which has deps can be executed on page load(first time)
230245 ) {
231246 const next = super . reduce ( action ) ;
@@ -250,6 +265,18 @@ QueryCompTmp = class extends QueryCompTmp {
250265 const dependsChanged = ! _ . isEqual ( preDepends , depends ) ;
251266 const dslNotChanged = _ . isEqual ( preDsl , dsl ) ;
252267
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+
253280 // If the dsl has not changed, but the dependent node value has changed, then trigger the query execution
254281 // FIXME, this should be changed to a reference judgement, but for unknown reasons if the reference is modified once, it will change twice.
255282 if ( dependsChanged ) {
@@ -277,7 +304,10 @@ function QueryView(props: QueryViewProps) {
277304 useEffect ( ( ) => {
278305 // Automatically load when page load
279306 if (
280- getTriggerType ( comp ) === "automatic" &&
307+ (
308+ getTriggerType ( comp ) === "automatic"
309+ || getTriggerType ( comp ) === "onPageLoad"
310+ ) &&
281311 ( comp as any ) . isDepReady &&
282312 ! comp . children . isNewCreate . value
283313 ) {
@@ -292,9 +322,9 @@ function QueryView(props: QueryViewProps) {
292322 getPromiseAfterDispatch ( comp . dispatch , executeQueryAction ( { } ) , {
293323 notHandledError : trans ( "query.fixedDelayError" ) ,
294324 } ) ,
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
298328 ) ;
299329
300330 return null ;
0 commit comments