Skip to content

Commit c54b692

Browse files
vchikoti1998rli
andauthored
UX change in Gateway to support 3P repos (#3532)
* UX change to support 3P repos * Addressed Feedback * Flipping the new branch option back * If 3p repo selected, set branchType as Existing * Removed changeLog --------- Co-authored-by: Richard Li <[email protected]>
1 parent 7f6afcf commit c54b692

File tree

2 files changed

+50
-18
lines changed

2 files changed

+50
-18
lines changed

jetbrains-gateway/src/software/aws/toolkits/jetbrains/gateway/CawsConnectorViewPanels.kt

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.intellij.ui.ScrollPaneFactory
2121
import com.intellij.ui.SimpleListCellRenderer
2222
import com.intellij.ui.components.JBCheckBox
2323
import com.intellij.ui.components.JBLoadingPanel
24+
import com.intellij.ui.components.JBRadioButton
2425
import com.intellij.ui.components.JBTextField
2526
import com.intellij.ui.components.panels.Wrapper
2627
import com.intellij.ui.dsl.builder.BottomGap
@@ -53,6 +54,7 @@ import software.aws.toolkits.core.utils.getLogger
5354
import software.aws.toolkits.core.utils.tryOrNull
5455
import software.aws.toolkits.jetbrains.AwsToolkit
5556
import software.aws.toolkits.jetbrains.core.AwsClientManager
57+
import software.aws.toolkits.jetbrains.core.AwsResourceCache
5658
import software.aws.toolkits.jetbrains.core.awsClient
5759
import software.aws.toolkits.jetbrains.core.credentials.sono.lazilyGetUserId
5860
import software.aws.toolkits.jetbrains.core.utils.buildMap
@@ -61,8 +63,10 @@ import software.aws.toolkits.jetbrains.gateway.connection.extractRepoName
6163
import software.aws.toolkits.jetbrains.gateway.connection.normalizeRepoUrl
6264
import software.aws.toolkits.jetbrains.gateway.welcomescreen.recursivelySetBackground
6365
import software.aws.toolkits.jetbrains.gateway.welcomescreen.setDefaultBackgroundAndBorder
66+
import software.aws.toolkits.jetbrains.services.caws.CawsCodeRepository
6467
import software.aws.toolkits.jetbrains.services.caws.CawsEndpoints
6568
import software.aws.toolkits.jetbrains.services.caws.CawsProject
69+
import software.aws.toolkits.jetbrains.services.caws.CawsResources
6670
import software.aws.toolkits.jetbrains.services.caws.InactivityTimeout
6771
import software.aws.toolkits.jetbrains.services.caws.isSubscriptionFreeTier
6872
import software.aws.toolkits.jetbrains.services.caws.isSupportedInFreeTier
@@ -105,7 +109,8 @@ class CawsSettings(
105109

106110
// intermediate values
107111
var connectionSettings: ClientConnectionSettings<*>? = null,
108-
var branchCloneType: BranchCloneType = BranchCloneType.EXISTING
112+
var branchCloneType: BranchCloneType = BranchCloneType.EXISTING,
113+
var is3P: Boolean = false
109114
)
110115

111116
fun cawsWizard(lifetime: Lifetime, settings: CawsSettings = CawsSettings()) = MultistagePanelContainer(
@@ -136,6 +141,10 @@ fun cawsWizard(lifetime: Lifetime, settings: CawsSettings = CawsSettings()) = Mu
136141
error("Not implemented")
137142
}
138143

144+
if (context.is3P) {
145+
context.branchCloneType = BranchCloneType.EXISTING
146+
}
147+
139148
if (context.branchCloneType == BranchCloneType.NEW_FROM_EXISTING) {
140149
withTextAboveProgressBar(message("caws.creating_branch")) {
141150
cawsClient.createSourceRepositoryBranch {
@@ -334,27 +343,32 @@ class EnvironmentDetailsPanel(private val context: CawsSettings, lifetime: Lifet
334343

335344
row {
336345
label(message("caws.workspace.details.branch_title"))
337-
.comment(message("caws.workspace.details.create_branch_comment"))
338346
}
339347

348+
row { comment(message("caws.workspace.details.create_branch_comment")) }
349+
350+
lateinit var branchOptions: Row
351+
lateinit var newBranchOption: Cell<JBRadioButton>
340352
lateinit var newBranch: Row
341353
buttonsGroup {
342-
row {
343-
radioButton(message("caws.workspace.details.branch_new"), BranchCloneType.NEW_FROM_EXISTING).applyToComponent {
344-
isSelected = context.branchCloneType == BranchCloneType.NEW_FROM_EXISTING
345-
}.bindSelected(
346-
{ context.branchCloneType == BranchCloneType.NEW_FROM_EXISTING },
347-
{ if (it) context.branchCloneType = BranchCloneType.NEW_FROM_EXISTING }
348-
).actionListener { event, component ->
349-
newBranch.visibleIf(component.selected)
350-
}
354+
branchOptions = row {
355+
newBranchOption = radioButton(message("caws.workspace.details.branch_new"), BranchCloneType.NEW_FROM_EXISTING)
356+
.applyToComponent {
357+
isSelected = context.branchCloneType == BranchCloneType.NEW_FROM_EXISTING
358+
}.bindSelected(
359+
{ context.branchCloneType == BranchCloneType.NEW_FROM_EXISTING },
360+
{ if (it) context.branchCloneType = BranchCloneType.NEW_FROM_EXISTING }
361+
).actionListener { event, component ->
362+
newBranch.visibleIf(component.selected)
363+
}
351364

352-
radioButton(message("caws.workspace.details.branch_existing"), BranchCloneType.EXISTING).applyToComponent {
353-
isSelected = context.branchCloneType == BranchCloneType.EXISTING
354-
}.bindSelected(
355-
{ context.branchCloneType == BranchCloneType.EXISTING },
356-
{ if (it) context.branchCloneType = BranchCloneType.EXISTING }
357-
)
365+
radioButton(message("caws.workspace.details.branch_existing"), BranchCloneType.EXISTING)
366+
.applyToComponent {
367+
isSelected = context.branchCloneType == BranchCloneType.EXISTING
368+
}.bindSelected(
369+
{ context.branchCloneType == BranchCloneType.EXISTING },
370+
{ if (it) context.branchCloneType = BranchCloneType.EXISTING }
371+
)
358372
}
359373
}.bind({ context.branchCloneType }, { context.branchCloneType = it })
360374

@@ -377,6 +391,16 @@ class EnvironmentDetailsPanel(private val context: CawsSettings, lifetime: Lifet
377391
linkedBranchCombo.proposeModelUpdate { model ->
378392
projectCombo.selected()?.let { project ->
379393
linkedRepoCombo.selected()?.let { repo ->
394+
context.is3P = isRepo3P(project, repo.name)
395+
if (context.is3P) {
396+
branchOptions.visible(false)
397+
newBranch.visible(false)
398+
} else {
399+
branchOptions.visible(true)
400+
if (newBranchOption.component.isSelected) {
401+
newBranch.visible(true)
402+
}
403+
}
380404
val branches = getBranchNames(project, repo.name, client)
381405
branches.forEach { model.addElement(it) }
382406
}
@@ -559,6 +583,14 @@ class EnvironmentDetailsPanel(private val context: CawsSettings, lifetime: Lifet
559583
.map { it.toSourceRepository() }
560584
.sortedBy { it.name }
561585

586+
private fun isRepo3P(project: CawsProject, repo: String): Boolean {
587+
val connectionSettings = context.connectionSettings ?: throw RuntimeException("ConnectionSettings was not set")
588+
val url = AwsResourceCache.getInstance().getResource(
589+
CawsResources.cloneUrls(CawsCodeRepository(project.space, project.project, repo)), connectionSettings
590+
).toCompletableFuture().get()
591+
return !url.contains(CawsEndpoints.CAWS_GIT_PATTERN)
592+
}
593+
562594
private fun getBranchNames(project: CawsProject, repo: String, client: CodeCatalystClient) =
563595
client.listSourceRepositoryBranchesPaginator {
564596
it.spaceName(project.space)

resources/resources/software/aws/toolkits/resources/MessagesBundle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ caws.workspace.details.branch_new=New Branch:
255255
caws.workspace.details.branch_new_validation=New branch name is required
256256
caws.workspace.details.branch_title=Branch:
257257
caws.workspace.details.branch_validation=Branch selection is required
258-
caws.workspace.details.create_branch_comment=Choose an existing branch or create a new branch
258+
caws.workspace.details.create_branch_comment=Choose an existing branch or create a new branch. If you choose a third-party source repository, you must work in an existing branch.
259259
caws.workspace.details.create_from_existing_branch=Existing Branch
260260
caws.workspace.details.create_from_new_branch=New Branch
261261
caws.workspace.details.developer_tool_settings=Toolkit Developer Settings

0 commit comments

Comments
 (0)