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 280 model select sorting #283

Merged
merged 7 commits into from
Oct 10, 2024
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
dist
node_modules

.env*
.DS_Store
src/.DS_Store
.npmrc
9 changes: 8 additions & 1 deletion src/components/trays/model-selection/catalogItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ export default function CatalogItems(data) {
}
// return all the data cards
else {
// get the sorting parameter
const sortParam = (data.isTropical) ? 'advisory_number' : 'cycle';

// simple sort comparer for more than 1 level of strings
const compare = (x, y) => (x > y) - (x < y);

// render the results of the data query
return (
<Fragment>
Expand All @@ -172,7 +178,8 @@ export default function CatalogItems(data) {
// filter by the group name, get the top 1
.filter((val, idx, self) =>
( idx === self.findIndex((t)=> ( t['group'] === val['group']) )))
.sort((a, b) => a.properties['product_name'] < b.properties['product_name'] ? -1 : 1)
.sort((a, b) => compare(b.properties[sortParam], a.properties[sortParam]) || compare(a.properties['event_type'], b.properties['event_type']))
//((b.properties[sortParam] + b.properties['event_type']).localeCompare(a.properties[sortParam] + a.properties['event_type'])))
// output summarized details of each group member
.map((mbr, mbrIdx) => (
// create the checkbox
Expand Down