Skip to content

Add drag and drop reordering for included posts - #187

Open
ryanwelcher wants to merge 1 commit into
trunkfrom
ryanwelcher/included-posts-add-drag-and-drop-reordering
Open

ryanwelcher wants to merge 1 commit into
trunkfrom
ryanwelcher/included-posts-add-drag-and-drop-reordering

Conversation

@ryanwelcher

Copy link
Copy Markdown
Owner

What

Lets you set the order of manually included posts. Fixes #63 (from this support forum topic).

In AQL: Post → Include posts, the token field is now used for search only. Picked posts appear in a list below it, and each row has:

  • a drag handle (drag the row to reorder)
  • up/down buttons, the keyboard way to reorder (focus stays on the button and the move is announced with speak())
  • a remove button

With two or more included posts, the help text says to set Order By to Included Posts if it isn't already. Nothing switches automatically. Search results no longer suggest posts that are already in the list.

Exclude posts is unchanged.

Why

post__in ordering already worked on the server, but FormTokenField can only add and remove tokens, so there was no way to change the order in the editor.

Notes

  • Built with @wordpress/components only (ItemGroup, Item, HStack, Truncate, Button), so it works back to WP 6.7. @wordpress/ui was ruled out: it needs the wp-theme script and a wp-private-apis opt-in that only exist in WP 7.0+, so the editor script would not load on 6.7 to 6.9.
  • The four icons are local copies in src/components/icons.js, built from @wordpress/primitives. The @wordpress/icons npm package pulls in React 19, which gets bundled under @wordpress/scripts 24 and crashes the editor.
  • No PHP or saved data changes. include_posts keeps its {id, title} shape.

Testing

New e2e spec tests/e2e/tests/include-posts-order.spec.ts (6 tests, all passing locally):

  • picked posts are added to the end of the list and aren't suggested again
  • move buttons reorder posts (first up and last down are disabled)
  • remove button removes only that post
  • dragging a row reorders posts
  • help text points to the Included Posts order
  • the frontend shows the posts in the chosen order

Manual check in the editor: add three posts, reorder with drag and with the buttons, set Order By to Included Posts, and check the preview and frontend.

Included posts are now listed below the search field as a sortable list.
Rows can be dragged, or moved with up/down buttons (focus stays on the
button and the move is announced). Each row has a remove button. When
there are two or more posts and Order By is not "Included Posts", the
help text says to set it. Exclude posts is unchanged.

Built with @wordpress/components only, so it works back to WP 6.7. The
icons are local copies built from @wordpress/primitives because the
@wordpress/icons package bundles React 19 under @wordpress/scripts 24.

Adds e2e tests for adding, moving, removing, dragging, the help text,
and the frontend order.

Fixes #63
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.

Included Posts: Add drag and drop reordering

1 participant