Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1d9645b

Browse files
author
FalkWolsky
committed
Updating Query Library Function update 2
1 parentd653f74 commit1d9645b

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

‎client/packages/lowcoder/src/comps/queries/libraryQuery.tsx‎

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { default as LoadingOutlined } from "@ant-design/icons/LoadingOutlined";
22
import{defaultasSpin}from"antd/es/spin";
33
importDataSourceIconfrom"components/DataSourceIcon";
44
import{ContextControlType,ContextJsonControl}from"comps/controls/contextCodeControl";
5+
import{FunctionControl}from"comps/controls/codeControl";
56
import{trans}from"i18n";
67
import{
78
CompAction,
@@ -155,26 +156,35 @@ export const LibraryQuery = class extends LibraryQueryBase {
155156
constscript=this.queryInfo.query.comp.script||"";
156157
constoptions: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
constinputValues=Object.entries(this.children.inputs.children).reduce((acc,[name,input])=>{
160-
// Get the actual value from the input component's text property
161-
constvalue=input.children.text.getView();
161+
// Get the raw value from the input component's text property
162+
letvalue=input.children.text.getView();
163+
164+
// Resolve any variables in the value
165+
if(typeofvalue==='string'){
166+
value=value.replace(/\{\{([^}]+)\}\}/g,(match,path)=>{
167+
constparts=path.split('.');
168+
letcurrent=props.args||{};
169+
for(constpartofparts){
170+
if(current&&typeofcurrent==='object'){
171+
current=current[part];
172+
}else{
173+
returnmatch;// Return original if path not found
174+
}
175+
}
176+
returncurrent?.value??match;
177+
});
178+
}
179+
162180
acc[name]=value;
163181
returnacc;
164182
},{}asRecord<string,any>);
165183

166-
// Combine props.args with input values
167-
constcontext={
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-
constdata=awaitevalFunc(script,context,undefined,options);
187+
constdata=awaitevalFunc(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> }) => {
337347
constQueryLabelWrapper=styled.div`
338348
display: flex;
339349
align-items: center;
340-
`;
350+
`;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp