Fix bug with checking user preferences for report column visibility.

This commit is contained in:
Jeff Stieler 2019-08-16 12:05:43 -07:00
parent 90edd4e5a6
commit 974566ea0c
2 changed files with 20 additions and 7 deletions

View File

@ -108,14 +108,19 @@ class ReportTable extends Component {
} }
filterShownHeaders( headers, hiddenKeys ) { filterShownHeaders( headers, hiddenKeys ) {
if ( ! hiddenKeys || ! hiddenKeys.length ) { // If no user preferences, set visibilty based on column default.
return headers; if ( ! hiddenKeys ) {
return headers.map( header => ( {
...header,
visible: header.required || ! header.hiddenByDefault,
} ) );
} }
return headers.map( header => { // Set visibilty based on user preferences.
const hidden = hiddenKeys.includes( header.key ) && ! header.required; return headers.map( header => ( {
return { ...header, hiddenByDefault: hidden }; ...header,
} ); visible: header.required || ! hiddenKeys.includes( header.key ),
} ) );
} }
render() { render() {

View File

@ -93,7 +93,15 @@ class TableCard extends Component {
} }
getShowCols( headers ) { getShowCols( headers ) {
return headers.map( ( { key, hiddenByDefault } ) => ! hiddenByDefault && key ).filter( Boolean ); return headers.map( ( { key, visible } ) => {
if (
'undefined' === typeof visible ||
visible
) {
return key;
}
return false;
} ).filter( Boolean );
} }
getVisibleHeaders() { getVisibleHeaders() {