Skip to content

Commit 3d40b30

Browse files
authored
Merge branch 'dev' into ee-setup
2 parents 465dcef + 9f8b89b commit 3d40b30

File tree

13 files changed

+314
-227
lines changed

13 files changed

+314
-227
lines changed

client/packages/lowcoder/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"main": "src/index.sdk.ts",
77
"types": "src/index.sdk.ts",
88
"dependencies": {
9-
"@ant-design/icons": "^6.0.0",
9+
"@ant-design/icons": "^5.3.0",
1010
"@codemirror/autocomplete": "^6.11.1",
1111
"@codemirror/commands": "^6.3.2",
1212
"@codemirror/lang-css": "^6.2.1",

client/packages/lowcoder/src/comps/comps/signatureComp.tsx

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,27 @@ const SignatureCanvas = React.lazy(() => import("react-signature-canvas"));
112112

113113
let SignatureTmpComp = (function () {
114114
return new UICompBuilder(childrenMap, (props, dispatch) => {
115-
let canvas: SignatureCanvasType | null = null;
115+
const canvasRef = useRef<SignatureCanvasType | null>(null);
116116
const [isBegin, setIsBegin] = useState(false);
117117
const [canvasSize, setCanvasSize] = useState([0, 0]);
118118
const conRef = useRef<HTMLDivElement>(null);
119119

120120
const updateValue = (isClear: boolean = false) => {
121-
const clear = isClear || canvas?.toData().length === 0;
122-
if (canvas) {
123-
clear && canvas?.clear();
121+
if (!canvasRef.current) return;
122+
123+
const clear = isClear || canvasRef.current.toData().length === 0;
124+
if (clear) {
125+
canvasRef.current.clear();
126+
setIsBegin(false);
124127
dispatch(
125128
multiChangeAction({
126-
value: changeValueAction(clear ? "" : canvas.toDataURL(), false),
129+
value: changeValueAction("", false),
130+
})
131+
);
132+
} else {
133+
dispatch(
134+
multiChangeAction({
135+
value: changeValueAction(canvasRef.current.toDataURL(), false),
127136
})
128137
);
129138
}
@@ -132,15 +141,27 @@ let SignatureTmpComp = (function () {
132141
useResizeDetector({
133142
targetRef: conRef,
134143
onResize: ({width, height}: ResizePayload) => {
135-
width && height && setCanvasSize([width, height]);
136-
updateValue(true);
144+
if (width && height) {
145+
setCanvasSize([width, height]);
146+
// Don't clear on resize as it breaks the drawing functionality
147+
// updateValue(true);
148+
}
137149
},
138150
});
139151

152+
// Cleanup on unmount
153+
useEffect(() => {
154+
return () => {
155+
if (canvasRef.current) {
156+
canvasRef.current.clear();
157+
}
158+
};
159+
}, []);
160+
140161
return props.label({
141162
style: props.style,
142163
labelStyle: props.labelStyle,
143-
inputFieldStyle:props.inputFieldStyle,
164+
inputFieldStyle: props.inputFieldStyle,
144165
children: (
145166
<Wrapper
146167
ref={conRef}
@@ -153,9 +174,7 @@ let SignatureTmpComp = (function () {
153174
<div key="signature" className="signature">
154175
<Suspense fallback={<Skeleton />}>
155176
<SignatureCanvas
156-
ref={(ref) => {
157-
canvas = ref;
158-
}}
177+
ref={canvasRef}
159178
penColor={props.inputFieldStyle.pen}
160179
clearOnResize={false}
161180
canvasProps={{
@@ -168,7 +187,9 @@ let SignatureTmpComp = (function () {
168187
setIsBegin(false);
169188
props.onEvent("change");
170189
}}
171-
onBegin={() => setIsBegin(true)}
190+
onBegin={() => {
191+
setIsBegin(true);
192+
}}
172193
/>
173194
</Suspense>
174195
</div>
@@ -178,10 +199,11 @@ let SignatureTmpComp = (function () {
178199
<span className="anticon">
179200
<UndoIcon
180201
onClick={() => {
181-
const data = canvas?.toData();
182-
if (data) {
183-
data?.pop();
184-
canvas?.fromData(data);
202+
if (!canvasRef.current) return;
203+
const data = canvasRef.current.toData();
204+
if (data && data.length > 0) {
205+
data.pop();
206+
canvasRef.current.fromData(data);
185207
updateValue();
186208
props.onEvent("change");
187209
}

client/packages/lowcoder/src/comps/queries/libraryQuery.tsx

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import {
1212
MultiBaseComp,
1313
wrapChildAction,
1414
evalFunc,
15+
changeValueAction,
16+
multiChangeAction,
17+
isDynamicSegment,
1518
} from "lowcoder-core";
1619
import {
1720
Dropdown,
@@ -39,6 +42,9 @@ import { toQueryView } from "./queryCompUtils";
3942
import { getGlobalSettings } from "comps/utils/globalSettings";
4043
import { QUERY_EXECUTION_ERROR, QUERY_EXECUTION_OK } from "../../constants/queryConstants";
4144
import type { SandBoxOption } from "lowcoder-core/src/eval/utils/evalScript";
45+
import { QueryLibraryApi } from "@lowcoder-ee/api/queryLibraryApi";
46+
import { validateResponse } from "@lowcoder-ee/api/apiUtils";
47+
import { JSONValue } from "@lowcoder-ee/util/jsonTypes";
4248

4349
const NoInputsWrapper = styled.div`
4450
color: ${GreyTextColor};
@@ -126,6 +132,8 @@ type QueryLibraryUpdateAction = {
126132
const childrenMap = {
127133
libraryQueryId: valueComp<string>(""),
128134
libraryQueryRecordId: valueComp<string>("latest"),
135+
libraryQueryType: valueComp<string>(""),
136+
libraryQueryDSL: valueComp<JSONValue>(null),
129137
inputs: InputsComp,
130138
error: stateComp<string>(""),
131139
};
@@ -147,23 +155,26 @@ export const LibraryQuery = class extends LibraryQueryBase {
147155

148156
override getView() {
149157
// Check if this is a JS query
150-
if (this.queryInfo?.query?.compType === "js") {
158+
const queryInfo = this.children.libraryQueryDSL.getView() as any;
159+
const queryType = this.children.libraryQueryType.getView() as any;
160+
if (queryType === "js") {
151161
return async (props: any) => {
152162
try {
153163
const { orgCommonSettings } = getGlobalSettings();
154164
const runInHost = !!orgCommonSettings?.runJavaScriptInHost;
155165
const timer = performance.now();
156-
const script = this.queryInfo.query.comp.script || "";
166+
const script = queryInfo.query.comp.script || "";
157167
const options: SandBoxOption = { disableLimit: runInHost };
158168

159169
// Get input values from the inputs component and resolve any variables
160170
const inputValues = Object.entries(this.children.inputs.children).reduce((acc, [name, input]) => {
161171
// Get the raw value from the input component's text property
172+
let { unevaledValue } = input.children.text;
162173
let value = input.children.text.getView();
163-
174+
164175
// Resolve any variables in the value
165-
if (typeof value === 'string') {
166-
value = value.replace(/\{\{([^}]+)\}\}/g, (match, path) => {
176+
if (typeof unevaledValue === 'string') {
177+
unevaledValue = unevaledValue.replace(/\{\{([^}]+)\}\}/g, (match, path) => {
167178
const parts = path.split('.');
168179
let current = props.args || {};
169180
for (const part of parts) {
@@ -173,17 +184,14 @@ export const LibraryQuery = class extends LibraryQueryBase {
173184
return match; // Return original if path not found
174185
}
175186
}
176-
return current?.value ?? match;
187+
return current ?? match;
177188
});
178189
}
179190

180-
acc[name] = value;
191+
acc[name] = isDynamicSegment(unevaledValue) ? value : unevaledValue;
181192
return acc;
182193
}, {} as Record<string, any>);
183194

184-
console.log("script: " + script);
185-
console.log("inputValues: ", inputValues);
186-
187195
const data = await evalFunc(script, inputValues, undefined, options);
188196
return {
189197
data: data,
@@ -223,10 +231,13 @@ export const LibraryQuery = class extends LibraryQueryBase {
223231

224232
override reduce(action: CompAction): this {
225233
if (isMyCustomAction<QueryLibraryUpdateAction>(action, "queryLibraryUpdate")) {
226-
this.queryInfo = action.value?.dsl;
234+
const isJSQuery = this.children.libraryQueryType.getView() === 'js'
235+
const queryDSL = isJSQuery ? action.value?.dsl : null;
236+
const queryDSLValue = this.children.libraryQueryDSL.reduce(this.children.libraryQueryDSL.changeValueAction(queryDSL))
237+
227238
const inputs = this.children.inputs.setInputs(action.value?.dsl?.["inputs"] ?? []);
228239
return setFieldsNoTypeCheck(this, {
229-
children: { ...this.children, inputs: inputs },
240+
children: { ...this.children, inputs: inputs, libraryQueryDSL: queryDSLValue },
230241
isReady: true,
231242
});
232243
}
@@ -315,7 +326,17 @@ const PropertyView = (props: { comp: InstanceType<typeof LibraryQuery> }) => {
315326
value: meta.libraryQueryMetaView.id,
316327
}))}
317328
value={queryId ?? queryLibraryMeta[0]?.libraryQueryMetaView.id}
318-
onChange={(value) => dispatch(props.comp.changeChildAction("libraryQueryId", value))}
329+
onChange={(value) => {
330+
const queryDSL = queryLibraryMeta[value]?.libraryQueryMetaView || null;
331+
const { datasourceType } = queryDSL as any;
332+
333+
props.comp.dispatch(
334+
multiChangeAction({
335+
libraryQueryId: changeValueAction(value, false),
336+
libraryQueryType: changeValueAction(datasourceType, false),
337+
})
338+
)
339+
}}
319340
/>
320341
</div>
321342
<QueryTutorialButton

client/packages/lowcoder/src/constants/themeConstants.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ const tree = {
186186

187187
}
188188

189+
const signature = {
190+
inputFieldStyle: {
191+
pen: "#222222",
192+
}
193+
}
189194

190195
export const defaultTheme: ThemeDetail = {
191196
...theme,
@@ -219,6 +224,7 @@ export const defaultTheme: ThemeDetail = {
219224
select: select,
220225
multiSelect: select,
221226
treeSelect: select,
222-
tree:tree
227+
tree:tree,
228+
signature,
223229
},
224230
};

0 commit comments

Comments
 (0)