Update table columns visibility on finish loading (https://github.com/woocommerce/woocommerce-admin/pull/1729)

This commit is contained in:
Albert Juhé Lluveras 2019-03-05 18:26:29 +01:00 committed by GitHub
parent 0650524977
commit 3de2bd1953
1 changed files with 9 additions and 2 deletions

View File

@ -58,8 +58,8 @@ class TableCard extends Component {
this.selectAllRows = this.selectAllRows.bind( this ); this.selectAllRows = this.selectAllRows.bind( this );
} }
componentDidUpdate( { query: prevQuery } ) { componentDidUpdate( { headers: prevHeaders, isLoading: prevIsLoading, query: prevQuery } ) {
const { compareBy, onColumnsChange, query } = this.props; const { compareBy, headers, isLoading, onColumnsChange, query } = this.props;
const { showCols } = this.state; const { showCols } = this.state;
if ( query.filter || prevQuery.filter ) { if ( query.filter || prevQuery.filter ) {
@ -73,6 +73,13 @@ class TableCard extends Component {
/* eslint-enable react/no-did-update-set-state */ /* eslint-enable react/no-did-update-set-state */
} }
} }
if ( ! isLoading && prevIsLoading && ! isEqual( headers, prevHeaders ) ) {
/* eslint-disable react/no-did-update-set-state */
this.setState( {
showCols: headers.map( ( { key, hiddenByDefault } ) => ! hiddenByDefault && key ).filter( Boolean ),
} );
/* eslint-enable react/no-did-update-set-state */
}
if ( query.orderby !== prevQuery.orderby && ! showCols.includes( query.orderby ) ) { if ( query.orderby !== prevQuery.orderby && ! showCols.includes( query.orderby ) ) {
const newShowCols = showCols.concat( query.orderby ); const newShowCols = showCols.concat( query.orderby );
/* eslint-disable react/no-did-update-set-state */ /* eslint-disable react/no-did-update-set-state */