From 9e4e47253b88715af91299340f55f078563c9f66 Mon Sep 17 00:00:00 2001 From: Juan Manuel Pereira Date: Thu, 14 Nov 2024 13:05:40 -0300 Subject: [PATCH] Disable reordering when sort by name is enabled (#3552) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task/Issue URL: https://app.asana.com/0/1204006570077678/1208661547711012/f Tech Design URL: CC: **Description**: This fixes a bug where we enabled reordering bookmarks in both the panel and the manager when sort by name was enabled. **Steps to test this PR**: 1. Go to the bookmarks panel or manager 2. Sort by name descending or ascending 3. Try to re-order bookmarks 4. It shouldn’t let you drop bookmarks to re-order them **Definition of Done**: * [x] Does this PR satisfy our [Definition of Done](https://app.asana.com/0/1202500774821704/1207634633537039/f)? — ###### Internal references: [Pull Request Review Checklist](https://app.asana.com/0/1202500774821704/1203764234894239/f) [Software Engineering Expectations](https://app.asana.com/0/59792373528535/199064865822552) [Technical Design Template](https://app.asana.com/0/59792373528535/184709971311943) [Pull Request Documentation](https://app.asana.com/0/1202500774821704/1204012835277482/f) --- .../Bookmarks/Model/BookmarkOutlineViewDataSource.swift | 6 ++++++ .../View/BookmarkManagementDetailViewController.swift | 1 + DuckDuckGo/Bookmarks/ViewModel/SortBookmarksViewModel.swift | 4 ++++ UnitTests/Bookmarks/ViewModels/BookmarksSortModeTests.swift | 6 ++++++ 4 files changed, 17 insertions(+) diff --git a/DuckDuckGo/Bookmarks/Model/BookmarkOutlineViewDataSource.swift b/DuckDuckGo/Bookmarks/Model/BookmarkOutlineViewDataSource.swift index a4a3f63e8e..d5ca01e50e 100644 --- a/DuckDuckGo/Bookmarks/Model/BookmarkOutlineViewDataSource.swift +++ b/DuckDuckGo/Bookmarks/Model/BookmarkOutlineViewDataSource.swift @@ -48,6 +48,7 @@ final class BookmarkOutlineViewDataSource: NSObject, BookmarksOutlineViewDataSou private var outlineView: BookmarksOutlineView? private let contentMode: ContentMode + private var sortMode: BookmarksSortMode private(set) var expandedNodesIDs = Set() @Published private(set) var isSearching = false @@ -95,6 +96,7 @@ final class BookmarkOutlineViewDataSource: NSObject, BookmarksOutlineViewDataSou self.dragDropManager = dragDropManager self.treeController = treeController self.presentFaviconsFetcherOnboarding = presentFaviconsFetcherOnboarding + self.sortMode = sortMode super.init() } @@ -102,11 +104,13 @@ final class BookmarkOutlineViewDataSource: NSObject, BookmarksOutlineViewDataSou func reloadData(with sortMode: BookmarksSortMode, withRootFolder rootFolder: BookmarkFolder? = nil) { isSearching = false dragDestinationFolder = nil + self.sortMode = sortMode treeController.rebuild(for: sortMode, withRootFolder: rootFolder) } func reloadData(forSearchQuery searchQuery: String, sortMode: BookmarksSortMode) { isSearching = true + self.sortMode = sortMode treeController.rebuild(forSearchQuery: searchQuery, sortMode: sortMode) } @@ -260,6 +264,8 @@ final class BookmarkOutlineViewDataSource: NSObject, BookmarksOutlineViewDataSou } func outlineView(_ outlineView: NSOutlineView, validateDrop info: NSDraggingInfo, proposedItem item: Any?, proposedChildIndex index: Int) -> NSDragOperation { + if !sortMode.isReorderingEnabled { return .none } + let destinationNode = nodeForItem(item) if contentMode == .foldersOnly, destinationNode.isRoot { diff --git a/DuckDuckGo/Bookmarks/View/BookmarkManagementDetailViewController.swift b/DuckDuckGo/Bookmarks/View/BookmarkManagementDetailViewController.swift index 1179c44b3e..ca181a64fa 100644 --- a/DuckDuckGo/Bookmarks/View/BookmarkManagementDetailViewController.swift +++ b/DuckDuckGo/Bookmarks/View/BookmarkManagementDetailViewController.swift @@ -555,6 +555,7 @@ extension BookmarkManagementDetailViewController: NSTableViewDelegate, NSTableVi validateDrop info: NSDraggingInfo, proposedRow row: Int, proposedDropOperation dropOperation: NSTableView.DropOperation) -> NSDragOperation { + if !sortBookmarksViewModel.selectedSortMode.isReorderingEnabled { return .none } let destination = destination(for: dropOperation, at: row) guard !isSearching || destination is BookmarkFolder else { return .none } diff --git a/DuckDuckGo/Bookmarks/ViewModel/SortBookmarksViewModel.swift b/DuckDuckGo/Bookmarks/ViewModel/SortBookmarksViewModel.swift index 729408802a..3f10dcd297 100644 --- a/DuckDuckGo/Bookmarks/ViewModel/SortBookmarksViewModel.swift +++ b/DuckDuckGo/Bookmarks/ViewModel/SortBookmarksViewModel.swift @@ -55,6 +55,10 @@ enum BookmarksSortMode: Codable { return self == .nameAscending || self == .nameDescending } + var isReorderingEnabled: Bool{ + return self == .manual + } + func menu(target: AnyObject) -> NSMenu { switch self { case .manual: diff --git a/UnitTests/Bookmarks/ViewModels/BookmarksSortModeTests.swift b/UnitTests/Bookmarks/ViewModels/BookmarksSortModeTests.swift index d3cbaf14fb..87bf16d394 100644 --- a/UnitTests/Bookmarks/ViewModels/BookmarksSortModeTests.swift +++ b/UnitTests/Bookmarks/ViewModels/BookmarksSortModeTests.swift @@ -100,4 +100,10 @@ class BookmarksSortModeTests: XCTestCase { XCTAssertEqual(descendingMenu.items[4].title, UserText.bookmarksSortByNameDescending) XCTAssertEqual(descendingMenu.items[4].state, .on) } + + func testReorderingValueIsCorrect() { + XCTAssertTrue(BookmarksSortMode.manual.isReorderingEnabled) + XCTAssertFalse(BookmarksSortMode.nameAscending.isReorderingEnabled) + XCTAssertFalse(BookmarksSortMode.nameDescending.isReorderingEnabled) + } }