Skip to content

Serialize Skills Sort Field/Direction#531

Merged
Reetus merged 2 commits intomasterfrom
serialize-skill-sort
Nov 9, 2025
Merged

Serialize Skills Sort Field/Direction#531
Reetus merged 2 commits intomasterfrom
serialize-skill-sort

Conversation

@Reetus
Copy link
Owner

@Reetus Reetus commented Nov 9, 2025

Summary by CodeRabbit

  • New Features
    • Skills grid columns are now sortable by clicking column headers.
    • Repeated header clicks toggle sort direction between ascending and descending.
    • Sorting preferences are automatically saved and restored on next app load.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 9, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Refactors Skills tab sorting from code-behind to a new WPF behavior. Adds SkillsGridViewSortBehaviour and SkillsSortInfo, moves sort state and persistence into SkillsTabViewModel, updates XAML to use the behavior, and removes the previous header-click sorting logic from the control's code-behind.

Changes

Cohort / File(s) Summary
New Behavior Implementation
ClassicAssist/UI/Misc/Behaviours/SkillsGridViewSortBehaviour.cs
Adds a public WPF behavior that handles GridView column header clicks, determines/toggles sort direction, finds the associated SkillsGridViewColumn, applies SortDescription and a SkillComparer to the ListCollectionView, and exposes command hooks (SetSortCommand, SortChangedCommand, SetSortCommandImpl). Includes attach/detach header wiring and null/guard checks.
Sort Data Class
ClassicAssist/UI/Misc/Behaviours/SkillsGridViewSortBehaviour.cs
Adds public SkillsSortInfo class encapsulating SortBy (SkillsGridViewColumn.Enums) and Direction (ListSortDirection) with a constructor and read-only properties.
ViewModel: Sort State & Persistence
ClassicAssist/UI/ViewModels/SkillsTabViewModel.cs
Adds SetSortCommand public property and SortChangedCommand (RelayCommand) with _sortInfo internal state and OnSortChanged handler. Serialises SkillsSort into JSON when present and deserialises/restores saved SkillsSort on load, invoking the sort flow after restoration.
View: Behavior Binding
ClassicAssist/UI/Views/SkillsTabControl.xaml
Adds XAML namespace mappings for behaviours and attaches SkillsGridViewSortBehaviour to the ListView with SortChangedCommand and SetSortCommand bindings; removes previous GridView header click handler and the ListView x:Name attribute.
Code-behind: Removal of Old Sorting
ClassicAssist/UI/Views/SkillsTabControl.xaml.cs
Removes header-click handler and sorting methods (GridViewHeaderOnClick, Sort), related private fields (_lastHeaderClicked, _lastDirection) and unused usings; leaves constructor only.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor User
    participant Header as GridView Header
    participant Behaviour as SkillsGridViewSortBehaviour
    participant VM as SkillsTabViewModel
    participant LCV as ListCollectionView

    User->>Header: Click column header
    Header->>Behaviour: Header click event
    Behaviour->>Behaviour: Resolve SortField & compute direction (toggle if same)
    Behaviour->>Behaviour: Locate SkillsGridViewColumn by SortField
    Behaviour->>LCV: Apply SortDescription & SkillComparer (update view)
    Behaviour->>VM: Execute SortChangedCommand (pass SkillsSortInfo)
    VM->>VM: Update internal _sortInfo and persist to JSON
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Check behavior attach/detach and event-handling edge cases (null targets, non-GridView).
  • Verify correctness of SortField lookup and SkillComparer usage.
  • Validate ViewModel serialization/deserialization and that restored sort triggers UI sorting.
  • Confirm XAML command bindings and removal of code-behind sorting left no regressions.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main objective of the pull request: adding serialization and deserialization of skill sort field and direction state across the SkillsTabViewModel and supporting behaviour classes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between abe5db8 and 0e054af.

📒 Files selected for processing (1)
  • ClassicAssist/UI/Misc/Behaviours/SkillsGridViewSortBehaviour.cs (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between caef415 and abe5db8.

📒 Files selected for processing (4)
  • ClassicAssist/UI/Misc/Behaviours/SkillsGridViewSortBehaviour.cs (1 hunks)
  • ClassicAssist/UI/ViewModels/SkillsTabViewModel.cs (6 hunks)
  • ClassicAssist/UI/Views/SkillsTabControl.xaml (2 hunks)
  • ClassicAssist/UI/Views/SkillsTabControl.xaml.cs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
ClassicAssist/UI/ViewModels/SkillsTabViewModel.cs (2)
ClassicAssist/UI/Misc/Behaviours/SkillsGridViewSortBehaviour.cs (2)
  • SkillsSortInfo (133-143)
  • SkillsSortInfo (135-139)
ClassicAssist/UI/Misc/SkillsGridViewColumn.cs (1)
  • SkillsGridViewColumn (6-26)
ClassicAssist/UI/Misc/Behaviours/SkillsGridViewSortBehaviour.cs (2)
ClassicAssist/UI/Misc/SkillsGridViewColumn.cs (1)
  • SkillsGridViewColumn (6-26)
ClassicAssist.Shared/UI/Behaviours/GridViewSort.cs (2)
  • GridViewSort (31-93)
  • ClassicAssist (29-94)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build

Comment on lines +126 to +128
dataView.SortDescriptions.Clear();
dataView.SortDescriptions.Add( new SortDescription( column.Header.ToString(), direction ) );
dataView.CustomSort = new SkillComparer( direction, column.SortField );
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Stop deriving the sort key from the header text

column.Header.ToString() yields captions such as "+/-" (see ClassicAssist/UI/Views/SkillsTabControl.xaml Line 74) and other localised strings, but ListCollectionView.SortDescriptions.Add requires an actual property identifier. Clicking the "+/-" column now throws an ArgumentException because there is no property named "+/-" on SkillEntry. Please drive the sort description from a real property name (e.g. map the enum to the underlying property) or drop the SortDescriptions.Add call and rely solely on CustomSort, so users can sort the delta/status columns without crashing the tab.

-            dataView.SortDescriptions.Add( new SortDescription( column.Header.ToString(), direction ) );
🤖 Prompt for AI Agents
In ClassicAssist/UI/Misc/Behaviours/SkillsGridViewSortBehaviour.cs around lines
126-128, the code builds a SortDescription using column.Header.ToString() which
can be UI text like "+/-" and causes ArgumentException; replace that by using a
real property identifier: if column.SortField (or an equivalent property name)
is non-empty and corresponds to a SkillEntry property, add the SortDescription
with that name, otherwise skip adding SortDescriptions entirely and rely solely
on dataView.CustomSort = new SkillComparer(direction, column.SortField); ensure
you clear SortDescriptions first as before and only call SortDescriptions.Add
when the SortField is valid.

@Reetus Reetus merged commit f49b039 into master Nov 9, 2025
0 of 2 checks passed
@Reetus Reetus deleted the serialize-skill-sort branch November 9, 2025 16:16
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 9, 2025

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.

1 participant