Skip to content

Commit 3b4a1a3

Browse files
add onClick listener method in charts
1 parent 1df9973 commit 3b4a1a3

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

client/packages/lowcoder-comps/src/comps/chartComp/chartComp.tsx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import {
3939
import 'echarts-extension-gmap';
4040
import log from "loglevel";
4141

42+
let clickEventCallback = () => {};
43+
4244
let ChartTmpComp = (function () {
4345
return new UICompBuilder(chartChildrenMap, () => null)
4446
.setPropertyViewFn(chartPropertyView)
@@ -84,6 +86,15 @@ ChartTmpComp = withViewFn(ChartTmpComp, (comp) => {
8486
echartsCompInstance?.on("selectchanged", (param: any) => {
8587
const option: any = echartsCompInstance?.getOption();
8688
//log.log("chart select change", param);
89+
// trigger click event listener
90+
document.dispatchEvent(new CustomEvent("clickEvent", {
91+
bubbles: true,
92+
detail: {
93+
action: param.fromAction,
94+
data: getSelectedPoints(param, option)
95+
}
96+
}));
97+
8798
if (param.fromAction === "select") {
8899
comp.dispatch(changeChildAction("selectedPoints", getSelectedPoints(param, option)));
89100
onUIEvent("select");
@@ -93,7 +104,10 @@ ChartTmpComp = withViewFn(ChartTmpComp, (comp) => {
93104
}
94105
});
95106
// unbind
96-
return () => echartsCompInstance?.off("selectchanged");
107+
return () => {
108+
echartsCompInstance?.off("selectchanged");
109+
document.removeEventListener('clickEvent', clickEventCallback)
110+
};
97111
}, [mode, onUIEvent]);
98112

99113
const echartsConfigChildren = _.omit(comp.children, echartsConfigOmitChildren);
@@ -339,6 +353,21 @@ ChartComp = withMethodExposing(ChartComp, [
339353
});
340354
}
341355
},
356+
{
357+
method: {
358+
name: "onClick",
359+
params: [
360+
{
361+
name: "callback",
362+
type: "function",
363+
},
364+
],
365+
},
366+
execute: (comp, params) => {
367+
clickEventCallback = params[0];
368+
document.addEventListener('clickEvent', clickEventCallback);
369+
}
370+
},
342371
])
343372

344373
export const ChartCompWithDefault = withDefault(ChartComp, {

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import DataSourceIcon from "components/DataSourceIcon";
88
import { SimpleNameComp } from "comps/comps/simpleNameComp";
99
import { StringControl } from "comps/controls/codeControl";
1010
import { eventHandlerControl } from "comps/controls/eventHandlerControl";
11-
import { EditorState } from "comps/editorState";
11+
import { EditorContext, EditorState } from "comps/editorState";
1212
import {
1313
stateComp,
1414
valueComp,
@@ -43,7 +43,7 @@ import {
4343
wrapActionExtraInfo,
4444
} from "lowcoder-core";
4545
import { ValueFromOption } from "lowcoder-design";
46-
import { ReactNode, useEffect } from "react";
46+
import { ReactNode, useContext, useEffect } from "react";
4747
import {
4848
BottomResComp,
4949
BottomResCompResult,
@@ -271,18 +271,25 @@ interface QueryViewProps {
271271
}
272272

273273
function QueryView(props: QueryViewProps) {
274+
const editorState = useContext(EditorContext);
274275
const { comp } = props;
275276

276277
useEffect(() => {
277278
// Automatically load when page load
279+
const depList = Object.keys(comp.children.comp.node()?.dependValues() ?? {});
280+
const depName = depList.length ? depList[0] : null;
281+
const depComp = depName ? editorState.getUICompByName(depName) : undefined;
282+
const isModule = depComp ? depComp.children.compType.getView() === 'module' : false;
283+
278284
if (
285+
isModule &&
279286
getTriggerType(comp) === "automatic" &&
280287
(comp as any).isDepReady &&
281288
!comp.children.isNewCreate.value
282289
) {
283290
setTimeout(() => {
284291
comp.dispatch(deferAction(executeQueryAction({})));
285-
}, 100);
292+
}, 1000);
286293
}
287294
}, []);
288295

0 commit comments

Comments
 (0)