From 0263a7b85c4b84dac732d0060e572213329f2651 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Fri, 26 Jan 2024 10:06:08 +0800 Subject: [PATCH] refactor(autocrud): update progress indicator messages #81 - Update progress indicator messages in AutoCrudAction.kt and AutoDevRunProfileState.kt to use the "autocrud" prefix instead of "devti". - Update the corresponding message keys in AutoDevBundle.properties to use the "autocrud" prefix instead of "devti". --- .../unitmesh/ide/javascript/flow/AutoPage.kt | 7 +++-- .../ide/javascript/flow/ReactAutoPage.kt | 30 ++++++++++++++----- .../javascript/flow/model/AutoPageContext.kt | 2 +- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/javascript/src/main/kotlin/cc/unitmesh/ide/javascript/flow/AutoPage.kt b/javascript/src/main/kotlin/cc/unitmesh/ide/javascript/flow/AutoPage.kt index 98a5412bce..e98f5bdad9 100644 --- a/javascript/src/main/kotlin/cc/unitmesh/ide/javascript/flow/AutoPage.kt +++ b/javascript/src/main/kotlin/cc/unitmesh/ide/javascript/flow/AutoPage.kt @@ -18,10 +18,11 @@ interface AutoPage : TaskFlow { var userTask: String /** - * Get all routes in the project, including the routes in the submodules - * @return list of routes + * Retrieves all routes in the project, including the routes in the submodules. + * + * @return A map of routes, where the key represents the route name and the value represents the route URL. */ - fun getRoutes(): List + fun getRoutes(): Map /** * Get all pages in the project, based on the naming convention, like the PascalCase under `src/pages` diff --git a/javascript/src/main/kotlin/cc/unitmesh/ide/javascript/flow/ReactAutoPage.kt b/javascript/src/main/kotlin/cc/unitmesh/ide/javascript/flow/ReactAutoPage.kt index 071f9afcd8..530e842b82 100644 --- a/javascript/src/main/kotlin/cc/unitmesh/ide/javascript/flow/ReactAutoPage.kt +++ b/javascript/src/main/kotlin/cc/unitmesh/ide/javascript/flow/ReactAutoPage.kt @@ -30,7 +30,8 @@ class ReactAutoPage( override var userTask: String, private val editor: Editor ) : AutoPage { - private val routes: List = emptyList() + // todo: add post routes design + private val routes: MutableMap = mutableMapOf() private val pages: MutableList = mutableListOf() private val components: MutableList = mutableListOf() @@ -39,10 +40,6 @@ class ReactAutoPage( init { val searchScope: GlobalSearchScope = ProjectScope.getContentScope(project) - // todo: find .umirc.ts in root, find in modules - val umirc = FileTypeIndex.getFiles(TypeScriptJSXFileType.INSTANCE, searchScope).firstOrNull { - it.name == ".umirc.ts" - } val psiManager = com.intellij.psi.PsiManager.getInstance(project) val virtualFiles = @@ -69,6 +66,10 @@ class ReactAutoPage( else -> { if (root.findChild(file.name) != null) { + RouterFile.values().filter { it.filename == file.name }.map { + routes += it to jsFile + } + configs.add(jsFile) } } @@ -92,6 +93,7 @@ class ReactAutoPage( } dsComponents } + else -> { logger().warn("unknown language: ${jsFile.language}") null @@ -99,7 +101,21 @@ class ReactAutoPage( } } - override fun getRoutes(): List = routes + override fun getRoutes(): Map { + return this.routes.map { + when (it.key) { + RouterFile.UMI -> emptyMap() + RouterFile.NEXT -> { + pages.associate { page -> + val route = page.name.replace(Regex("([A-Z])"), "-$1").lowercase() + route to route + } + } + + RouterFile.VITE -> emptyMap() + } + }.reduce { acc, map -> acc + map } + } // load prompts/context/ds.json from project root override fun getDesignSystemComponents(): List { @@ -129,7 +145,7 @@ class ReactAutoPage( TODO("Not yet implemented") } - fun filterComponents(components: List) : List { + fun filterComponents(components: List): List { val comps = this.pages + this.components return components.mapNotNull { component -> comps.find { it.name == component } diff --git a/javascript/src/main/kotlin/cc/unitmesh/ide/javascript/flow/model/AutoPageContext.kt b/javascript/src/main/kotlin/cc/unitmesh/ide/javascript/flow/model/AutoPageContext.kt index ac96c74b85..ca17550d69 100644 --- a/javascript/src/main/kotlin/cc/unitmesh/ide/javascript/flow/model/AutoPageContext.kt +++ b/javascript/src/main/kotlin/cc/unitmesh/ide/javascript/flow/model/AutoPageContext.kt @@ -18,7 +18,7 @@ data class AutoPageContext( pageNames = reactAutoPage.getPages().map { it.name }, components = reactAutoPage.getComponents().map { it.format() }, componentNames = reactAutoPage.getComponents().map { it.name }, - routes = reactAutoPage.getRoutes(), + routes = reactAutoPage.getRoutes().map { "${it.key}: ${it.value}" }, ) } }