Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix disappearing columns for no data #2167

Merged
merged 1 commit into from
Jan 28, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions jsapp/js/components/table.es6
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,36 @@ export class DataTable extends React.Component {
console.error(error);
});
}

_prepColumns(data) {
var excludes = ['_xform_id_string', '_attachments', '_notes', '_bamboo_dataset_id', '_status',
'formhub/uuid', '_tags', '_geolocation', '_submitted_by', 'meta/instanceID', 'meta/deprecatedID', '_validation_status'];
const excludedKeys = [
'_xform_id_string',
'_attachments',
'_notes',
'_bamboo_dataset_id',
'_status',
'formhub/uuid',
'_tags',
'_geolocation',
'_submitted_by',
'meta/instanceID',
'meta/deprecatedID',
'_validation_status'
];

var uniqueKeys = Object.keys(data.reduce(function(result, obj) {
const dataKeys = Object.keys(data.reduce(function(result, obj) {
return Object.assign(result, obj);
}, {}));

uniqueKeys = uniqueKeys.filter((el, ind, arr) => excludes.includes(el) === false);
const surveyKeys = [];
this.props.asset.content.survey.forEach((row) => {
surveyKeys.push(row.$autoname);
});

// make sure the survey columns are displayed, even if current data's
// submissions doesn't have them
let uniqueKeys = [...new Set([...dataKeys, ...surveyKeys])];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌈

uniqueKeys = uniqueKeys.filter((key) => excludedKeys.includes(key) === false);

let showLabels = this.state.showLabels,
showGroupName = this.state.showGroupName,
Expand Down