plotly / react-pivottable

React-based drag'n'drop pivot table with Plotly.js charts
https://react-pivottable.js.org/
MIT License
1k stars 259 forks source link

Uncaught TypeError after entering invalid filter text and clicking 'Select 0' #67

Open manderdev opened 5 years ago

manderdev commented 5 years ago

Using v0.9.0 with react v16.7.0

When an invalid filter (i.e. a value that does not exist in the data for that property) is entered in the filter textbox and then the search button is clicked, an uncaught TypeError is thrown because the valueFilter for the filter key is undefined.

see Utilities.js:

filter(record) {
    for (const k in this.props.valueFilter) {
      if (record[k] in this.props.valueFilter[k]) {
        return false;
      }
    }
    return true;
  }

Repro:

Select a filter and enter an invalid value in 'Filter values' textbox. The 'Select' button text changes from 'Select All' to 'Select 0' Click the button.

Throws following error:

Uncaught TypeError: Cannot use 'in' operator to search for '' in undefined
    at PivotData.filter (Utilities.js:619)
    at Utilities.js:609
    at Utilities.js:977
    at Function.PivotData.forEachRecord (Utilities.js:995)
    at new PivotData (Utilities.js:608)
    at TableRenderer.render (TableRenderers.js:88)
    at finishClassComponent (react-dom.development.js:14534)
    at updateClassComponent (react-dom.development.js:14489)
    at beginWork (react-dom.development.js:15335)
    at performUnitOfWork (react-dom.development.js:18150)

If you first select from the list of values and then enter either a valid or an invalid filter value in the textbox, there is no error.

Similar/related issue: if you first type a valid value into the filter textbox and click the select button, it throws a different error, but this one is at least caught somewhere in the stack and doesn't blow the whole render:

Uncaught TypeError: Cannot convert undefined or null to object
    at hasOwnProperty (<anonymous>)
    at index.js:141
    at Array.forEach (<anonymous>)
    at Object.$unset (index.js:140)
    at index.js:76
    at Array.forEach (<anonymous>)
    at update (index.js:73)
    at index.js:84
    at Array.forEach (<anonymous>)
    at update (index.js:73)
gnyan9494 commented 4 years ago

@manderdev I am also facing the same issue. Any update on this?