Skip to content

Add sort plugin for managing orderable entities#309

Open
dswbx wants to merge 3 commits intomainfrom
feat/sort-plugin
Open

Add sort plugin for managing orderable entities#309
dswbx wants to merge 3 commits intomainfrom
feat/sort-plugin

Conversation

@dswbx
Copy link
Contributor

@dswbx dswbx commented Nov 26, 2025

This PR introduces a new plugin that enables automatic position management for sortable entities with support for scoped sorting.

Features:

  • Automatic position assignment on insert (starting from 0)
  • Automatic reordering when positions are updated
  • Scoped sorting (e.g., sort within categories or projects)
  • API endpoints for manual reordering and recalculation
  • Batch recalculation support for large datasets

Usage:

import { sort } from "bknd/plugins";

const app = createApp({
  plugins: [
    sort({
      entities: {
        tasks: {
          field: "position",
          scope: "project_id", // optional
        },
      },
    }),
  ],
});

The plugin automatically adds the sort field to configured entities and creates two API endpoints per entity:

  • POST /api/sort/{entity}/reorder - move an item to a new position
  • POST /api/sort/{entity}/recalculate - recalculate all positions (useful for cleanup)

When a scope field is specified, sorting only happens within items that share the same scope value.

- Introduced a new sort plugin that allows sorting of entities based on a specified field.
- Added API endpoints for reordering items and recalculating sort order.
- Implemented tests to ensure correct functionality of sorting and reordering features.
@dswbx dswbx changed the base branch from main to release/0.20 November 26, 2025 09:10
Base automatically changed from release/0.20 to main January 9, 2026 13:32
@cameronapak
Copy link
Collaborator

Where do you feel the status of this PR is?

@dswbx
Copy link
Contributor Author

dswbx commented Feb 11, 2026

in my shallow tests it worked good, but it would need more testing :)

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.

2 participants