Skip to content

Commit 8564f79

Browse files
committed
overwrite variables before executeQuery
1 parent 6f9ae41 commit 8564f79

File tree

3 files changed

+10
-25
lines changed

3 files changed

+10
-25
lines changed

client/packages/lowcoder/src/comps/controls/actionSelector/executeQueryAction.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export class ExecuteQueryAction extends ExecuteQueryTmpAction {
3434
.filter(item => item.children.key.unevaledValue !== "" && item.children.value.unevaledValue !== "")
3535
.map(item => ({[item.children.key.unevaledValue]: item.children.value.unevaledValue}))
3636
.reduce((acc, curr) => Object.assign(acc, curr), {});
37-
console.log(result);
3837
if (!queryName) {
3938
return () => Promise.resolve();
4039
}
@@ -43,9 +42,7 @@ export class ExecuteQueryAction extends ExecuteQueryTmpAction {
4342
this.dispatch,
4443
routeByNameAction(
4544
queryName,
46-
executeQueryAction({
47-
// can add context in the future
48-
})
45+
executeQueryAction({args: result})
4946
),
5047
{ notHandledError: trans("eventHandler.notHandledError") }
5148
);

client/packages/lowcoder/src/comps/queries/queryComp.tsx

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ const childrenMap = {
135135
data: stateComp<JSONValue>(null),
136136
extra: stateComp<JSONValue>({}),
137137
isFetching: stateComp<boolean>(false),
138+
variable: stateComp<JSONObject>({}),
138139
lastQueryStartTime: stateComp<number>(-1), // The last execution time of the query, in order to avoid multiple executions overwriting each other, not persistent
139140
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
141141
runTime: stateComp<number>(0), // query run time
142142

143143
datasourceId: StringControl,
@@ -364,6 +364,14 @@ QueryCompTmp = class extends QueryCompTmp {
364364
}
365365
if (action.type === CompActionTypes.EXECUTE_QUERY) {
366366
if (getReduceContext().disableUpdateState) return this;
367+
let variableVal = {};
368+
if(action.args) variableVal = action.args;
369+
else variableVal = this.children.variables.children.variables.toJsonValue().reduce((acc, curr) => Object.assign(acc, {[curr.key as string]:curr.value}), {});
370+
//Update query.variable
371+
const changeValAction = this.children.variable.changeValueAction(variableVal);
372+
const changeValAction2 = this.changeChildAction("variable", variableVal)
373+
this.dispatch(changeValAction2);
374+
console.log("changed value: ", this.children.variable.toJsonValue());
367375
return this.executeQuery(action);
368376
}
369377
if (action.type === CompActionTypes.CHANGE_VALUE) {
@@ -430,24 +438,6 @@ QueryCompTmp = class extends QueryCompTmp {
430438
extra: this.children.extra.changeValueAction(result.extra ?? {}),
431439
isFetching: this.children.isFetching.changeValueAction(false),
432440
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-
451441
runTime: this.children.runTime.changeValueAction(result.runTime ?? 0),
452442
});
453443
getPromiseAfterDispatch(this.dispatch, changeAction, {

client/packages/lowcoder/src/comps/queries/queryComp/queryPropertyView.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,6 @@ export const QueryGeneralPropertyView = (props: {
274274
return options;
275275
}, [editorState]);
276276

277-
console.log(children.variable)
278-
279277
return (
280278
<QueryPropertyViewWrapper>
281279
<QuerySectionWrapper>

0 commit comments

Comments
 (0)