Skip to content

Commit 6a9d379

Browse files
committed
refactor(mcp): consolidate ParameterDisplay into RequestDetailPanel
#371 - Move ParameterDisplay implementation into RequestDetailPanel file - Simplify response duration label in ResponseDetailPanel - Remove standalone ParameterDisplay.kt file
1 parent 408a787 commit 6a9d379

File tree

3 files changed

+75
-80
lines changed

3 files changed

+75
-80
lines changed

core/src/main/kotlin/cc/unitmesh/devti/mcp/ui/eval/ParameterDisplay.kt

-79
This file was deleted.

core/src/main/kotlin/cc/unitmesh/devti/mcp/ui/eval/RequestDetailPanel.kt

+74
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ package cc.unitmesh.devti.mcp.ui.eval
33
import cc.unitmesh.devti.mcp.ui.model.McpMessage
44
import com.intellij.ui.JBColor
55
import com.intellij.ui.components.JBLabel
6+
import com.intellij.ui.components.JBScrollPane
67
import com.intellij.util.ui.JBUI
78
import kotlinx.serialization.json.Json
9+
import kotlinx.serialization.json.JsonElement
810
import kotlinx.serialization.json.jsonObject
911
import java.awt.BorderLayout
12+
import java.awt.Dimension
1013
import java.awt.Font
1114
import javax.swing.*
15+
import kotlin.collections.component1
16+
import kotlin.collections.component2
17+
import kotlin.collections.forEach
1218

1319
/**
1420
* Panel for displaying request details from MCP messages
@@ -61,3 +67,71 @@ class RequestDetailPanel : JPanel(BorderLayout()) {
6167
}
6268
}
6369
}
70+
71+
/**
72+
* A reusable component for displaying key-value parameters from JSON
73+
*/
74+
class ParameterDisplay : JPanel(BorderLayout()) {
75+
private val contentPanel = JPanel().apply {
76+
layout = BoxLayout(this, BoxLayout.Y_AXIS)
77+
background = JBColor(0xFFFFFF, 0x2B2D30)
78+
border = JBUI.Borders.empty(10)
79+
}
80+
81+
init {
82+
background = JBColor(0xFFFFFF, 0x2B2D30)
83+
add(JBScrollPane(contentPanel), BorderLayout.CENTER)
84+
}
85+
86+
fun displayParameters(parameters: Map<String, JsonElement>?) {
87+
contentPanel.removeAll()
88+
89+
if (parameters == null || parameters.isEmpty()) {
90+
contentPanel.add(JBLabel("No parameters").apply {
91+
foreground = JBColor.GRAY
92+
alignmentX = LEFT_ALIGNMENT
93+
})
94+
} else {
95+
contentPanel.add(JBLabel("Parameters:").apply {
96+
font = font.deriveFont(Font.BOLD, font.size + 1f)
97+
alignmentX = LEFT_ALIGNMENT
98+
border = JBUI.Borders.emptyBottom(10)
99+
})
100+
101+
parameters.forEach { (key, value) ->
102+
val paramPanel = JPanel(BorderLayout()).apply {
103+
background = contentPanel.background
104+
border = JBUI.Borders.emptyBottom(5)
105+
alignmentX = LEFT_ALIGNMENT
106+
maximumSize = Dimension(Int.MAX_VALUE, getPreferredSize().height)
107+
}
108+
109+
paramPanel.add(JBLabel("$key:").apply {
110+
font = font.deriveFont(Font.BOLD)
111+
border = JBUI.Borders.emptyRight(10)
112+
}, BorderLayout.WEST)
113+
114+
val valueText = formatJsonValue(value)
115+
val valueTextArea = JTextArea(valueText).apply {
116+
lineWrap = true
117+
wrapStyleWord = true
118+
isEditable = false
119+
border = null
120+
background = contentPanel.background
121+
}
122+
123+
paramPanel.add(valueTextArea, BorderLayout.CENTER)
124+
contentPanel.add(paramPanel)
125+
}
126+
}
127+
128+
contentPanel.add(Box.createVerticalGlue())
129+
130+
contentPanel.revalidate()
131+
contentPanel.repaint()
132+
}
133+
134+
private fun formatJsonValue(element: JsonElement): String {
135+
return element.toString()
136+
}
137+
}

core/src/main/kotlin/cc/unitmesh/devti/mcp/ui/eval/ResponseDetailPanel.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ResponseDetailPanel : JPanel(BorderLayout()) {
3131
}
3232

3333
init {
34-
headerPanel.add(JBLabel("Response Duration:"))
34+
headerPanel.add(JBLabel("Duration:"))
3535
headerPanel.add(durationLabel)
3636

3737
add(headerPanel, BorderLayout.NORTH)

0 commit comments

Comments
 (0)