Skip to content

feat: use due date as secondary key for priority sorting - #665

Open
Neo-matrix-coder wants to merge 1 commit into
CCExtractor:mainfrom
Neo-matrix-coder:feature/priority-secondary-sort
Open

Neo-matrix-coder wants to merge 1 commit into
CCExtractor:mainfrom
Neo-matrix-coder:feature/priority-secondary-sort

Conversation

@Neo-matrix-coder

@Neo-matrix-coder Neo-matrix-coder commented Oct 25, 2026 •

Copy link
Copy Markdown

Description

When sorting tasks by priority, tasks sharing the same priority level were previously ordered arbitrarily (or solely based on how they were fetched/inserted).

This PR enhances priority-based sorting across the app by introducing due date as a secondary sorting key:

  • Tasks with the same priority (H, M, L, or none) are now broken down by due date in ascending order (earlier due dates appear first).
  • Tasks with an assigned due date take precedence over tasks without a due date within the same priority bracket.
  • Implemented a consistent _priorityRank severity mapping (H > M > L > unassigned) across the task views and comparator functions.
  • Updated both TaskViewBuilder and TaskReplicaViewBuilder as well as HomeController to maintain consistent sorting behavior everywhere tasks are displayed.

Changes Summary:

  1. lib/app/utils/taskfunctions/comparator.dart:
    • Added _priorityRank and _compareDue helpers.
    • Tied Priority, Priority+, and Priority- comparators to break priority ties using _compareDue.
  2. lib/app/modules/home/views/show_tasks.dart & show_tasks_replica.dart:
    • Integrated _priorityRank and _compareDue into the view sorting switches.
  3. lib/app/modules/home/controllers/home_controller.dart:
    • Ensured Priority column delegates properly to compareTasks.
  4. test/utils/taskfunctions/comparator_test.dart:
    • Added comprehensive unit tests covering:
      • Same priority tie-breaking by due date.
      • Tasks with due dates ordering before tasks without due dates.
      • Safe handling of null priorities and null due dates.
      • Ascending (Priority+) and descending (Priority-) sort consistency.

Fixes #527

Checklist

  • Tests have been added or updated to cover the changes
  • Documentation has been updated to reflect the changes
  • Code follows the established coding style guidelines
  • All tests are passing

Summary by CodeRabbit

  • Bug Fixes
    • Improved priority sorting so high, medium, and low priorities appear in the expected order in both sort directions; other or missing priorities are ranked after them.
    • Tasks with the same priority now sort by due date, with earlier dates first.
    • Due-date sorting handles missing or invalid dates consistently: dated tasks appear first, and tasks without a valid date compare equally.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6be5a55c-2f5a-42ee-8a33-595862712a96
Commits

Reviewing files that changed from the base of the PR and between 05f7c0c and 783ff92.

Files selected for processing: 5
  • lib/app/modules/home/controllers/home_controller.dart
  • lib/app/modules/home/views/show_tasks.dart
  • lib/app/modules/home/views/show_tasks_replica.dart
  • lib/app/utils/taskfunctions/comparator.dart
  • test/utils/taskfunctions/comparator_test.dart

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Walkthrough

Priority sorting now ranks H, M, and L, and uses due dates to resolve ties. Due-date comparisons handle missing or invalid dates. The home controller passes the full selected priority sort value to the shared comparator.

Changes: Task sorting

Layer / File(s) Summary
Shared priority comparator and validation
lib/app/utils/taskfunctions/comparator.dart, test/utils/taskfunctions/comparator_test.dart
The shared comparator ranks H, M, and L as 3, 2, and 1. Other and null priorities rank 0. Equal ranks sort by due date, with dated tasks before undated tasks. Tests cover both sort directions, ties, and null priorities.
Home task sorting behavior
lib/app/modules/home/controllers/home_controller.dart, lib/app/modules/home/views/show_tasks.dart, lib/app/modules/home/views/show_tasks_replica.dart
The controller passes the full selected sort value to compareTasks for priority sorting. Both task views use priority ranks and due-date tie-breaks. Due-date sorting handles absent or invalid dates.

Priority: Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Suggested reviewers: nishantsinghal19, brawlerxull, its-me-abhishek

Merge Risk: Minimal · up to 783ff

No issue introduced by this change remains established after the review. The preexisting null-priority rendering failure can be addressed separately.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: using due date as a secondary key for priority sorting.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The pull request description is mostly complete. It includes a detailed summary, the fixed issue number, implementation details, tests, and checklist status. It does not explicitly state whether depen…
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (5 skipped: 5 unsupported.)

Full details: Description check

Explanation

The pull request description is mostly complete. It includes a detailed summary, the fixed issue number, implementation details, tests, and checklist status. It does not explicitly state whether dependencies are required, and it omits the Screenshots section, but these omissions are non-critical for this change.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@Neo-matrix-coder

Copy link
Copy Markdown
Author

@MabudAlam PTAL!!

This branch has not been deployed

No deployments
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.

Improve priority sorting by using due date as secondary key

1 participant