Skip to content

Commit 732fd56

Browse files
committed
refactor(javascript): replace DsComponent with UiComponent #319
Deleted DsComponent.kt and introduced UiComponent.kt in a shared module. Updated all references to use the new UiComponent class, ensuring consistency across the codebase. This change centralizes the component model definition and improves maintainability.
1 parent eb60889 commit 732fd56

File tree

5 files changed

+31
-30
lines changed

5 files changed

+31
-30
lines changed

javascript/src/main/kotlin/cc/unitmesh/ide/javascript/flow/model/DsComponent.kt renamed to core/src/main/kotlin/cc/unitmesh/devti/bridge/tools/UiComponent.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
package cc.unitmesh.ide.javascript.flow.model
1+
package cc.unitmesh.devti.bridge.tools
22

33
import kotlinx.serialization.Serializable
44

5-
/**
6-
* the Design System Component
7-
*/
85
@Serializable
9-
data class DsComponent(
6+
data class UiComponent(
107
val name: String,
118
val path: String,
129
val signature: String = "",

javascript/src/main/kotlin/cc/unitmesh/ide/javascript/flow/AutoPage.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cc.unitmesh.ide.javascript.flow
22

33
import cc.unitmesh.devti.flow.TaskFlow
4-
import cc.unitmesh.ide.javascript.flow.model.DsComponent
4+
import cc.unitmesh.devti.bridge.tools.UiComponent
55

66
/**
77
* FrontendFlow is an interface that represents the flow of tasks in a frontend application.
@@ -28,20 +28,20 @@ interface AutoPage : TaskFlow<String> {
2828
* Get all pages in the project, based on the naming convention, like the PascalCase under `src/pages`
2929
* @return list of pages
3030
*/
31-
fun getPages(): List<DsComponent>
31+
fun getPages(): List<UiComponent>
3232

3333
/**
3434
* Get all components in the project, based on the naming convention, like the PascalCase under `src/components`
3535
* @return list of components
3636
*/
37-
fun getComponents(): List<DsComponent>
37+
fun getComponents(): List<UiComponent>
3838

3939
/**
4040
* Get the design system components, like the Ant Design in React.
4141
* Which will load the design system components from the remote
4242
* @return list of design system components
4343
*/
44-
fun getDesignSystemComponents(): List<DsComponent>
44+
fun getDesignSystemComponents(): List<UiComponent>
4545

4646
/**
4747
* Get remote call as a sample, like the axios in Vue, the fetch in React

javascript/src/main/kotlin/cc/unitmesh/ide/javascript/flow/AutoPageFlow.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import cc.unitmesh.devti.llms.LLMProvider
77
import cc.unitmesh.devti.template.GENIUS_PAGE
88
import cc.unitmesh.devti.template.TemplateRender
99
import cc.unitmesh.ide.javascript.flow.model.AutoPageContext
10-
import cc.unitmesh.ide.javascript.flow.model.DsComponent
10+
import cc.unitmesh.devti.bridge.tools.UiComponent
1111
import kotlinx.coroutines.runBlocking
1212

1313
class AutoPageFlow(val context: AutoPageContext, val panel: ChatCodingPanel, val llm: LLMProvider) :
@@ -36,7 +36,7 @@ class AutoPageFlow(val context: AutoPageContext, val panel: ChatCodingPanel, val
3636

3737

3838
override fun design(context: Any): List<String> {
39-
val componentList = context as List<DsComponent>
39+
val componentList = context as List<UiComponent>
4040
val stepTwoPrompt = generateStepTwoPrompt(componentList)
4141

4242
panel.addMessage(stepTwoPrompt, true, stepTwoPrompt)
@@ -48,7 +48,7 @@ class AutoPageFlow(val context: AutoPageContext, val panel: ChatCodingPanel, val
4848
}.let { listOf(it) }
4949
}
5050

51-
private fun generateStepTwoPrompt(selectedComponents: List<DsComponent>): String {
51+
private fun generateStepTwoPrompt(selectedComponents: List<UiComponent>): String {
5252
val templateRender = TemplateRender(GENIUS_PAGE)
5353
val template = templateRender.getTemplate("page-gen-design.vm")
5454

javascript/src/main/kotlin/cc/unitmesh/ide/javascript/flow/ReactAutoPage.kt

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package cc.unitmesh.ide.javascript.flow
22

3-
import cc.unitmesh.ide.javascript.flow.model.DsComponent
3+
import cc.unitmesh.devti.bridge.tools.UiComponent
44
import cc.unitmesh.ide.javascript.util.ReactPsiUtil
55
import com.intellij.lang.javascript.JavaScriptFileType
66
import com.intellij.lang.javascript.TypeScriptJSXFileType
@@ -32,10 +32,8 @@ class ReactAutoPage(
3232
) : AutoPage {
3333
// todo: add post routes design
3434
private val routes: MutableMap<RouterFile, JSFile> = mutableMapOf()
35-
private val pages: MutableList<DsComponent> = mutableListOf()
36-
private val components: MutableList<DsComponent> = mutableListOf()
37-
38-
// config files
35+
private val pages: MutableList<UiComponent> = mutableListOf()
36+
private val components: MutableList<UiComponent> = mutableListOf()
3937
private val configs: MutableList<JSFile> = mutableListOf()
4038

4139
init {
@@ -55,6 +53,10 @@ class ReactAutoPage(
5553
if (jsFile.isTestFile) return@forEach
5654

5755
when {
56+
path.contains("views") -> buildComponent(jsFile)?.let {
57+
pages += it
58+
}
59+
5860
path.contains("pages") -> buildComponent(jsFile)?.let {
5961
pages += it
6062
}
@@ -65,7 +67,7 @@ class ReactAutoPage(
6567

6668
else -> {
6769
if (root.findChild(file.name) != null) {
68-
RouterFile.values().filter { it.filename == file.name }.map {
70+
RouterFile.entries.filter { it.filename == file.name }.map {
6971
routes += it to jsFile
7072
}
7173

@@ -76,11 +78,11 @@ class ReactAutoPage(
7678
}
7779
}
7880

79-
override fun getPages(): List<DsComponent> = pages
81+
override fun getPages(): List<UiComponent> = pages
8082

81-
override fun getComponents(): List<DsComponent> = components
83+
override fun getComponents(): List<UiComponent> = components
8284

83-
private fun buildComponent(jsFile: JSFile): List<DsComponent>? {
85+
private fun buildComponent(jsFile: JSFile): List<UiComponent>? {
8486
return when (jsFile.language) {
8587
is TypeScriptJSXLanguageDialect,
8688
is ECMA6LanguageDialect
@@ -116,34 +118,36 @@ class ReactAutoPage(
116118
}
117119

118120
// load prompts/context/ds.json from project root
119-
override fun getDesignSystemComponents(): List<DsComponent> {
121+
override fun getDesignSystemComponents(): List<UiComponent> {
120122
val rootConfig = project.guessProjectDir()
121123
?.findChild("prompts")
122124
?.findChild("context")
123125
?.findChild("ds.json") ?: return emptyList()
124126

125127
val json = rootConfig.inputStream.reader().readText()
126128
return try {
127-
val result: List<DsComponent> = Json.decodeFromString(json)
129+
val result: List<UiComponent> = Json.decodeFromString(json)
128130
result
129131
} catch (e: Exception) {
130132
emptyList()
131133
}
132134
}
133135

134136
override fun sampleRemoteCall(): String {
137+
// search for axios usage if exist package.json in code
135138
TODO("Not yet implemented")
136139
}
137140

138141
override fun sampleStateManagement(): String? {
142+
// lookup for redux usage if exist package.json in code
139143
TODO("Not yet implemented")
140144
}
141145

142146
override fun clarify(): String {
143147
TODO("Not yet implemented")
144148
}
145149

146-
fun filterComponents(components: List<String>): List<DsComponent> {
150+
fun filterComponents(components: List<String>): List<UiComponent> {
147151
val comps = this.pages + this.components
148152
return components.mapNotNull { component ->
149153
comps.find { it.name == component }

javascript/src/main/kotlin/cc/unitmesh/ide/javascript/util/ReactPsiUtil.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package cc.unitmesh.ide.javascript.util
22

3-
import cc.unitmesh.ide.javascript.flow.model.DsComponent
3+
import cc.unitmesh.devti.bridge.tools.UiComponent
44
import com.intellij.lang.ecmascript6.psi.ES6ExportDeclaration
55
import com.intellij.lang.ecmascript6.psi.ES6ExportDefaultAssignment
66
import com.intellij.lang.javascript.presentable.JSFormatUtil
@@ -36,7 +36,7 @@ object ReactPsiUtil {
3636
return map + defaultAssignment
3737
}
3838

39-
fun tsxComponentToComponent(jsFile: JSFile): List<DsComponent> = getExportElements(jsFile).map { psiElement ->
39+
fun tsxComponentToComponent(jsFile: JSFile): List<UiComponent> = getExportElements(jsFile).map { psiElement ->
4040
val name = psiElement.name
4141
if (name == null) {
4242
logger<ReactPsiUtil>().warn("name is null")
@@ -50,11 +50,11 @@ object ReactPsiUtil {
5050

5151
return@map when (psiElement) {
5252
is TypeScriptFunction -> {
53-
DsComponent(name = name, path)
53+
UiComponent(name = name, path)
5454
}
5555

5656
is TypeScriptClass -> {
57-
DsComponent(name = name, path)
57+
UiComponent(name = name, path)
5858
}
5959

6060
is TypeScriptVariable, is JSVariable -> {
@@ -77,11 +77,11 @@ object ReactPsiUtil {
7777
}
7878
} ?: emptyList()
7979

80-
DsComponent(name = name, path, props = props, signature = signature)
80+
UiComponent(name = name, path, props = props, signature = signature)
8181
}
8282

8383
else -> {
84-
println("unknown type: ${psiElement::class.java}")
84+
logger<ReactPsiUtil>().warn("unknown type: ${psiElement::class.java}")
8585
null
8686
}
8787
}

0 commit comments

Comments
 (0)