From 3de2bd19531570bea4d9fbd13280d78aac07dba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Tue, 5 Mar 2019 18:26:29 +0100 Subject: [PATCH] Update table columns visibility on finish loading (https://github.com/woocommerce/woocommerce-admin/pull/1729) --- .../packages/components/src/table/index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/woocommerce-admin/packages/components/src/table/index.js b/plugins/woocommerce-admin/packages/components/src/table/index.js index 31798c4bfac..456784461fe 100644 --- a/plugins/woocommerce-admin/packages/components/src/table/index.js +++ b/plugins/woocommerce-admin/packages/components/src/table/index.js @@ -58,8 +58,8 @@ class TableCard extends Component { this.selectAllRows = this.selectAllRows.bind( this ); } - componentDidUpdate( { query: prevQuery } ) { - const { compareBy, onColumnsChange, query } = this.props; + componentDidUpdate( { headers: prevHeaders, isLoading: prevIsLoading, query: prevQuery } ) { + const { compareBy, headers, isLoading, onColumnsChange, query } = this.props; const { showCols } = this.state; if ( query.filter || prevQuery.filter ) { @@ -73,6 +73,13 @@ class TableCard extends Component { /* 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 ) ) { const newShowCols = showCols.concat( query.orderby ); /* eslint-disable react/no-did-update-set-state */