@@ -6,9 +6,8 @@ import com.intellij.ui.components.JBPanel
66import com.intellij.util.ui.JBUI.Borders.empty
77import org.apache.commons.lang3.StringUtils
88import org.digma.intellij.plugin.document.CodeObjectsUtil
9- import org.digma.intellij.plugin.editor.addInsightPaginationInfo
10- import org.digma.intellij.plugin.editor.getFocusedDocumentName
11- import org.digma.intellij.plugin.editor.getInsightPaginationInfo
9+ import org.digma.intellij.plugin.editor.getCurrentPageNumberForInsight
10+ import org.digma.intellij.plugin.editor.updateListOfEntriesToDisplay
1211import org.digma.intellij.plugin.model.rest.insights.SpanDurationBreakdown
1312import org.digma.intellij.plugin.model.rest.insights.SpanDurationBreakdownInsight
1413import org.digma.intellij.plugin.ui.common.Laf
@@ -21,6 +20,7 @@ import javax.swing.*
2120
2221
2322private const val P_50 : Float = 0.5F
23+ private const val RECORDS_PER_PAGE_DURATION_BREAKDOWN = 3
2424
2525fun spanDurationBreakdownPanel (
2626 project : Project ,
@@ -30,48 +30,33 @@ fun spanDurationBreakdownPanel(
3030
3131 val uniqueInsightId = insight.codeObjectId + insight.type
3232 val lastPageNum: Int
33- var currPageNum = 0
3433 var resultBreakdownPanel: DigmaResettablePanel ? = null
3534 val paginationPanel = JPanel ()
3635 val durationBreakdownEntriesToDisplay = ArrayList <SpanDurationBreakdown >()
37- val prev = ActionLink (" Prev" )
38- val next = ActionLink (" Next" )
3936
4037 val validBreakdownEntries = insight.breakdownEntries
4138 .filter { entry -> entry.percentiles.any { breakdown -> breakdown.percentile.equals(P_50 ) } }
4239 .sortedWith(compareByDescending { getValueOfPercentile(it, P_50 ) })
4340
4441 // calculate how many pages there are
45- lastPageNum = validBreakdownEntries.size / RECORDS_PER_PAGE + if (validBreakdownEntries.size % RECORDS_PER_PAGE != 0 ) 1 else 0
46- getInsightPaginationInfo(uniqueInsightId)?.let { currPageNum = getInsightPaginationInfo(uniqueInsightId)!! }
47- if (currPageNum < 1 ) {
48- currPageNum = if (lastPageNum > 0 ) 1 else 0
49- }
50-
42+ lastPageNum = validBreakdownEntries.size / RECORDS_PER_PAGE_DURATION_BREAKDOWN + if (validBreakdownEntries.size % RECORDS_PER_PAGE_DURATION_BREAKDOWN != 0 ) 1 else 0
5143
5244 resultBreakdownPanel = object : DigmaResettablePanel () {
5345 override fun reset () {
54- buildDurationBreakdownRowPanel (
46+ rebuildDurationBreakdownRowPanel (
5547 resultBreakdownPanel!! ,
5648 durationBreakdownEntriesToDisplay,
5749 project,
5850 moreData
5951 )
60- rebuildPaginationPanel(paginationPanel, currPageNum, lastPageNum, prev, next)
52+ rebuildPaginationPanel(paginationPanel, lastPageNum,
53+ validBreakdownEntries, resultBreakdownPanel, durationBreakdownEntriesToDisplay, uniqueInsightId, RECORDS_PER_PAGE_DURATION_BREAKDOWN )
6154 }
6255 }
6356
64- prev.addActionListener {
65- if (-- currPageNum <= 0 ) currPageNum = 1
66- updateDurationBreakdownPanel(validBreakdownEntries, resultBreakdownPanel, durationBreakdownEntriesToDisplay, uniqueInsightId, currPageNum)
67- }
68- next.addActionListener {
69- if (++ currPageNum > lastPageNum) currPageNum = lastPageNum
70- updateDurationBreakdownPanel(validBreakdownEntries, resultBreakdownPanel, durationBreakdownEntriesToDisplay, uniqueInsightId, currPageNum)
71- }
57+ updateListOfEntriesToDisplay(validBreakdownEntries, durationBreakdownEntriesToDisplay, getCurrentPageNumberForInsight(uniqueInsightId, lastPageNum), RECORDS_PER_PAGE_DURATION_BREAKDOWN )
58+ buildDurationBreakdownRowPanel(resultBreakdownPanel, durationBreakdownEntriesToDisplay, project, moreData)
7259
73- updateDurationBreakdownPanel(validBreakdownEntries, resultBreakdownPanel, durationBreakdownEntriesToDisplay,
74- uniqueInsightId, currPageNum)
7560 return createInsightPanel(
7661 project = project,
7762 insight = insight,
@@ -80,25 +65,35 @@ fun spanDurationBreakdownPanel(
8065 iconsList = listOf (Laf .Icons .Insight .DURATION ),
8166 bodyPanel = resultBreakdownPanel,
8267 buttons = null ,
83- paginationComponent = buildPaginationRowPanel(currPageNum, lastPageNum, paginationPanel, prev, next),
68+ paginationComponent = buildPaginationRowPanel(lastPageNum, paginationPanel,
69+ validBreakdownEntries, resultBreakdownPanel, durationBreakdownEntriesToDisplay, uniqueInsightId, RECORDS_PER_PAGE_DURATION_BREAKDOWN ),
8470 )
8571}
8672
8773private fun buildDurationBreakdownRowPanel (
8874 durationBreakdownPanel : DigmaResettablePanel ,
89- durationBreakdownEntries : List <SpanDurationBreakdown >,
75+ durationBreakdownEntriesToDisplay : List <SpanDurationBreakdown >,
9076 project : Project ,
9177 moreData : HashMap <String , Any >
9278) {
93- durationBreakdownPanel.removeAll()
9479 durationBreakdownPanel.layout = BoxLayout (durationBreakdownPanel, BoxLayout .Y_AXIS )
9580 durationBreakdownPanel.isOpaque = false
9681
97- durationBreakdownEntries .forEach { durationBreakdown: SpanDurationBreakdown ->
82+ durationBreakdownEntriesToDisplay .forEach { durationBreakdown: SpanDurationBreakdown ->
9883 durationBreakdownPanel.add(durationBreakdownRowPanel(durationBreakdown, project, moreData))
9984 }
10085}
10186
87+ private fun rebuildDurationBreakdownRowPanel (
88+ durationBreakdownPanel : DigmaResettablePanel ,
89+ durationBreakdownEntriesToDisplay : List <SpanDurationBreakdown >,
90+ project : Project ,
91+ moreData : HashMap <String , Any >
92+ ) {
93+ durationBreakdownPanel.removeAll()
94+ buildDurationBreakdownRowPanel(durationBreakdownPanel, durationBreakdownEntriesToDisplay, project, moreData)
95+ }
96+
10297private fun durationBreakdownRowPanel (
10398 durationBreakdown : SpanDurationBreakdown ,
10499 project : Project ,
@@ -116,31 +111,6 @@ private fun durationBreakdownRowPanel(
116111 return durationBreakdownPanel
117112}
118113
119- private fun updateDurationBreakdownPanel (
120- durationBreakdownEntries : List <SpanDurationBreakdown >,
121- resultBreakdownPanel : DigmaResettablePanel ,
122- durationBreakdownEntriesToDisplay : ArrayList <SpanDurationBreakdown >,
123- uniqueInsightId : String ,
124- currPageNum : Int
125- ) {
126- val focusedDocumentName = getFocusedDocumentName()
127- addInsightPaginationInfo(focusedDocumentName, uniqueInsightId, currPageNum)
128- durationBreakdownEntriesToDisplay.clear()
129-
130- if (durationBreakdownEntries.isNotEmpty()) {
131- val start = (currPageNum - 1 ) * RECORDS_PER_PAGE
132- var end = start + RECORDS_PER_PAGE
133- if (end >= durationBreakdownEntries.size) {
134- end = durationBreakdownEntries.size
135- }
136- for (i in start until end) {
137- durationBreakdownEntriesToDisplay.add(durationBreakdownEntries[i])
138- }
139- }
140-
141- resultBreakdownPanel.reset()
142- }
143-
144114private fun getDurationBreakdownPanel (): JPanel {
145115 val durationBreakdownPanel = JBPanel <JBPanel <* >>()
146116 durationBreakdownPanel.layout = BorderLayout (5 , 0 )
0 commit comments