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

Issue 1473/sort tag value #1499

Merged
merged 3 commits into from
Sep 11, 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
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,39 @@ export default class PersonTagColumnType implements IColumnType {
/>
);
},
sortComparator: (v1: ZetkinTag, v2: ZetkinTag) => {
// TODO: simplify code when v1.value, v2.value can't be null
//if v1 or v1.value is null and v2 or v2.value is null then it should return 0 otherwise v1(null) should be placed before v2(value)
if (!v1 || !v1.value) {
return !v2 || !v2.value ? 0 : -1;
}
//if v2 or v2.value is null then v1(value) should be placed after v2(null)
if (!v2 || !v2.value) {
return 1;
}

if (typeof v1.value === 'string' && typeof v2.value === 'string') {
if (isNaN(Number(v1.value)) && isNaN(Number(v2.value))) {
return v1.value.localeCompare(v2.value);
}
if (!isNaN(Number(v1.value)) && !isNaN(Number(v2.value))) {
return parseInt(v1.value) - parseInt(v2.value);
}
if (isNaN(Number(v1.value))) {
return 1;
}
if (isNaN(Number(v2.value))) {
return -1;
} else {
return v1.value.localeCompare(v2.value);
}
}

if (typeof v1.value === 'number' && typeof v2.value === 'number') {
return v1.value - v2.value;
}
return 0;
},
};
}

Expand Down
Loading