From 7d6e6dfbea3b9f2aaba5a830284cf89ff482888c Mon Sep 17 00:00:00 2001 From: Leszek Pietrzak Date: Thu, 17 Jan 2019 22:38:36 +0100 Subject: [PATCH] ensure survey keys are always included --- jsapp/js/components/table.es6 | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/jsapp/js/components/table.es6 b/jsapp/js/components/table.es6 index f4c8807786..26c0f94bb2 100644 --- a/jsapp/js/components/table.es6 +++ b/jsapp/js/components/table.es6 @@ -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])]; + uniqueKeys = uniqueKeys.filter((key) => excludedKeys.includes(key) === false); let showLabels = this.state.showLabels, showGroupName = this.state.showGroupName,