Skip to content

Commit 2c73080

Browse files
committed
Added Variables to every queries of Data Queries in your App of left panel.
Added ability to apply query variables when running a query in the bottom panel.
1 parent 338a8fa commit 2c73080

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ const ExecuteQueryTmpAction = (function () {
2525
export class ExecuteQueryAction extends ExecuteQueryTmpAction {
2626
override getView() {
2727
const queryName = this.children.queryName.getView();
28-
const queryParams = keyValueListToSearchStr(Array.isArray(this?.children?.query) ? (this.children.query as unknown as any[]).map((i: any) => i.getView() as KeyValue) : []);
29-
console.log(queryParams, queryName);
28+
// const queryParams = keyValueListToSearchStr(Array.isArray(this?.children?.query) ? (this.children.query as unknown as any[]).map((i: any) => i.getView() as KeyValue) : []);
29+
const result = Object.values(this.children.query.children as Record<string, {
30+
children: {
31+
key: { unevaledValue: string },
32+
value: { unevaledValue: string }
33+
}}>)
34+
.filter(item => item.children.key.unevaledValue !== "" && item.children.value.unevaledValue !== "")
35+
.map(item => ({[item.children.key.unevaledValue]: item.children.value.unevaledValue}));
3036
if (!queryName) {
3137
return () => Promise.resolve();
3238
}

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ import { QueryNotificationControl } from "./queryComp/queryNotificationControl";
7575
import { QueryPropertyView } from "./queryComp/queryPropertyView";
7676
import { getTriggerType, onlyManualTrigger } from "./queryCompUtils";
7777
import { messageInstance } from "lowcoder-design/src/components/GlobalInstances";
78-
import {VariablesComp} from "@lowcoder-ee/comps/queries/queryComp/variablesCompl";
78+
import {VariablesComp} from "@lowcoder-ee/comps/queries/queryComp/variablesComp";
7979

8080
const latestExecution: Record<string, string> = {};
8181

@@ -137,6 +137,7 @@ const childrenMap = {
137137
isFetching: stateComp<boolean>(false),
138138
lastQueryStartTime: stateComp<number>(-1), // The last execution time of the query, in order to avoid multiple executions overwriting each other, not persistent
139139
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
140141
runTime: stateComp<number>(0), // query run time
141142

142143
datasourceId: StringControl,
@@ -406,16 +407,21 @@ QueryCompTmp = class extends QueryCompTmp {
406407
return this;
407408
}
408409

410+
411+
412+
409413
/**
410414
* Process the execution result
411415
*/
412416
private processResult(result: QueryResult, action: ExecuteQueryAction, startTime: number) {
413417
const lastQueryStartTime = this.children.lastQueryStartTime.getView();
418+
414419
if (lastQueryStartTime > startTime) {
415420
// There are more new requests, ignore this result
416421
// FIXME: cancel this request in advance in the future
417422
return;
418423
}
424+
419425
const changeAction = multiChangeAction({
420426
code: this.children.code.changeValueAction(result.code ?? QUERY_EXECUTION_OK),
421427
success: this.children.success.changeValueAction(result.success ?? true),
@@ -424,6 +430,24 @@ QueryCompTmp = class extends QueryCompTmp {
424430
extra: this.children.extra.changeValueAction(result.extra ?? {}),
425431
isFetching: this.children.isFetching.changeValueAction(false),
426432
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+
427451
runTime: this.children.runTime.changeValueAction(result.runTime ?? 0),
428452
});
429453
getPromiseAfterDispatch(this.dispatch, changeAction, {
@@ -655,6 +679,7 @@ export const QueryComp = withExposingConfigs(QueryCompTmp, [
655679
new NameConfig("isFetching", trans("query.isFetchingExportDesc")),
656680
new NameConfig("runTime", trans("query.runTimeExportDesc")),
657681
new NameConfig("latestEndTime", trans("query.latestEndTimeExportDesc")),
682+
new NameConfig("variable", trans("query.variables")),
658683
new NameConfig("triggerType", trans("query.triggerTypeExportDesc")),
659684
]);
660685

0 commit comments

Comments
 (0)