Skip to content

Added variables to data query #1470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
Imiss-U1025 committed Jan 24, 2025
commit 2c730804050b080211373c1b93af6707c22ef93c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ const ExecuteQueryTmpAction = (function () {
export class ExecuteQueryAction extends ExecuteQueryTmpAction {
override getView() {
const queryName = this.children.queryName.getView();
const queryParams = keyValueListToSearchStr(Array.isArray(this?.children?.query) ? (this.children.query as unknown as any[]).map((i: any) => i.getView() as KeyValue) : []);
console.log(queryParams, queryName);
// const queryParams = keyValueListToSearchStr(Array.isArray(this?.children?.query) ? (this.children.query as unknown as any[]).map((i: any) => i.getView() as KeyValue) : []);
const result = Object.values(this.children.query.children as Record<string, {
children: {
key: { unevaledValue: string },
value: { unevaledValue: string }
}}>)
.filter(item => item.children.key.unevaledValue !== "" && item.children.value.unevaledValue !== "")
.map(item => ({[item.children.key.unevaledValue]: item.children.value.unevaledValue}));
if (!queryName) {
return () => Promise.resolve();
}
Expand Down
27 changes: 26 additions & 1 deletion client/packages/lowcoder/src/comps/queries/queryComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import { QueryNotificationControl } from "./queryComp/queryNotificationControl";
import { QueryPropertyView } from "./queryComp/queryPropertyView";
import { getTriggerType, onlyManualTrigger } from "./queryCompUtils";
import { messageInstance } from "lowcoder-design/src/components/GlobalInstances";
import {VariablesComp} from "@lowcoder-ee/comps/queries/queryComp/variablesCompl";
import {VariablesComp} from "@lowcoder-ee/comps/queries/queryComp/variablesComp";

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

Expand Down Expand Up @@ -137,6 +137,7 @@ const childrenMap = {
isFetching: stateComp<boolean>(false),
lastQueryStartTime: stateComp<number>(-1), // The last execution time of the query, in order to avoid multiple executions overwriting each other, not persistent
latestEndTime: stateComp<number>(0), // The time when the query was last executed
variable: stateComp<number>(0), // The time when the query was last executed
runTime: stateComp<number>(0), // query run time

datasourceId: StringControl,
Expand Down Expand Up @@ -406,16 +407,21 @@ QueryCompTmp = class extends QueryCompTmp {
return this;
}




/**
* Process the execution result
*/
private processResult(result: QueryResult, action: ExecuteQueryAction, startTime: number) {
const lastQueryStartTime = this.children.lastQueryStartTime.getView();

if (lastQueryStartTime > startTime) {
// There are more new requests, ignore this result
// FIXME: cancel this request in advance in the future
return;
}

const changeAction = multiChangeAction({
code: this.children.code.changeValueAction(result.code ?? QUERY_EXECUTION_OK),
success: this.children.success.changeValueAction(result.success ?? true),
Expand All @@ -424,6 +430,24 @@ QueryCompTmp = class extends QueryCompTmp {
extra: this.children.extra.changeValueAction(result.extra ?? {}),
isFetching: this.children.isFetching.changeValueAction(false),
latestEndTime: this.children.latestEndTime.changeValueAction(Date.now()),
variable: this.children.variable.changeValueAction(

Object.values(this.children?.variables?.children?.variables?.children || {})
.filter(
(item: any) =>
item?.children?.key?.children?.text?.unevaledValue !== "" &&
item?.children?.value?.children?.text?.unevaledValue !== ""
)
.reduce((acc: any, item: any) => {
const key = item?.children?.key?.children?.text?.unevaledValue;
const value = item?.children?.value?.children?.text?.unevaledValue;
if (key !== undefined && value !== undefined) {
acc[key] = value;
}
return acc;
}, {})
),

runTime: this.children.runTime.changeValueAction(result.runTime ?? 0),
});
getPromiseAfterDispatch(this.dispatch, changeAction, {
Expand Down Expand Up @@ -655,6 +679,7 @@ export const QueryComp = withExposingConfigs(QueryCompTmp, [
new NameConfig("isFetching", trans("query.isFetchingExportDesc")),
new NameConfig("runTime", trans("query.runTimeExportDesc")),
new NameConfig("latestEndTime", trans("query.latestEndTimeExportDesc")),
new NameConfig("variable", trans("query.variables")),
new NameConfig("triggerType", trans("query.triggerTypeExportDesc")),
]);

Expand Down