Skip to content

Commit 3af9414

Browse files
Implement links and pagination for N+1 endpoint insight
1 parent 36a2873 commit 3af9414

File tree

7 files changed

+266
-102
lines changed

7 files changed

+266
-102
lines changed

ide-common/src/main/java/org/digma/intellij/plugin/insights/view/GroupListViewItemBuilder.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ public List<ListViewItem<?>> build(Project project, T insight, ListGroupManager
4141
break;
4242
}
4343
case SpanDurationBreakdown:{
44-
WorkspaceUrisHelper.findWorkspaceUrisForSpans(project,theListView, getSpanIds((SpanDurationBreakdownInsight) insight), insight.getCodeObjectId());
44+
WorkspaceUrisHelper.findWorkspaceUrisForSpans(project, theListView, getSpanIds((SpanDurationBreakdownInsight) insight), insight.getCodeObjectId());
45+
break;
46+
}
47+
case EndpointSpaNPlusOne:{
48+
WorkspaceUrisHelper.findWorkspaceUrisForSpans(project, theListView, getSpanIds((EPNPlusSpansInsight) insight), insight.getCodeObjectId());
4549
break;
4650
}
4751
case SpanScaling:{
@@ -74,4 +78,12 @@ private List<String> getSpanIds(SpanDurationBreakdownInsight insight) {
7478
.collect(Collectors.toList());
7579
}
7680

81+
private List<String> getSpanIds(EPNPlusSpansInsight insight) {
82+
return insight.getSpans().stream().filter(it -> it.getInternalSpan() != null)
83+
.map(it -> CodeObjectsUtil.createSpanId(
84+
it.getInternalSpan().getInstrumentationLibrary(),
85+
it.getInternalSpan().getName()))
86+
.collect(Collectors.toList());
87+
}
88+
7789
}

ide-common/src/main/kotlin/org/digma/intellij/plugin/editor/PaginationUtil.kt

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ fun addInsightPaginationInfo(focusedDocumentName: String, uniqueInsightId: Strin
1414
filesAndInsightsPaginationInfosMap[uniqueInsightId] = activePage
1515
insightsPaginationInfo[focusedDocumentName] = filesAndInsightsPaginationInfosMap
1616
}
17-
} else if (insightsPaginationInfo.contains(uniqueInsightId)) {
17+
} else if (insightsPaginationInfo[focusedDocumentName] != null && insightsPaginationInfo[focusedDocumentName]!!.containsKey(uniqueInsightId)) {
1818
// remove pagination info for insights which had some page selected before
19-
insightsPaginationInfo.remove(uniqueInsightId)
19+
insightsPaginationInfo[focusedDocumentName]!!.remove(uniqueInsightId)
2020
}
2121
}
2222

@@ -28,4 +28,32 @@ fun removeInsightsPaginationInfoForClosedDocument(documentName: String) {
2828
if (insightsPaginationInfo.isNotEmpty()) {
2929
insightsPaginationInfo.remove(documentName)
3030
}
31+
}
32+
33+
fun <T> updateListOfEntriesToDisplay(
34+
entries: List<T>,
35+
entriesToDisplay: ArrayList<T>,
36+
currPageNum: Int,
37+
recordsPerPage: Int
38+
) {
39+
entriesToDisplay.clear()
40+
if (entries.isNotEmpty()) {
41+
val start = (currPageNum - 1) * recordsPerPage
42+
var end = start + recordsPerPage
43+
if (end >= entries.size) {
44+
end = entries.size
45+
}
46+
for (i in start until end) {
47+
entriesToDisplay.add(entries[i])
48+
}
49+
}
50+
}
51+
52+
fun getCurrentPageNumberForInsight(uniqueInsightId: String, lastPageNum: Int): Int {
53+
var currPageNum = 0
54+
getInsightPaginationInfo(uniqueInsightId)?.let { currPageNum = getInsightPaginationInfo(uniqueInsightId)!! }
55+
if (currPageNum < 1) {
56+
currPageNum = if (lastPageNum > 0) 1 else 0
57+
}
58+
return currPageNum
3159
}

src/main/kotlin/org/digma/intellij/plugin/ui/list/insights/DurationBreakdownPanel.kt

Lines changed: 23 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import com.intellij.ui.components.JBPanel
66
import com.intellij.util.ui.JBUI.Borders.empty
77
import org.apache.commons.lang3.StringUtils
88
import 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
1211
import org.digma.intellij.plugin.model.rest.insights.SpanDurationBreakdown
1312
import org.digma.intellij.plugin.model.rest.insights.SpanDurationBreakdownInsight
1413
import org.digma.intellij.plugin.ui.common.Laf
@@ -21,6 +20,7 @@ import javax.swing.*
2120

2221

2322
private const val P_50: Float = 0.5F
23+
private const val RECORDS_PER_PAGE_DURATION_BREAKDOWN = 3
2424

2525
fun 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

8773
private 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+
10297
private 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-
144114
private fun getDurationBreakdownPanel(): JPanel {
145115
val durationBreakdownPanel = JBPanel<JBPanel<*>>()
146116
durationBreakdownPanel.layout = BorderLayout(5, 0)

0 commit comments

Comments
 (0)