Skip to content

fix: Indexing calculation#88

Merged
dkorecko merged 2 commits intomainfrom
fix/another-indexing-issue
Aug 1, 2025
Merged

fix: Indexing calculation#88
dkorecko merged 2 commits intomainfrom
fix/another-indexing-issue

Conversation

@dkorecko
Copy link
Copy Markdown
Owner

@dkorecko dkorecko commented Aug 1, 2025

Summary by CodeRabbit

  • New Features
    • Cards and columns now have unique identifiers in their HTML markup, improving accessibility and tracking.
  • Improvements
    • Drag-and-drop reordering now uses item IDs instead of index positions, resulting in more accurate and reliable card and column movement.
    • Enhanced handling of moves between columns, including checks for column capacity and clearer notifications.
    • Expanded debug logging for drag-and-drop operations to aid troubleshooting.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 1, 2025

Walkthrough

The changes transition the drag-and-drop logic for cards and columns from index-based tracking to ID-based tracking across the frontend and backend. In the Blazor components, event callback signatures and handler methods now use moved and target item IDs instead of integer indices. The JavaScript interop logic is updated to extract and pass element IDs during drag-and-drop events, and debug logging is enabled. The BoardView logic is refactored to use IDs for item movement, updating index calculations and ensuring order consistency. Additionally, HTML markup for cards and columns is updated to include unique ID attributes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • The review involves verifying correctness in event signature changes, JavaScript-to-.NET interop, and the new ID-based reordering logic, as well as ensuring markup and index updates are consistent. The changes span several files but are focused and systematic, representing a moderate review effort.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between cf2fd44 and 86016d3.

📒 Files selected for processing (1)
  • Ticky.Web/Components/Elements/Sortable/SortableList.razor.js (4 hunks)
⏰ 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: Analyze (csharp)
🔇 Additional comments (3)
Ticky.Web/Components/Elements/Sortable/SortableList.razor.js (3)

2-2: Debug mode properly disabled.

Good fix! Debug mode is now disabled by default, addressing the previous production concern.


66-98: Well-structured ID-based implementation for cross-container moves.

The onRemove handler correctly implements ID-based tracking for cross-container drag operations. The approach of getting the moved card from the destination container (customToChildNodes[event.newIndex]) is appropriate since the element has moved containers.

Add bounds checking to prevent potential array access errors:

-            let movedCard = customToChildNodes[event.newIndex]
+            let movedCard = customToChildNodes[event.newIndex]
+            if (!movedCard) {
+                console.error('Failed to find moved card at index', event.newIndex);
+                return;
+            }

Also verify that the ID extraction will always succeed by checking if all sortable elements have required ID attributes.


25-64: Draggable item IDs confirmed – no further changes needed

Our search across all .razor files shows:

  • SortableList.razor defines id="@Id" on the list container
  • CardView.razor defines id="@Card.Id" on each card
  • There are no duplicate declarations of these IDs in the codebase

All draggable elements will therefore have unique id attributes, and the onUpdate handler’s ID‐based logic can safely rely on event.item.id.


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@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: 2

🔭 Outside diff range comments (3)
Ticky.Web/Components/Pages/BoardView.razor (3)

312-355: Review ID conversion and error handling.

The method correctly implements ID-based reordering, but there are potential issues with type conversion and error handling.

Consider adding error handling for ID conversions and validating the converted IDs:

 private async Task OnMovedWithinList((string movedCardId, string? targetCardId, string columnId) args)
 {
+    if (!int.TryParse(args.movedCardId, out int movedCardIdInt))
+    {
+        // Log error and return
+        return;
+    }
+    
     using var db = _dbContextFactory.CreateDbContext();
 
     var targetColumn = db.Columns
         .Include(x => x.Cards)
         .FirstOrDefault(x => x.Id.Equals(GetColumnIdFromString(args.columnId)));
 
     if(targetColumn is null)
         return;
 
-    var movedCard = targetColumn.Cards.OrderBy(x => x.Index).FirstOrDefault(x => x.Id.Equals(Convert.ToInt32(args.movedCardId)));
+    var movedCard = targetColumn.Cards.OrderBy(x => x.Index).FirstOrDefault(x => x.Id.Equals(movedCardIdInt));

357-401: Apply same error handling improvements for column reordering.

Similar to the card reordering method, this needs better error handling for ID conversions.

 private async Task OnColumnMoved((string movedItemId, string? targetItemId, string _) args)
 {
+    if (!int.TryParse(args.movedItemId, out int movedColumnIdInt))
+        return;
+        
     using var db = _dbContextFactory.CreateDbContext();
     
     // ... rest of the method with proper error handling

403-468: Apply consistent error handling for cross-column moves.

The method implements the logic correctly but needs the same error handling improvements as the other methods.

Consider adding proper error handling for all ID conversions and validating that the converted IDs exist in the database before proceeding with the operations.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 3d785c2 and cf2fd44.

📒 Files selected for processing (4)
  • Ticky.Web/Components/Elements/CardView.razor (1 hunks)
  • Ticky.Web/Components/Elements/Sortable/SortableList.razor.cs (2 hunks)
  • Ticky.Web/Components/Elements/Sortable/SortableList.razor.js (4 hunks)
  • Ticky.Web/Components/Pages/BoardView.razor (5 hunks)
⏰ 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: Analyze (csharp)
🔇 Additional comments (11)
Ticky.Web/Components/Elements/CardView.razor (1)

3-3: LGTM! ID attribute addition supports the new ID-based drag-and-drop system.

The addition of id="@Card.Id" to the card container is essential for the transition from index-based to ID-based drag-and-drop tracking. This provides the unique identifier needed by the JavaScript interop layer.

Ticky.Web/Components/Elements/Sortable/SortableList.razor.cs (4)

35-42: LGTM! Event callback signature improved for ID-based tracking.

The transition from integer indices to string IDs with nullable targetItemId is a solid improvement that makes drag-and-drop operations more reliable and precise.


45-49: LGTM! OnUpdate callback signature consistently updated.

The signature change aligns with the OnRemove callback and maintains consistency across the component.


75-85: LGTM! JavaScript interop method updated correctly.

The OnRemoveJS method signature and parameter passing are updated consistently with the new ID-based approach.


88-91: LGTM! OnUpdateJS method signature updated correctly.

The method signature and invocation are properly aligned with the new ID-based callback parameters.

Ticky.Web/Components/Elements/Sortable/SortableList.razor.js (3)

27-31: Review the early return logic for single child nodes.

The early return when there's only one child node might prevent valid moves. This could occur when moving the last remaining item in a list or in other edge cases where the move is actually valid.

Consider removing this check or adding more specific conditions to ensure valid moves aren't blocked:

-            if (customChildNodes.length === 1) {
-                if (DEBUG_MODE)
-                    console.log('ignoring move because moved into the same place')
-                return
-            }

64-64: LGTM! Backend method call updated correctly.

The call to OnUpdateJS properly passes the new ID-based parameters instead of indices.


98-98: LGTM! OnRemoveJS call updated correctly.

The method call properly passes the ID-based parameters, maintaining consistency with the backend changes.

Ticky.Web/Components/Pages/BoardView.razor (3)

69-69: LGTM! Column ID attribute added for drag-and-drop support.

The addition of id="@column.Id" is necessary for the ID-based drag-and-drop system and aligns with the changes in other components.


328-347: LGTM! Index calculation logic is correct.

The logic for calculating target indices and adjusting existing card indices is well-implemented. It properly handles both cases where a target card exists and where the item is moved to the end of the list.


421-425: LGTM! Column capacity validation added.

The check for column capacity is an excellent addition that prevents moving cards into full columns and provides appropriate user feedback.

@dkorecko dkorecko merged commit 993591b into main Aug 1, 2025
5 checks passed
@dkorecko dkorecko deleted the fix/another-indexing-issue branch August 1, 2025 14:34
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