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

Fix #21856: Support the 'Order' setting in pages list #24181

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Modules/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let package = Package(
.package(url: "https://github.com/wordpress-mobile/MediaEditor-iOS", branch: "task/spm-support"),
.package(url: "https://github.com/wordpress-mobile/NSObject-SafeExpectations", from: "0.0.6"),
.package(url: "https://github.com/wordpress-mobile/NSURL-IDN", branch: "trunk"),
.package(url: "https://github.com/wordpress-mobile/WordPressKit-iOS", branch: "wpios-edition"),
.package(url: "https://github.com/wordpress-mobile/WordPressKit-iOS", branch: "parse-page-order-property"),
.package(url: "https://github.com/zendesk/support_sdk_ios", from: "8.0.3"),
// We can't use wordpress-rs branches nor commits here. Only tags work.
.package(url: "https://github.com/Automattic/wordpress-rs", revision: "alpha-20250127"),
Expand Down
6 changes: 3 additions & 3 deletions WordPress.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "b048f2348f14b6f12b4a4b8588355abe499af3f8f4e91cacc054e98187a7746c",
"originHash" : "22d0c1b3f7e39812921cdd883dd43d6502abbb0b8d294779f4db4f79c6ce80fb",
"pins" : [
{
"identity" : "alamofire",
Expand Down Expand Up @@ -391,8 +391,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/wordpress-mobile/WordPressKit-iOS",
"state" : {
"branch" : "wpios-edition",
"revision" : "ba542bae62a1d9b80b0baee44d610bfac55936ea"
"branch" : "parse-page-order-property",
"revision" : "7c2c1d0f2851eb6744376b4d61f03211826ed7f0"
}
},
{
Expand Down
1 change: 1 addition & 0 deletions WordPress/Classes/Models/AbstractPost.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ typedef NS_ENUM(NSUInteger, AbstractPostRemoteStatus) {
@property (weak, readonly) AbstractPost *revision;
@property (nonatomic, strong) NSSet *comments;
@property (nonatomic, strong, nullable) Media *featuredImage;
@property (nonatomic, assign) NSInteger order;

/// This array will contain a list of revision IDs.
@property (nonatomic, strong, nullable) NSArray *revisions;
Expand Down
1 change: 1 addition & 0 deletions WordPress/Classes/Models/AbstractPost.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ @implementation AbstractPost
@dynamic autosaveModifiedDate;
@dynamic autosaveIdentifier;
@dynamic foreignID;
@dynamic order;
@synthesize voiceContent;

#pragma mark - Life Cycle Methods
Expand Down
1 change: 1 addition & 0 deletions WordPress/Classes/Services/PostHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ + (void)updatePost:(AbstractPost *)post withRemotePost:(RemotePost *)remotePost
post.content = remotePost.content;
post.status = remotePost.status;
post.password = remotePost.password;
post.order = remotePost.order;

if (remotePost.postThumbnailID != nil) {
post.featuredImage = [Media existingOrStubMediaWithMediaID: remotePost.postThumbnailID inBlog:post.blog];
Expand Down
17 changes: 7 additions & 10 deletions WordPress/Classes/Utility/PageTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ final class PageTree {

// A node in a tree, which of course is also a tree itself.
private class TreeNode {
struct PageData {
var postID: NSNumber?
var parentID: NSNumber?
}
let page: Page
var children = [TreeNode]()
var parentNode: TreeNode?
Expand All @@ -16,7 +12,7 @@ final class PageTree {

func dfsList() -> [Page] {
var pages = [Page]()
_ = depthFirstSearch { level, node in
_ = depthFirstSearch(sortByPageOrder: true) { level, node in
let page = node.page
page.hierarchyIndex = level
page.hasVisibleParent = node.parentNode != nil
Expand All @@ -32,18 +28,19 @@ final class PageTree {
/// a boolean value indicate whether the search should be stopped.
/// - Returns: `true` if search has been stopped by the closure.
@discardableResult
func depthFirstSearch(using closure: (Int, TreeNode) -> Bool) -> Bool {
depthFirstSearch(level: 0, using: closure)
func depthFirstSearch(sortByPageOrder: Bool, using closure: (Int, TreeNode) -> Bool) -> Bool {
depthFirstSearch(level: 0, sortByPageOrder: sortByPageOrder, using: closure)
}

private func depthFirstSearch(level: Int, using closure: (Int, TreeNode) -> Bool) -> Bool {
private func depthFirstSearch(level: Int, sortByPageOrder: Bool, using closure: (Int, TreeNode) -> Bool) -> Bool {
let shouldStop = closure(level, self)
if shouldStop {
return true
}

for child in children {
let shouldStop = child.depthFirstSearch(level: level + 1, using: closure)
let pages = sortByPageOrder ? children.sorted(using: KeyPathComparator(\TreeNode.page.order)) : children
for child in pages {
let shouldStop = child.depthFirstSearch(level: level + 1, sortByPageOrder: sortByPageOrder, using: closure)
if shouldStop {
return true
}
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/WordPress.xcdatamodeld/.xccurrentversion
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<plist version="1.0">
<dict>
<key>_XCCurrentVersionName</key>
<string>WordPress 154.xcdatamodel</string>
<string>WordPress 155.xcdatamodel</string>
</dict>
</plist>
Loading