Skip to content

Commit a0190a5

Browse files
committed
Merge branch 'dev' into doubleClick_event_component
2 parents a65010b + 51b9205 commit a0190a5

File tree

3 files changed

+45
-36
lines changed

3 files changed

+45
-36
lines changed

client/packages/lowcoder/src/comps/comps/tableComp/selectionControl.tsx

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import { TableOnEventView } from "./tableTypes";
77
import { OB_ROW_ORI_INDEX, RecordType } from "comps/comps/tableComp/tableUtils";
88
import { ControlNodeCompBuilder } from "comps/generators/controlCompBuilder";
99

10+
// double-click detection constants
11+
const DOUBLE_CLICK_THRESHOLD = 300; // ms
12+
let lastClickTime = 0;
13+
let clickTimer: ReturnType<typeof setTimeout>;
14+
1015
const modeOptions = [
1116
{
1217
label: trans("selectionControl.single"),
@@ -38,8 +43,9 @@ export function getSelectedRowKeys(
3843
return [selection.children.selectedRowKey.getView()];
3944
case "multiple":
4045
return selection.children.selectedRowKeys.getView();
46+
default:
47+
return [];
4148
}
42-
return [];
4349
}
4450

4551
export const SelectionControl = (function () {
@@ -50,40 +56,52 @@ export const SelectionControl = (function () {
5056
};
5157
return new ControlNodeCompBuilder(childrenMap, (props, dispatch) => {
5258
const changeSelectedRowKey = (record: RecordType) => {
53-
if (getKey(record) !== props.selectedRowKey) {
54-
dispatch(changeChildAction("selectedRowKey", getKey(record), false));
59+
const key = getKey(record);
60+
if (key !== props.selectedRowKey) {
61+
dispatch(changeChildAction("selectedRowKey", key, false));
5562
}
5663
};
64+
5765
return (onEvent: TableOnEventView) => {
66+
const handleClick = (record: RecordType) => {
67+
return () => {
68+
const now = Date.now();
69+
clearTimeout(clickTimer);
70+
if (now - lastClickTime < DOUBLE_CLICK_THRESHOLD) {
71+
72+
changeSelectedRowKey(record);
73+
onEvent("doubleClick");
74+
if (getKey(record) !== props.selectedRowKey) {
75+
onEvent("rowSelectChange");
76+
}
77+
} else {
78+
clickTimer = setTimeout(() => {
79+
changeSelectedRowKey(record);
80+
onEvent("rowClick");
81+
if (getKey(record) !== props.selectedRowKey) {
82+
onEvent("rowSelectChange");
83+
}
84+
}, DOUBLE_CLICK_THRESHOLD);
85+
}
86+
lastClickTime = now;
87+
};
88+
};
89+
5890
if (props.mode === "single" || props.mode === "close") {
5991
return {
6092
rowKey: getKey,
6193
rowClassName: (record: RecordType, index: number, indent: number) => {
62-
// Turn off row selection mode, only do visual shutdown, selectedRow still takes effect
6394
if (props.mode === "close") {
6495
return "";
6596
}
6697
return getKey(record) === props.selectedRowKey ? "ant-table-row-selected" : "";
6798
},
68-
onRow: (record: RecordType, index: number | undefined) => {
69-
return {
70-
onClick: () => {
71-
changeSelectedRowKey(record);
72-
onEvent("rowClick");
73-
if (getKey(record) !== props.selectedRowKey) {
74-
onEvent("rowSelectChange");
75-
}
76-
},
77-
onDoubleClick: () => {
78-
onEvent("doubleClick");
79-
if (getKey(record) !== props.selectedRowKey) {
80-
onEvent("rowSelectChange");
81-
}
82-
}
83-
};
84-
},
99+
onRow: (record: RecordType, index: number | undefined) => ({
100+
onClick: handleClick(record),
101+
}),
85102
};
86103
}
104+
87105
const result: TableRowSelection<any> = {
88106
type: "checkbox",
89107
selectedRowKeys: props.selectedRowKeys,
@@ -92,7 +110,6 @@ export const SelectionControl = (function () {
92110
dispatch(changeChildAction("selectedRowKeys", selectedRowKeys as string[], false));
93111
onEvent("rowSelectChange");
94112
},
95-
// click checkbox also trigger row click event
96113
onSelect: (record: RecordType) => {
97114
changeSelectedRowKey(record);
98115
onEvent("rowClick");
@@ -101,18 +118,9 @@ export const SelectionControl = (function () {
101118
return {
102119
rowKey: getKey,
103120
rowSelection: result,
104-
onRow: (record: RecordType) => {
105-
return {
106-
onClick: () => {
107-
changeSelectedRowKey(record);
108-
onEvent("rowClick");
109-
},
110-
onDoubleClick: () => {
111-
changeSelectedRowKey(record);
112-
onEvent("doubleClick");
113-
}
114-
};
115-
},
121+
onRow: (record: RecordType) => ({
122+
onClick: handleClick(record),
123+
}),
116124
};
117125
};
118126
})
@@ -123,4 +131,4 @@ export const SelectionControl = (function () {
123131
})
124132
)
125133
.build();
126-
})();
134+
})();

client/packages/lowcoder/src/comps/comps/tableComp/tableSummaryComp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export const TableSummary = memo(function TableSummary(props: {
203203

204204
const visibleColumns = useMemo(() => {
205205
let cols = columns.filter(col => !col.getView().hide);
206-
if (dynamicColumn) {
206+
if (dynamicColumn && dynamicColumnConfig?.length) {
207207
cols = cols.filter(col => {
208208
const colView = col.getView();
209209
return dynamicColumnConfig.includes(colView.isCustom ? colView.title : colView.dataIndex)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ export const en = {
591591
"chartBorderColor": "Border Color",
592592
"chartTextColor": "Text Color",
593593
"detailSize": "Detail Size",
594+
"hideColumn": "Hide Column",
594595

595596
"radiusTip": "Specifies the radius of the element's corners. Example: 5px, 50%, or 1em.",
596597
"gapTip": "Specifies the gap between rows and columns in a grid or flex container. Example: 10px, 1rem, or 5%.",

0 commit comments

Comments
 (0)