Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce feature allowing modifying parent/child relationships. #172

Merged
merged 23 commits into from Jan 22, 2024

Conversation

peterwilsoncc
Copy link
Contributor

@peterwilsoncc peterwilsoncc commented Oct 20, 2023

Description of the Change

Adds row actions to move a page up or down the page hierarchy.

The "Move Out from under Parent Page name" action:

  • modifies the parent of child pages to their grandparent
  • pages without a grandparent are set to top level pages
  • the child tree of the post is unmodified, it moves with the parent.

The "Move Under Page Name" action

  • sets top level pages' parent to the post immediately above it in the list
  • sets existing child pages to be the child of the preceding child post on the same level
  • the child tree of the post is unmodified, it moves with the parent

At the moment this always triggers a full page refresh.

Closes #25.

How to test the Change

  1. Generate some pages with wp post generate --post_type=page
  • these pages will not have a menu_order specified
  • the tests below should work as expected without the menu_order
  1. Click the "Move Under Page Name" action of a page
  2. The post should be made a child of the preceding page in the list
  3. Click "Move Under Page Name" of the page following the page you've already edited.
  4. The second page should be made a child of the same parent
  5. Attempt to move the first page in the list in or out (you'll need to get the action to display via the CSS browser tools), ensure nothing happens to the posts parent setting.
  6. Click "Move Under Page Name" of the final child page in your tree
  7. This should be made a child of the page above it, a grandchild of the previous parent
  8. Click "Move Under Page Name" of the first child page
  9. The entire tree should be move in one. The page you clicked should become a top level page

Changelog Entry

Added - Ability to modify the page hierarchy.

Credits

Props @peterwilsoncc.

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

esc_url( $move_out_link ),
/* translators: %s: Post title. */
esc_attr( sprintf( __( 'Move “%s” out', 'simple-page-ordering' ), $title ) ),
__( 'Move out >', 'simple-page-ordering' )
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super keen on move in / move out as the text links -- it needs something clearer but also short so it fits the actions toolbar. Suggestions are encouraged, thanks.

@peterwilsoncc
Copy link
Contributor Author

peterwilsoncc commented Oct 23, 2023

Some shell commands for getting a bunch of posts with the same ID in the title as the post ID.

Warning: it empties the entire post table.

wp site empty
wp post generate --post_type=page
for i in {1..100}; do wp post update $i --post_title="Page $i"; done;

# To set menu order to the ID too
for i in {1..100}; do wp post update $i --post_title="Page $i" --menu_order=$i; done;

@jeffpaul jeffpaul added this to the 2.7.0 milestone Dec 18, 2023
@shannonmfisher
Copy link

Hello hi!

After some noodling, I think the best option is Nest page and Un-nest page (could be nest/un-nest if the page part make it too long, but I'd leave the page part if possible to be super clear).

Make subpage is another option, but I think it's too complicated because there's no succinct opposite and because nesting it further isn't as intuitive with this command.

Rank page higher/lower could be another option, but I don't think "rank" is intuitive and it's long.

Order or level page up/down are also possibilities, but again, not as intuitive as nest.

Lmk if any of these feel right or if you'd like me to keep thinking on it!

@ankitguptaindia
Copy link
Member

Hello @peterwilsoncc, I have just tested this new edition, and it works well for me. I was wondering if we could implement a similar behavior for moving in and out of pages by using drag and drop? similar to how we navigate up and down pages.

I am not familiar with the technical aspects of this change, but I wanted to share the idea and get your feedback.

I noticed a similar flow in menu ordering as well:

Screen.recording.1.webm

@peterwilsoncc
Copy link
Contributor Author

@ankitguptaindia I had an attempt at that but couldn't get it working in an intuitive fashion. As the pages use tables rather than lists, the jQuery UI library only expects items to move up or down, I attempted to fake it but the drop targets' behaviour wasn't great.

@jeffpaul
Copy link
Member

@peterwilsoncc besides tweaking the copy, is there anything else needed here before this can move forward towards review/release?

@peterwilsoncc
Copy link
Contributor Author

@jeffpaul That should do.

I'm worried un nest implies that it moves the page to the top level (ie without a parent) but I can push the change and we can get some real-world feedback and improve if required.

@jeffpaul
Copy link
Member

@peterwilsoncc I'm fine with you YOLOing the decision on the copy and we can iterate as needed if there's a consensus in the community for something different

@peterwilsoncc
Copy link
Contributor Author

@jeffpaul I've just pushed some changes that alter the copy to match that of the native menu pages in WordPress Core.

Screen Shot 2024-01-18 at 11 44 51 am

"Move Under Page Name" sets the page as a child of page name
"Move Out from under Parent Page name" sets the page as a child of it's grandparent or top level if no grandparent exists.

I think the copy is clearer than move in/move out and matching existing core text is probably the best thing to do here.

@peterwilsoncc peterwilsoncc marked this pull request as ready for review January 18, 2024 00:59
@github-actions github-actions bot added the needs:code-review This requires code review. label Jan 18, 2024
@jeffpaul jeffpaul requested review from a team and faisal-alvi and removed request for dkotter, jeffpaul and a team January 18, 2024 14:25
Copy link
Member

@faisal-alvi faisal-alvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peterwilsoncc thank you The PR LGTM and also work as expected.

image

Only the description should be updated that mentions the "Move in"/"Move out" links.

@peterwilsoncc
Copy link
Contributor Author

@faisal-alvi I've updated the description with the new link text.

@peterwilsoncc peterwilsoncc merged commit 175ea98 into develop Jan 22, 2024
15 checks passed
@peterwilsoncc peterwilsoncc deleted the try/25-modify-parenting branch January 22, 2024 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs:code-review This requires code review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow pages to be moved to be children of other pages
5 participants