Skip to content

Commit 63faec2

Browse files
show query variables in event handlers popup
1 parent 5e1cf9e commit 63faec2

File tree

2 files changed

+100
-76
lines changed

2 files changed

+100
-76
lines changed

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

Lines changed: 94 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,98 @@ import { getPromiseAfterDispatch } from "util/promiseUtils";
99
import { trans } from "i18n";
1010
import {keyValueListControl, keyValueListToSearchStr, withDefault} from "lowcoder-sdk";
1111
import {KeyValue} from "@lowcoder-ee/types/common";
12+
import { useCallback, useContext, useEffect, useMemo } from "react";
1213

14+
const ExecuteQueryPropertyView = ({
15+
comp,
16+
placement,
17+
}: {
18+
comp: any,
19+
placement?: "query" | "table"
20+
}) => {
21+
const getQueryOptions = useCallback((editorState?: EditorState) => {
22+
const options: { label: string; value: string; variable?: Record<string, string> }[] =
23+
editorState
24+
?.queryCompInfoList()
25+
.map((info) => {
26+
return {
27+
label: info.name,
28+
value: info.name,
29+
variable: info.data.variable,
30+
}
31+
})
32+
.filter(
33+
// Filter out the current query under query
34+
(option) => {
35+
if (
36+
placement === "query" &&
37+
editorState.selectedBottomResType === BottomResTypeEnum.Query
38+
) {
39+
return option.value !== editorState.selectedBottomResName;
40+
}
41+
return true;
42+
}
43+
) || [];
44+
45+
// input queries
46+
editorState
47+
?.getModuleLayoutComp()
48+
?.getInputs()
49+
.forEach((i) => {
50+
const { name, type } = i.getView();
51+
if (type === InputTypeEnum.Query) {
52+
options.push({ label: name, value: name });
53+
}
54+
});
55+
return options;
56+
}, [placement]);
57+
58+
const getVariableOptions = useCallback((editorState?: EditorState) => {
59+
return comp.children.queryVariables.propertyView({
60+
label: trans("eventHandler.queryParams"),
61+
layout: "vertical",
62+
isStatic: true,
63+
keyFixed: true,
64+
});
65+
}, [comp.children.queryVariables.getView()])
66+
67+
return (
68+
<>
69+
<BranchDiv $type={"inline"}>
70+
<EditorContext.Consumer>
71+
{(editorState) => (
72+
<>
73+
<Dropdown
74+
showSearch={true}
75+
value={comp.children.queryName.getView()}
76+
options={getQueryOptions(editorState)}
77+
label={trans("eventHandler.selectQuery")}
78+
onChange={(value) => {
79+
const options = getQueryOptions(editorState);
80+
const selectedQuery = options.find(option => option.value === value);
81+
const variables = selectedQuery ? Object.keys(selectedQuery.variable || {}) : [];
82+
comp.dispatchChangeValueAction({
83+
queryName: value,
84+
queryVariables: variables.map((variable) => ({key: variable, value: ''})),
85+
});
86+
}}
87+
/>
88+
</>
89+
)}
90+
</EditorContext.Consumer>
91+
</BranchDiv>
92+
<BranchDiv>
93+
<EditorContext.Consumer>
94+
{(editorState) => getVariableOptions(editorState)}
95+
</EditorContext.Consumer>
96+
</BranchDiv>
97+
</>
98+
);
99+
}
13100
const ExecuteQueryTmpAction = (function () {
14101
const childrenMap = {
15102
queryName: SimpleNameComp,
16-
query: withDefault(keyValueListControl(false, [], "string"), [{ key: "", value: "" }])
103+
queryVariables: withDefault(keyValueListControl(false, [], "string"), [])
17104
};
18105
return new MultiCompBuilder(childrenMap, () => {
19106
return () => Promise.resolve(undefined as unknown);
@@ -26,7 +113,7 @@ export class ExecuteQueryAction extends ExecuteQueryTmpAction {
26113
override getView() {
27114
const queryName = this.children.queryName.getView();
28115
// 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, {
116+
const result = Object.values(this.children.queryVariables.children as Record<string, {
30117
children: {
31118
key: { unevaledValue: string },
32119
value: { unevaledValue: string }
@@ -56,80 +143,11 @@ export class ExecuteQueryAction extends ExecuteQueryTmpAction {
56143
}
57144

58145
propertyView({ placement }: { placement?: "query" | "table" }) {
59-
const getQueryOptions = (editorState?: EditorState) => {
60-
const options: { label: string; value: string }[] =
61-
editorState
62-
?.queryCompInfoList()
63-
.map((info) => ({
64-
label: info.name,
65-
value: info.name,
66-
}))
67-
.filter(
68-
// Filter out the current query under query
69-
(option) => {
70-
if (
71-
placement === "query" &&
72-
editorState.selectedBottomResType === BottomResTypeEnum.Query
73-
) {
74-
return option.value !== editorState.selectedBottomResName;
75-
}
76-
return true;
77-
}
78-
) || [];
79-
80-
// input queries
81-
editorState
82-
?.getModuleLayoutComp()
83-
?.getInputs()
84-
.forEach((i) => {
85-
const { name, type } = i.getView();
86-
if (type === InputTypeEnum.Query) {
87-
options.push({ label: name, value: name });
88-
}
89-
});
90-
return options;
91-
};
92-
const getVariableOptions = (editorState?: EditorState) => {
93-
const options =
94-
editorState
95-
?.getQueriesComp()
96-
.getView()
97-
.filter(
98-
// Filter out the current query under query
99-
(option) => {
100-
return option.children.name.getView() === this.children.queryName.getView();
101-
}
102-
) || [];
103-
return this.children.query.propertyView({
104-
label: trans("eventHandler.queryParams"),
105-
layout: "vertical",
106-
isStatic: true,
107-
keyFixed: true,
108-
});
109-
}
110146
return (
111-
<>
112-
<BranchDiv $type={"inline"}>
113-
<EditorContext.Consumer>
114-
{(editorState) => (
115-
<>
116-
<Dropdown
117-
showSearch={true}
118-
value={this.children.queryName.getView()}
119-
options={getQueryOptions(editorState)}
120-
label={trans("eventHandler.selectQuery")}
121-
onChange={(value) => this.dispatchChangeValueAction({ queryName: value })}
122-
/>
123-
</>
124-
)}
125-
</EditorContext.Consumer>
126-
</BranchDiv>
127-
<BranchDiv>
128-
<EditorContext.Consumer>
129-
{(editorState) => getVariableOptions(editorState)}
130-
</EditorContext.Consumer>
131-
</BranchDiv>
132-
</>
133-
);
147+
<ExecuteQueryPropertyView
148+
comp={this}
149+
placement={placement}
150+
/>
151+
)
134152
}
135153
}

client/packages/lowcoder/src/comps/controls/eventHandlerControl.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,18 @@ const EventHandlerControlPropertyView = (props: {
167167
if (eventConfigs.length === 0) {
168168
return;
169169
}
170+
171+
const queryVariables = editorState
172+
?.selectedOrFirstQueryComp()
173+
?.children.variables.children.variables.toJsonValue();
174+
170175
const queryExecHandler = {
171176
compType: "executeQuery",
172177
comp: {
173178
queryName: editorState
174179
?.selectedOrFirstQueryComp()
175180
?.children.name.getView(),
181+
queryVariables: queryVariables?.map((variable) => ({...variable, value: ''})),
176182
},
177183
};
178184
const messageHandler = {

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