Skip to content

Commit 9a2c44a

Browse files
committed
impl: support for Toolbox 2.6.0.38881 (7)
- fix compiler errors for the Sign-In page - associated strings converted to LocalizedString instances - observable properties are now moved to Kotlin's StateFlow
1 parent 11be558 commit 9a2c44a

File tree

4 files changed

+70
-19
lines changed

4 files changed

+70
-19
lines changed

src/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,15 @@ class CoderRemoteProvider(
286286
firstRun = false
287287

288288
// Login flow.
289-
val signInPage = SignInPage(getDeploymentURL()) { deploymentURL ->
289+
val signInPage =
290+
SignInPage(serviceLocator, i18n.ptrl("Sign In to Coder"), getDeploymentURL()) { deploymentURL ->
290291
ui.showUiPage(
291-
TokenPage(deploymentURL, getToken(deploymentURL)) { selectedToken ->
292+
TokenPage(
293+
serviceLocator,
294+
i18n.ptrl("Enter your token"),
295+
deploymentURL,
296+
getToken(deploymentURL)
297+
) { selectedToken ->
292298
ui.showUiPage(createConnectPage(deploymentURL, selectedToken))
293299
},
294300
)

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package com.coder.toolbox.views
22

33
import com.coder.toolbox.settings.Source
4+
import com.jetbrains.toolbox.api.core.ServiceLocator
5+
import com.jetbrains.toolbox.api.localization.LocalizableString
6+
import com.jetbrains.toolbox.api.localization.LocalizableStringFactory
47
import com.jetbrains.toolbox.api.ui.actions.RunnableActionDescription
58
import com.jetbrains.toolbox.api.ui.components.LabelField
69
import com.jetbrains.toolbox.api.ui.components.TextField
710
import com.jetbrains.toolbox.api.ui.components.TextType
811
import com.jetbrains.toolbox.api.ui.components.UiField
12+
import kotlinx.coroutines.flow.MutableStateFlow
13+
import kotlinx.coroutines.flow.StateFlow
914
import java.net.URL
1015

1116
/**
@@ -15,35 +20,42 @@ import java.net.URL
1520
* enter their own.
1621
*/
1722
class SignInPage(
23+
serviceLocator: ServiceLocator,
24+
title: LocalizableString,
1825
private val deploymentURL: Pair<String, Source>?,
1926
private val onSignIn: (deploymentURL: URL) -> Unit,
20-
) : CoderPage("Sign In to Coder") {
21-
private val urlField = TextField("Deployment URL", deploymentURL?.first ?: "", TextType.General)
27+
) : CoderPage(serviceLocator, title) {
28+
private val i18n: LocalizableStringFactory = serviceLocator.getService(LocalizableStringFactory::class.java)
29+
private val urlField = TextField(i18n.ptrl("Deployment URL"), deploymentURL?.first ?: "", TextType.General)
2230

2331
/**
2432
* Fields for this page, displayed in order.
2533
*
2634
* TODO@JB: Fields are reset when you navigate back.
2735
* Ideally they remember what the user entered.
2836
*/
29-
override val fields: MutableList<UiField> = listOfNotNull(
37+
override val fields: StateFlow<List<UiField>> = MutableStateFlow(
38+
listOfNotNull(
3039
urlField,
31-
deploymentURL?.let { LabelField(deploymentURL.second.description("URL")) },
40+
deploymentURL?.let { LabelField(i18n.pnotr(deploymentURL.second.description("URL"))) },
3241
errorField,
33-
).toMutableList()
42+
)
43+
)
3444

3545
/**
3646
* Buttons displayed at the bottom of the page.
3747
*/
38-
override val actionButtons: MutableList<RunnableActionDescription> = mutableListOf(
39-
Action("Sign In", closesPage = false) { submit() },
48+
override val actionButtons: StateFlow<List<RunnableActionDescription>> = MutableStateFlow(
49+
listOf(
50+
Action(i18n.ptrl("Sign In"), closesPage = false) { submit() },
51+
)
4052
)
4153

4254
/**
4355
* Call onSignIn with the URL, or error if blank.
4456
*/
4557
private fun submit() {
46-
val urlRaw = urlField.text.value
58+
val urlRaw = urlField.textState.value
4759
// Ensure the URL can be parsed.
4860
try {
4961
if (urlRaw.isBlank()) {

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ package com.coder.toolbox.views
22

33
import com.coder.toolbox.settings.Source
44
import com.coder.toolbox.util.withPath
5+
import com.jetbrains.toolbox.api.core.ServiceLocator
6+
import com.jetbrains.toolbox.api.localization.LocalizableString
7+
import com.jetbrains.toolbox.api.localization.LocalizableStringFactory
58
import com.jetbrains.toolbox.api.ui.actions.RunnableActionDescription
69
import com.jetbrains.toolbox.api.ui.components.LabelField
710
import com.jetbrains.toolbox.api.ui.components.LinkField
811
import com.jetbrains.toolbox.api.ui.components.TextField
912
import com.jetbrains.toolbox.api.ui.components.TextType
1013
import com.jetbrains.toolbox.api.ui.components.UiField
14+
import kotlinx.coroutines.flow.MutableStateFlow
15+
import kotlinx.coroutines.flow.StateFlow
1116
import java.net.URL
1217

1318
/**
@@ -17,34 +22,44 @@ import java.net.URL
1722
* enter their own.
1823
*/
1924
class TokenPage(
25+
serviceLocator: ServiceLocator,
26+
title: LocalizableString,
2027
deploymentURL: URL,
2128
token: Pair<String, Source>?,
2229
private val onToken: ((token: String) -> Unit),
23-
) : CoderPage("Enter your token") {
24-
private val tokenField = TextField("Token", token?.first ?: "", TextType.General)
30+
) : CoderPage(serviceLocator, title) {
31+
private val i18n: LocalizableStringFactory = serviceLocator.getService(LocalizableStringFactory::class.java)
32+
33+
private val tokenField = TextField(i18n.ptrl("Token"), token?.first ?: "", TextType.General)
2534

2635
/**
2736
* Fields for this page, displayed in order.
2837
*
2938
* TODO@JB: Fields are reset when you navigate back.
3039
* Ideally they remember what the user entered.
3140
*/
32-
override val fields: MutableList<UiField> = listOfNotNull(
41+
override val fields: StateFlow<List<UiField>> = MutableStateFlow(
42+
listOfNotNull(
3343
tokenField,
3444
LabelField(
35-
token?.second?.description("token")
36-
?: "No existing token for ${deploymentURL.host} found.",
45+
i18n.pnotr(
46+
token?.second?.description("token")
47+
?: "No existing token for ${deploymentURL.host} found."
48+
),
3749
),
3850
// TODO@JB: The link text displays twice.
39-
LinkField("Get a token", deploymentURL.withPath("/login?redirect=%2Fcli-auth").toString()),
51+
LinkField(i18n.ptrl("Get a token"), deploymentURL.withPath("/login?redirect=%2Fcli-auth").toString()),
4052
errorField,
41-
).toMutableList()
53+
)
54+
)
4255

4356
/**
4457
* Buttons displayed at the bottom of the page.
4558
*/
46-
override val actionButtons: MutableList<RunnableActionDescription> = mutableListOf(
47-
Action("Connect", closesPage = false) { submit(tokenField.text.value) },
59+
override val actionButtons: StateFlow<List<RunnableActionDescription>> = MutableStateFlow(
60+
listOf(
61+
Action(i18n.ptrl("Connect"), closesPage = false) { submit(tokenField.textState.value) },
62+
)
4863
)
4964

5065
/**

src/main/resources/localization/defaultMessages.po

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,21 @@ msgstr ""
126126

127127
msgid "Retry"
128128
msgstr ""
129+
130+
msgid "Sign In"
131+
msgstr ""
132+
133+
msgid "Sign In to Coder"
134+
msgstr ""
135+
136+
msgid "Enter your token"
137+
msgstr ""
138+
139+
msgid "Token"
140+
msgstr ""
141+
142+
msgid "Get a token"
143+
msgstr ""
144+
145+
msgid "Connect"
146+
msgstr ""

0 commit comments

Comments
 (0)