Skip to content

Commit 08f82a1

Browse files
committed
Switched to combo box for selection of branch.
This addresses #18.
1 parent ce86210 commit 08f82a1

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

CCMenu/Source/Pipeline Window/GitHub Sheets/AddGitHubPipelineSheet.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct AddGitHubPipelineSheet: View {
1515
@StateObject private var repository = DebouncedText()
1616
@StateObject private var repositoryList = GitHubRepositoryList()
1717
@StateObject private var workflowList = GitHubWorkflowList()
18+
@StateObject private var branch = DebouncedText()
1819
@StateObject private var branchList = GitHubBranchList()
1920
@StateObject private var builder = GitHubPipelineBuilder()
2021

@@ -105,15 +106,16 @@ struct AddGitHubPipelineSheet: View {
105106
builder.workflow = workflowList.selected
106107
}
107108

108-
Picker("Branch:", selection: $branchList.selected) {
109-
ForEach(branchList.items) { b in
110-
Text(b.name).tag(b)
111-
}
112-
}
113-
.accessibilityIdentifier("Branch picker")
114-
.disabled(!branchList.selected.isValid)
115-
.onChange(of: branchList.selected) { _ in
116-
builder.branch = branchList.selected
109+
LabeledContent("Branch:") {
110+
ComboBox(items: branchList.items.map({ $0.name }), text: $branch.input)
111+
.accessibilityIdentifier("Branch combo box")
112+
.disabled(owner.text.isEmpty || repository.text.isEmpty || repository.text.starts(with: "("))
113+
.onReceive(branch.$text) { t in
114+
builder.branch = t
115+
}
116+
.onSubmit {
117+
branch.takeInput()
118+
}
117119
}
118120
.padding(.bottom)
119121

CCMenu/Source/Pipeline Window/GitHub Sheets/GitHubBranchList.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class GitHubBranchList: ObservableObject {
2222
if branches.count > 0 && !branches[0].isValid {
2323
return branches
2424
}
25-
branches.insert(GitHubBranch(name: "all branches"), at: 0)
25+
branches.insert(GitHubBranch(name: ""), at: 0)
2626
return branches
2727
}
2828

CCMenu/Source/Pipeline Window/GitHub Sheets/GitHubPipelineBuilder.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class GitHubPipelineBuilder: ObservableObject {
1111
var owner: String?
1212
var repository: String? { didSet { setDefaultName() } }
1313
var workflow: GitHubWorkflow? { didSet { setDefaultName() } }
14-
var branch: GitHubBranch? { didSet { setDefaultName() } }
14+
var branch: String? { didSet { setDefaultName() } }
1515

1616
func setDefaultName() {
1717
var newName = ""
@@ -29,7 +29,7 @@ class GitHubPipelineBuilder: ObservableObject {
2929
guard let owner else { return false }
3030
guard let repository else { return false }
3131
guard let workflow, workflow.isValid else { return false }
32-
guard let branch, branch.isValid else { return false }
32+
guard let branch else { return false }
3333
return true
3434
}
3535

@@ -38,8 +38,8 @@ class GitHubPipelineBuilder: ObservableObject {
3838
guard let owner else { return nil }
3939
guard let repository else { return nil }
4040
guard let workflow, workflow.isValid else { return nil }
41-
guard let branch, branch.isValid else { return nil }
42-
let branchName = branch.isAllBranchPlaceholder ? nil : branch.name
41+
guard let branch else { return nil }
42+
let branchName = branch.isEmpty ? nil : branch
4343

4444
var url: URL? = nil
4545
let workflowPathComponents = [ workflow.filename, String(workflow.id) ]

CCMenuUITests/GitHubTests.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,15 @@ class GitHubTests: XCTestCase {
203203
// Make sure that the repositories and branches are loaded
204204
let repositoryBox = sheet.comboBoxes["Repository combo box"]
205205
expectation(for: NSPredicate(format: "value == 'ccmenu2'"), evaluatedWith: repositoryBox)
206-
let branchPicker = sheet.popUpButtons["Branch picker"]
207-
expectation(for: NSPredicate(format: "value == 'all branches'"), evaluatedWith: branchPicker)
206+
let branchBox = sheet.comboBoxes["Branch combo box"]
207+
expectation(for: NSPredicate(format: "value == ''"), evaluatedWith: branchBox)
208208
waitForExpectations(timeout: 5)
209209

210-
// Open the branch picker, select the main branch, and close the sheet
211-
branchPicker.click()
212-
branchPicker.menuItems["main"].click()
210+
// Open the branch combo box, select the main branch, and close the sheet
211+
branchBox.descendants(matching: .button).firstMatch.click()
212+
branchBox.textFields["main"].click()
213+
expectation(for: NSPredicate(format: "value == 'main'"), evaluatedWith: branchBox)
214+
waitForExpectations(timeout: 2)
213215
sheet.buttons["Apply"].click()
214216

215217
// Make sure the status is fetched and the request uses the branch

0 commit comments

Comments
 (0)