Skip to content

Commit 296e25b

Browse files
authored
Merge pull request #1506 from lowcoder-org/fix/variable_header_control_type
Added validation check to input boxes of variables
2 parents 5a374db + 3e41004 commit 296e25b

File tree

5 files changed

+78
-5
lines changed

5 files changed

+78
-5
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { ControlParams } from "comps/controls/controlParams";
2+
import { CompAction, SimpleComp } from "lowcoder-core";
3+
import { ControlPropertyViewWrapper, PopupCard, Input } from "lowcoder-design";
4+
import { useEffect, useState } from "react";
5+
import { trans } from "i18n";
6+
import { checkName } from "../utils/rename";
7+
const SimpleVariableHeaderPropertyView = ({params, comp, isCheck}: any) => {
8+
const [error, setError] = useState<string | undefined>();
9+
const [value, setValue] = useState(comp.value);
10+
useEffect(() => {
11+
setValue(comp.value);
12+
isCheck && setError(undefined);
13+
}, [comp]);
14+
return (
15+
<ControlPropertyViewWrapper {...params}>
16+
<Input
17+
value={value}
18+
placeholder={params.placeholder}
19+
onChange={(e) => {
20+
const error = isCheck && checkName(e.target.value);
21+
isCheck && setError(error || undefined);
22+
setValue(e.target.value);
23+
}}
24+
onBlur={(e) => {
25+
if(!isCheck || !error) comp.dispatchChangeValueAction(value);
26+
else {
27+
setValue(comp.value);
28+
setError(undefined);
29+
}
30+
}}
31+
/>
32+
{isCheck && <PopupCard
33+
editorFocus={!!error}
34+
title={error ? trans("error") : ""}
35+
content={error}
36+
hasError={!!error}
37+
/>}
38+
</ControlPropertyViewWrapper>
39+
);
40+
}
41+
export const SimpleVariableHeaderComp = (isCheck: boolean = false) => {
42+
return class SimpleVariableHeaderComp extends SimpleComp<string> {
43+
override reduce(action: CompAction): this {
44+
// if (isBroadcastAction<RenameAction>(action, CompActionTypes.RENAME)) {
45+
// if (this.getView() === action.action.oldName) {
46+
// return super.reduce(this.changeValueAction(action.action.name));
47+
// }
48+
// }
49+
return super.reduce(action);
50+
}
51+
52+
readonly IGNORABLE_DEFAULT_VALUE = "";
53+
protected getDefaultValue(): string {
54+
return "";
55+
}
56+
57+
getPropertyView() {
58+
return this.propertyView({});
59+
}
60+
61+
propertyView(params: ControlParams) {
62+
return <SimpleVariableHeaderPropertyView params={params} comp={this} isCheck={isCheck}></SimpleVariableHeaderPropertyView>
63+
}
64+
}
65+
}

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(true) 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)
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