1
1
/* eslint-disable complexity */
2
2
import React , { Component } from 'react' ;
3
3
import { connect } from 'react-redux' ;
4
- import PropTypes from 'prop-types' ;
4
+ import throttle from 'lodash.throttle' ;
5
+
5
6
import './App.css' ;
6
7
7
8
// actions
@@ -101,6 +102,9 @@ class App extends Component {
101
102
TableauSettings . setEnvName ( this . props . isConfig ? 'CONFIG' : 'EXTENSION' ) ;
102
103
103
104
this . unregisterHandlerFunctions = [ ] ;
105
+ this . applyingMouseActions = false ;
106
+ this . clickCallBack = throttle ( this . clickCallBack , 200 ) ;
107
+ this . hoverCallBack = throttle ( this . hoverCallBack , 200 ) ;
104
108
}
105
109
106
110
// eslint-disable-next-line react/sort-comp
@@ -109,7 +113,7 @@ class App extends Component {
109
113
// since we add them back later in this function.
110
114
// provided by tableau extension samples
111
115
112
- log ( '%c addEventListeners' , 'background: purple; color:yellow' ) ;
116
+ console . log ( '%c addEventListeners' , 'background: purple; color:yellow' ) ;
113
117
this . removeEventListeners ( ) ;
114
118
115
119
const localUnregisterHandlerFunctions = [ ] ;
@@ -137,27 +141,17 @@ class App extends Component {
137
141
} ) ;
138
142
139
143
this . unregisterHandlerFunctions = localUnregisterHandlerFunctions ;
140
- log ( `%c added ${ this . unregisterHandlerFunctions . length } EventListeners` , 'background: purple, color:yellow' ) ;
141
-
142
- // this.setState({unregisterHandlerFunctions: localUnregisterHandlerFunctions }
143
- // , () => console.log('event listeners added', this.state)
144
- // );
144
+ // log(`%c added ${this.unregisterHandlerFunctions.length} EventListeners`, 'background: purple, color:yellow');
145
145
}
146
146
147
147
removeEventListeners = ( ) => {
148
- // let localUnregisterHandlerFunctions = [ ...this.unregisterHandlerFunctions ];
149
-
150
- log ( `%c remove ${ this . unregisterHandlerFunctions . length } EventListeners` , 'background: green; color:black' ) ;
148
+ console . log ( `%c remove ${ this . unregisterHandlerFunctions . length } EventListeners` , 'background: green; color:black' ) ;
151
149
152
150
this . unregisterHandlerFunctions . forEach ( unregisterHandlerFunction => {
153
151
unregisterHandlerFunction ( ) ;
154
152
} ) ;
155
153
156
- // localUnregisterHandlerFunctions = [];
157
154
this . unregisterHandlerFunctions = [ ] ;
158
- // this.setState({ unregisterHandlerFunctions: []}
159
- // , () => console.log('event listeners removed', this.state)
160
- // );
161
155
}
162
156
163
157
onNextStep = ( ) => {
@@ -179,12 +173,12 @@ class App extends Component {
179
173
clickCallBack = d => {
180
174
const { clickField, clickAction} = this . state . tableauSettings ;
181
175
182
- log (
176
+ console . log (
183
177
'%c in on click callback' ,
184
178
'background: brown' ,
185
- d ,
186
- findColumnIndexByFieldName ( this . state , clickField ) ,
187
- clickAction
179
+ // d,
180
+ // findColumnIndexByFieldName(this.state, clickField),
181
+ // clickAction
188
182
) ;
189
183
190
184
this . applyMouseActionsToSheets ( d , clickAction , clickField ) ;
@@ -193,19 +187,22 @@ class App extends Component {
193
187
hoverCallBack = d => {
194
188
const { hoverField, hoverAction} = this . state . tableauSettings ;
195
189
196
- log (
190
+ console . log (
197
191
'%c in on hover callback' ,
198
192
'background: OLIVE' ,
199
- d ,
200
- findColumnIndexByFieldName ( this . state , hoverField ) ,
201
- hoverAction
193
+ // d,
194
+ // findColumnIndexByFieldName(this.state, hoverField),
195
+ // hoverAction
202
196
) ;
203
197
204
198
this . applyMouseActionsToSheets ( d , hoverAction , hoverField ) ;
205
199
// go through each worksheet and select marks
206
200
} ;
207
201
208
202
applyMouseActionsToSheets = ( d , action , fieldName ) => {
203
+ if ( this . applyingMouseActions ) {
204
+ return ;
205
+ }
209
206
const { ConfigSheet} = this . state . tableauSettings ;
210
207
const toHighlight = action === 'Highlight' && ( fieldName || 'None' ) !== 'None' ;
211
208
const toFilter = action === 'Filter' && ( fieldName || 'None' ) !== 'None' ;
@@ -217,6 +214,8 @@ class App extends Component {
217
214
218
215
// remove EventListeners before apply any async actions
219
216
this . removeEventListeners ( ) ;
217
+ this . applyingMouseActions = true ;
218
+
220
219
let tasks = [ ] ;
221
220
222
221
if ( d ) {
@@ -235,8 +234,10 @@ class App extends Component {
235
234
}
236
235
237
236
Promise . all ( tasks ) . then ( ( ) => {
237
+ // all selection should be completed
238
238
// Add event listeners back
239
239
this . addEventListeners ( ) ;
240
+ this . applyingMouseActions = false ;
240
241
} ) ;
241
242
}
242
243
@@ -372,7 +373,10 @@ class App extends Component {
372
373
373
374
marksSelected = e => {
374
375
if ( this . state . tableauSettings . keplerFilterField ) {
375
- log (
376
+ if ( this . applyingMouseActions ) {
377
+ return ;
378
+ }
379
+ console . log (
376
380
'%c ==============App Marker selected' ,
377
381
'background: red; color: white'
378
382
) ;
@@ -395,7 +399,6 @@ class App extends Component {
395
399
}
396
400
397
401
const keplerData = dataToKeplerRow ( marksDataTable . data , keplerFields ) ;
398
- // console.log('zzz mark do we see data', marksDataTable.data.length, marksDataTable.data, keplerData, keplerFields, col_indexes);
399
402
400
403
const filterKeplerObject = {
401
404
field : keplerFilterField ,
@@ -405,9 +408,6 @@ class App extends Component {
405
408
// @shan you can remove this console once you are good with the object
406
409
this . props . dispatch ( markerSelect ( filterKeplerObject ) ) ;
407
410
this . setState ( { filterKeplerObject} , ( ) => this . addEventListeners ( ) ) ;
408
- // console the select marks table
409
- // log('marks', marksDataTable, col_indexes, data, this.state.tableauSettings.hoverField, this.state.tableauSettings.clickField);
410
-
411
411
} ) ;
412
412
}
413
413
}
0 commit comments