@@ -75,7 +75,7 @@ import { QueryNotificationControl } from "./queryComp/queryNotificationControl";
7575import { QueryPropertyView } from "./queryComp/queryPropertyView" ;
7676import { getTriggerType , onlyManualTrigger } from "./queryCompUtils" ;
7777import { messageInstance } from "lowcoder-design/src/components/GlobalInstances" ;
78- import { VariablesComp } from "@lowcoder-ee/comps/queries/queryComp/variablesCompl " ;
78+ import { VariablesComp } from "@lowcoder-ee/comps/queries/queryComp/variablesComp " ;
7979
8080const latestExecution : Record < string , string > = { } ;
8181
@@ -137,6 +137,7 @@ const childrenMap = {
137137 isFetching : stateComp < boolean > ( false ) ,
138138 lastQueryStartTime : stateComp < number > ( - 1 ) , // The last execution time of the query, in order to avoid multiple executions overwriting each other, not persistent
139139 latestEndTime : stateComp < number > ( 0 ) , // The time when the query was last executed
140+ variable : stateComp < number > ( 0 ) , // The time when the query was last executed
140141 runTime : stateComp < number > ( 0 ) , // query run time
141142
142143 datasourceId : StringControl ,
@@ -406,16 +407,21 @@ QueryCompTmp = class extends QueryCompTmp {
406407 return this ;
407408 }
408409
410+
411+
412+
409413 /**
410414 * Process the execution result
411415 */
412416 private processResult ( result : QueryResult , action : ExecuteQueryAction , startTime : number ) {
413417 const lastQueryStartTime = this . children . lastQueryStartTime . getView ( ) ;
418+
414419 if ( lastQueryStartTime > startTime ) {
415420 // There are more new requests, ignore this result
416421 // FIXME: cancel this request in advance in the future
417422 return ;
418423 }
424+
419425 const changeAction = multiChangeAction ( {
420426 code : this . children . code . changeValueAction ( result . code ?? QUERY_EXECUTION_OK ) ,
421427 success : this . children . success . changeValueAction ( result . success ?? true ) ,
@@ -424,6 +430,24 @@ QueryCompTmp = class extends QueryCompTmp {
424430 extra : this . children . extra . changeValueAction ( result . extra ?? { } ) ,
425431 isFetching : this . children . isFetching . changeValueAction ( false ) ,
426432 latestEndTime : this . children . latestEndTime . changeValueAction ( Date . now ( ) ) ,
433+ variable : this . children . variable . changeValueAction (
434+
435+ Object . values ( this . children ?. variables ?. children ?. variables ?. children || { } )
436+ . filter (
437+ ( item : any ) =>
438+ item ?. children ?. key ?. children ?. text ?. unevaledValue !== "" &&
439+ item ?. children ?. value ?. children ?. text ?. unevaledValue !== ""
440+ )
441+ . reduce ( ( acc : any , item : any ) => {
442+ const key = item ?. children ?. key ?. children ?. text ?. unevaledValue ;
443+ const value = item ?. children ?. value ?. children ?. text ?. unevaledValue ;
444+ if ( key !== undefined && value !== undefined ) {
445+ acc [ key ] = value ;
446+ }
447+ return acc ;
448+ } , { } )
449+ ) ,
450+
427451 runTime : this . children . runTime . changeValueAction ( result . runTime ?? 0 ) ,
428452 } ) ;
429453 getPromiseAfterDispatch ( this . dispatch , changeAction , {
@@ -655,6 +679,7 @@ export const QueryComp = withExposingConfigs(QueryCompTmp, [
655679 new NameConfig ( "isFetching" , trans ( "query.isFetchingExportDesc" ) ) ,
656680 new NameConfig ( "runTime" , trans ( "query.runTimeExportDesc" ) ) ,
657681 new NameConfig ( "latestEndTime" , trans ( "query.latestEndTimeExportDesc" ) ) ,
682+ new NameConfig ( "variable" , trans ( "query.variables" ) ) ,
658683 new NameConfig ( "triggerType" , trans ( "query.triggerTypeExportDesc" ) ) ,
659684] ) ;
660685
0 commit comments