Skip to content

Commit 0b2e70f

Browse files
authored
Merge pull request #802 from raheeliftikhar5/echarts-click-listener
Standard Charts Click listener
2 parents 2baa2d6 + aabdc71 commit 0b2e70f

File tree

5 files changed

+58
-8
lines changed

5 files changed

+58
-8
lines changed

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

+30-1
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/comps/appSettingsComp.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { StringControl } from "comps/controls/codeControl";
1818
import { IconControl } from "comps/controls/iconControl";
1919
import { dropdownControl } from "comps/controls/dropdownControl";
2020
import { ApplicationCategoriesEnum } from "constants/applicationConstants";
21+
import { BoolControl } from "../controls/boolControl";
2122

2223
const TITLE = trans("appSetting.title");
2324
const USER_DEFINE = "__USER_DEFINE";
@@ -182,6 +183,7 @@ const childrenMap = {
182183
description: withDefault(StringControl, ''),
183184
icon: IconControl,
184185
category: dropdownControl(AppCategories, ApplicationCategoriesEnum.BUSINESS),
186+
showHeaderInPublic: withDefault(BoolControl, true),
185187
maxWidth: dropdownInputSimpleControl(OPTIONS, USER_DEFINE, "1920"),
186188
themeId: valueComp<string>(DEFAULT_THEMEID),
187189
customShortcuts: CustomShortcutsComp,
@@ -202,6 +204,7 @@ function AppSettingsModal(props: ChildrenInstance) {
202204
description,
203205
icon,
204206
category,
207+
showHeaderInPublic,
205208
} = props;
206209
const THEME_OPTIONS = themeList?.map((theme) => ({
207210
label: theme.name,
@@ -255,6 +258,11 @@ function AppSettingsModal(props: ChildrenInstance) {
255258
tooltip: trans("aggregation.iconTooltip"),
256259
})}
257260
</div>
261+
<div style={{ margin: '20px 0'}}>
262+
{showHeaderInPublic.propertyView({
263+
label: trans("appSetting.showPublicHeader"),
264+
})}
265+
</div>
258266
{maxWidth.propertyView({
259267
dropdownLabel: trans("appSetting.canvasMaxWidth"),
260268
inputLabel: trans("appSetting.userDefinedMaxWidth"),

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

+10-3
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

client/packages/lowcoder/src/i18n/locales/en.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2087,6 +2087,7 @@ export const en = {
20872087
"appTitle": "Title",
20882088
"appDescription": "Description",
20892089
"appCategory": "Category",
2090+
"showPublicHeader": "Show header in public view"
20902091
},
20912092
"customShortcut": {
20922093
"title": "Custom Shortcuts",

client/packages/lowcoder/src/pages/editor/editorView.tsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { default as Sider} from "antd/es/layout/Sider";
44
import { PreloadComp } from "comps/comps/preLoadComp";
55
import UIComp from "comps/comps/uiComp";
66
import { EditorContext } from "comps/editorState";
7-
import { AppUILayoutType } from "constants/applicationConstants";
7+
import { AppPathParams, AppUILayoutType } from "constants/applicationConstants";
88
import { Layers } from "constants/Layers";
99
import { TopHeaderHeight } from "constants/style";
1010
import { trans } from "i18n";
@@ -38,7 +38,7 @@ import React, {
3838
} from "react";
3939
import { Helmet } from "react-helmet";
4040
import { useDispatch, useSelector } from "react-redux";
41-
import { useLocation } from "react-router-dom";
41+
import { useLocation, useParams } from "react-router-dom";
4242
import { setEditorExternalStateAction } from "redux/reduxActions/configActions";
4343
import { currentApplication } from "redux/selectors/applicationSelector";
4444
import { showAppSnapshotSelector } from "redux/selectors/appSnapshotSelector";
@@ -274,6 +274,7 @@ const aggregationSiderItems = [
274274

275275
function EditorView(props: EditorViewProps) {
276276
const { uiComp } = props;
277+
const params = useParams<AppPathParams>();
277278
const editorState = useContext(EditorContext);
278279
const { readOnly, hideHeader } = useContext(ExternalEditorContext);
279280
const application = useSelector(currentApplication);
@@ -296,6 +297,11 @@ function EditorView(props: EditorViewProps) {
296297
const [prePanelStatus, setPrePanelStatus] =
297298
useState<PanelStatus>(DefaultPanelStatus);
298299

300+
const isViewMode = params.viewMode === 'view';
301+
302+
const appSettingsComp = editorState.getAppSettingsComp();
303+
const { showHeaderInPublic } = appSettingsComp.getView();
304+
299305
const togglePanel: TogglePanel = useCallback(
300306
(key) => {
301307
let newPanelStatus;
@@ -363,7 +369,7 @@ function EditorView(props: EditorViewProps) {
363369
return () => window.removeEventListener(eventType, updateSize);
364370
}, []);
365371

366-
const hideBodyHeader = useTemplateViewMode();
372+
const hideBodyHeader = useTemplateViewMode() || (isViewMode && !showHeaderInPublic);
367373

368374
// we check if we are on the public cloud
369375
const isLowCoderDomain = window.location.hostname === 'app.lowcoder.cloud';
@@ -430,7 +436,6 @@ function EditorView(props: EditorViewProps) {
430436
savePanelStatus({ ...panelStatus, left });
431437
setMenuKey(params.key);
432438
};
433-
const appSettingsComp = editorState.getAppSettingsComp();
434439

435440
return (
436441
<Height100Div

0 commit comments

Comments
 (0)