Skip to content

Commit dcba5ec

Browse files
committed
impl: ask the user only once in the login screen for fallback strategy
The user can opt in to fallback on releases.coder.com from the login screen only once. Later on he can change his mind in the Settings page.
1 parent f57c07d commit dcba5ec

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

src/main/kotlin/com/coder/toolbox/views/DeploymentUrlStep.kt

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package com.coder.toolbox.views
22

33
import com.coder.toolbox.CoderToolboxContext
4+
import com.coder.toolbox.settings.SignatureFallbackStrategy
45
import com.coder.toolbox.util.toURL
56
import com.coder.toolbox.views.state.CoderCliSetupContext
67
import com.coder.toolbox.views.state.CoderCliSetupWizardState
8+
import com.jetbrains.toolbox.api.ui.components.CheckboxField
9+
import com.jetbrains.toolbox.api.ui.components.LabelField
10+
import com.jetbrains.toolbox.api.ui.components.LabelStyleType
711
import com.jetbrains.toolbox.api.ui.components.RowGroup
812
import com.jetbrains.toolbox.api.ui.components.TextField
913
import com.jetbrains.toolbox.api.ui.components.TextType
@@ -24,12 +28,34 @@ class DeploymentUrlStep(
2428
) :
2529
WizardStep {
2630
private val urlField = TextField(context.i18n.ptrl("Deployment URL"), "", TextType.General)
27-
private val errorField = ValidationErrorField(context.i18n.pnotr(""))
31+
private val emptyLine = LabelField(context.i18n.pnotr(""), LabelStyleType.Normal)
2832

29-
override val panel: RowGroup = RowGroup(
30-
RowGroup.RowField(urlField),
31-
RowGroup.RowField(errorField)
33+
private val signatureFallbackStrategyField = CheckboxField(
34+
context.settingsStore.fallbackOnCoderForSignatures.isAllowed(),
35+
context.i18n.ptrl("Fallback on releases.coder.com when CLI signatures can't be found")
3236
)
37+
private val infoLine =
38+
LabelField(context.i18n.ptrl("Can be reconfigured later on from the Settings page"), LabelStyleType.Secondary)
39+
40+
private val errorField = ValidationErrorField(context.i18n.pnotr(""))
41+
42+
override val panel: RowGroup
43+
get() {
44+
if (context.settingsStore.fallbackOnCoderForSignatures == SignatureFallbackStrategy.NOT_CONFIGURED) {
45+
return RowGroup(
46+
RowGroup.RowField(urlField),
47+
RowGroup.RowField(emptyLine),
48+
RowGroup.RowField(signatureFallbackStrategyField),
49+
RowGroup.RowField(infoLine),
50+
RowGroup.RowField(errorField)
51+
)
52+
53+
}
54+
return RowGroup(
55+
RowGroup.RowField(urlField),
56+
RowGroup.RowField(errorField)
57+
)
58+
}
3359

3460
override fun onVisible() {
3561
errorField.textState.update {
@@ -38,9 +64,14 @@ class DeploymentUrlStep(
3864
urlField.textState.update {
3965
context.secrets.lastDeploymentURL
4066
}
67+
68+
signatureFallbackStrategyField.checkedState.update {
69+
context.settingsStore.fallbackOnCoderForSignatures.isAllowed()
70+
}
4171
}
4272

4373
override fun onNext(): Boolean {
74+
context.settingsStore.updateSignatureFallbackStrategy(signatureFallbackStrategyField.checkedState.value)
4475
var url = urlField.textState.value
4576
if (url.isBlank()) {
4677
errorField.textState.update { context.i18n.ptrl("URL is required") }

0 commit comments

Comments
 (0)