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

use custom comparator to sort participants table #1871

Merged
merged 2 commits into from
Aug 10, 2023
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
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
Loading