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

Commit9f8b89b

Browse files
fixed edge cases in JS library queries
1 parent587019b commit9f8b89b

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

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

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import {
1212
MultiBaseComp,
1313
wrapChildAction,
1414
evalFunc,
15+
changeValueAction,
16+
multiChangeAction,
17+
isDynamicSegment,
1518
}from"lowcoder-core";
1619
import{
1720
Dropdown,
@@ -39,6 +42,9 @@ import { toQueryView } from "./queryCompUtils";
3942
import{getGlobalSettings}from"comps/utils/globalSettings";
4043
import{QUERY_EXECUTION_ERROR,QUERY_EXECUTION_OK}from"../../constants/queryConstants";
4144
importtype{SandBoxOption}from"lowcoder-core/src/eval/utils/evalScript";
45+
import{QueryLibraryApi}from"@lowcoder-ee/api/queryLibraryApi";
46+
import{validateResponse}from"@lowcoder-ee/api/apiUtils";
47+
import{JSONValue}from"@lowcoder-ee/util/jsonTypes";
4248

4349
constNoInputsWrapper=styled.div`
4450
color:${GreyTextColor};
@@ -126,6 +132,8 @@ type QueryLibraryUpdateAction = {
126132
constchildrenMap={
127133
libraryQueryId:valueComp<string>(""),
128134
libraryQueryRecordId:valueComp<string>("latest"),
135+
libraryQueryType:valueComp<string>(""),
136+
libraryQueryDSL:valueComp<JSONValue>(null),
129137
inputs:InputsComp,
130138
error:stateComp<string>(""),
131139
};
@@ -147,23 +155,26 @@ export const LibraryQuery = class extends LibraryQueryBase {
147155

148156
overridegetView(){
149157
// Check if this is a JS query
150-
if(this.queryInfo?.query?.compType==="js"){
158+
constqueryInfo=this.children.libraryQueryDSL.getView()asany;
159+
constqueryType=this.children.libraryQueryType.getView()asany;
160+
if(queryType==="js"){
151161
returnasync(props:any)=>{
152162
try{
153163
const{ orgCommonSettings}=getGlobalSettings();
154164
construnInHost=!!orgCommonSettings?.runJavaScriptInHost;
155165
consttimer=performance.now();
156-
constscript=this.queryInfo.query.comp.script||"";
166+
constscript=queryInfo.query.comp.script||"";
157167
constoptions:SandBoxOption={disableLimit:runInHost};
158168

159169
// Get input values from the inputs component and resolve any variables
160170
constinputValues=Object.entries(this.children.inputs.children).reduce((acc,[name,input])=>{
161171
// Get the raw value from the input component's text property
172+
let{ unevaledValue}=input.children.text;
162173
letvalue=input.children.text.getView();
163-
174+
164175
// Resolve any variables in the value
165-
if(typeofvalue==='string'){
166-
value=value.replace(/\{\{([^}]+)\}\}/g,(match,path)=>{
176+
if(typeofunevaledValue==='string'){
177+
unevaledValue=unevaledValue.replace(/\{\{([^}]+)\}\}/g,(match,path)=>{
167178
constparts=path.split('.');
168179
letcurrent=props.args||{};
169180
for(constpartofparts){
@@ -173,17 +184,14 @@ export const LibraryQuery = class extends LibraryQueryBase {
173184
returnmatch;// Return original if path not found
174185
}
175186
}
176-
returncurrent?.value??match;
187+
returncurrent??match;
177188
});
178189
}
179190

180-
acc[name]=value;
191+
acc[name]=isDynamicSegment(unevaledValue) ?value :unevaledValue;
181192
returnacc;
182193
},{}asRecord<string,any>);
183194

184-
console.log("script: "+script);
185-
console.log("inputValues: ",inputValues);
186-
187195
constdata=awaitevalFunc(script,inputValues,undefined,options);
188196
return{
189197
data:data,
@@ -223,10 +231,13 @@ export const LibraryQuery = class extends LibraryQueryBase {
223231

224232
overridereduce(action:CompAction): this{
225233
if(isMyCustomAction<QueryLibraryUpdateAction>(action,"queryLibraryUpdate")){
226-
this.queryInfo=action.value?.dsl;
234+
constisJSQuery=this.children.libraryQueryType.getView()==='js'
235+
constqueryDSL=isJSQuery ?action.value?.dsl :null;
236+
constqueryDSLValue=this.children.libraryQueryDSL.reduce(this.children.libraryQueryDSL.changeValueAction(queryDSL))
237+
227238
constinputs=this.children.inputs.setInputs(action.value?.dsl?.["inputs"]??[]);
228239
returnsetFieldsNoTypeCheck(this,{
229-
children:{ ...this.children,inputs:inputs},
240+
children:{ ...this.children,inputs:inputs,libraryQueryDSL:queryDSLValue},
230241
isReady:true,
231242
});
232243
}
@@ -315,7 +326,17 @@ const PropertyView = (props: { comp: InstanceType<typeof LibraryQuery> }) => {
315326
value:meta.libraryQueryMetaView.id,
316327
}))}
317328
value={queryId??queryLibraryMeta[0]?.libraryQueryMetaView.id}
318-
onChange={(value)=>dispatch(props.comp.changeChildAction("libraryQueryId",value))}
329+
onChange={(value)=>{
330+
constqueryDSL=queryLibraryMeta[value]?.libraryQueryMetaView||null;
331+
const{ datasourceType}=queryDSLasany;
332+
333+
props.comp.dispatch(
334+
multiChangeAction({
335+
libraryQueryId:changeValueAction(value,false),
336+
libraryQueryType:changeValueAction(datasourceType,false),
337+
})
338+
)
339+
}}
319340
/>
320341
</div>
321342
<QueryTutorialButton

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp