Skip to content

Commit

Permalink
Review option fixes, and "highest-most" routing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ptsochantaris committed Aug 30, 2023
1 parent 595705a commit c28a87b
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 49 deletions.
8 changes: 4 additions & 4 deletions PocketTrailer/AdvancedSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ final class AdvancedSettingsViewController: UITableViewController, PickerViewCon
valueDisplayed: { Settings.assignedItemDirectHandlingPolicy.placementName },
optionSelected: { [weak self] originalIndex, section, setting in
guard let self else { return }
let v = PickerViewController.Info(title: setting.title, values: Section.assignmentPlacementLabels, selectedIndex: Settings.assignedItemDirectHandlingPolicy.assignmentPolictMenuIndex, sourceIndexPath: IndexPath(row: originalIndex, section: section.rawValue))
let v = PickerViewController.Info(title: setting.title, values: Section.assignmentPlacementLabels, selectedIndex: Settings.assignedItemDirectHandlingPolicy.assignmentPolicyMenuIndex, sourceIndexPath: IndexPath(row: originalIndex, section: section.rawValue))
performSegue(withIdentifier: "showPicker", sender: v)
}),
Setting(section: .Display,
Expand All @@ -112,7 +112,7 @@ final class AdvancedSettingsViewController: UITableViewController, PickerViewCon
valueDisplayed: { Settings.assignedItemTeamHandlingPolicy.placementName },
optionSelected: { [weak self] originalIndex, section, setting in
guard let self else { return }
let v = PickerViewController.Info(title: setting.title, values: Section.assignmentPlacementLabels, selectedIndex: Settings.assignedItemTeamHandlingPolicy.assignmentPolictMenuIndex, sourceIndexPath: IndexPath(row: originalIndex, section: section.rawValue))
let v = PickerViewController.Info(title: setting.title, values: Section.assignmentPlacementLabels, selectedIndex: Settings.assignedItemTeamHandlingPolicy.assignmentPolicyMenuIndex, sourceIndexPath: IndexPath(row: originalIndex, section: section.rawValue))
performSegue(withIdentifier: "showPicker", sender: v)
}),
Setting(section: .Display,
Expand Down Expand Up @@ -449,7 +449,7 @@ final class AdvancedSettingsViewController: UITableViewController, PickerViewCon
valueDisplayed: { Settings.assignedDirectReviewHandlingPolicy.placementName },
optionSelected: { [weak self] originalIndex, section, setting in
guard let self else { return }
let v = PickerViewController.Info(title: setting.title, values: Section.assignmentPlacementLabels, selectedIndex: Settings.assignedDirectReviewHandlingPolicy.assignmentPolictMenuIndex, sourceIndexPath: IndexPath(row: originalIndex, section: section.rawValue))
let v = PickerViewController.Info(title: setting.title, values: Section.assignmentPlacementLabels, selectedIndex: Settings.assignedDirectReviewHandlingPolicy.assignmentPolicyMenuIndex, sourceIndexPath: IndexPath(row: originalIndex, section: section.rawValue))
performSegue(withIdentifier: "showPicker", sender: v)
}),
Setting(section: .Reviews,
Expand All @@ -458,7 +458,7 @@ final class AdvancedSettingsViewController: UITableViewController, PickerViewCon
valueDisplayed: { Settings.assignedTeamReviewHandlingPolicy.placementName },
optionSelected: { [weak self] originalIndex, section, setting in
guard let self else { return }
let v = PickerViewController.Info(title: setting.title, values: Section.assignmentPlacementLabels, selectedIndex: Settings.assignedTeamReviewHandlingPolicy.assignmentPolictMenuIndex, sourceIndexPath: IndexPath(row: originalIndex, section: section.rawValue))
let v = PickerViewController.Info(title: setting.title, values: Section.assignmentPlacementLabels, selectedIndex: Settings.assignedTeamReviewHandlingPolicy.assignmentPolicyMenuIndex, sourceIndexPath: IndexPath(row: originalIndex, section: section.rawValue))
performSegue(withIdentifier: "showPicker", sender: v)
}),
Setting(section: .Reviews,
Expand Down
8 changes: 4 additions & 4 deletions Shared/Enums.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ enum Section: CaseIterable, Equatable {
}
}

var assignmentPolictMenuIndex: Int {
var assignmentPolicyMenuIndex: Int {
switch self {
case .mine:
return 0
Expand All @@ -273,11 +273,11 @@ enum Section: CaseIterable, Equatable {

init(assignmentPolicyMenuIndex: Int) {
switch assignmentPolicyMenuIndex {
case Section.mine.assignmentPolictMenuIndex:
case Section.mine.assignmentPolicyMenuIndex:
self = .mine
case Section.participated.assignmentPolictMenuIndex:
case Section.participated.assignmentPolicyMenuIndex:
self = .participated
case Section.mentioned.assignmentPolictMenuIndex:
case Section.mentioned.assignmentPolicyMenuIndex:
self = .mentioned
default:
self = .hidden(cause: .unknown)
Expand Down
54 changes: 32 additions & 22 deletions Shared/ListableItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,11 @@ class ListableItem: DataItem, Listable {
return true

case .mineAndParticipated:
let preConditionSection = preferredSection(takingItemConditionIntoAccount: false, settings: settings)
let preConditionSection = highestPreferredSection(takingItemConditionIntoAccount: false, settings: settings)
return preConditionSection == .mine || preConditionSection == .participated

case .mine:
let preConditionSection = preferredSection(takingItemConditionIntoAccount: false, settings: settings)
let preConditionSection = highestPreferredSection(takingItemConditionIntoAccount: false, settings: settings)
return preConditionSection == .mine

case .nothing:
Expand All @@ -349,10 +349,12 @@ class ListableItem: DataItem, Listable {
return false

case .me:
return section == settings.assignedItemDirectHandlingPolicy
let policy = settings.assignedItemDirectHandlingPolicy
return policy.visible && section == policy

case .myTeam:
return section == settings.assignedItemTeamHandlingPolicy
let policy = settings.assignedItemTeamHandlingPolicy
return policy.visible && section == policy
}
}

Expand Down Expand Up @@ -460,7 +462,7 @@ class ListableItem: DataItem, Listable {
nil
}

private func preferredSection(takingItemConditionIntoAccount: Bool, settings: Settings.Cache) -> Section {
private func highestPreferredSection(takingItemConditionIntoAccount: Bool, settings: Settings.Cache) -> Section {
if takingItemConditionIntoAccount {
if condition == ItemCondition.merged.rawValue {
return .merged
Expand All @@ -478,34 +480,42 @@ class ListableItem: DataItem, Listable {
return .mine
}

if shouldGo(to: .participated, settings: settings) || commentedByMe || reviewedByMe {
return .participated
}
var targetSection = Section.all

if shouldGo(to: .mentioned, settings: settings) {
return .mentioned
if targetSection.sectionIndex > Section.participated.sectionIndex,
shouldGo(to: .participated, settings: settings) || commentedByMe || reviewedByMe {
targetSection = .participated
}

if let section = preferredSectionBasedOnReviewAssignment {
return section
if targetSection.sectionIndex > Section.mentioned.sectionIndex,
shouldGo(to: .mentioned, settings: settings) {
targetSection = .mentioned
}

if let section = settings.preferredMovePolicySection,
if let potentialSection = settings.preferredMovePolicySection,
potentialSection.sectionIndex < targetSection.sectionIndex,
contains(terms: ["@\(apiServer.userName.orEmpty)"]) {
return section
targetSection = potentialSection
}

if let section = settings.preferredTeamMentionPolicy,
if let potentialSection = settings.preferredTeamMentionPolicy,
potentialSection.sectionIndex < targetSection.sectionIndex,
contains(terms: apiServer.teams.compactMap(\.calculatedReferral)) {
return section
targetSection = potentialSection
}

if let section = settings.newItemInOwnedRepoMovePolicy,
if let potentialSection = settings.newItemInOwnedRepoMovePolicy,
potentialSection.sectionIndex < targetSection.sectionIndex,
repo.isMine {
return section
targetSection = potentialSection
}

if let potentialSection = preferredSectionBasedOnReviewAssignment,
potentialSection.sectionIndex < targetSection.sectionIndex {
targetSection = potentialSection
}

return .all
return targetSection
}

func canBadge(in targetSection: Section? = nil, settings: Settings.Cache) -> Bool {
Expand All @@ -516,7 +526,7 @@ class ListableItem: DataItem, Listable {
}

if targetSection == .closed || targetSection == .merged {
return preferredSection(takingItemConditionIntoAccount: false, settings: settings).shouldBadgeComments(settings: settings)
return highestPreferredSection(takingItemConditionIntoAccount: false, settings: settings).shouldBadgeComments(settings: settings)
}

return true
Expand Down Expand Up @@ -628,8 +638,8 @@ class ListableItem: DataItem, Listable {
?? shouldHideBecauseOfInclusionRules(settings: settings) {
targetSection = .hidden(cause: cause)
} else {
targetSection = preferredSection(takingItemConditionIntoAccount: true, settings: settings)

targetSection = highestPreferredSection(takingItemConditionIntoAccount: true, settings: settings)
if targetSection.visible, let cause
= shouldHideBecauseOfRepoDisplayPolicy(targetSection: targetSection)
?? shouldHideBecauseOfRedStatuses(in: targetSection, settings: settings) {
Expand Down
8 changes: 4 additions & 4 deletions Trailer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1716;
CURRENT_PROJECT_VERSION = 1718;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand All @@ -1653,7 +1653,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.8.10;
MARKETING_VERSION = 1.8.11;
ONLY_ACTIVE_ARCH = YES;
OTHER_SWIFT_FLAGS = "-D DEBUG";
SWIFT_ENFORCE_EXCLUSIVE_ACCESS = "debug-only";
Expand Down Expand Up @@ -1691,7 +1691,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1716;
CURRENT_PROJECT_VERSION = 1718;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEPLOYMENT_POSTPROCESSING = YES;
Expand All @@ -1715,7 +1715,7 @@
);
LLVM_LTO = YES;
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.8.10;
MARKETING_VERSION = 1.8.11;
SEPARATE_STRIP = YES;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_DISABLE_SAFETY_CHECKS = YES;
Expand Down
8 changes: 4 additions & 4 deletions Trailer/PreferencesWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,8 @@ final class PreferencesWindow: NSWindow, NSWindowDelegate, NSTableViewDelegate,
autoRemoveMergedItems.integerValue = Settings.autoRemoveMergedItems
autoRemoveClosedItems.integerValue = Settings.autoRemoveClosedItems

assignedItemDirectHandlingPolicy.selectItem(at: Settings.assignedItemDirectHandlingPolicy.assignmentPolictMenuIndex)
assignedItemTeamHandlingPolicy.selectItem(at: Settings.assignedItemTeamHandlingPolicy.assignmentPolictMenuIndex)
assignedItemDirectHandlingPolicy.selectItem(at: Settings.assignedItemDirectHandlingPolicy.assignmentPolicyMenuIndex)
assignedItemTeamHandlingPolicy.selectItem(at: Settings.assignedItemTeamHandlingPolicy.assignmentPolicyMenuIndex)

defaultOpenApp.stringValue = Settings.defaultAppForOpeningItems
defaultOpenLinks.stringValue = Settings.defaultAppForOpeningWeb
Expand All @@ -724,10 +724,10 @@ final class PreferencesWindow: NSWindow, NSWindowDelegate, NSTableViewDelegate,
hotkeyOptionModifier.integerValue = Settings.hotkeyOptionModifier.asInt
hotkeyShiftModifier.integerValue = Settings.hotkeyShiftModifier.asInt

let assignedDirectMenuIndex = Settings.assignedDirectReviewHandlingPolicy.assignmentPolictMenuIndex
let assignedDirectMenuIndex = Settings.assignedDirectReviewHandlingPolicy.assignmentPolicyMenuIndex
assignedDirectReviewHandlingPolicy.select(assignedDirectReviewHandlingPolicy.item(at: assignedDirectMenuIndex))

let assignedTeamMenuIndex = Settings.assignedTeamReviewHandlingPolicy.assignmentPolictMenuIndex
let assignedTeamMenuIndex = Settings.assignedTeamReviewHandlingPolicy.assignmentPolicyMenuIndex
assignedTeamReviewHandlingPolicy.select(assignedTeamReviewHandlingPolicy.item(at: assignedTeamMenuIndex))

enableHotkeySegments()
Expand Down
Loading

0 comments on commit c28a87b

Please sign in to comment.