8000 Fix #6563: Fixed In Transit Sorting in Warehouse Tab by IllianiBird · Pull Request #6585 · MegaMek/mekhq · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix #6563: Fixed In Transit Sorting in Warehouse Tab #6585

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

Merged
merged 4 commits into from
Apr 11, 2025

Conversation

IllianiBird
Copy link
Collaborator
  • Implemented a new StringAndThenNumberSorter comparator to handle sorting of strings with embedded numeric values.
  • Updated WarehouseTab to use StringAndThenNumberSorter for the COL_STATUS column in the parts table.
  • Enhanced sorting behavior to properly order entries with mixed alphanumeric content, i.e. In Transit (6 days) will appear before In Transit (10 days), but both will appear after Functional.

Fix #6563

Dev Notes

RegEx is freakin' sorcery, I swear.

I stole this pattern from the internet so don't ask me how it works, I just know it does.

- Implemented a new `StringAndThenNumberSorter` comparator to handle sorting of strings with embedded numeric values.
- Updated `WarehouseTab` to use `StringAndThenNumberSorter` for the `COL_STATUS` column in the parts table.
- Enhanced sorting behavior to properly order entries with mixed alphanumeric content, i.e. `In Transit (6 days)` will appear before `In Transit (10 days)`, but both will appear after `Functional`.
@IllianiBird IllianiBird added GUI UX User experience labels Apr 7, 2025
@IllianiBird IllianiBird self-assigned this Apr 7, 2025
Copy link
codecov bot commented Apr 7, 2025

Codecov Report

Attention: Patch coverage is 0% with 20 lines in your changes missing coverage. Please review.

Project coverage is 11.43%. Comparing base (f2af508) to head (f5829de).
Report is 67 commits behind head on master.

Files with missing lines Patch % Lines
...HQ/src/mekhq/gui/sorter/WarehouseStatusSorter.java 0.00% 19 Missing ⚠️
MekHQ/src/mekhq/gui/WarehouseTab.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master    #6585   +/-   ##
=========================================
  Coverage     11.43%   11.43%           
- Complexity     6451     6452    +1     
=========================================
  Files          1087     1088    +1     
  Lines        139451   139468   +17     
  Branches      21560    21563    +3     
=========================================
+ Hits          15943    15951    +8     
- Misses       121916   121923    +7     
- Partials       1592     1594    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines 65 to 68
*/
private static final Pattern NUMBER_PATTERN = Pattern.compile("(\\d+|\\D+)");

/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pattern is incorrect. that will match all numbers and non-numbers.

To match all numbers it is \d+ (or for that variation \\d+)

Copy link
Collaborator

Choose a reason for hiding this comment

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

If it's only displayed in days, the \\d+ will work. Otherwise you'll need to adjust it to be \\(((\\d+) (\\D+)\\) to capture the number of days AND interval to compare days, weeks, months, years...

Copy link
Collaborator Author
@IllianiBird IllianiBird Apr 7, 2025

Choose a reason for hiding this comment

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

I'm not sure what I need to do here, could you provide a little more information?

For context, the table column uses a mix of both numbers and non-numbers. For example, the column might have 'damaged', 'functional', 'in transit (5 days)', 'in transit (353 days)'. The intention is that it will sort based on letters and then, when it hits a number, start sorting based on that.

Right now, the implementation visually works correctly, but if I move it to \\d+ I run into Comparison method violates its general contract! errors, presumably because I'm left with empty strings to compare because all the non-digits get filtered out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also, if it helps, it only appears in batches of 'days', we don't convert that to months or similar

…ter`.

- Updated the comparator logic sort strings numerically for "day(s)" and alphabetically otherwise.
- Renamed and refactored the sorter to align with its updated functionality and naming conventions.
- Adjusted the `WarehouseTab` to utilize the new `WarehouseStatusSorter`.
@IllianiBird
Copy link
Collaborator Author
  • Replaced StringAndThenNumberSorter with a new WarehouseStatusSorter.
  • Updated the comparator logic sort strings numerically for "day(s)" and alphabetically otherwise.
  • Renamed and refactored the sorter to align with its updated functionality and naming conventions.
  • Adjusted the WarehouseTab to utilize the new WarehouseStatusSorter.

… methods and class were introduced.

- Included `@author Illiani` annotations for proper attribution.
Copy link
Collaborator
@psikomonkie psikomonkie left a comment

Choose a reason for hiding this comment

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

Nice!

I think I prefer c872c04. While both currently work, I think the older commit version would be more robust. The older commit implementation will natively support translations as long as it follows the pattern of . The older commit implementation will better support if a second warehouse part status gets "days" added to it, like days remaining for repairing something broken. I know this contradicts what we discussed yesterday but after comparing the two and taking translation support more seriously I think the original commit will be more robust.

Does anyone else have any thoughts on this?

*
* <p>Matches strings like "(5 days)" or "(1 day)" and captures the numeric part.</p>
*/
private static final Pattern DAYS_PATTERN = Pattern.compile("\\((\\d+)\\s*day(s)?\\)");
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can make a group a "non-capturing" group by starting it with ?: day(?:s)?. Though in this case you don't need the capture group at all, you should get the same result with days?.

@IllianiBird
Copy link
Collaborator Author

Does anyone else have any thoughts on this?

@IllianiBird IllianiBird merged commit b5fc92d into MegaMek:master Apr 11, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI UX User experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Issue] Leading 0's needed in delivery times to sort correctly 01,02,03 days vs 1,20,2,35,37,38,3 days
3 participants
0