@@ -97,10 +97,25 @@ interface AfterExecuteQueryAction {
9797 result : QueryResult ;
9898}
9999
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 ,
101109 { label : trans ( "query.triggerTypeAuto" ) , value : "automatic" } ,
102110 { label : trans ( "query.triggerTypeManual" ) , value : "manual" } ,
103111] 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+
104119export type TriggerType = ValueFromOption < typeof TriggerTypeOptions > ;
105120
106121const EventOptions = [
@@ -151,6 +166,13 @@ const childrenMap = {
151166 } ,
152167 } ) ,
153168 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+ } )
154176} ;
155177
156178let QueryCompTmp = withTypeAndChildren < typeof QueryMap , ToInstanceType < typeof childrenMap > > (
@@ -174,6 +196,7 @@ export type QueryChildrenType = InstanceType<typeof QueryCompTmp> extends MultiB
174196 ? X
175197 : never ;
176198
199+ let blockInputChangeQueries = true ;
177200/**
178201 * Logic to automatically trigger execution
179202 */
@@ -222,11 +245,17 @@ QueryCompTmp = class extends QueryCompTmp {
222245 const isJsQuery = this . children . compType . getView ( ) === "js" ;
223246 const notExecuted = this . children . lastQueryStartTime . getView ( ) === - 1 ;
224247 const isAutomatic = getTriggerType ( this ) === "automatic" ;
248+ const isPageLoadTrigger = getTriggerType ( this ) === "onPageLoad" ;
249+ const isInputChangeTrigger = getTriggerType ( this ) === "onInputChange" ;
225250
226251 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)
230259 ) {
231260 const next = super . reduce ( action ) ;
232261 const depends = this . children . comp . node ( ) ?. dependValues ( ) ;
@@ -250,6 +279,18 @@ QueryCompTmp = class extends QueryCompTmp {
250279 const dependsChanged = ! _ . isEqual ( preDepends , depends ) ;
251280 const dslNotChanged = _ . isEqual ( preDsl , dsl ) ;
252281
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+
253294 // If the dsl has not changed, but the dependent node value has changed, then trigger the query execution
254295 // FIXME, this should be changed to a reference judgement, but for unknown reasons if the reference is modified once, it will change twice.
255296 if ( dependsChanged ) {
@@ -277,24 +318,33 @@ function QueryView(props: QueryViewProps) {
277318 useEffect ( ( ) => {
278319 // Automatically load when page load
279320 if (
280- getTriggerType ( comp ) === "automatic" &&
321+ (
322+ getTriggerType ( comp ) === "automatic"
323+ || getTriggerType ( comp ) === "onPageLoad"
324+ ) &&
281325 ( comp as any ) . isDepReady &&
282326 ! comp . children . isNewCreate . value
283327 ) {
284328 setTimeout ( ( ) => {
285329 comp . dispatch ( deferAction ( executeQueryAction ( { } ) ) ) ;
286330 } , 300 ) ;
287331 }
332+
333+ if ( getTriggerType ( comp ) === "onTimeout" ) {
334+ setTimeout ( ( ) => {
335+ comp . dispatch ( deferAction ( executeQueryAction ( { } ) ) ) ;
336+ } , comp . children . delayTime . getView ( ) ) ;
337+ }
288338 } , [ ] ) ;
289339
290340 useFixedDelay (
291341 ( ) =>
292342 getPromiseAfterDispatch ( comp . dispatch , executeQueryAction ( { } ) , {
293343 notHandledError : trans ( "query.fixedDelayError" ) ,
294344 } ) ,
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
298348 ) ;
299349
300350 return null ;
@@ -609,6 +659,29 @@ export const QueryComp = withExposingConfigs(QueryCompTmp, [
609659const QueryListTmpComp = list ( QueryComp ) ;
610660
611661class 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+
612685 nameAndExposingInfo ( ) : NameAndExposingInfo {
613686 const result : NameAndExposingInfo = { } ;
614687 Object . values ( this . children ) . forEach ( ( comp ) => {
0 commit comments