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

Feature/sort datasets #74

Merged
merged 8 commits into from
Oct 11, 2021
Merged

Feature/sort datasets #74

merged 8 commits into from
Oct 11, 2021

Conversation

meganrm
Copy link
Contributor

@meganrm meganrm commented Oct 6, 2021

Problem

closes: https://aicsjira.corp.alleninstitute.org/browse/CFE-102

Solution

I'm currently sorting them by reverse alphabetical order and by version within dataset name. I thought about using the "isNew" to sort by, but it seems breakable since that's a user defined category. Plus we need to group the datasets by being members of one megaset, and only show the most recent version of each dataset, with the option to load earlier versions, which will both change this code. I added notes to this effect in the selector itself. This solves the temporary problem of getting the datasets in the correct order, but there are a lot of things up in the air and I didn't want to over engineer this just to change it later.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires updated or new tests

Steps to Verify:

  1. npm start
  2. the cards are now in reverse order

Screenshots (optional):

Uploading Screen Shot 2021-10-05 at 5.13.55 PM.png…

// sort function to get the newest datasets on top
if (a.name === b.name) {
// if it's the same dataset, return the newest version first
if (a.version > b.version) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because version numbers are strings and can be SemVer or CalVer or whateVer, we are probably going to need some better way of doing this comparison. For example, does 2021.10 vs 2021.1 break this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it would, i can fix that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have any great ideas for this except for keeping an internal autoincremented single integer... or having the data creators specify what ordering they want. We rely on the data creators to consistently enforce their own preferred versioning scheme... I guess you could split on "." and hope for the best.

Copy link
Contributor Author

@meganrm meganrm Oct 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I don't think this PR will cover all cases, it's even only ordering the correct dataset group first because it's just reversed alphabetized. Firebase does have time stamps too, so we could keep them ordered by last updated, however, that only works once we have more concrete ways of grouping mega sets together and grouping versions of the same name into one card

Comment on lines 41 to 52
if (a.version > b.version) {
return -1;
} else {
return 1;
}
// otherwise sort by name
} else if (a.name > b.name){
return -1;
} else if (a.name < b.name) {
return 1;
} else {
return 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sorting function has always been kinda confusing for me, but is it possible to just write return a.version - b.version instead of the if-else statements returning -1, 1, and 0, and just write return a.name - b.name under // otherwise sort by name?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be return b.version - a.version for newest first? Anyway you see what I'm trying to say.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, so i've updated it based on Dan's comment, but you're right, I am now comparing numbers so I could just subtract them instead of doing a comparison, that will reduce the number of checks I have to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I miss read this comment a bit. For string comparisons you can't subtract them, this comparison is a pseudo alphabetical sort, mostly I just want the same names grouped together.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the sort function, let me know what you think

if (!patchA || !patchA || patchA === patchB) {
if (minorANum === minorBNum) {
// if minor versions are also equal, check patch number
if (patchA === patchB) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] I don't think lines 42-44 are necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I removed them already. You were just too fast on the review :)

@meganrm meganrm requested a review from toloudis October 8, 2021 19:13
expect(resultDoubleDigit).to.be.lessThan(0);
});
it("returns negative if the patch version of the first item is greater", () => {
const result = compareVersions("2020.2.2", "2020.1.0");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this test be 2020.2.2 vs 2020.2.0 ? the minor version is different, preventing the patch version from being tested

@meganrm meganrm merged commit 11b1536 into main Oct 11, 2021
@meganrm meganrm deleted the feature/sort-datasets branch October 11, 2021 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants