Skip to content

Commit 8a0884e

Browse files
committed
Add custom control for variable header
1 parent 6a3d7d3 commit 8a0884e

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { CompAction } from "lowcoder-core";
2+
import SimpleStringControl from "../controls/simpleStringControl";
3+
4+
export class SimpleVariableHeaderComp extends SimpleStringControl {
5+
override reduce(action: CompAction): this {
6+
// if (isBroadcastAction<RenameAction>(action, CompActionTypes.RENAME)) {
7+
// if (this.getView() === action.action.oldName) {
8+
// return super.reduce(this.changeValueAction(action.action.name));
9+
// }
10+
// }
11+
return super.reduce(action);
12+
}
13+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const ExecuteQueryPropertyView = ({
9999
const ExecuteQueryTmpAction = (function () {
100100
const childrenMap = {
101101
queryName: SimpleNameComp,
102-
queryVariables: withDefault(keyValueListControl(false, [], "string"), [])
102+
queryVariables: withDefault(keyValueListControl(false, [], "variable"), [])
103103
};
104104
return new MultiCompBuilder(childrenMap, () => {
105105
return () => Promise.resolve(undefined as unknown);

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { StringControl } from "./codeControl";
66
import { ControlParams } from "./controlParams";
77
import { dropdownControl } from "./dropdownControl";
88
import { ParamsStringControl } from "./paramsControl";
9+
import { SimpleVariableHeaderComp } from "../comps/simpleVariableHeaderComp";
910

1011
const KeyValueWrapper = styled.div`
1112
display: flex;
@@ -58,13 +59,20 @@ export type KeyValueControlParams = ControlParams & {
5859
export function keyValueControl<T extends OptionsType>(
5960
hasType: boolean = false,
6061
types: T,
61-
controlType: "params" | "string" = "params"
62+
controlType: "params" | "string" | "variable" = "params"
6263
) {
63-
const childrenMap = {
64+
let childrenMap = {
6465
key: controlType === "params" ? ParamsStringControl : StringControl,
6566
value: controlType === "params" ? ParamsStringControl : StringControl,
6667
type: dropdownControl(types, types[0]?.value),
6768
};
69+
if(controlType === "variable") {
70+
childrenMap = {
71+
key: SimpleVariableHeaderComp as any,
72+
value: SimpleVariableHeaderComp as any,
73+
type: dropdownControl(types, types[0]?.value),
74+
};
75+
}
6876
return class extends new MultiCompBuilder(childrenMap, (props) => {
6977
return hasType
7078
? {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { keyValueControl, KeyValueControlParams } from "./keyValueControl"
1414
export function keyValueListControl<T extends OptionsType>(
1515
hasType: boolean = false,
1616
types: T | OptionsType = [],
17-
controlType: "params" | "string" = "params"
17+
controlType: "params" | "string" | "variable" = "params"
1818
) {
1919
return class extends list(keyValueControl(hasType, types, controlType)) {
2020
getQueryParams() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { keyValueListControl } from "../../controls/keyValueListControl";
33

44
export const VariablesComp = new MultiCompBuilder(
55
{
6-
variables: withDefault(keyValueListControl(false, [], "string"), [{ key: "", value: "" }]),
6+
variables: withDefault(keyValueListControl(false, [], "variable"), [{ key: "", value: "" }]),
77
},
88
(props) => props //props.variables
99
)

0 commit comments

Comments
 (0)