Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Search for labels in-app #2309

Closed
wants to merge 4 commits into from
Closed
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
3 changes: 3 additions & 0 deletions Classes/Issues/GithubClient+Issues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ extension GithubClient {
)

let timeline = issueType.timelineViewModels(
client: self,
owner: owner,
repo: repo,
contentSizeCategory: contentSizeCategory,
Expand Down Expand Up @@ -354,6 +355,7 @@ extension GithubClient {
for newLabel in labels {
if !oldLabelNames.contains(newLabel.name) {
newEvents.append(IssueLabeledModel(
client: self,
id: UUID().uuidString,
actor: actor,
title: newLabel.name,
Expand All @@ -370,6 +372,7 @@ extension GithubClient {
for oldLabel in previous.labels.labels {
if !newLabelNames.contains(oldLabel.name) {
newEvents.append(IssueLabeledModel(
client: self,
id: UUID().uuidString,
actor: actor,
title: oldLabel.name,
Expand Down
3 changes: 3 additions & 0 deletions Classes/Issues/Issue+IssueType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ extension IssueOrPullRequestQuery.Data.Repository.IssueOrPullRequest.AsIssue: Is
}

func timelineViewModels(
client: GithubClient,
owner: String,
repo: String,
contentSizeCategory: UIContentSizeCategory,
Expand Down Expand Up @@ -100,6 +101,7 @@ extension IssueOrPullRequestQuery.Data.Repository.IssueOrPullRequest.AsIssue: Is
} else if let unlabeled = node.asUnlabeledEvent,
let date = unlabeled.createdAt.githubDate {
let model = IssueLabeledModel(
client: client,
id: unlabeled.fragments.nodeFields.id,
actor: unlabeled.actor?.login ?? Constants.Strings.unknown,
title: unlabeled.label.name,
Expand All @@ -115,6 +117,7 @@ extension IssueOrPullRequestQuery.Data.Repository.IssueOrPullRequest.AsIssue: Is
} else if let labeled = node.asLabeledEvent,
let date = labeled.createdAt.githubDate {
let model = IssueLabeledModel(
client: client,
id: labeled.fragments.nodeFields.id,
actor: labeled.actor?.login ?? Constants.Strings.unknown,
title: labeled.label.name,
Expand Down
1 change: 1 addition & 0 deletions Classes/Issues/IssueType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ protocol IssueType {
func mergeModel(availableTypes: [IssueMergeType]) -> IssueMergeModel?

func timelineViewModels(
client: GithubClient,
owner: String,
repo: String,
contentSizeCategory: UIContentSizeCategory,
Expand Down
2 changes: 1 addition & 1 deletion Classes/Issues/IssuesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ final class IssuesViewController: MessageViewController,
switch object {
// header and metadata
case is IssueTitleModel: return IssueTitleSectionController()
case is IssueLabelsModel: return IssueLabelsSectionController(issue: model)
case is IssueLabelsModel: return IssueLabelsSectionController(client: client, issue: model)
case is IssueAssigneesModel: return IssueAssigneesSectionController()
case is Milestone: return IssueMilestoneSectionController(issueModel: model)
case is IssueFileChangesModel: return IssueViewFilesSectionController(issueModel: model, client: client)
Expand Down
3 changes: 2 additions & 1 deletion Classes/Issues/Labeled/IssueLabeledModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ final class IssueLabeledModel: ListDiffable {
let string: StyledTextRenderer

init(
client: GithubClient,
id: String,
actor: String,
title: String,
Expand Down Expand Up @@ -68,7 +69,7 @@ final class IssueLabeledModel: ListDiffable {
.backgroundColor: labelColor,
.foregroundColor: labelColor.textOverlayColor ?? .black,
.baselineOffset: 1, // offset for better rounded background colors
MarkdownAttribute.label: LabelDetails(owner: repoOwner, repo: repoName, label: title)
MarkdownAttribute.label: LabelDetails(client: client, owner: repoOwner, repo: repoName, label: title)
]
)))
.restore()
Expand Down
16 changes: 13 additions & 3 deletions Classes/Issues/Labels/IssueLabelsSectionController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
//

import UIKit
import GitHubAPI
import IGListKit

final class IssueLabelsSectionController: ListBindingSectionController<IssueLabelsModel>,
ListBindingSectionControllerDataSource,
ListBindingSectionControllerSelectionDelegate {


private let client: GithubClient
private let issue: IssueDetailsModel
private var sizeCache = [String: CGSize]()
private let lockedModel = Constants.Strings.locked

init(issue: IssueDetailsModel) {
init(client: GithubClient, issue: IssueDetailsModel) {
self.client = client
self.issue = issue
super.init()
minimumInteritemSpacing = Styles.Sizes.labelSpacing
Expand Down Expand Up @@ -97,7 +100,14 @@ ListBindingSectionControllerSelectionDelegate {

func sectionController(_ sectionController: ListBindingSectionController<ListDiffable>, didSelectItemAt index: Int, viewModel: Any) {
guard let viewModel = viewModel as? RepositoryLabel else { return }
viewController?.presentLabels(owner: issue.owner, repo: issue.repo, label: viewModel.name)
viewController?.presentLabels(
label: LabelDetails(
client: client,
owner: issue.owner,
repo: issue.repo,
label: viewModel.name
)
)
}

}
3 changes: 3 additions & 0 deletions Classes/Issues/PullRequest+IssueType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ extension IssueOrPullRequestQuery.Data.Repository.IssueOrPullRequest.AsPullReque
}

func timelineViewModels(
client: GithubClient,
owner: String,
repo: String,
contentSizeCategory: UIContentSizeCategory,
Expand Down Expand Up @@ -131,6 +132,7 @@ extension IssueOrPullRequestQuery.Data.Repository.IssueOrPullRequest.AsPullReque
} else if let unlabeled = node.asUnlabeledEvent,
let date = unlabeled.createdAt.githubDate {
let model = IssueLabeledModel(
client: client,
id: unlabeled.fragments.nodeFields.id,
actor: unlabeled.actor?.login ?? Constants.Strings.unknown,
title: unlabeled.label.name,
Expand All @@ -146,6 +148,7 @@ extension IssueOrPullRequestQuery.Data.Repository.IssueOrPullRequest.AsPullReque
} else if let labeled = node.asLabeledEvent,
let date = labeled.createdAt.githubDate {
let model = IssueLabeledModel(
client: client,
id: labeled.fragments.nodeFields.id,
actor: labeled.actor?.login ?? Constants.Strings.unknown,
title: labeled.label.name,
Expand Down
4 changes: 3 additions & 1 deletion Classes/Models/LabelDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import Foundation

final class LabelDetails {

let client: GithubClient
Copy link
Member

Choose a reason for hiding this comment

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

Is there another way to pass the client around beside attaching it to a model? This puts a lot of baggage in these models (the client object is basically a full app session!)

Copy link
Member Author

Choose a reason for hiding this comment

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

Re-tried this in a new PR - didn't do enough homework on how this is handled elsewhere in the app. Thanks for the feedback!

let owner: String
let repo: String
let label: String

init(owner: String, repo: String, label: String) {
init(client: GithubClient, owner: String, repo: String, label: String) {
self.client = client
self.owner = owner
self.repo = repo
self.label = label
Expand Down
25 changes: 17 additions & 8 deletions Classes/Repository/RepositoryIssuesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,24 @@ BaseListViewControllerDataSource,
SearchBarSectionControllerDelegate {

private var models = [ListDiffable]()
private let repo: RepositoryDetails
private let owner: String
private let repo: String
private let client: RepositoryClient
private let type: RepositoryIssuesType
private let searchKey: ListDiffable = "searchKey" as ListDiffable
private let debouncer = Debouncer()
private var previousSearchString = "is:open "
private let label: String?

init(client: GithubClient, repo: RepositoryDetails, type: RepositoryIssuesType) {
init(client: GithubClient, owner: String, repo: String, type: RepositoryIssuesType, label: String? = nil) {
self.owner = owner
self.repo = repo
self.client = RepositoryClient(githubClient: client, owner: repo.owner, name: repo.name)
self.client = RepositoryClient(githubClient: client, owner: owner, name: repo)
self.type = type
self.label = label
if let label = label {
previousSearchString += "label:\(label) "
}

super.init(
emptyErrorMessage: NSLocalizedString("Cannot load issues.", comment: "")
Expand All @@ -51,10 +58,12 @@ SearchBarSectionControllerDelegate {
super.viewDidLoad()

makeBackBarItemEmpty()


if label == nil {
// set the frame in -viewDidLoad is required when working with TabMan
feed.collectionView.frame = view.bounds
feed.collectionView.contentInsetAdjustmentBehavior = .never
feed.collectionView.frame = view.bounds
feed.collectionView.contentInsetAdjustmentBehavior = .never
}
}

// MARK: Overrides
Expand Down Expand Up @@ -105,7 +114,7 @@ SearchBarSectionControllerDelegate {
query: previousSearchString
)
}
return RepositorySummarySectionController(client: client.githubClient, repo: repo)
return RepositorySummarySectionController(client: client.githubClient, owner: owner, repo: repo)
}

func emptySectionController(listAdapter: ListAdapter) -> ListSectionController {
Expand All @@ -129,7 +138,7 @@ SearchBarSectionControllerDelegate {
case .issues: typeQuery = "is:issue"
case .pullRequests: typeQuery = "is:pr"
}
return "repo:\(repo.owner)/\(repo.name) \(typeQuery) \(previousSearchString)"
return "repo:\(owner)/\(repo) \(typeQuery) \(previousSearchString)"
}

}
8 changes: 5 additions & 3 deletions Classes/Repository/RepositorySummarySectionController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import IGListKit
final class RepositorySummarySectionController: ListGenericSectionController<RepositoryIssueSummaryModel> {

private let client: GithubClient
private let repo: RepositoryDetails
private let owner: String
private let repo: String

init(client: GithubClient, repo: RepositoryDetails) {
init(client: GithubClient, owner: String, repo: String) {
self.owner = owner
self.client = client
self.repo = repo
super.init()
Expand Down Expand Up @@ -53,7 +55,7 @@ final class RepositorySummarySectionController: ListGenericSectionController<Rep

override func didSelectItem(at index: Int) {
guard let number = self.object?.number else { return }
let issueModel = IssueDetailsModel(owner: repo.owner, repo: repo.name, number: number)
let issueModel = IssueDetailsModel(owner: owner, repo: repo, number: number)
let controller = IssuesViewController(client: client, model: issueModel)
viewController?.view.endEditing(false) // resign keyboard if it was triggered to become active by SearchBar
viewController?.navigationController?.pushViewController(controller, animated: trueUnlessReduceMotionEnabled)
Expand Down
4 changes: 2 additions & 2 deletions Classes/Repository/RepositoryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ ContextMenuDelegate {

var controllers: [UIViewController] = [RepositoryOverviewViewController(client: client, repo: repo)]
if repo.hasIssuesEnabled {
controllers.append(RepositoryIssuesViewController(client: client, repo: repo, type: .issues))
controllers.append(RepositoryIssuesViewController(client: client, owner: repo.owner, repo: repo.name, type: .issues))
}
controllers += [
RepositoryIssuesViewController(client: client, repo: repo, type: .pullRequests),
RepositoryIssuesViewController(client: client, owner: repo.owner, repo: repo.name, type: .pullRequests),
RepositoryCodeDirectoryViewController.createRoot(client: client, repo: repo, branch: repo.defaultBranch)
]
self.controllers = controllers
Expand Down
2 changes: 1 addition & 1 deletion Classes/Utility/UIViewController+Routing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extension UIViewController {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
case .username(let username): presentProfile(login: username)
case .label(let label): presentLabels(owner: label.owner, repo: label.repo, label: label.label)
case .label(let label): presentLabels(label: label)
case .commit(let commit): presentCommit(owner: commit.owner, repo: commit.repo, hash: commit.hash)
default: return false
}
Expand Down
27 changes: 27 additions & 0 deletions Classes/View Controllers/UIViewController+PresentLabels.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// UIViewController+PresentLabels.swift
// Freetime
//
// Created by B_Litwin on 10/17/18.
// Copyright © 2018 Ryan Nystrom. All rights reserved.
//

import UIKit

extension UIViewController {
func presentLabels(label: LabelDetails) {
let repositoryIssuesViewController =
RepositoryIssuesViewController(
client: label.client,
owner: label.owner,
repo: label.repo,
type: .issues,
label: label.label
)

navigationController?.pushViewController(
repositoryIssuesViewController,
animated: true
)
}
}
5 changes: 0 additions & 5 deletions Classes/View Controllers/UIViewController+Safari.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ extension UIViewController {
presentSafari(url: url)
}

func presentLabels(owner: String, repo: String, label: String) {
guard let url = URL(string: "https://github.com/\(owner)/\(repo)/labels/\(label)") else { return }
presentSafari(url: url)
}

func presentMilestone(owner: String, repo: String, milestone: Int) {
guard let url = URL(string: "https://github.com/\(owner)/\(repo)/milestone/\(milestone)") else { return }
presentSafari(url: url)
Expand Down