Skip to content

implemented uniqueness of variable name among editorState, queries (including query duplication) #1516

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 4 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,12 @@ 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) : []);
const result = Object.values(this.children.queryVariables.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}))
const result = this.children.queryVariables.toJsonValue()
.filter(item => item.key !== "" && item.value !== "")
.map(item => ({[item.key as string]: item.value}))
.reduce((acc, curr) => Object.assign(acc, curr), {});

result.$queryName = queryName;
if (!queryName) {
return () => Promise.resolve();
}
Expand Down
21 changes: 17 additions & 4 deletions client/packages/lowcoder/src/comps/queries/queryComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ QueryCompTmp = class extends QueryCompTmp {
if (action.type === CompActionTypes.EXECUTE_QUERY) {
if (getReduceContext().disableUpdateState) return this;
if(!action.args) action.args = this.children.variables.children.variables.toJsonValue().reduce((acc, curr) => Object.assign(acc, {[curr.key as string]:curr.value}), {});
action.args.$queryName = this.children.name.getView();

return this.executeQuery(action);
}
Expand Down Expand Up @@ -673,8 +674,8 @@ export const QueryComp = withExposingConfigs(QueryCompTmp, [
return undefined;
}
const newNode = Object.values(input.data)
.filter((kvNode: any) => kvNode.key.value)
.map((kvNode: any) => ({[kvNode.key.value]: kvNode.value.value}))
.filter((kvNode: any) => kvNode.key)
.map((kvNode: any) => ({[kvNode.key]: kvNode.value}))
.reduce((prev, obj) => ({...prev, ...obj}), {});
return newNode;
},
Expand Down Expand Up @@ -773,12 +774,24 @@ class QueryListComp extends QueryListTmpComp implements BottomResListComp {
if (!originQuery) {
return;
}

const jsonData = originQuery.toJsonValue();
//Regenerate variable header
jsonData.variables?.variables?.forEach(kv => {
const [prefix, _] = (kv.key as string).split(/(?=\d+$)/);
let i=1, newName = "";
do {
newName = prefix + (i++);
} while(editorState.checkRename("", newName));
kv.key = newName;
})

const newQueryName = this.genNewName(editorState);
const id = genQueryId();
this.dispatch(
wrapActionExtraInfo(
this.pushAction({
...originQuery.toJsonValue(),
...jsonData,
id: id,
name: newQueryName,
isNewCreate: true,
Expand All @@ -789,7 +802,7 @@ class QueryListComp extends QueryListTmpComp implements BottomResListComp {
{
type: "add",
compName: name,
compType: originQuery.children.compType.getView(),
compType: jsonData.compType,
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ export function toQueryView(params: FunctionProperty[]) {
variables?: any;
timeout: InstanceType<ParamsControlType>;
}): Promise<QueryResult> => {
console.log("toQueryView props", props, params);
const { applicationId, isViewMode } = getGlobalSettings();

const mappedVariables = Object.keys(props.variables).map(key => ({key: `query1.variable.${key}`, value: props.variables[key]}));
const mappedVariables = Object.keys(props.variables).map(key => ({key: `${props.args?.$queryName}.variables.${key}`, value: props.variables[key]}));
let request: QueryExecuteRequest = {
path: props.applicationPath,
params: [
Expand Down
Loading