Skip to content

Fix reordering when tags are treated as categories - #1594

Merged
KodeStar merged 3 commits into
2.xfrom
fix/reorder-categories
Aug 28, 2026
Merged

Fix reordering when tags are treated as categories#1594
KodeStar merged 3 commits into
2.xfrom
fix/reorder-categories

Conversation

@KodeStar

Copy link
Copy Markdown
Member

Fixes #1591

What

With "treat tags as" set to categories, the dashboard renders .category blocks with the items nested inside them. The single Sortable instance on #sortable was configured with draggable: .item-container, which only matches direct children, so in categories mode nothing was draggable at all and the reorder button appeared to do nothing.

Fix

  • Create one Sortable for the categories (dragged via their title bar, which gets a category-title class to act as the handle) plus one per category for the items inside it.
  • Each instance posts its own toArray() to /order; setOrder already treats tags and apps the same way (both are Item rows with an order column), so no backend change is needed.
  • The config-mode toggle now enables/disables every instance instead of a single one.
  • Folders/tags modes are unchanged (still one instance on #sortable).

Tests

  • New DashTest::test_categories_mode_renders_sortable_category_and_item_markup guards the markup the JS depends on (container class, category data-id, the drag-handle class, item data-id).
  • Full suite green locally, eslint clean.

Note on the bundle

public/js/app.js was rebuilt with npx mix. The diff is larger than the source change because the committed bundle was built against sortablejs 1.15.2 while package-lock.json pins 1.15.6; this brings it in line with the lockfile. CSS output was left untouched.

In categories mode the dashboard renders category blocks (.category) with
the items nested inside them, but the single Sortable instance on #sortable
only knew about direct .item-container children, so nothing was draggable
and the reorder button did nothing.

Create one Sortable for the categories themselves (dragged by their title
bar) plus one per category for the items inside it. Every instance posts
its own order to /order, which already handles tags and apps alike. The
config-mode toggle now enables/disables all instances.

public/js/app.js is rebuilt with 'npx mix'; the diff also picks up the
lockfile's sortablejs 1.15.6, which the committed bundle was behind on.

Fixes #1591
- Detect categories mode by the presence of .category blocks instead of
  the CSS hook class, and build the item sortables from one code path
  for both modes.
- Drag categories by '.category > .title' (the selector the stylesheet
  already uses) rather than adding a marker class to the markup.
- Narrow createSortable to the two options that vary, share one onEnd
  via Sortable.get(evt.to), and note why the item sortables have no
  group.
- Reuse the DashTest helpers for tag/item creation and assert only the
  ids Sortable posts.
- The category drag handle is the title bar, whose only content is a
  link. Anchors are natively draggable, so on Firefox (native DnD) the
  dragstart source was the link and the existing anchor guard cancelled
  the drag. Mark the link draggable="false" so the .category block is
  the drag source.
- setOrder used array_filter with no callback, which dropped id 0 - the
  home dashboard tag, now a valid category to reorder - and would 500 on
  an id that no longer exists. Filter blanks only and skip missing ids.
- Only pass a handle option when one is set.
- Tests: /order with the home tag and with a stale id; the categories
  view renders the item inside its category and the non-draggable link.
@KodeStar

Copy link
Copy Markdown
Member Author

Review note, not addressed in this PR: items and tags share the single items.order column, so reordering apps inside one category also changes the position of any app that is tagged into several categories, and reordering categories writes tag order values that the tags/default modes also sort on. That is pre-existing data-model behaviour (per-category ordering would need an order on the item_tag pivot); this PR only makes the drag UI work in categories mode.

@KodeStar
KodeStar merged commit bc5d2bb into 2.x Aug 28, 2026
1 check passed
@LinuxServer-CI LinuxServer-CI moved this from PRs to Done in Issue & PR Tracker Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

Unable to reorder tiles when tags are set to categories

2 participants