Skip to content

Commit d3e06ba

Browse files
updated query's variableComp to expose value properly
1 parent 57e34bb commit d3e06ba

File tree

1 file changed

+34
-21
lines changed

1 file changed

+34
-21
lines changed

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

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { simpleMultiComp } from "../../generators";
1+
import { MultiCompBuilder, simpleMultiComp } from "../../generators";
22
import { SimpleNameComp } from "@lowcoder-ee/comps/comps/simpleNameComp";
33
import { StringControl } from "@lowcoder-ee/comps/controls/codeControl";
44
import { list } from "@lowcoder-ee/comps/generators/list";
@@ -9,7 +9,9 @@ import { KeyValueList } from "components/keyValueList";
99
import { trans } from "i18n";
1010
import { PopupCard } from "components/popupCard";
1111
import { EditorContext, EditorState } from "@lowcoder-ee/comps/editorState";
12-
import { migrateOldData } from "@lowcoder-ee/comps/generators/simpleGenerators";
12+
import { withExposingRaw } from "@lowcoder-ee/comps/generators/withExposing";
13+
import { NameAndExposingInfo } from "@lowcoder-ee/comps/utils/exposingTypes";
14+
import { fromRecord } from "lowcoder-core";
1315

1416
interface VariablesParams {
1517
// variables: string[]; todo support parse variables
@@ -50,33 +52,44 @@ const VariableKey = ({children, dispatch}: any) => {
5052
</>
5153
)
5254
}
53-
const VariableItem = class extends simpleMultiComp({
55+
56+
const VariableItemBase = new MultiCompBuilder({
5457
key: SimpleNameComp,
5558
value: StringControl,
56-
}) {
57-
propertyView(params: VariablesParams): ReactNode {
58-
return (
59-
<>
60-
<div style={{ display: "flex", gap: "8px", flexGrow: 1 }}>
61-
<VariableKey
62-
children={this.children}
63-
dispatch={this.dispatch}
64-
/>
65-
<div style={{ width: "232px", flexGrow: 1 }}>
66-
{this.children.value.propertyView({ placeholder: "value" })}
67-
</div>
68-
</div>
69-
</>
70-
)
71-
}
72-
}
59+
}, (props) => props)
60+
.setPropertyViewFn((children, dispatch) => (<>
61+
<div style={{ display: "flex", gap: "8px", flexGrow: 1 }}>
62+
<VariableKey
63+
children={children}
64+
dispatch={dispatch}
65+
/>
66+
<div style={{ width: "232px", flexGrow: 1 }}>
67+
{children.value.propertyView({ placeholder: "value" })}
68+
</div>
69+
</div>
70+
</>))
71+
.build()
72+
73+
const VariableItem = withExposingRaw(VariableItemBase, {}, (comp) =>
74+
fromRecord({
75+
value: comp.children.value.exposingNode(),
76+
})
77+
);
7378

7479
const VariableListPropertyViewWrapper = ({children}: any) => {
7580
const editorState = useContext(EditorContext);
7681
return children(editorState);
7782
}
7883

7984
export const VariablesComp = class extends list(VariableItem) {
85+
nameAndExposingInfo(): NameAndExposingInfo {
86+
const result: NameAndExposingInfo = {};
87+
Object.values(this.children).forEach((comp) => {
88+
result[comp.children.key.getView()] = comp.exposingInfo();
89+
})
90+
return result;
91+
}
92+
8093
genNewName(editorState: EditorState) {
8194
const name = editorState.getNameGenerator().genItemName("variable");
8295
return name;
@@ -99,7 +112,7 @@ export const VariablesComp = class extends list(VariableItem) {
99112
<ControlPropertyViewWrapper {...params}>
100113
<KeyValueList
101114
allowDeletingAll
102-
list={this.getView().map((child) => child.propertyView(params))}
115+
list={this.getView().map((child) => child.getPropertyView())}
103116
onAdd={() => this.add(editorState)}
104117
onDelete={(item, index) => this.dispatch(this.deleteAction(index))}
105118
/>

0 commit comments

Comments
 (0)