Skip to content

Commit 5e1cf9e

Browse files
committed
use overwritten variable in query request
1 parent 845f9c1 commit 5e1cf9e

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import { JSONObject, JSONValue } from "../../util/jsonTypes";
6767
import { BoolPureControl } from "../controls/boolControl";
6868
import { millisecondsControl } from "../controls/millisecondControl";
6969
import { paramsMillisecondsControl } from "../controls/paramsControl";
70-
import { NameConfig, withExposingConfigs } from "../generators/withExposing";
70+
import { DepsConfig, NameConfig, withExposingConfigs } from "../generators/withExposing";
7171
import { HttpQuery } from "./httpQuery/httpQuery";
7272
import { StreamQuery } from "./httpQuery/streamQuery";
7373
import { QueryConfirmationModal } from "./queryComp/queryConfirmationModal";
@@ -135,7 +135,6 @@ const childrenMap = {
135135
data: stateComp<JSONValue>(null),
136136
extra: stateComp<JSONValue>({}),
137137
isFetching: stateComp<boolean>(false),
138-
variable: stateComp<JSONObject>({}),
139138
lastQueryStartTime: stateComp<number>(-1), // The last execution time of the query, in order to avoid multiple executions overwriting each other, not persistent
140139
latestEndTime: stateComp<number>(0), // The time when the query was last executed
141140
runTime: stateComp<number>(0), // query run time
@@ -364,14 +363,8 @@ QueryCompTmp = class extends QueryCompTmp {
364363
}
365364
if (action.type === CompActionTypes.EXECUTE_QUERY) {
366365
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());
366+
if(!action.args) action.args = this.children.variables.children.variables.toJsonValue().reduce((acc, curr) => Object.assign(acc, {[curr.key as string]:curr.value}), {});
367+
375368
return this.executeQuery(action);
376369
}
377370
if (action.type === CompActionTypes.CHANGE_VALUE) {
@@ -486,6 +479,7 @@ QueryCompTmp = class extends QueryCompTmp {
486479
applicationId: applicationId,
487480
applicationPath: parentApplicationPath,
488481
args: action.args,
482+
variables: action.args,
489483
timeout: this.children.timeout,
490484
callback: (result) => this.processResult(result, action, startTime)
491485
});
@@ -669,7 +663,23 @@ export const QueryComp = withExposingConfigs(QueryCompTmp, [
669663
new NameConfig("isFetching", trans("query.isFetchingExportDesc")),
670664
new NameConfig("runTime", trans("query.runTimeExportDesc")),
671665
new NameConfig("latestEndTime", trans("query.latestEndTimeExportDesc")),
672-
new NameConfig("variable", trans("query.variables")),
666+
new DepsConfig(
667+
"variable",
668+
(children: any) => {
669+
return {data: children.variables.children.variables.node()};
670+
},
671+
(input) => {
672+
if (!input.data) {
673+
return undefined;
674+
}
675+
const newNode = Object.values(input.data)
676+
.filter((kvNode: any) => kvNode.key.text.value)
677+
.map((kvNode: any) => ({[kvNode.key.text.value]: kvNode.value.text.value}))
678+
.reduce((prev, obj) => ({...prev, ...obj}), {});
679+
return newNode;
680+
},
681+
trans("query.variables")
682+
),
673683
new NameConfig("triggerType", trans("query.triggerTypeExportDesc")),
674684
]);
675685

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,23 @@ export function toQueryView(params: FunctionProperty[]) {
2525
applicationId: string;
2626
applicationPath: string[];
2727
args?: Record<string, unknown>;
28+
variables?: any;
2829
timeout: InstanceType<ParamsControlType>;
2930
}): Promise<QueryResult> => {
3031
const { applicationId, isViewMode } = getGlobalSettings();
3132

33+
const mappedVariables = Object.keys(props.variables).map(key => ({key: `query1.variable.${key}`, value: props.variables[key]}));
3234
let request: QueryExecuteRequest = {
3335
path: props.applicationPath,
3436
params: [
35-
...params.map(({ key, value }) => ({ key, value: value(props.args) })),
37+
...params.filter(param => {
38+
return !mappedVariables.map(v => v.key).includes(param.key);
39+
}).map(({ key, value }) => ({ key, value: value(props.args) })),
3640
...Object.entries(props.timeout.getView()).map(([key, value]) => ({
3741
key,
3842
value: value(props.args),
3943
})),
44+
...mappedVariables,
4045
],
4146
viewMode: !!isViewMode,
4247
};

0 commit comments

Comments
 (0)