[WIKI-769] chore: added sort order for pages
Description
added sorting of page in project level pages.
Type of Change
- [x] Feature (non-breaking change which adds functionality)
Summary by CodeRabbit
Release Notes
- New Features
- Page sort order now exposed in API responses for improved ordering and management capabilities
- New pages automatically assigned sort order values when created within a project
- Existing pages updated with sort order values during system upgrade to ensure data consistency
βοΈ Tip: You can customize this high-level summary in your review settings.
Walkthrough
This change introduces a sort_order field to ProjectPage for managing page sorting within projects. A database migration populates existing data with robust duplicate-handling logic, the model initializes sort orders for new pages, the view prefetches related data, and the serializer exposes the computed sort order value.
Changes
| Cohort / File(s) | Summary |
|---|---|
Database Schema & Migration apps/api/plane/db/migrations/0113_auto_20251215_0934.py |
Adds sort_order FloatField to ProjectPage with default 65535. Includes set_page_sort_order() function that copies parent sort orders and resolves duplicates by workspace with batched updates. Includes reverse migration reverse_set_page_sort_order(). |
Model Layer apps/api/plane/db/models/page.py |
Adds sort_order FloatField field to ProjectPage. Introduces _set_sort_for_root_page() initialization method and overrides save() to auto-set sort order for new root pages. |
View & Serializer Layer apps/api/plane/app/views/page/base.py, apps/api/plane/app/serializers/page.py |
View adds Prefetch for current-project filtered project_pages relation. Serializer adds sort_order SerializerMethodField with get_sort_order() method that returns prefetched data or DEFAULT_SORT_ORDER fallback. |
Estimated code review effort
π― 4 (Complex) | β±οΈ ~45 minutes
- Migration logic: Batched bulk operations with duplicate detection and per-workspace sort-order reassignment require careful verification
- Model initialization:
_set_sort_for_root_page()logic for computing new sort orders based on project-wide maximums needs validation - Prefetch setup: Confirm filter conditions and relation assumptions in view's
get_queryset() - Serializer fallback: Verify the prefetch relation is always available when accessed in
get_sort_order()
Poem
π° A new sort order hops into place, Pages now dance with numeric grace, Prefetch and serialize, side by side, Duplicates handled with batched pride, Organization's our rabbit delight! π
Pre-merge checks and finishing touches
β Failed checks (2 warnings)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Description check | β οΈ Warning | The description is incomplete. While it identifies the feature and indicates the type of change, it lacks detail on implementation specifics, test scenarios, and references to related issues. | Expand the description to explain how sort order works, add specific test scenarios, and include a reference to issue WIKI-769 linked in the title. |
| Docstring Coverage | β οΈ Warning | Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
β Passed checks (1 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | β Passed | The title accurately describes the main change: adding sort order functionality for pages. It is concise and clearly summarizes the primary modification across the changeset. |
β¨ Finishing touches
- [ ] π Generate docstrings
π§ͺ Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
- [ ] Commit unit tests in branch
chore-page-sort-order
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.
Comment @coderabbitai help to get the list of available commands and usage tips.