Skip to content

Commit 42a8018

Browse files
authored
Merge pull request #1516 from lowcoder-org/fix/global_unique_variable_name
implemented uniqueness of variable name among editorState, queries (including query duplication)
2 parents fe3eddd + 6786b8e commit 42a8018

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,12 @@ export class ExecuteQueryAction extends ExecuteQueryTmpAction {
112112
override getView() {
113113
const queryName = this.children.queryName.getView();
114114
// const queryParams = keyValueListToSearchStr(Array.isArray(this?.children?.query) ? (this.children.query as unknown as any[]).map((i: any) => i.getView() as KeyValue) : []);
115-
const result = Object.values(this.children.queryVariables.children as Record<string, {
116-
children: {
117-
key: { unevaledValue: string },
118-
value: { unevaledValue: string }
119-
}}>)
120-
.filter(item => item.children.key.unevaledValue !== "" && item.children.value.unevaledValue !== "")
121-
.map(item => ({[item.children.key.unevaledValue]: item.children.value.unevaledValue}))
115+
const result = this.children.queryVariables.toJsonValue()
116+
.filter(item => item.key !== "" && item.value !== "")
117+
.map(item => ({[item.key as string]: item.value}))
122118
.reduce((acc, curr) => Object.assign(acc, curr), {});
119+
120+
result.$queryName = queryName;
123121
if (!queryName) {
124122
return () => Promise.resolve();
125123
}

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ QueryCompTmp = class extends QueryCompTmp {
364364
if (action.type === CompActionTypes.EXECUTE_QUERY) {
365365
if (getReduceContext().disableUpdateState) return this;
366366
if(!action.args) action.args = this.children.variables.children.variables.toJsonValue().reduce((acc, curr) => Object.assign(acc, {[curr.key as string]:curr.value}), {});
367+
action.args.$queryName = this.children.name.getView();
367368

368369
return this.executeQuery(action);
369370
}
@@ -673,8 +674,8 @@ export const QueryComp = withExposingConfigs(QueryCompTmp, [
673674
return undefined;
674675
}
675676
const newNode = Object.values(input.data)
676-
.filter((kvNode: any) => kvNode.key.value)
677-
.map((kvNode: any) => ({[kvNode.key.value]: kvNode.value.value}))
677+
.filter((kvNode: any) => kvNode.key)
678+
.map((kvNode: any) => ({[kvNode.key]: kvNode.value}))
678679
.reduce((prev, obj) => ({...prev, ...obj}), {});
679680
return newNode;
680681
},
@@ -773,12 +774,24 @@ class QueryListComp extends QueryListTmpComp implements BottomResListComp {
773774
if (!originQuery) {
774775
return;
775776
}
777+
778+
const jsonData = originQuery.toJsonValue();
779+
//Regenerate variable header
780+
jsonData.variables?.variables?.forEach(kv => {
781+
const [prefix, _] = (kv.key as string).split(/(?=\d+$)/);
782+
let i=1, newName = "";
783+
do {
784+
newName = prefix + (i++);
785+
} while(editorState.checkRename("", newName));
786+
kv.key = newName;
787+
})
788+
776789
const newQueryName = this.genNewName(editorState);
777790
const id = genQueryId();
778791
this.dispatch(
779792
wrapActionExtraInfo(
780793
this.pushAction({
781-
...originQuery.toJsonValue(),
794+
...jsonData,
782795
id: id,
783796
name: newQueryName,
784797
isNewCreate: true,
@@ -789,7 +802,7 @@ class QueryListComp extends QueryListTmpComp implements BottomResListComp {
789802
{
790803
type: "add",
791804
compName: name,
792-
compType: originQuery.children.compType.getView(),
805+
compType: jsonData.compType,
793806
},
794807
],
795808
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ export function toQueryView(params: FunctionProperty[]) {
2828
variables?: any;
2929
timeout: InstanceType<ParamsControlType>;
3030
}): Promise<QueryResult> => {
31+
console.log("toQueryView props", props, params);
3132
const { applicationId, isViewMode } = getGlobalSettings();
3233

33-
const mappedVariables = Object.keys(props.variables).map(key => ({key: `query1.variable.${key}`, value: props.variables[key]}));
34+
const mappedVariables = Object.keys(props.variables).map(key => ({key: `${props.args?.$queryName}.variables.${key}`, value: props.variables[key]}));
3435
let request: QueryExecuteRequest = {
3536
path: props.applicationPath,
3637
params: [

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy