@@ -2,6 +2,7 @@ import { default as LoadingOutlined } from "@ant-design/icons/LoadingOutlined";
22import { default as Spin } from "antd/es/spin" ;
33import DataSourceIcon from "components/DataSourceIcon" ;
44import { ContextControlType , ContextJsonControl } from "comps/controls/contextCodeControl" ;
5+ import { FunctionControl } from "comps/controls/codeControl" ;
56import { trans } from "i18n" ;
67import {
78 CompAction ,
@@ -155,26 +156,35 @@ export const LibraryQuery = class extends LibraryQueryBase {
155156 const script = this . queryInfo . query . comp . script || "" ;
156157 const options : SandBoxOption = { disableLimit : runInHost } ;
157158
158- // Get input values from the inputs component
159+ // Get input values from the inputs component and resolve any variables
159160 const inputValues = Object . entries ( this . children . inputs . children ) . reduce ( ( acc , [ name , input ] ) => {
160- // Get the actual value from the input component's text property
161- const value = input . children . text . getView ( ) ;
161+ // Get the raw value from the input component's text property
162+ let value = input . children . text . getView ( ) ;
163+
164+ // Resolve any variables in the value
165+ if ( typeof value === 'string' ) {
166+ value = value . replace ( / \{ \{ ( [ ^ } ] + ) \} \} / g, ( match , path ) => {
167+ const parts = path . split ( '.' ) ;
168+ let current = props . args || { } ;
169+ for ( const part of parts ) {
170+ if ( current && typeof current === 'object' ) {
171+ current = current [ part ] ;
172+ } else {
173+ return match ; // Return original if path not found
174+ }
175+ }
176+ return current ?. value ?? match ;
177+ } ) ;
178+ }
179+
162180 acc [ name ] = value ;
163181 return acc ;
164182 } , { } as Record < string , any > ) ;
165183
166- // Combine props.args with input values
167- const context = {
168- ...props . args ,
169- ...inputValues ,
170- } ;
171-
172184 console . log ( "script: " + script ) ;
173- console . log ( "context : " , context ) ;
185+ console . log ( "inputValues : " , inputValues ) ;
174186
175- // Wrap the script in a return statement to ensure it returns a value
176- // const wrappedScript = `return (${script});`;
177- const data = await evalFunc ( script , context , undefined , options ) ;
187+ const data = await evalFunc ( script , inputValues , undefined , options ) ;
178188 return {
179189 data : data ,
180190 code : QUERY_EXECUTION_OK ,
@@ -311,7 +321,7 @@ const PropertyView = (props: { comp: InstanceType<typeof LibraryQuery> }) => {
311321 < QueryTutorialButton
312322 label = { trans ( "queryLibrary.viewQuery" ) }
313323 url = { `/query-library?forwardQueryId=${ queryId } ` }
314- styleName = { "dropdownRight" }
324+ styleName = "dropdownRight"
315325 />
316326 </ QueryConfigWrapper >
317327
@@ -337,4 +347,4 @@ const PropertyView = (props: { comp: InstanceType<typeof LibraryQuery> }) => {
337347const QueryLabelWrapper = styled . div `
338348 display: flex;
339349 align-items: center;
340- ` ;
350+ ` ;
0 commit comments