diff --git a/jsx/StaticDataTable.js b/jsx/StaticDataTable.js index 50f3dae044..07f91c0a57 100644 --- a/jsx/StaticDataTable.js +++ b/jsx/StaticDataTable.js @@ -290,6 +290,63 @@ class StaticDataTable extends Component { }); } + /** + * Get if the current sorting column has mixed types in its values. + * + * @return {boolean} true if mixed types, else false. + */ + hasMixedTypes() { + // TODO: data column type check should probably be done once at init, + // meaning when receiving data, to find which columns have mixed types. + let typeFound = null; + + // not the default column + if (this.state.SortColumn === -1) { + return false; + } + + // Only checks string or number types, others are considered undefined. + // Break out of this loop once we encounter two mixed types: + // number and string inside the sorted column. + for (const row of this.props.Data) { + // cell value + let val = row[this.state.SortColumn]; + + // if null or undefined, go to the next iteration + if (val == null) { + continue; + } + + // check number + if (!isNaN(val) && typeof val !== 'object') { + // if string is found, mix of types, break + if (typeFound === 'string') { + return true; + } + // register number only if not already in + if (typeFound == null) { + typeFound = 'number'; + } + + // avoid string section + continue; + } + + // check string + if (typeof val === 'string' || val instanceof String) { + // if number is found, mix of types, break + if (typeFound === 'number') { + return true; + } + // register string only if not already in + if (typeFound == null) { + typeFound = 'string'; + } + } + } + return false; + } + /** * Sort the rows according to the sort configuration * @@ -298,6 +355,10 @@ class StaticDataTable extends Component { getSortedRows() { const index = []; + // is the current sorted column with mixed type? + const isMixedType = this.hasMixedTypes(); + + // for (let i = 0; i < this.props.Data.length; i += 1) { let val = this.props.Data[i][this.state.SortColumn] || undefined; // If SortColumn is equal to default No. column, set value to be @@ -311,10 +372,12 @@ class StaticDataTable extends Component { if (val === '.') { // hack to handle non-existent items in DQT val = null; - } else if (isNumber) { + } else if (isNumber && !isMixedType) { // perform type conversion (from string to int/float) val = Number(val); - } else if (isString) { + } else if (isString || isMixedType) { + // in case of mixed types, force values to string. + val = String(val); // if string with text convert to lowercase val = val.toLowerCase(); } else { diff --git a/modules/issue_tracker/php/edit.class.inc b/modules/issue_tracker/php/edit.class.inc index 8cefd0c440..b0f36c254c 100644 --- a/modules/issue_tracker/php/edit.class.inc +++ b/modules/issue_tracker/php/edit.class.inc @@ -96,7 +96,7 @@ class Edit extends \NDB_Page implements ETagCalculator $inactive_users_expanded = $db->pselect( "SELECT DISTINCT u.Real_name, u.UserID FROM users u LEFT JOIN user_psc_rel upr ON (upr.UserID=u.ID) - WHERE FIND_IN_SET(upr.CenterID,:CenterID) OR (upr.CenterID=:DCC) + WHERE (FIND_IN_SET(upr.CenterID,:CenterID) OR (upr.CenterID=:DCC)) AND Active='N'", [ 'CenterID' => $CenterID, diff --git a/tools/detect_duplicated_commentids.php b/tools/detect_duplicated_commentids.php index 2c0d0070cb..ac183c5ef3 100755 --- a/tools/detect_duplicated_commentids.php +++ b/tools/detect_duplicated_commentids.php @@ -102,7 +102,7 @@ $candid = $candidate['CandID']; $pscid = $candidate['PSCID']; foreach ($cohortids as $cohortid) { - $session_info = $DB->pselectRow( + $session_info = $DB->pselect( "SELECT DISTINCT s.Visit_label,s.ID from session s JOIN candidate c on (c.candid=s.candid) JOIN flag f on (f.sessionid=s.id) @@ -115,8 +115,8 @@ ] ); if (($session_info!=null) && (!empty($session_info))) { - $sessionid = $session_info['ID']; - $visit_label = $session_info['Visit_label']; + $sessionid = $session_info[0]['ID']; + $visit_label = $session_info[0]['Visit_label']; if ($sessionid !=null) { $commentid = getCommentIDs( $instrument,