Apache Solr open-source search software
SOLR-17658: Implement start screen (#3388)
Christos Malliaridisf935888437f0
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.tomlindex 1b7983a633f..063b6f8d7f9 100644--- a/gradle/libs.versions.toml+++ b/gradle/libs.versions.toml@@ -439,6 +439,7 @@ kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serializaktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }ktor-client-contentNegotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }+ktor-client-mock = { module = "io.ktor:ktor-client-mock", version.ref = "ktor" }ktor-client-serialization-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }langchain4j-cohere = { module = "dev.langchain4j:langchain4j-cohere", version.ref = "langchain4j" }langchain4j-core = { module = "dev.langchain4j:langchain4j-core", version.ref = "langchain4j" }diff --git a/solr/ui/build.gradle.kts b/solr/ui/build.gradle.ktsindex 0bf7e4fac53..caf814f61c4 100644--- a/solr/ui/build.gradle.kts+++ b/solr/ui/build.gradle.kts@@ -107,6 +107,7 @@ kotlin {implementation(libs.kotlinx.coroutines.test)@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)implementation(compose.uiTest)+ implementation(libs.ktor.client.mock)}}diff --git a/solr/ui/gradle.lockfile b/solr/ui/gradle.lockfileindex 801aadb00b5..7e333c89923 100644--- a/solr/ui/gradle.lockfile+++ b/solr/ui/gradle.lockfile@@ -66,6 +66,9 @@ io.ktor:ktor-client-content-negotiation:3.1.0=allSourceSetsCompileDependenciesMeio.ktor:ktor-client-core-jvm:3.1.0=desktopCompileClasspath,desktopRuntimeClasspath,desktopTestCompileClasspath,desktopTestRuntimeClasspathio.ktor:ktor-client-core-wasm-js:3.1.0=wasmJsCompileClasspath,wasmJsNpmAggregated,wasmJsRuntimeClasspath,wasmJsTestCompileClasspath,wasmJsTestNpmAggregated,wasmJsTestRuntimeClasspathio.ktor:ktor-client-core:3.1.0=allSourceSetsCompileDependenciesMetadata,allTestSourceSetsCompileDependenciesMetadata,commonMainApiDependenciesMetadata,commonMainCompileOnlyDependenciesMetadata,commonMainImplementationDependenciesMetadata,commonMainResolvableDependenciesMetadata,commonTestApiDependenciesMetadata,commonTestCompileOnlyDependenciesMetadata,commonTestImplementationDependenciesMetadata,commonTestResolvableDependenciesMetadata,desktopCompileClasspath,desktopMainApiDependenciesMetadata,desktopMainCompileOnlyDependenciesMetadata,desktopMainImplementationDependenciesMetadata,desktopMainResolvableDependenciesMetadata,desktopRuntimeClasspath,desktopTestApiDependenciesMetadata,desktopTestCompileClasspath,desktopTestCompileOnlyDependenciesMetadata,desktopTestImplementationDependenciesMetadata,desktopTestResolvableDependenciesMetadata,desktopTestRuntimeClasspath,metadataCommonMainCompileClasspath,metadataCompileClasspath,wasmJsCompileClasspath,wasmJsMainApiDependenciesMetadata,wasmJsMainCompileOnlyDependenciesMetadata,wasmJsMainImplementationDependenciesMetadata,wasmJsMainResolvableDependenciesMetadata,wasmJsNpmAggregated,wasmJsRuntimeClasspath,wasmJsTestApiDependenciesMetadata,wasmJsTestCompileClasspath,wasmJsTestCompileOnlyDependenciesMetadata,wasmJsTestImplementationDependenciesMetadata,wasmJsTestNpmAggregated,wasmJsTestResolvableDependenciesMetadata,wasmJsTestRuntimeClasspath+io.ktor:ktor-client-mock-jvm:3.1.0=desktopTestCompileClasspath,desktopTestRuntimeClasspath+io.ktor:ktor-client-mock-wasm-js:3.1.0=wasmJsTestCompileClasspath,wasmJsTestNpmAggregated,wasmJsTestRuntimeClasspath+io.ktor:ktor-client-mock:3.1.0=allTestSourceSetsCompileDependenciesMetadata,commonTestApiDependenciesMetadata,commonTestCompileOnlyDependenciesMetadata,commonTestImplementationDependenciesMetadata,commonTestResolvableDependenciesMetadata,desktopTestApiDependenciesMetadata,desktopTestCompileClasspath,desktopTestCompileOnlyDependenciesMetadata,desktopTestImplementationDependenciesMetadata,desktopTestResolvableDependenciesMetadata,desktopTestRuntimeClasspath,wasmJsTestApiDependenciesMetadata,wasmJsTestCompileClasspath,wasmJsTestCompileOnlyDependenciesMetadata,wasmJsTestImplementationDependenciesMetadata,wasmJsTestNpmAggregated,wasmJsTestResolvableDependenciesMetadata,wasmJsTestRuntimeClasspathio.ktor:ktor-events-jvm:3.1.0=desktopCompileClasspath,desktopRuntimeClasspath,desktopTestCompileClasspath,desktopTestRuntimeClasspathio.ktor:ktor-events-wasm-js:3.1.0=wasmJsCompileClasspath,wasmJsNpmAggregated,wasmJsRuntimeClasspath,wasmJsTestCompileClasspath,wasmJsTestNpmAggregated,wasmJsTestRuntimeClasspathio.ktor:ktor-events:3.1.0=allSourceSetsCompileDependenciesMetadata,allTestSourceSetsCompileDependenciesMetadata,commonMainApiDependenciesMetadata,commonMainCompileOnlyDependenciesMetadata,commonMainImplementationDependenciesMetadata,commonMainResolvableDependenciesMetadata,commonTestApiDependenciesMetadata,commonTestCompileOnlyDependenciesMetadata,commonTestImplementationDependenciesMetadata,commonTestResolvableDependenciesMetadata,desktopCompileClasspath,desktopMainApiDependenciesMetadata,desktopMainCompileOnlyDependenciesMetadata,desktopMainImplementationDependenciesMetadata,desktopMainResolvableDependenciesMetadata,desktopRuntimeClasspath,desktopTestApiDependenciesMetadata,desktopTestCompileClasspath,desktopTestCompileOnlyDependenciesMetadata,desktopTestImplementationDependenciesMetadata,desktopTestResolvableDependenciesMetadata,desktopTestRuntimeClasspath,metadataCommonMainCompileClasspath,metadataCompileClasspath,wasmJsCompileClasspath,wasmJsMainApiDependenciesMetadata,wasmJsMainCompileOnlyDependenciesMetadata,wasmJsMainImplementationDependenciesMetadata,wasmJsMainResolvableDependenciesMetadata,wasmJsNpmAggregated,wasmJsRuntimeClasspath,wasmJsTestApiDependenciesMetadata,wasmJsTestCompileClasspath,wasmJsTestCompileOnlyDependenciesMetadata,wasmJsTestImplementationDependenciesMetadata,wasmJsTestNpmAggregated,wasmJsTestResolvableDependenciesMetadata,wasmJsTestRuntimeClasspathdiff --git a/solr/ui/src/commonMain/composeResources/drawable/solr-sun.svg b/solr/ui/src/commonMain/composeResources/drawable/solr-sun.svgnew file mode 100644index 00000000000..54bb00f9b2e--- /dev/null+++ b/solr/ui/src/commonMain/composeResources/drawable/solr-sun.svg@@ -0,0 +1,10 @@+<svg width="128" height="128" viewBox="0 0 128 128" fill="none" xmlns="http://www.w3.org/2000/svg">+<path d="M105.05 26.8253L49.5636 84.144L119.296 53.4041C117.234 43.2307 112.183 34.0866 105.05 26.8253Z" fill="#D9411E"/>+<path d="M63.8818 8.98004C56.1972 8.98004 48.8739 10.4621 42.1943 13.1362L34.7462 73.3791L71.9538 9.54135C69.3135 9.17555 66.6272 8.98004 63.8818 8.98004Z" fill="#D9411E"/>+<path d="M119.854 58.0954L53.7737 92.4065L115.769 85.5809C118.711 79.2367 120.34 72.2526 120.34 64.9089C120.34 62.5992 120.163 60.326 119.854 58.0954Z" fill="#D9411E"/>+<path d="M95.4934 109.562C102.876 105.246 109.004 99.4614 113.332 92.6955L55.2251 102.654L95.4934 109.562Z" fill="#D9411E"/>+<path d="M75.3561 10.1491L43.0087 77.5891L103.007 24.2007C95.4869 17.2381 85.9699 12.2594 75.3561 10.1491Z" fill="#D9411E"/>+<path d="M68.6041 119.02C74.8569 118.668 80.814 117.634 86.3246 116.012L53.7736 113.391L68.6041 119.02Z" fill="#D9411E"/>+<path d="M12.4216 42.2271C9.87981 47.406 8.23124 53.0326 7.65983 58.9435L16.4281 73.379L12.4216 42.2271Z" fill="#D9411E"/>+<path d="M37.3011 15.6269C29.3342 19.6967 22.5166 25.5287 17.4067 32.5898L25.5904 71.9275L37.3011 15.6269Z" fill="#D9411E"/>+</svg>diff --git a/solr/ui/src/commonMain/composeResources/values/strings.xml b/solr/ui/src/commonMain/composeResources/values/strings.xmlindex 1f686e87cf9..055d4ce06ac 100644--- a/solr/ui/src/commonMain/composeResources/values/strings.xml+++ b/solr/ui/src/commonMain/composeResources/values/strings.xml@@ -17,10 +17,22 @@--><resources>- <!-- Content Descriptions (CD) -->+ <!-- Actions (action) -->+ <string name="action_connect">Connect</string>+ <string name="action_logout">Logout</string>++ <!-- Content Descriptions (cd) --><string name="cd_solr_logo">Solr Logo</string>- <!-- Navigation (NAV) -->+ <!-- Descriptions (desc) -->+ <string name="desc_to_get_started">To get started, please provide a Solr host URL:</string>++ <!-- Errors (error) -->+ <string name="error_invalid_url">The provided URL is invalid.</string>+ <string name="error_solr_host_not_found">Solr host could not be found.</string>+ <string name="error_unknown">An unknown error occurred.</string>++ <!-- Navigation (nav) --><string name="nav_cluster">Cluster</string><string name="nav_collections">Collections</string><string name="nav_configsets">Configsets</string>@@ -32,15 +44,21 @@<string name="nav_security">Security</string><string name="nav_thread_dump">Thread Dump</string>+ <!-- Placeholders (ph) -->+ <string name="ph_solr_url">http://127.0.0.1:8983/</string>++ <!-- Titles (title) -->+ <string name="title_welcome_to_solr">Welcome to Solr Admin UI</string>+<!-- General Text --><string name="community">Community</string><string name="documentation">Documentation</string><string name="irc">IRC</string><string name="issue_tracker">Issue Tracker</string>- <string name="logout">Logout</string><string name="slack">Slack</string><string name="solr_query_syntax">Solr Query Syntax</string><string name="support">Support</string>+ <string name="connecting">Connecting...</string><!-- Uncategorized --></resources>diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/auth/UnauthenticatedComponent.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/auth/UnauthenticatedComponent.ktnew file mode 100644index 00000000000..9989982364a--- /dev/null+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/auth/UnauthenticatedComponent.kt@@ -0,0 +1,44 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.components.auth++import io.ktor.http.Url++interface UnauthenticatedComponent {++ /**+ * Aborts the authentication attempt.+ */+ fun onAbort()++ sealed interface Output {++ /**+ * Emitted when the user successfully authenticated against+ * the Solr instance.+ *+ * @property url The URL the connection was established with+ */+ data class OnConnected(val url: Url): Output++ /**+ * Emitted when the user aborts the authentication flow.+ */+ data object OnAbort: Output+ }+}diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/auth/integration/DefaultUnauthenticatedComponent.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/auth/integration/DefaultUnauthenticatedComponent.ktnew file mode 100644index 00000000000..a107e4c3210--- /dev/null+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/auth/integration/DefaultUnauthenticatedComponent.kt@@ -0,0 +1,35 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.components.auth.integration++import com.arkivanov.mvikotlin.core.store.StoreFactory+import io.ktor.client.HttpClient+import org.apache.solr.ui.components.auth.UnauthenticatedComponent+import org.apache.solr.ui.utils.AppComponentContext++class DefaultUnauthenticatedComponent(+ componentContext: AppComponentContext,+ storeFactory: StoreFactory,+ httpClient: HttpClient,+ private val output: (UnauthenticatedComponent.Output) -> Unit+) : UnauthenticatedComponent, AppComponentContext by componentContext {++ // TODO Implement me++ override fun onAbort() = output(UnauthenticatedComponent.Output.OnAbort)+}\ No newline at end of filediff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/environment/integration/DefaultEnvironmentComponent.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/environment/integration/DefaultEnvironmentComponent.ktindex 17456a43822..5b9c5551950 100644--- a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/environment/integration/DefaultEnvironmentComponent.kt+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/environment/integration/DefaultEnvironmentComponent.kt@@ -22,6 +22,7 @@ import com.arkivanov.mvikotlin.core.store.StoreFactoryimport com.arkivanov.mvikotlin.extensions.coroutines.stateFlowimport io.ktor.client.HttpClientimport kotlinx.coroutines.ExperimentalCoroutinesApi+import kotlinx.coroutines.SupervisorJobimport org.apache.solr.ui.components.environment.EnvironmentComponentimport org.apache.solr.ui.components.environment.store.EnvironmentStoreProviderimport org.apache.solr.ui.utils.AppComponentContext@@ -37,13 +38,15 @@ class DefaultEnvironmentComponent(httpClient: HttpClient,) : EnvironmentComponent, AppComponentContext by componentContext {- private val mainScope = coroutineScope(mainContext)+ private val mainScope = coroutineScope(SupervisorJob() + mainContext)+ private val ioScope = coroutineScope(SupervisorJob() + ioContext)private val store = instanceKeeper.getStore {EnvironmentStoreProvider(storeFactory = storeFactory,client = HttpEnvironmentStoreClient(httpClient),- ioContext = ioContext,+ mainContext = mainScope.coroutineContext,+ ioContext = ioScope.coroutineContext,).provide()}diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/environment/store/EnvironmentStoreProvider.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/environment/store/EnvironmentStoreProvider.ktindex fea0f1fcf73..699e98b9c3c 100644--- a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/environment/store/EnvironmentStoreProvider.kt+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/environment/store/EnvironmentStoreProvider.kt@@ -40,6 +40,7 @@ import org.apache.solr.ui.components.environment.store.EnvironmentStore.Stateinternal class EnvironmentStoreProvider(private val storeFactory: StoreFactory,private val client: Client,+ private val mainContext: CoroutineContext,private val ioContext: CoroutineContext,) {@@ -58,7 +59,7 @@ internal class EnvironmentStoreProvider(/*** Action used for initiating the initial fetch of environment data.*/- data object FetchInitialSystemData: Action+ data object FetchInitialSystemData : Action}private sealed interface Message {@@ -78,9 +79,10 @@ internal class EnvironmentStoreProvider(data class JavaPropertiesUpdated(val properties: List<JavaProperty>) : Message}- private inner class ExecutorImpl : CoroutineExecutor<Intent, Action, State, Message, Nothing>() {+ private inner class ExecutorImpl :+ CoroutineExecutor<Intent, Action, State, Message, Nothing>(mainContext) {- override fun executeAction(action: Action) = when(action) {+ override fun executeAction(action: Action) = when (action) {Action.FetchInitialSystemData -> {fetchSystemData()fetchJavaProperties()@@ -145,6 +147,7 @@ internal class EnvironmentStoreProvider(system = msg.data.system,node = msg.data.node,)+is Message.JavaPropertiesUpdated -> copy(javaProperties = msg.properties,)diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/root/RootComponent.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/root/RootComponent.ktindex bd0c89f1842..30ad4931c37 100644--- a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/root/RootComponent.kt+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/root/RootComponent.kt@@ -19,7 +19,9 @@ package org.apache.solr.ui.components.rootimport com.arkivanov.decompose.router.stack.ChildStackimport com.arkivanov.decompose.value.Value+import org.apache.solr.ui.components.auth.UnauthenticatedComponentimport org.apache.solr.ui.components.main.MainComponent+import org.apache.solr.ui.components.start.StartComponent/*** Root component used by each target as an entry point to the application.@@ -33,9 +35,10 @@ interface RootComponent {sealed interface Child {+ data class Start(val component: StartComponent): Child+data class Main(val component: MainComponent): Child- // TODO Add child once authentication is checked- // data class Unauthenticated(val component: UnauthenticatedComponent): Child+ data class Unauthenticated(val component: UnauthenticatedComponent): Child}}diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/root/integration/SimpleRootComponent.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/root/integration/SimpleRootComponent.ktindex 4789db8c611..b1a3f5b4c0c 100644--- a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/root/integration/SimpleRootComponent.kt+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/root/integration/SimpleRootComponent.kt@@ -20,14 +20,24 @@ package org.apache.solr.ui.components.root.integrationimport com.arkivanov.decompose.router.stack.ChildStackimport com.arkivanov.decompose.router.stack.StackNavigationimport com.arkivanov.decompose.router.stack.childStack+import com.arkivanov.decompose.router.stack.pop+import com.arkivanov.decompose.router.stack.pushNew+import com.arkivanov.decompose.router.stack.replaceAllimport com.arkivanov.decompose.value.Valueimport com.arkivanov.mvikotlin.core.store.StoreFactoryimport io.ktor.client.HttpClient+import io.ktor.http.Urlimport kotlinx.serialization.Serializable+import org.apache.solr.ui.components.auth.UnauthenticatedComponent+import org.apache.solr.ui.components.auth.integration.DefaultUnauthenticatedComponentimport org.apache.solr.ui.components.main.MainComponentimport org.apache.solr.ui.components.main.integration.DefaultMainComponentimport org.apache.solr.ui.components.root.RootComponent+import org.apache.solr.ui.components.root.RootComponent.Child.*+import org.apache.solr.ui.components.start.StartComponent+import org.apache.solr.ui.components.start.integration.DefaultStartComponentimport org.apache.solr.ui.utils.AppComponentContext+import org.apache.solr.ui.utils.getDefaultClient/*** A simple root component implementation that does not check the user's access level and redirects@@ -39,14 +49,16 @@ import org.apache.solr.ui.utils.AppComponentContextclass SimpleRootComponent(componentContext: AppComponentContext,storeFactory: StoreFactory,- private val mainComponent: (AppComponentContext) -> MainComponent,+ private val startComponent: (AppComponentContext, (StartComponent.Output) -> Unit) -> StartComponent,+ private val mainComponent: (AppComponentContext, Url) -> MainComponent,+ private val unauthenticatedComponent: (AppComponentContext, Url, (UnauthenticatedComponent.Output) -> Unit) -> UnauthenticatedComponent,) : RootComponent, AppComponentContext by componentContext {private val navigation = StackNavigation<Configuration>()private val stack = childStack(source = navigation,serializer = Configuration.serializer(),- initialStack = { listOf(Configuration.Main) },+ initialStack = { listOf(Configuration.Start) },handleBackButton = true,childFactory = ::createChild)@@ -61,27 +73,78 @@ class SimpleRootComponent() : this(componentContext = componentContext,storeFactory = storeFactory,- mainComponent = { childContext ->- DefaultMainComponent(+ startComponent = { childContext, output ->+ DefaultStartComponent(componentContext = childContext,storeFactory = storeFactory,httpClient = httpClient,+ output = output,+ )+ },+ mainComponent = { childContext, url ->+ DefaultMainComponent(+ componentContext = childContext,+ storeFactory = storeFactory,+ httpClient = getDefaultClient(url),destination = destination,)},+ unauthenticatedComponent = { childContext, url, output ->+ DefaultUnauthenticatedComponent(+ componentContext = childContext,+ storeFactory = storeFactory,+ httpClient = getDefaultClient(url),+ output = output,+ )+ })private fun createChild(configuration: Configuration,componentContext: AppComponentContext,): RootComponent.Child = when (configuration) {- Configuration.Main -> RootComponent.Child.Main(mainComponent(componentContext))+ is Configuration.Start -> Start(startComponent(componentContext, ::startOutput))+ is Configuration.Main -> Main(mainComponent(componentContext, configuration.url))+ is Configuration.Unauthenticated -> Unauthenticated(+ unauthenticatedComponent(+ componentContext,+ configuration.url,+ ::unauthenticatedOutput,+ )+ )+ }++ /**+ * Output handler for any output returned by the [StartComponent].+ *+ * @param output The output returned by the start component implementation.+ */+ private fun startOutput(output: StartComponent.Output) = when (output) {+ is StartComponent.Output.OnAuthRequired -> navigation.pushNew(Configuration.Unauthenticated(output.url))+ is StartComponent.Output.OnConnected ->+ navigation.replaceAll(Configuration.Main(url = output.url))+ }++ /**+ * Output handler for any output returned by the [UnauthenticatedComponent].+ *+ * @param output The output returned by the unauthenticated component implementation.+ */+ private fun unauthenticatedOutput(output: UnauthenticatedComponent.Output) = when (output) {+ is UnauthenticatedComponent.Output.OnConnected -> navigation.replaceAll(Configuration.Main(output.url))+ is UnauthenticatedComponent.Output.OnAbort -> navigation.pop()}@Serializableprivate sealed interface Configuration {@Serializable- data object Main : Configuration+ data object Start : Configuration++ @Serializable+ data class Unauthenticated(val url: Url) : Configuration++ @Serializable+ data class Main(val url: Url) : Configuration}}diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/StartComponent.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/StartComponent.ktnew file mode 100644index 00000000000..213efba1afd--- /dev/null+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/StartComponent.kt@@ -0,0 +1,73 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.components.start++import io.ktor.http.Url+import kotlinx.coroutines.flow.StateFlow+import org.jetbrains.compose.resources.StringResource++/**+ * Component interface that represents the start screen.+ */+interface StartComponent {++ val model: StateFlow<Model>++ /**+ * Function for when the input value for the Solr URL changes.+ *+ * @param url The new URL value+ */+ fun onSolrUrlChange(url: String)++ /**+ * Called when the user wants to connect with the current [Model.url].+ */+ fun onConnect()++ /**+ * State class that holds values of the [StartComponent]'s sate.+ */+ data class Model(+ val url: String = "",+ val isConnecting: Boolean = false,+ val error: StringResource? = null,+ )++ /**+ * Possible component outputs that may be emitted to the parent component.+ */+ sealed interface Output {++ /**+ * Emitted when a connection to a Solr instance has been+ * established and no authentication is required.+ *+ * @property url The URL the connection was established.+ */+ data class OnConnected(val url: Url) : Output++ /**+ * Emitted when a connection to a Solr instance has been established and authentication+ * is needed.+ *+ * @property url The URL the connection was established but requires authentication.+ */+ data class OnAuthRequired(val url: Url) : Output+ }+}diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/integration/DefaultStartComponent.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/integration/DefaultStartComponent.ktnew file mode 100644index 00000000000..264d84573d7--- /dev/null+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/integration/DefaultStartComponent.kt@@ -0,0 +1,73 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.components.start.integration++import com.arkivanov.mvikotlin.core.instancekeeper.getStore+import com.arkivanov.mvikotlin.core.store.StoreFactory+import com.arkivanov.mvikotlin.extensions.coroutines.labels+import com.arkivanov.mvikotlin.extensions.coroutines.stateFlow+import io.ktor.client.HttpClient+import kotlinx.coroutines.ExperimentalCoroutinesApi+import kotlinx.coroutines.SupervisorJob+import kotlinx.coroutines.flow.launchIn+import kotlinx.coroutines.flow.onEach+import org.apache.solr.ui.components.start.StartComponent+import org.apache.solr.ui.components.start.store.StartStore+import org.apache.solr.ui.components.start.store.StartStore.Intent+import org.apache.solr.ui.components.start.store.StartStoreProvider+import org.apache.solr.ui.utils.AppComponentContext+import org.apache.solr.ui.utils.coroutineScope+import org.apache.solr.ui.utils.map++class DefaultStartComponent(+ componentContext: AppComponentContext,+ storeFactory: StoreFactory,+ httpClient: HttpClient,+ output: (StartComponent.Output) -> Unit,+) : StartComponent, AppComponentContext by componentContext {++ private val mainScope = coroutineScope(SupervisorJob() + mainContext)+ private val ioScope = coroutineScope(SupervisorJob() + ioContext)++ private val store = instanceKeeper.getStore {+ StartStoreProvider(+ storeFactory = storeFactory,+ client = HttpStartStoreClient(httpClient),+ mainContext = mainScope.coroutineContext,+ ioContext = ioScope.coroutineContext,+ ).provide()+ }++ init {+ store.labels.onEach { label ->+ when (label) {+ is StartStore.Label.AuthRequired ->+ output(StartComponent.Output.OnAuthRequired(url = label.url))+ is StartStore.Label.Connected ->+ output(StartComponent.Output.OnConnected(url = label.url))+ }+ }.launchIn(mainScope)+ }++ @OptIn(ExperimentalCoroutinesApi::class)+ override val model = store.stateFlow.map(mainScope, startStateToModel)++ override fun onSolrUrlChange(url: String) = store.accept(Intent.UpdateSolrUrl(url))++ override fun onConnect() = store.accept(Intent.Connect)+}diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/integration/HttpStartStoreClient.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/integration/HttpStartStoreClient.ktnew file mode 100644index 00000000000..60d42a64486--- /dev/null+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/integration/HttpStartStoreClient.kt@@ -0,0 +1,61 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.components.start.integration++import io.ktor.client.HttpClient+import io.ktor.client.plugins.timeout+import io.ktor.client.request.get+import io.ktor.http.HttpStatusCode+import io.ktor.http.URLBuilder+import io.ktor.http.Url+import io.ktor.http.path+import org.apache.solr.ui.components.start.store.StartStoreProvider+import org.apache.solr.ui.errors.UnauthorizedException+import org.apache.solr.ui.errors.UnknownResponseException++/**+ * Client implementation of the [StartStoreProvider.Client] that makes use+ * of a preconfigured HTTP client for accessing the Solr API.+ *+ * @property httpClient HTTP client to use for accessing the API. The client has to be+ * configured with a default request that includes the host, port and schema. The client+ * should also include the necessary authentication data if authentication / authorization+ * is enabled.+ */+class HttpStartStoreClient(+ private val httpClient: HttpClient,+) : StartStoreProvider.Client {++ override suspend fun connect(url: Url): Result<Unit> {+ val url = URLBuilder(url).apply {+ // Try getting system data for checking if Solr host exists,+ // since there is no explicit endpoint for the connection establishment.+ path("api/node/system")+ }.build()++ val response = httpClient.get(url) {+ timeout { connectTimeoutMillis = 5000 }+ }++ return when (response.status) {+ HttpStatusCode.OK -> Result.success(Unit)+ HttpStatusCode.Unauthorized -> Result.failure(UnauthorizedException())+ else -> Result.failure(UnknownResponseException(response))+ }+ }+}diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/integration/Mappers.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/integration/Mappers.ktnew file mode 100644index 00000000000..fb2cfcc4589--- /dev/null+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/integration/Mappers.kt@@ -0,0 +1,42 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.components.start.integration++import io.ktor.client.network.sockets.ConnectTimeoutException+import io.ktor.http.URLParserException+import org.apache.solr.ui.components.start.StartComponent+import org.apache.solr.ui.components.start.store.StartStore+import org.apache.solr.ui.errors.HostNotFoundException+import org.apache.solr.ui.generated.resources.Res+import org.apache.solr.ui.generated.resources.error_invalid_url+import org.apache.solr.ui.generated.resources.error_solr_host_not_found+import org.apache.solr.ui.generated.resources.error_unknown++internal val startStateToModel: (StartStore.State) -> StartComponent.Model = {+ StartComponent.Model(+ url = it.url,+ error = it.error?.let { error ->+ when (error) {+ is URLParserException -> Res.string.error_invalid_url+ is HostNotFoundException -> Res.string.error_solr_host_not_found+ is ConnectTimeoutException -> Res.string.error_solr_host_not_found+ else -> Res.string.error_unknown+ }+ },+ )+}diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/store/StartStore.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/store/StartStore.ktnew file mode 100644index 00000000000..28dd0241281--- /dev/null+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/store/StartStore.kt@@ -0,0 +1,74 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.components.start.store++import com.arkivanov.mvikotlin.core.store.Store+import io.ktor.http.Url+import org.apache.solr.ui.components.start.store.StartStore.Intent+import org.apache.solr.ui.components.start.store.StartStore.Label+import org.apache.solr.ui.components.start.store.StartStore.State++/**+ * State store interface of the environment.+ *+ * Implementations of this state store manage detailed information of the environment.+ */+internal interface StartStore : Store<Intent, State, Label> {++ /**+ * Intent for interacting with the environment store.+ */+ sealed interface Intent {++ /**+ * Intent for updating the current Solr URL.+ */+ data class UpdateSolrUrl(val url: String): Intent++ /**+ * Intent for initiating a new connection to a Solr instance.+ */+ data object Connect: Intent+ }++ sealed interface Label {++ /**+ * Label that is published when a connection to a Solr instance has been established+ * successful.+ *+ * @property url URL of the Solr instance.+ */+ data class Connected(val url: Url): Label++ /**+ * Label that is published when a Solr server was found, but authentication is required.+ *+ * @property url URL of the Solr instance that requires authentication.+ */+ data class AuthRequired(val url: Url): Label+ }++ /**+ * State class that holds the data of the [StartStore].+ */+ data class State(+ val url: String = "",+ val error: Throwable? = null,+ )+}diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/store/StartStoreProvider.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/store/StartStoreProvider.ktnew file mode 100644index 00000000000..c7389049e21--- /dev/null+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/components/start/store/StartStoreProvider.kt@@ -0,0 +1,146 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.components.start.store++import com.arkivanov.mvikotlin.core.store.Reducer+import com.arkivanov.mvikotlin.core.store.SimpleBootstrapper+import com.arkivanov.mvikotlin.core.store.Store+import com.arkivanov.mvikotlin.core.store.StoreFactory+import com.arkivanov.mvikotlin.extensions.coroutines.CoroutineExecutor+import io.ktor.http.URLParserException+import io.ktor.http.Url+import io.ktor.http.parseUrl+import kotlin.coroutines.CoroutineContext+import kotlinx.coroutines.CoroutineExceptionHandler+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.SupervisorJob+import kotlinx.coroutines.launch+import kotlinx.coroutines.withContext+import org.apache.solr.ui.components.start.store.StartStore.Intent+import org.apache.solr.ui.components.start.store.StartStore.Label+import org.apache.solr.ui.components.start.store.StartStore.State+import org.apache.solr.ui.errors.UnauthorizedException+import org.apache.solr.ui.errors.parseError+import org.apache.solr.ui.utils.DEFAULT_SOLR_URL++/**+ * Store provider that [provide]s instances of [StartStore].+ *+ * @property storeFactory Store factory to use for creating the store.+ * @property client Client implementation to use for resolving [Intent]s.+ * @property ioContext Coroutine context used for IO activity.+ */+internal class StartStoreProvider(+ private val storeFactory: StoreFactory,+ private val client: Client,+ private val mainContext: CoroutineContext,+ private val ioContext: CoroutineContext,+) {++ fun provide(): StartStore = object :+ StartStore,+ Store<Intent, State, Label> by storeFactory.create(+ name = "StartStore",+ initialState = State(),+ bootstrapper = SimpleBootstrapper(),+ executorFactory = ::ExecutorImpl,+ reducer = ReducerImpl,+ ) {}++ private sealed interface Message {++ /**+ * Message that is dispatched when the stored Solr URL is updated.+ *+ * @property url The new Solr URL.+ */+ data class UrlUpdated(val url: String) : Message++ /**+ * Message that is dispatch when an unknown error occurs during connection.+ *+ * @property error Error that was thrown.+ */+ data class ConnectionFailed(val error: Throwable) : Message+ }++ private inner class ExecutorImpl : CoroutineExecutor<Intent, Unit, State, Message, Label>(mainContext) {+ override fun executeIntent(intent: Intent) {+ when (intent) {+ is Intent.UpdateSolrUrl -> dispatch(Message.UrlUpdated(intent.url))+ is Intent.Connect -> {+ var urlValue = state().url+ if (urlValue == "") urlValue = DEFAULT_SOLR_URL // use placeholder value if empty++ try {+ val url = parseUrl(urlValue) ?: throw URLParserException(+ urlString = urlValue,+ cause = Error("Invalid URL"),+ )++ scope.launch(context = CoroutineExceptionHandler { _, throwable ->+ // error returned here is platform-specific and needs further parsing+ dispatch(Message.ConnectionFailed(error = parseError(throwable)))+ }) {+ withContext(ioContext) {+ client.connect(url)+ }.onSuccess {+ // Solr server found with no auth active+ publish(Label.Connected(url))+ }.onFailure { error ->+ when (error) {+ is UnauthorizedException -> {+ // Solr server found, but user is unauthorized+ publish(Label.AuthRequired(url))+ }+ else -> dispatch(Message.ConnectionFailed(error))+ }+ }+ }+ } catch (error: Exception) {+ dispatch(Message.ConnectionFailed(error))+ }+ }+ }+ }+ }++ /**+ * Reducer implementation that consumes [Message]s and updates the store's [State].+ */+ private object ReducerImpl : Reducer<State, Message> {+ override fun State.reduce(msg: Message): State = when (msg) {+ is Message.UrlUpdated -> copy(url = msg.url, error = null)+ is Message.ConnectionFailed -> copy(error = msg.error)+ }+ }++ /**+ * Client interface for fetching environment information.+ */+ interface Client {++ /**+ * Tries to connect to a Solr instance with the given URL.+ *+ * @param url The Solr URL to connect to.+ * @return Result of whether the connection was established.+ */+ suspend fun connect(url: Url): Result<Unit>+ }+}diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/errors/HostNotFoundException.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/errors/HostNotFoundException.ktnew file mode 100644index 00000000000..b1730edd14a--- /dev/null+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/errors/HostNotFoundException.kt@@ -0,0 +1,25 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.errors++/**+ * Exception that is thrown when the client has failed to connect to a host.+ *+ * @property cause The root cause that caused this exception.+ */+class HostNotFoundException(cause: Throwable? = null): Throwable(cause)diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/errors/UnauthorizedException.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/errors/UnauthorizedException.ktnew file mode 100644index 00000000000..531f0451c12--- /dev/null+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/errors/UnauthorizedException.kt@@ -0,0 +1,29 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.errors++import io.ktor.http.Url++/**+ * Exception that is thrown for unauthorized access to the API.+ *+ * This is usually used when a response has HTTP status code 401.+ *+ * @property url The URL that threw the unauthorized response.+ */+class UnauthorizedException(val url: Url? = null): Exception()diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/errors/UnknownResponseException.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/errors/UnknownResponseException.ktnew file mode 100644index 00000000000..c86adc1c097--- /dev/null+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/errors/UnknownResponseException.kt@@ -0,0 +1,29 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.errors++import io.ktor.client.statement.HttpResponse++/**+ * Exception that is thrown when an unknown response has been received.+ *+ * This is usually the case when an unhandled status code was received.+ *+ * @property response The response that could not be handled.+ */+class UnknownResponseException(val response: HttpResponse): Exception()diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/errors/parseError.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/errors/parseError.ktnew file mode 100644index 00000000000..f3af77cd4df--- /dev/null+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/errors/parseError.kt@@ -0,0 +1,26 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.errors++/**+ * Parsing function for mapping platform-specific errors.+ *+ * @param error The error to try to parse+ * @return A mapped error or [error] if it could not be parsed.+ */+expect fun parseError(error: Throwable): Throwablediff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/Constants.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/Constants.ktnew file mode 100644index 00000000000..8b2b9f8f3dc--- /dev/null+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/Constants.kt@@ -0,0 +1,23 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.utils++/**+ * The default Solr URL that may be used in various places.+ */+const val DEFAULT_SOLR_URL = "http://127.0.0.1:8983/"diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/HttpClientUtils.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/HttpClientUtils.ktindex 3e894a5f938..def403e3918 100644--- a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/HttpClientUtils.kt+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/utils/HttpClientUtils.kt@@ -20,6 +20,7 @@ package org.apache.solr.ui.utilsimport io.ktor.client.HttpClientimport io.ktor.client.plugins.contentnegotiation.ContentNegotiationimport io.ktor.client.plugins.defaultRequest+import io.ktor.http.Urlimport io.ktor.serialization.kotlinx.json.jsonimport kotlinx.serialization.json.Json@@ -27,9 +28,9 @@ import kotlinx.serialization.json.Json* Function that returns a simple HTTP client that is preconfigured with a base* URL.*/-fun getDefaultClient() = HttpClient {+fun getDefaultClient(url: Url = Url("http://127.0.0.1:8983/")) = HttpClient {defaultRequest {- url("http://localhost:8983/")+ url(url.toString())}install(ContentNegotiation) {diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/auth/UserAuthenticationContent.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/auth/UserAuthenticationContent.ktnew file mode 100644index 00000000000..565c06afa99--- /dev/null+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/auth/UserAuthenticationContent.kt@@ -0,0 +1,46 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.views.auth++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+import androidx.compose.material3.Text+import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier+import androidx.compose.ui.unit.dp+import org.apache.solr.ui.components.auth.UnauthenticatedComponent+import org.apache.solr.ui.views.components.SolrButton++/**+ * The user authentication content is the composable that will check and display+ * the available authentication options to the user.+ */+@Composable+fun UserAuthenticationContent(+ component: UnauthenticatedComponent,+ modifier: Modifier = Modifier,+) = Column(+ modifier = modifier,+ verticalArrangement = Arrangement.spacedBy(16.dp),+) {+ Text(text = "Authentication not implemented yet")++ SolrButton(onClick = component::onAbort) {+ Text(text = "Go Back")+ }+}diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/components/SolrButton.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/components/SolrButton.ktnew file mode 100644index 00000000000..f1c036a61d2--- /dev/null+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/components/SolrButton.kt@@ -0,0 +1,56 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.views.components++import androidx.compose.foundation.BorderStroke+import androidx.compose.foundation.interaction.MutableInteractionSource+import androidx.compose.foundation.layout.PaddingValues+import androidx.compose.foundation.layout.RowScope+import androidx.compose.material3.Button+import androidx.compose.material3.ButtonColors+import androidx.compose.material3.ButtonDefaults+import androidx.compose.material3.ButtonElevation+import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier+import androidx.compose.ui.graphics.RectangleShape+import androidx.compose.ui.graphics.Shape++@Composable+fun SolrButton(+ onClick: () -> Unit,+ modifier: Modifier = Modifier,+ enabled: Boolean = true,+ shape: Shape = RectangleShape, // override the button shapes+ colors: ButtonColors = ButtonDefaults.buttonColors(),+ elevation: ButtonElevation? = ButtonDefaults.buttonElevation(),+ border: BorderStroke? = null,+ contentPadding: PaddingValues = ButtonDefaults.ContentPadding,+ interactionSource: MutableInteractionSource? = null,+ content: @Composable RowScope.() -> Unit+) = Button(+ onClick = onClick,+ modifier = modifier,+ enabled = enabled,+ shape = shape,+ colors = colors,+ elevation = elevation,+ border = border,+ contentPadding = contentPadding,+ interactionSource = interactionSource,+ content = content,+)diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/components/SolrLinearProgressIndicator.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/components/SolrLinearProgressIndicator.ktnew file mode 100644index 00000000000..5c0f60d1e49--- /dev/null+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/components/SolrLinearProgressIndicator.kt@@ -0,0 +1,47 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.views.components++import androidx.compose.material3.LinearProgressIndicator+import androidx.compose.material3.ProgressIndicatorDefaults+import androidx.compose.runtime.Composable+import androidx.compose.ui.Modifier+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.StrokeCap+import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.dp++/**+ * A [LinearProgressIndicator] which uses sharp edges instead of round as defaults.+ *+ * @see [LinearProgressIndicator]+ */+@Composable+fun SolrLinearProgressIndicator(+ modifier: Modifier = Modifier,+ color: Color = ProgressIndicatorDefaults.linearColor,+ trackColor: Color = ProgressIndicatorDefaults.linearTrackColor,+ strokeCap: StrokeCap = StrokeCap.Butt,+ gapSize: Dp = 0.dp,+) = LinearProgressIndicator(+ modifier = modifier,+ color = color,+ trackColor = trackColor,+ strokeCap = strokeCap,+ gapSize = gapSize,+)diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/navigation/NavigationSideBar.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/navigation/NavigationSideBar.ktindex a51e859296e..c87d5f35e05 100644--- a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/navigation/NavigationSideBar.kt+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/navigation/NavigationSideBar.kt@@ -50,7 +50,7 @@ import androidx.compose.ui.graphics.Colorimport androidx.compose.ui.graphics.vector.ImageVectorimport androidx.compose.ui.unit.dpimport org.apache.solr.ui.generated.resources.Res-import org.apache.solr.ui.generated.resources.logout+import org.apache.solr.ui.generated.resources.action_logoutimport org.apache.solr.ui.generated.resources.nav_clusterimport org.apache.solr.ui.generated.resources.nav_collectionsimport org.apache.solr.ui.generated.resources.nav_configsets@@ -102,7 +102,7 @@ fun NavigationSideBar(// TODO Add condition for displaying logout button if user identity / auth presentMenuElement(- text = stringResource(Res.string.logout),+ text = stringResource(Res.string.action_logout),imageVector = Icons.AutoMirrored.Rounded.Logout,modifier = Modifier.fillMaxWidth(),onClick = {}, // TODO Call logout on auth componentdiff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/root/RootContent.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/root/RootContent.ktindex b30c4d5a267..14432d6bc00 100644--- a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/root/RootContent.kt+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/root/RootContent.kt@@ -20,12 +20,16 @@ package org.apache.solr.ui.views.rootimport androidx.compose.foundation.layout.Columnimport androidx.compose.foundation.layout.fillMaxSizeimport androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.paddingimport androidx.compose.runtime.Composableimport androidx.compose.ui.Modifier+import androidx.compose.ui.unit.dpimport com.arkivanov.decompose.extensions.compose.stack.Childrenimport org.apache.solr.ui.components.root.RootComponent+import org.apache.solr.ui.views.auth.UserAuthenticationContentimport org.apache.solr.ui.views.main.MainContentimport org.apache.solr.ui.views.navigation.Footer+import org.apache.solr.ui.views.start.StartContent/*** The root composable of the Compose application. This function is used as the shared entry@@ -45,10 +49,20 @@ fun RootContent(modifier = Modifier.weight(1f),) {when(val child = it.instance) {+ is RootComponent.Child.Start -> StartContent(+ component = child.component,+ modifier = Modifier.fillMaxSize(),+ )+is RootComponent.Child.Main -> MainContent(component = child.component,modifier = Modifier.fillMaxSize(),)++ is RootComponent.Child.Unauthenticated -> UserAuthenticationContent(+ component = child.component,+ modifier = Modifier.padding(16.dp),+ )}}Footer(modifier = Modifier.fillMaxWidth())diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/start/StartContent.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/start/StartContent.ktnew file mode 100644index 00000000000..403b9a412d3--- /dev/null+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/start/StartContent.kt@@ -0,0 +1,137 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.views.start++import androidx.compose.foundation.Image+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.aspectRatio+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.widthIn+import androidx.compose.material3.MaterialTheme+import androidx.compose.material3.OutlinedTextField+import androidx.compose.material3.Text+import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.scale+import androidx.compose.ui.platform.testTag+import androidx.compose.ui.unit.dp+import org.apache.solr.ui.components.start.StartComponent+import org.apache.solr.ui.generated.resources.Res+import org.apache.solr.ui.generated.resources.action_connect+import org.apache.solr.ui.generated.resources.connecting+import org.apache.solr.ui.generated.resources.cd_solr_logo+import org.apache.solr.ui.generated.resources.desc_to_get_started+import org.apache.solr.ui.generated.resources.solr_sun+import org.apache.solr.ui.generated.resources.title_welcome_to_solr+import org.apache.solr.ui.utils.DEFAULT_SOLR_URL+import org.apache.solr.ui.views.components.SolrButton+import org.apache.solr.ui.views.components.SolrCard+import org.apache.solr.ui.views.components.SolrLinearProgressIndicator+import org.jetbrains.compose.resources.painterResource+import org.jetbrains.compose.resources.stringResource++/**+ * The composable used for users that have already authenticated.+ *+ * @param component Component that manages the state of the composable.+ */+@Composable+fun StartContent(+ component: StartComponent,+ modifier: Modifier = Modifier,+) = Row(+ modifier = modifier,+ horizontalArrangement = Arrangement.spacedBy(16.dp),+ verticalAlignment = Alignment.CenterVertically,+) {+ val model by component.model.collectAsState()++ Image(+ modifier = Modifier.weight(1f)+ .align(Alignment.Bottom)+ .fillMaxWidth()+ .aspectRatio(1f)+ .scale(1.5f),+ alpha = .3f,+ painter = painterResource(Res.drawable.solr_sun),+ contentDescription = stringResource(Res.string.cd_solr_logo)+ )++ Column(+ modifier = Modifier.weight(1f).padding(64.dp),+ ) {+ SolrCard(+ modifier = Modifier.widthIn(min = 512.dp, max = 640.dp),+ verticalArrangement = Arrangement.spacedBy(16.dp),+ ) {+ Text(+ modifier = Modifier.testTag("start_title"),+ text = stringResource(Res.string.title_welcome_to_solr),+ style = MaterialTheme.typography.headlineMedium,+ )+ Text(+ modifier = Modifier.testTag("start_description"),+ text = stringResource(Res.string.desc_to_get_started),+ style = MaterialTheme.typography.bodyLarge,+ )++ OutlinedTextField(+ modifier = Modifier.fillMaxWidth().testTag("solr_url_input"),+ value = model.url,+ singleLine = true,+ onValueChange = component::onSolrUrlChange,+ placeholder = { Text(text = DEFAULT_SOLR_URL) },+ enabled = !model.isConnecting,+ supportingText = {+ model.error?.let {+ Text(+ modifier = Modifier.testTag("input_error"),+ text = stringResource(it),+ color = MaterialTheme.colorScheme.error,+ )+ }+ }+ // TODO Update colors if necessary+ )++ Column {+ SolrButton(+ modifier = Modifier.fillMaxWidth().testTag("connect_button"),+ enabled = !model.isConnecting,+ onClick = component::onConnect,+ ) {+ Text(+ text = stringResource(+ if (model.isConnecting) Res.string.connecting+ else Res.string.action_connect+ ),+ )+ }+ if (model.isConnecting) SolrLinearProgressIndicator(+ modifier = Modifier.fillMaxWidth().testTag("loading_indicator"),+ )+ }+ }+ }+}diff --git a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/theme/Shapes.kt b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/theme/Shapes.ktindex 0f6557739bf..7c7db99e2f4 100644--- a/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/theme/Shapes.kt+++ b/solr/ui/src/commonMain/kotlin/org/apache/solr/ui/views/theme/Shapes.kt@@ -33,7 +33,9 @@ import androidx.compose.ui.unit.dp* Custom shapes that do not use rounded corners for elements.*/internal val SolrShapes = Shapes(+ extraSmall = CutCornerShape(0.dp),small = CutCornerShape(0.dp),medium = CutCornerShape(0.dp),large = CutCornerShape(0.dp),+ extraLarge = CutCornerShape(0.dp),)diff --git a/solr/ui/src/commonTest/kotlin/org/apache/solr/ui/TestUtils.kt b/solr/ui/src/commonTest/kotlin/org/apache/solr/ui/TestUtils.ktnew file mode 100644index 00000000000..6dbec6112d5--- /dev/null+++ b/solr/ui/src/commonTest/kotlin/org/apache/solr/ui/TestUtils.kt@@ -0,0 +1,44 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui++import io.ktor.client.engine.mock.MockEngine+import io.ktor.client.engine.mock.MockEngineConfig+import io.ktor.client.engine.mock.MockRequestHandler+import kotlinx.coroutines.test.StandardTestDispatcher+import kotlinx.coroutines.test.TestScope++/**+ * Creates a mock engine with the given handlers and a standard test dispatcher.+ *+ * @param handlers The handlers to attach to the mock engine that will handle the requests+ * in the same order.+ *+ */+fun TestScope.createMockEngine(+ vararg handlers: MockRequestHandler,+ reuseHandlers: Boolean = true,+): MockEngine {+ return MockEngine(+ MockEngineConfig().apply {+ dispatcher = StandardTestDispatcher(testScheduler)+ handlers.forEach(::addHandler)+ this.reuseHandlers = reuseHandlers+ }+ )+}diff --git a/solr/ui/src/commonTest/kotlin/org/apache/solr/ui/components/environment/store/EnvironmentStoreProviderTest.kt b/solr/ui/src/commonTest/kotlin/org/apache/solr/ui/components/environment/store/EnvironmentStoreProviderTest.ktindex 45fa54180c2..688ed3a458f 100644--- a/solr/ui/src/commonTest/kotlin/org/apache/solr/ui/components/environment/store/EnvironmentStoreProviderTest.kt+++ b/solr/ui/src/commonTest/kotlin/org/apache/solr/ui/components/environment/store/EnvironmentStoreProviderTest.kt@@ -42,6 +42,7 @@ class EnvironmentStoreProviderTest {val store = EnvironmentStoreProvider(storeFactory = DefaultStoreFactory(),client = client,+ mainContext = coroutineContext,ioContext = backgroundScope.coroutineContext).provide()@@ -84,6 +85,7 @@ class EnvironmentStoreProviderTest {val store = EnvironmentStoreProvider(storeFactory = DefaultStoreFactory(),client = client,+ mainContext = coroutineContext,ioContext = backgroundScope.coroutineContext,).provide()diff --git a/solr/ui/src/commonTest/kotlin/org/apache/solr/ui/components/start/integration/DefaultStartComponentIntegrationTest.kt b/solr/ui/src/commonTest/kotlin/org/apache/solr/ui/components/start/integration/DefaultStartComponentIntegrationTest.ktnew file mode 100644index 00000000000..f8f188f4c51--- /dev/null+++ b/solr/ui/src/commonTest/kotlin/org/apache/solr/ui/components/start/integration/DefaultStartComponentIntegrationTest.kt@@ -0,0 +1,214 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.components.start.integration++import com.arkivanov.decompose.DefaultComponentContext+import com.arkivanov.essenty.lifecycle.LifecycleRegistry+import com.arkivanov.essenty.lifecycle.resume+import com.arkivanov.mvikotlin.core.store.StoreFactory+import com.arkivanov.mvikotlin.core.utils.isAssertOnMainThreadEnabled+import com.arkivanov.mvikotlin.main.store.DefaultStoreFactory+import io.ktor.client.HttpClient+import io.ktor.client.engine.mock.MockRequestHandleScope+import io.ktor.client.engine.mock.MockRequestHandler+import io.ktor.client.engine.mock.respond+import io.ktor.client.request.HttpRequestData+import io.ktor.http.HttpStatusCode+import io.ktor.http.URLBuilder+import io.ktor.http.path+import kotlin.test.AfterTest+import kotlin.test.BeforeTest+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertIs+import kotlin.test.assertNotNull+import kotlin.test.assertNull+import kotlinx.coroutines.ExperimentalCoroutinesApi+import kotlinx.coroutines.test.StandardTestDispatcher+import kotlinx.coroutines.test.TestCoroutineScheduler+import kotlinx.coroutines.test.TestScope+import kotlinx.coroutines.test.UnconfinedTestDispatcher+import kotlinx.coroutines.test.advanceUntilIdle+import kotlinx.coroutines.test.runTest+import org.apache.solr.ui.components.start.StartComponent+import org.apache.solr.ui.components.start.StartComponent.Output+import org.apache.solr.ui.createMockEngine+import org.apache.solr.ui.generated.resources.Res+import org.apache.solr.ui.generated.resources.error_invalid_url+import org.apache.solr.ui.utils.AppComponentContext+import org.apache.solr.ui.utils.DEFAULT_SOLR_URL+import org.apache.solr.ui.utils.DefaultAppComponentContext++@OptIn(ExperimentalCoroutinesApi::class)+class DefaultStartComponentIntegrationTest {++ /**+ * Response handler that always responds with HTTP code OK.+ */+ private val okResponseHandler: MockRequestHandler = { scope: MockRequestHandleScope, data: HttpRequestData ->+ scope.respond(content = "Ignore", status = HttpStatusCode.OK)+ }++ /**+ * Response handler that always responds with HTTP code Forbidden.+ */+ private val forbiddenResponseHandler: MockRequestHandler = { scope: MockRequestHandleScope, data: HttpRequestData ->+ scope.respond(content = "Forbidden", status = HttpStatusCode.Forbidden)+ }++ @BeforeTest+ fun beforeTest() {+ isAssertOnMainThreadEnabled = false+ }++ @AfterTest+ fun afterTest() {+ isAssertOnMainThreadEnabled = true+ }++ @Test+ fun `GIVEN initial state WHEN onConnect THEN use default Solr URL`() = runTest {+ val engine = createMockEngine(okResponseHandler)+ val component = createComponent(httpClient = HttpClient(engine))++ component.onConnect()+ advanceUntilIdle()++ assertEquals(+ expected = 1,+ actual = engine.requestHistory.size,+ message = "Expected one request in history",+ )+ assertEquals(expected = URLBuilder(DEFAULT_SOLR_URL).apply {+ // As of now connection is established by calling this endpoint+ path("api/node/system")+ }.build(), actual = engine.requestHistory[0].url)+ }++ @Test+ fun `GIVEN invalid URL WHEN onConnect THEN invalidUrlError`() = runTest {+ val engine = createMockEngine(okResponseHandler)+ val component = createComponent(httpClient = HttpClient(engine))++ component.onSolrUrlChange("some.-invalid-url")++ component.onConnect()+ advanceUntilIdle()++ assertEquals(+ expected = 0,+ actual = engine.requestHistory.size,+ message = "Expected no request in history",+ )++ assertEquals(+ expected = Res.string.error_invalid_url,+ actual = component.model.value.error,+ message = "Expected invalid url error",+ )+ }++ @Test+ fun `GIVEN valid Solr URL WHEN onConnect THEN connection request sent`() = runTest {+ val engine = createMockEngine(okResponseHandler)+ val component = createComponent(httpClient = HttpClient(engine))+ val validSolrUrl = "https://my-solr-instance.local/"++ component.onSolrUrlChange(validSolrUrl)+ component.onConnect()+ advanceUntilIdle()++ assertEquals(+ expected = 1,+ actual = engine.requestHistory.size,+ message = "Expected one request in history",+ )+ assertEquals(expected = URLBuilder(validSolrUrl).apply {+ // As of now connection is established by calling this endpoint+ path("api/node/system")+ }.build(), actual = engine.requestHistory[0].url)+ }++ @Test+ fun `GIVEN a solr instance with no auth WHEN onConnect THEN output Connected`() = runTest {+ val outputStack = mutableListOf<Output>()+ val engine = createMockEngine(okResponseHandler)+ val component = createComponent(+ output = { outputStack.add(it) },+ httpClient = HttpClient(engine),+ )++ component.onConnect()+ advanceUntilIdle()++ assertEquals(+ expected = 1,+ actual = outputStack.size,+ message = "Expected one output",+ )+ assertIs<Output.OnConnected>(+ value = outputStack[0],+ message = "Expected output to be Connected",+ )+ }++ @Test+ fun `GIVEN input error WHEN input changes THEN error resets`() = runTest {+ val component = createComponent()+ component.onSolrUrlChange("some.-invalid-url")+ // Cause an error in state+ component.onConnect()++ advanceUntilIdle()+ assertNotNull(component.model.value.error)++ component.onSolrUrlChange("some-other-url")+ advanceUntilIdle()++ assertNull(component.model.value.error)+ }++ /**+ * Helper function for creating an instance of the [DefaultStartComponent].+ */+ private fun TestScope.createComponent(+ lifecycle: LifecycleRegistry = LifecycleRegistry(),+ scheduler: TestCoroutineScheduler = testScheduler,+ componentContext: AppComponentContext = DefaultAppComponentContext(+ componentContext = DefaultComponentContext(lifecycle = lifecycle),+ mainContext = StandardTestDispatcher(scheduler),+ ioContext = UnconfinedTestDispatcher(scheduler),+ ),+ storeFactory: StoreFactory = DefaultStoreFactory(),+ httpClient: HttpClient = HttpClient(),+ output: (Output) -> Unit = {},+ ): StartComponent {+ val lifecycle = LifecycleRegistry()++ val component =+ DefaultStartComponent(+ componentContext = componentContext,+ storeFactory = storeFactory,+ httpClient = httpClient,+ output = output,+ )++ lifecycle.resume()+ return component+ }+}\ No newline at end of filediff --git a/solr/ui/src/commonTest/kotlin/org/apache/solr/ui/views/start/StartContentTest.kt b/solr/ui/src/commonTest/kotlin/org/apache/solr/ui/views/start/StartContentTest.ktnew file mode 100644index 00000000000..54bb84bc61f--- /dev/null+++ b/solr/ui/src/commonTest/kotlin/org/apache/solr/ui/views/start/StartContentTest.kt@@ -0,0 +1,96 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.views.start++import androidx.compose.ui.semantics.SemanticsProperties+import androidx.compose.ui.test.ExperimentalTestApi+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.assertIsNotEnabled+import androidx.compose.ui.test.isDisplayed+import androidx.compose.ui.test.onNodeWithTag+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.compose.ui.test.runComposeUiTest+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue+import org.apache.solr.ui.components.start.StartComponent.Model+import org.apache.solr.ui.generated.resources.Res+import org.apache.solr.ui.generated.resources.error_invalid_url+import org.jetbrains.compose.resources.stringResource++@OptIn(ExperimentalTestApi::class)+class StartContentTest {++ @Test+ fun `WHEN initialized THEN input is empty`() = runComposeUiTest {+ setContent {+ StartContent(createComponent())+ }++ assertEquals("", onNodeWithTag("solr_url_input")+ .assertExists()+ .fetchSemanticsNode()+ .config[SemanticsProperties.EditableText]+ .text)+ }++ @Test+ fun `GIVEN input error THEN error text shown`() = runComposeUiTest {+ val errorRes = Res.string.error_invalid_url+ lateinit var errorText: String+ setContent {+ StartContent(createComponent(Model(error = errorRes)))+ errorText = stringResource(errorRes)+ }++ onNodeWithText(errorText).isDisplayed()+ }++ @Test+ fun `WHEN on connect clicked THEN onConnect called`() = runComposeUiTest {+ val component = createComponent()+ setContent {+ StartContent(component)+ }++ onNodeWithTag("connect_button").performClick()+ assertTrue(component.onConnectClicked)+ }++ @Test+ fun `WHEN isConnecting THEN connect inputs disabled`() = runComposeUiTest {+ setContent {+ StartContent(createComponent(Model(isConnecting = true)))+ }++ onNodeWithTag("solr_url_input").assertIsNotEnabled()+ onNodeWithTag("connect_button").assertIsNotEnabled()+ }++ @Test+ fun `WHEN isConnecting THEN loading indicator displayed`() = runComposeUiTest {+ setContent {+ StartContent(createComponent(Model(isConnecting = true)))+ }++ onNodeWithTag("loading_indicator").assertIsDisplayed()+ }++ private fun createComponent(model: Model = Model()) = TestStartComponent(model)+}diff --git a/solr/ui/src/commonTest/kotlin/org/apache/solr/ui/views/start/TestStartComponent.kt b/solr/ui/src/commonTest/kotlin/org/apache/solr/ui/views/start/TestStartComponent.ktnew file mode 100644index 00000000000..21228c50883--- /dev/null+++ b/solr/ui/src/commonTest/kotlin/org/apache/solr/ui/views/start/TestStartComponent.kt@@ -0,0 +1,39 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.views.start++import kotlinx.coroutines.flow.MutableStateFlow+import kotlinx.coroutines.flow.StateFlow+import org.apache.solr.ui.components.start.StartComponent+import org.apache.solr.ui.components.start.StartComponent.Model++class TestStartComponent(model: Model = Model()): StartComponent {++ override val model: StateFlow<Model> = MutableStateFlow(model)++ var solrUrl = ""+ var onConnectClicked = false++ override fun onSolrUrlChange(url: String) {+ solrUrl = url+ }++ override fun onConnect() {+ onConnectClicked = true+ }+}\ No newline at end of filediff --git a/solr/ui/src/desktopMain/kotlin/org/apache/solr/ui/errors/parseError.desktop.kt b/solr/ui/src/desktopMain/kotlin/org/apache/solr/ui/errors/parseError.desktop.ktnew file mode 100644index 00000000000..586dcbd2d85--- /dev/null+++ b/solr/ui/src/desktopMain/kotlin/org/apache/solr/ui/errors/parseError.desktop.kt@@ -0,0 +1,27 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.errors++import java.net.ConnectException++actual fun parseError(error: Throwable): Throwable {+ return when (error) {+ is ConnectException -> HostNotFoundException(error)+ else -> error+ }+}\ No newline at end of filediff --git a/solr/ui/src/desktopMain/kotlin/org/apache/solr/ui/preview/start/PreviewStartContent.kt b/solr/ui/src/desktopMain/kotlin/org/apache/solr/ui/preview/start/PreviewStartContent.ktnew file mode 100644index 00000000000..b47e80ccab1--- /dev/null+++ b/solr/ui/src/desktopMain/kotlin/org/apache/solr/ui/preview/start/PreviewStartContent.kt@@ -0,0 +1,60 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.preview.start++import androidx.compose.desktop.ui.tooling.preview.Preview+import androidx.compose.runtime.Composable+import kotlinx.coroutines.flow.MutableStateFlow+import kotlinx.coroutines.flow.StateFlow+import org.apache.solr.ui.components.start.StartComponent+import org.apache.solr.ui.generated.resources.Res+import org.apache.solr.ui.generated.resources.error_invalid_url+import org.apache.solr.ui.preview.PreviewContainer+import org.apache.solr.ui.views.start.StartContent++@Preview+@Composable+fun PreviewStartContent() = PreviewContainer {+ StartContent(component = PreviewStartComponent)+}++@Preview+@Composable+fun PreviewStartContentWithError() = PreviewContainer {+ StartContent(component = PreviewStartComponentWithError)+}++private object PreviewStartComponent: StartComponent {+ override val model: StateFlow<StartComponent.Model> =+ MutableStateFlow(StartComponent.Model())++ override fun onSolrUrlChange(url: String) = Unit+ override fun onConnect() = Unit+}++private object PreviewStartComponentWithError: StartComponent {+ override val model: StateFlow<StartComponent.Model> = MutableStateFlow(+ StartComponent.Model(+ url = "some-invalid-url!",+ error = Res.string.error_invalid_url,+ )+ )++ override fun onSolrUrlChange(url: String) = Unit+ override fun onConnect() = Unit+}diff --git a/solr/ui/src/wasmJsMain/kotlin/org/apache/solr/ui/errors/parseError.kt b/solr/ui/src/wasmJsMain/kotlin/org/apache/solr/ui/errors/parseError.ktnew file mode 100644index 00000000000..241340f4c51--- /dev/null+++ b/solr/ui/src/wasmJsMain/kotlin/org/apache/solr/ui/errors/parseError.kt@@ -0,0 +1,27 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.ui.errors++actual fun parseError(error: Throwable): Throwable {+ // In JavaScript the errors do not have any type to distinguish them, so we strongly+ // rely on the error message.+ if (error.message?.contains(other = "Fail to fetch") == true) return HostNotFoundException(cause = error)++ // fallback+ return error+}