Skip to content

fix: use natural sort for caseInsensitiveSort to handle numbers#2380

Merged
meteyou merged 1 commit intomainsail-crew:developfrom
meteyou:fix/filament-sensor-sort
Jan 11, 2026
Merged

fix: use natural sort for caseInsensitiveSort to handle numbers#2380
meteyou merged 1 commit intomainsail-crew:developfrom
meteyou:fix/filament-sensor-sort

Conversation

@meteyou
Copy link
Member

@meteyou meteyou commented Jan 6, 2026

Description

This PR fixes the sorting of items with numeric suffixes (e.g., "Mmu Pre Gate 0", "Mmu Pre Gate 1", ..., "Mmu Pre Gate 10") by implementing natural sort in caseInsensitiveSort.

Previously, items were sorted alphabetically, causing "Mmu Pre Gate 10" to appear before "Mmu Pre Gate 2" because string comparison treats "10" < "2" (comparing character by character).

Whats in this PR:

  • Refactored caseInsensitiveSort to use localeCompare with numeric: true option
  • Added TypeScript generics for better type safety and key autocompletion
  • Extended function signature to support multiple sort keys via rest parameters
  • Updated getMiscellaneousSensors getter to use the improved helper function

Before:

  • Mmu Pre Gate 0
  • Mmu Pre Gate 1
  • Mmu Pre Gate 10
  • Mmu Pre Gate 2
  • ...

After:

  • Mmu Pre Gate 0
  • Mmu Pre Gate 1
  • Mmu Pre Gate 2
  • ...
  • Mmu Pre Gate 10

Related Tickets & Documents

Mobile & Desktop Screenshots/Recordings

n/a

[optional] Are there any post-deployment tasks we need to perform?

n/a

…xes correctly

Signed-off-by: Stefan Dej <meteyou@gmail.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the alphabetical sorting issue for items with numeric suffixes (e.g., "Mmu Pre Gate 10" appearing before "Mmu Pre Gate 2") by implementing natural sort in the caseInsensitiveSort utility function.

Key Changes:

  • Refactored caseInsensitiveSort to use localeCompare with numeric: true for natural number ordering
  • Enhanced the function with TypeScript generics and variadic parameters for multi-key sorting
  • Simplified the getMiscellaneousSensors getter implementation by leveraging the improved helper

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/plugins/helpers.ts Enhanced caseInsensitiveSort with TypeScript generics, natural sort via localeCompare, and multi-key support using rest parameters
src/store/printer/getters.ts Replaced verbose multi-level sorting logic with a single call to the improved caseInsensitiveSort helper

@meteyou meteyou added this to the v2.17.0 milestone Jan 7, 2026
@meteyou meteyou merged commit 765702a into mainsail-crew:develop Jan 11, 2026
12 checks passed
@meteyou meteyou deleted the fix/filament-sensor-sort branch January 11, 2026 12:18
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.

Feature request : sort using a natural sort to fix mmu gates sensors order

3 participants