-
Notifications
You must be signed in to change notification settings - Fork 79
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
LF-4415 Animals IDs not sorted in order #3541
base: integration
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Tbrid thanks for doing this one!
I am not quite sure I know what is the expected order... so I will ask some questions on the Jira ticket.
I think the length check works well specifically for the ID##'s but because the names are sometimes chosen as an identifier it is no longer quite alphabetical but based on length for those ones. The Del 6 in my picture must have been randomly sorted based on chance.
I will tag design who might have an opinion too just to get clarification.
…s-nor-sorted-in-correct-order
if (a.identification.length > b.identification.length) { | ||
return 1; | ||
} else { | ||
return a.identification.localeCompare(b.identification); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Tbrid thank you so much for contributing!!
Unfortunately I don't think this portion of the sorting function is correct, and in testing it I'm not getting the right sorting order. On one hand, we shouldn't be using the identification
property to sort since that's a string that can be either the name, the identifier or the internal identifier, but in this case we want to sort granularly, one property at the time, so we'll need to pass identifier
and internal_identifier
and use them to compare. On the other hand, I'm not sure I understand the reasoning behind comparing the length of the strings?
I think this is more or less what the function could look like
return inventory.sort((a, b) => {
if (a.name && !b.name) {
return -1;
}
if (b.name && !a.name) {
return 1;
}
if (a.identifier && !b.identifier) {
return -1;
}
if (b.identifier && !a.identifier) {
return 1;
}
return (
(a.name && b.name && a.name.localeCompare(b.name)) ||
(a.identifier && b.identifier && a.identifier.localeCompare(b.identifier)) ||
a.internal_identifier - b.internal_identifier
);
});
but I haven't tested it thoroughly!
If you have the time, a good idea could be to add some unit tests to verify that it's working properly. Otherwise we can just test it manually and make sure it works with a variety of records.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get that the length check was for the internal_identifier string that includes 'ID###' .
If the identification
property is no longer used here (it is just for label display now) then it should be a plain number as Anto described 👍
@@ -242,7 +261,7 @@ export const buildInventory = ({ | |||
), | |||
]; | |||
|
|||
const sortedInventory = inventory.sort(getComparator(orderEnum.ASC, 'identification')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for taking care of this!
getComparator
function is used for sorting when clicking the "IDENTIFICATION" column title, and I think the same logic needs to be applied there too.
Description
Fix the issue of animals IDs not sorted in ascending order in the inventory page.
Jira link: https://lite-farm.atlassian.net/browse/LF-4415
Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Checklist: