Skip to content
Merged
Show file tree
Hide file tree
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
67 changes: 65 additions & 2 deletions jsx/StaticDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion modules/issue_tracker/php/edit.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions tools/detect_duplicated_commentids.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down