From 70aa1b95790c231c8a6633567d23fe8a2b5ff9a0 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Sun, 13 May 2018 08:09:44 +0200 Subject: [PATCH] Revert "Merge pull request #13726 from NejcZdovc/fix/#13721-sort" This reverts commit 12d502fcd6137798fdf1fc0fb358131a009659f0, reversing changes made to 0abdd644e7acff5a4cb02a50653f45611dba64da. --- .../components/common/sortableTable.js | 131 ++++-------------- .../preferences/payment/ledgerTable.js | 7 - package-lock.json | 6 +- package.json | 2 +- 4 files changed, 29 insertions(+), 117 deletions(-) diff --git a/app/renderer/components/common/sortableTable.js b/app/renderer/components/common/sortableTable.js index 628fb39e040..a1afa10e61c 100644 --- a/app/renderer/components/common/sortableTable.js +++ b/app/renderer/components/common/sortableTable.js @@ -12,7 +12,6 @@ const globalStyles = require('../styles/global') // Utils const cx = require('../../../../js/lib/classSet') const eventUtil = require('../../../../js/lib/eventUtil') -const ImmutableUtil = require('../../../common/state/immutableUtil') tableSort.extend('number', (item) => { return typeof item === 'number' @@ -33,66 +32,16 @@ class SortableTable extends React.Component { } this.counter = 0 this.sortTable = null - this.dimensionCount = null } componentDidMount () { - this.sortTable = tableSort(this.table, { - descending: this.props.defaultHeadingSortOrder === 'desc' - }) + this.sortTable = tableSort(this.table) return this.sortTable } componentDidUpdate (prevProps) { - if (this.isMultiDimensioned) { - let count = 0 - if (this.dimensionCount == null && prevProps.rows) { - for (let i = 0; i < prevProps.rows.length; i++) { - if (this.props.rows[i].length > 0) { - if (this.props.rows[i]) { - count += this.props.rows[i].length - } - } - } - this.dimensionCount = count - } - - if (!this.props.rows) { - this.dimensionCount = null - return - } - - count = 0 - for (let i = 0; i < this.props.rows.length; i++) { - if (this.props.rows[i].length > 0) { - count += this.props.rows[i].length - } - } - - if (count !== this.dimensionCount) { - this.sortTable.refresh() - this.dimensionCount = count - return - } - - this.dimensionCount = count - } else { - if ( - this.props.rows && - ( - !prevProps.rows || - prevProps.rows.length !== this.props.rows.length - ) - ) { - this.sortTable.refresh() - return - } - } - - if (this.props.rows && typeof this.props.sortCheck === 'function') { - const shouldSort = this.props.sortCheck(prevProps.rows, this.props.rows) - - if (shouldSort) { - this.sortTable.refresh() - } + if (this.props.rows && + (!prevProps.rows || + prevProps.rows.length !== this.props.rows.length)) { + this.sortTable.refresh() } } /** @@ -253,11 +202,11 @@ class SortableTable extends React.Component { const tableID = parseInt(tableParts[0]) const rowIndex = parseInt(tableParts[1]) const handlerInput = this.props.totalRowObjects - ? (ImmutableUtil.isImmutable(this.props.totalRowObjects[parseInt(tableID)][rowIndex]) + ? (typeof this.props.totalRowObjects[parseInt(tableID)][rowIndex].toJS === 'function' ? this.props.totalRowObjects[parseInt(tableID)][rowIndex].toJS() : this.props.totalRowObjects[parseInt(tableID)][rowIndex]) : (this.props.rowObjects.size > 0 || this.props.rowObjects.length > 0) - ? (ImmutableUtil.isImmutable(this.props.rowObjects) + ? (typeof this.props.rowObjects.toJS === 'function' ? this.props.rowObjects.get(rowIndex).toJS() : this.props.rowObjects[rowIndex]) : null @@ -356,51 +305,23 @@ class SortableTable extends React.Component { // Object bound to this row. Not passed to multi-select handlers. if (this.isMultiDimensioned) { // Object bound to this row. Not passed to multi-select handlers. - if ( - this.props.rowObjects[bodyIndex] && - ( - this.props.rowObjects[bodyIndex].size > 0 || - this.props.rowObjects[bodyIndex].length > 0 - ) - ) { - let indexObj - if (ImmutableUtil.isImmutable(this.props.rowObjects[bodyIndex])) { - indexObj = this.props.rowObjects[bodyIndex].get(index) - } else { - indexObj = this.props.rowObjects[bodyIndex][index] - } - - handlerInput = indexObj - - if (ImmutableUtil.isImmutable(indexObj)) { - handlerInput = indexObj.toJS() - } - } else { - handlerInput = row - } + handlerInput = this.props.rowObjects[bodyIndex] && + (this.props.rowObjects[bodyIndex].size > 0 || this.props.rowObjects[bodyIndex].length > 0) + ? (typeof this.props.rowObjects[bodyIndex].toJS === 'function' + ? this.props.rowObjects[bodyIndex].get(index).toJS() + : (typeof this.props.rowObjects[bodyIndex][index].toJS === 'function' + ? this.props.rowObjects[bodyIndex][index].toJS() + : this.props.rowObjects[bodyIndex][index])) + : row } else { - if ( - this.props.rowObjects && - ( - this.props.rowObjects.size > 0 || - this.props.rowObjects.length > 0 - ) - ) { - let indexObj - if (ImmutableUtil.isImmutable(this.props.rowObjects)) { - indexObj = this.props.rowObjects.get(index) - } else { - indexObj = this.props.rowObjects[index] - } - - handlerInput = indexObj - - if (ImmutableUtil.isImmutable(indexObj)) { - handlerInput = indexObj.toJS() - } - } else { - handlerInput = row - } + handlerInput = this.props.rowObjects && + (this.props.rowObjects.size > 0 || this.props.rowObjects.length > 0) + ? (typeof this.props.rowObjects.toJS === 'function' + ? this.props.rowObjects.get(index).toJS() + : (typeof this.props.rowObjects[index].toJS === 'function' + ? this.props.rowObjects[index].toJS() + : this.props.rowObjects[index])) + : row } // Allow parent control to optionally specify context @@ -552,10 +473,9 @@ class SortableTable extends React.Component { if (dataType === 'object' && firstEntry.value) { dataType = typeof firstEntry.value } - const defaultSort = (this.sortingDisabled || heading === this.props.defaultHeading) || null const headerClasses = { 'sort-header': true, - 'sort-default': defaultSort, + 'sort-default': this.sortingDisabled || heading === this.props.defaultHeading, [css(styles.table__th, this.props.smallRow && styles.table__th_smallRow)]: true } const isString = typeof heading === 'string' @@ -566,9 +486,8 @@ class SortableTable extends React.Component { return diff --git a/app/renderer/components/preferences/payment/ledgerTable.js b/app/renderer/components/preferences/payment/ledgerTable.js index 86ab29a1921..765ff9ebb42 100644 --- a/app/renderer/components/preferences/payment/ledgerTable.js +++ b/app/renderer/components/preferences/payment/ledgerTable.js @@ -272,12 +272,6 @@ class LedgerTable extends ImmutableComponent { ] } - sortCheck (prevRows, currentRows) { - if (prevRows && currentRows) { - return JSON.stringify(prevRows) !== JSON.stringify(currentRows) - } - } - render () { if (!this.synopsis || !this.synopsis.size) { return null @@ -357,7 +351,6 @@ class LedgerTable extends ImmutableComponent { pinnedRows.map((synopsis) => this.getRow(synopsis)).toJS(), unPinnedRows.map((synopsis) => this.getRow(synopsis)).toJS() ]} - sortCheck={this.sortCheck} /> { showButton diff --git a/package-lock.json b/package-lock.json index da0ec691548..79817bd21fc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16153,9 +16153,9 @@ } }, "tablesort": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/tablesort/-/tablesort-5.0.2.tgz", - "integrity": "sha512-l0mDC2pDQJfXZbUogT+IYDHeYoqsW/Whqd2xMLAPltNrN0A8bVHtQXoU1sIc7/DofkgYnnINF5k7tlaG+QJJtw==" + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/tablesort/-/tablesort-5.0.1.tgz", + "integrity": "sha1-WYzts2I8glmVdLZ8QvkVo1wzbGk=" }, "tapable": { "version": "0.2.8", diff --git a/package.json b/package.json index 02624a7331f..c03ab0cfd3a 100644 --- a/package.json +++ b/package.json @@ -128,7 +128,7 @@ "snazzy": "^7.0.0", "string.prototype.endswith": "^0.2.0", "string.prototype.startswith": "^0.2.0", - "tablesort": "5.0.2", + "tablesort": "5.0.1", "tldjs": "^2.3.1", "underscore": "1.8.3", "url-loader": "~0.6.2",