Skip to content

Commit

Permalink
Merge pull request #1871 from methodic-labs/task/CHRONICLE-69-fix-sor…
Browse files Browse the repository at this point in the history
…ting

use custom comparator to sort participants table
  • Loading branch information
UnsungHero97 authored Aug 10, 2023
2 parents dbf84ce + e7ed1b4 commit 6d64d3f
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/containers/study/constants/tableHeaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,48 @@ import {
TUD_UNIQUE_DATES
} from '../../../common/constants';

const comparator = (a, b) => {
if (a === b) {
return 0;
}
const isDefinedA = a !== null && a !== undefined;
const isDefinedB = b !== null && b !== undefined;
if (isDefinedA && !isDefinedB) {
return 1;
}
if (isDefinedB && !isDefinedA) {
return -1;
}
if (a > b) {
return 1;
}
if (a < b) {
return -1;
}
return 0;
};

const TUD_COLUMNS = [
{
key: TUD_FIRST_DATE,
label: 'TUD First Submission',
comparator,
cellStyle: {
fontWeight: 500,
}
},
{
key: TUD_LAST_DATE,
label: 'TUD Last Submission',
comparator,
cellStyle: {
fontWeight: 500,
}
},
{
key: TUD_UNIQUE_DATES,
label: 'TUD Unique Submission Days',
label: 'TUD Unique Days',
sortable: false,
cellStyle: {
fontWeight: 500,
}
Expand All @@ -42,20 +66,23 @@ const IOS_COLUMNS = [
{
key: IOS_FIRST_DATE,
label: 'iOS First Data',
comparator,
cellStyle: {
fontWeight: 500,
}
},
{
key: IOS_LAST_DATE,
label: 'iOS Last Data',
comparator,
cellStyle: {
fontWeight: 500,
}
},
{
key: IOS_UNIQUE_DATES,
label: 'iOS Data Unique Days',
sortable: false,
cellStyle: {
fontWeight: 500,
}
Expand All @@ -66,13 +93,15 @@ const ANDROID_COLUMNS = [
{
key: ANDROID_FIRST_DATE,
label: 'Android First Data',
comparator,
cellStyle: {
fontWeight: 500,
}
},
{
key: ANDROID_LAST_DATE,
label: 'Android Last Data',
comparator,
cellStyle: {
fontWeight: 500,
}
Expand All @@ -90,6 +119,7 @@ const ANDROID_COLUMNS = [
const PARTICIPANT_ID_COLUMN = {
key: PARTICIPANT_ID,
label: 'Participant Id',
comparator,
cellStyle: {
fontWeight: 500,
width: '150px'
Expand Down

0 comments on commit 6d64d3f

Please sign in to comment.