@@ -5,9 +5,9 @@ import ReactResizeDetector from "react-resize-detector";
55import { TableStore } from "../store/store" ;
66import { SelectionMode , DynamicTableSettingsProps } from "../../typings/DynamicTableProps" ;
77import Table , { TableRowSelection , ColumnProps , TableEventListeners } from "antd/es/table" ;
8- import { TableRecord } from "../util/table " ;
8+ import { TableRecord } from "../lib/interfaces " ;
99import { SizeContainer } from "./SizeContainer" ;
10- import { ClickCellType } from "../util /titlehelper" ;
10+ import { ClickCellType } from "../lib /titlehelper" ;
1111import { Alerts } from "./Alerts" ;
1212
1313const DEBOUNCE = 250 ;
@@ -34,54 +34,16 @@ export interface DynamicTreeTableContainerProps {
3434export class DynamicTreeTableContainer extends Component < DynamicTreeTableContainerProps , { } > {
3535 onExpand = this . expanderHandler . bind ( this ) ;
3636 onRowClassName = this . rowClassName . bind ( this ) ;
37+ clearDebounce = this . _clearDebounce . bind ( this ) ;
38+ onRow = this . _onRow . bind ( this ) ;
3739
3840 private debounce : number | null = null ;
3941
4042 render ( ) : ReactNode {
41- const { selectMode, clickToSelect , store, hideSelectBoxes, className, ui } = this . props ;
43+ const { selectMode, store, hideSelectBoxes, className, ui } = this . props ;
4244
4345 const removeValidation = store . removeValidationMessage . bind ( store ) ;
4446
45- const clearDebounce = ( ) : void => {
46- if ( this . debounce !== null ) {
47- clearTimeout ( this . debounce ) ;
48- this . debounce = null ;
49- }
50- } ;
51-
52- const onRow = ( record : TableRecord ) : { [ name : string ] : ( ) => void } => {
53- return {
54- onClick : ( ) : void => {
55- clearDebounce ( ) ;
56- this . debounce = window . setTimeout ( ( ) => {
57- // this.onRowClick(record);
58- if ( selectMode && selectMode !== "none" && clickToSelect ) {
59- const selected = [ ...store . selectedRowsIds ] ;
60- const findKey = selected . findIndex ( s => s === record . key ) ;
61- const isSelected = findKey !== - 1 ;
62- if ( isSelected && selectMode === "single" ) {
63- store . setSelected ( [ ] ) ;
64- } else if ( isSelected && selectMode === "multi" ) {
65- selected . splice ( findKey , 1 ) ;
66- store . setSelected ( selected ) ;
67- } else if ( ! isSelected && selectMode === "single" ) {
68- store . setSelected ( [ record . key ] ) ;
69- } else if ( ! isSelected && selectMode === "multi" ) {
70- selected . push ( record . key ) ;
71- store . setSelected ( selected ) ;
72- }
73- }
74- } , DEBOUNCE ) ;
75- } ,
76- onDoubleClick : ( ) : void => {
77- clearDebounce ( ) ;
78- this . debounce = window . setTimeout ( ( ) => {
79- // this.onRowDblClick(record); // double click row
80- } , DEBOUNCE ) ;
81- }
82- } ;
83- } ;
84-
8547 let rowSelection : TableRowSelection < TableRecord > | undefined ;
8648
8749 if ( selectMode && selectMode !== "none" ) {
@@ -130,7 +92,7 @@ export class DynamicTreeTableContainer extends Component<DynamicTreeTableContain
13092 dataSource = { store . tableRows }
13193 loading = { store . isLoading }
13294 onExpand = { this . onExpand }
133- onRow = { onRow }
95+ onRow = { this . onRow ( ) }
13496 rowSelection = { rowSelection }
13597 pagination = { false }
13698 rowClassName = { this . onRowClassName }
@@ -161,6 +123,52 @@ export class DynamicTreeTableContainer extends Component<DynamicTreeTableContain
161123 ) ;
162124 }
163125
126+ private _clearDebounce ( ) : void {
127+ if ( this . debounce !== null ) {
128+ clearTimeout ( this . debounce ) ;
129+ this . debounce = null ;
130+ }
131+ }
132+
133+ private _onRow ( ) {
134+ const { selectMode, clickToSelect, store } = this . props ;
135+
136+ const onRow = ( record : TableRecord ) : { [ name : string ] : ( ) => void } => {
137+ return {
138+ onClick : ( ) : void => {
139+ this . clearDebounce ( ) ;
140+ this . debounce = window . setTimeout ( ( ) => {
141+ // this.onRowClick(record);
142+ if ( selectMode && selectMode !== "none" && clickToSelect ) {
143+ const selected = [ ...store . selectedRowsIds ] ;
144+ const findKey = selected . findIndex ( s => s === record . key ) ;
145+ const isSelected = findKey !== - 1 ;
146+ if ( isSelected && selectMode === "single" ) {
147+ store . setSelected ( [ ] ) ;
148+ } else if ( isSelected && selectMode === "multi" ) {
149+ selected . splice ( findKey , 1 ) ;
150+ store . setSelected ( selected ) ;
151+ } else if ( ! isSelected && selectMode === "single" ) {
152+ store . setSelected ( [ record . key ] ) ;
153+ } else if ( ! isSelected && selectMode === "multi" ) {
154+ selected . push ( record . key ) ;
155+ store . setSelected ( selected ) ;
156+ }
157+ }
158+ } , DEBOUNCE ) ;
159+ } ,
160+ onDoubleClick : ( ) : void => {
161+ this . clearDebounce ( ) ;
162+ this . debounce = window . setTimeout ( ( ) => {
163+ // this.onRowDblClick(record); // double click row
164+ } , DEBOUNCE ) ;
165+ }
166+ } ;
167+ } ;
168+
169+ return onRow ;
170+ }
171+
164172 private getColumns ( dataColumns : Array < ColumnProps < TableRecord > > ) : Array < ColumnProps < TableRecord > > {
165173 const { ui, emptyClickHandler } = this . props ;
166174 const leftWidth = ui . settingsTableLeftColumnWidth || 200 ;
0 commit comments