Skip to content

Commit 146c999

Browse files
Merge pull request #2237 from digma-ai/feature/ui-navigation
Refactor navigation
2 parents 9ceeb88 + be7df2d commit 146c999

File tree

53 files changed

+463
-1693
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+463
-1693
lines changed

build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ tasks {
334334

335335
val filesToFilter = listOf(
336336
"webview/recentactivity/recentActivityTemplate.ftl",
337-
"webview/notifications/notificationstemplate.ftl",
338337
"webview/navigation/navigationtemplate.ftl",
339338
"webview/jaegerui/jaegeruitemplate.ftl",
340339
"webview/documentation/documentation.ftl",

ide-common/src/main/java/org/digma/intellij/plugin/analytics/Environment.java

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,13 @@ Env getCurrent() {
5050
}
5151

5252

53-
void setCurrentById(@Nullable String envId) {
54-
55-
if (StringUtils.isEmpty(envId)) {
56-
return;
57-
}
58-
59-
setCurrentById(envId, null);
60-
}
61-
62-
63-
//this method does not handle illegal or null environment. it should be called with a non-null newEnv
64-
// that exists in the DB.
65-
void setCurrentById(@NotNull String envId, @Nullable Runnable taskToRunAfterChange) {
53+
void setCurrentById(@NotNull String envId) {
6654

6755
try {
6856
Log.log(LOGGER::debug, "Setting current environment by id , old={},new={}", current, envId);
6957

7058
if (StringUtils.isEmpty(envId) || StringUtils.isBlank(envId)) {
71-
Log.log(LOGGER::debug, "setCurrent was called with an empty environment {}", envId);
59+
Log.log(LOGGER::debug, "setCurrentById was called with an empty environment {}", envId);
7260
return;
7361
}
7462

@@ -87,11 +75,6 @@ void setCurrentById(@NotNull String envId, @Nullable Runnable taskToRunAfterChan
8775
envChangeLock.unlock();
8876
}
8977
}
90-
91-
//runs in background but not under lock
92-
if (taskToRunAfterChange != null) {
93-
taskToRunAfterChange.run();
94-
}
9578
};
9679

9780
Backgroundable.ensureBackgroundWithoutReadAccess(project, "Digma: environment changed " + envId, task);

ide-common/src/main/java/org/digma/intellij/plugin/ui/MainToolWindowCardsController.java

Lines changed: 25 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
/**
2626
* Controls the current view in digma tool window.
27-
* there is a main content, wizard,troubleshooting ,notifications and no connection.
27+
* there is a main content, wizard,troubleshooting and no connection.
2828
* the main content has a no connection empty card and the main card.
2929
* the tool window should have only one content.
3030
* Not handling any exceptions in this class. if an exception is thrown we must know that because it's probably a serious bug.
@@ -60,9 +60,6 @@ public enum MainWindowCard {
6060
private final TroubleshootingComponents troubleshooting = new TroubleshootingComponents();
6161
private Supplier<DisposablePanel> troubleshootingPanelBuilder;
6262

63-
private final NotificationsComponents notifications = new NotificationsComponents();
64-
private Supplier<DisposablePanel> allNotificationsPanelBuilder;
65-
6663
private final AtomicBoolean isConnectionLost = new AtomicBoolean(false);
6764

6865

@@ -92,36 +89,30 @@ public void connectionGained() {
9289
(AggressiveUpdateStateChangedEvent) this::updateStateChanged);
9390

9491

95-
project.getMessageBus().connect().subscribe(ApiClientChangedEvent.getAPI_CLIENT_CHANGED_TOPIC(),new ApiClientChangedEvent(){
96-
97-
@Override
98-
public void apiClientChanged(@NotNull String newUrl) {
99-
Backgroundable.ensurePooledThread(() -> {
100-
//on new install the wizard opens and lets user install digma backend.
101-
//if the user doesn't have docker and wants to change to centralized deployment,
102-
// user will change the url in settings, the plugin will connect to the centralized deployment,
103-
// but there will be no way out of the wizard because there is no close button and no finish button.
104-
//so here we close the wizard in this scenario, the wizard will close and user will see the login screen.
105-
//isFirstWizardLaunch will be true on new install, when the wizard opens first time,
106-
// the flag will change only when INSTALLATION_WIZARD/FINISH message, so while the wizard is open
107-
// isFirstWizardLaunch should be true.
108-
//if user had a working local deployment and then decides to change to centralized, if the wizard is open
109-
// in that stage the wizard should have a close button.
110-
if (wizard.isOn() && PersistenceService.getInstance().isFirstWizardLaunch()){
111-
if(isCentralized()){
112-
//do here everything that happens on INSTALLATION_WIZARD/FINISH message
113-
PersistenceService.getInstance().firstWizardLaunchDone();
114-
updateInstallationWizardFlag();
115-
EDT.ensureEDT(() -> {
116-
ToolWindowShower.getInstance(project).showToolWindow();
117-
project.getService(RecentActivityToolWindowShower.class).showToolWindow();
118-
wizardFinished();
119-
});
120-
}
121-
}
122-
});
92+
project.getMessageBus().connect().subscribe(ApiClientChangedEvent.getAPI_CLIENT_CHANGED_TOPIC(), (ApiClientChangedEvent) newUrl -> Backgroundable.ensurePooledThread(() -> {
93+
//on new install the wizard opens and lets user install digma backend.
94+
//if the user doesn't have docker and wants to change to centralized deployment,
95+
// user will change the url in settings, the plugin will connect to the centralized deployment,
96+
// but there will be no way out of the wizard because there is no close button and no finish button.
97+
//so here we close the wizard in this scenario, the wizard will close and user will see the login screen.
98+
//isFirstWizardLaunch will be true on new install, when the wizard opens first time,
99+
// the flag will change only when INSTALLATION_WIZARD/FINISH message, so while the wizard is open
100+
// isFirstWizardLaunch should be true.
101+
//if user had a working local deployment and then decides to change to centralized, if the wizard is open
102+
// in that stage the wizard should have a close button.
103+
if (wizard.isOn() && PersistenceService.getInstance().isFirstWizardLaunch()){
104+
if(isCentralized()){
105+
//do here everything that happens on INSTALLATION_WIZARD/FINISH message
106+
PersistenceService.getInstance().firstWizardLaunchDone();
107+
updateInstallationWizardFlag();
108+
EDT.ensureEDT(() -> {
109+
ToolWindowShower.getInstance(project).showToolWindow();
110+
project.getService(RecentActivityToolWindowShower.class).showToolWindow();
111+
wizardFinished();
112+
});
113+
}
123114
}
124-
});
115+
}));
125116
}
126117

127118

@@ -154,8 +145,7 @@ public void initComponents(@NotNull ToolWindow toolWindow,
154145
@NotNull Content mainContent,
155146
@NotNull JPanel mainCardsPanel,
156147
@NotNull Function<Boolean, DisposablePanel> wizardPanelBuilder,
157-
Supplier<DisposablePanel> troubleshootingPanelBuilder,
158-
Supplier<DisposablePanel> allNotificationsPanelBuilder) {
148+
Supplier<DisposablePanel> troubleshootingPanelBuilder) {
159149

160150
Log.log(LOGGER::debug, "initComponents called");
161151

@@ -171,8 +161,6 @@ public void initComponents(@NotNull ToolWindow toolWindow,
171161

172162
this.troubleshootingPanelBuilder = troubleshootingPanelBuilder;
173163

174-
this.allNotificationsPanelBuilder = allNotificationsPanelBuilder;
175-
176164
//it may be that there was a connection lost event before the panels were ready.
177165
// in that case show connection lost panel
178166
if (isConnectionLost.get() || BackendConnectionMonitor.getInstance(project).isConnectionError()) {
@@ -257,9 +245,6 @@ public void showTroubleshooting() {
257245
if (troubleshootingPanel != null) {
258246

259247
Content troubleshootingContent = ContentFactory.getInstance().createContent(troubleshootingPanel, null, false);
260-
// if (wizard.isOn()) {
261-
// wizardFinished();
262-
// }
263248

264249
toolWindow.getContentManager().removeContent(mainContent, false);
265250
toolWindow.getContentManager().addContent(troubleshootingContent);
@@ -293,58 +278,6 @@ public void troubleshootingFinished() {
293278
}
294279

295280

296-
public void showAllNotifications() {
297-
Log.log(LOGGER::debug, "showAllNotifications called");
298-
299-
//in case showAllNotifications is called while notifications is already on
300-
if (notifications.isOn()) {
301-
Log.log(LOGGER::debug, project, "showAllNotifications was called but notifications on. nothing to do.");
302-
return;
303-
}
304-
305-
//build the notifications panel every time its necessary and dispose it when the notifications closed.
306-
var notificationsPanel = allNotificationsPanelBuilder.get();
307-
if (notificationsPanel != null) {
308-
Content notificationsContent = ContentFactory.getInstance().createContent(notificationsPanel, null, false);
309-
toolWindow.getContentManager().removeContent(mainContent, false);
310-
toolWindow.getContentManager().addContent(notificationsContent);
311-
notifications.notificationsContent = notificationsContent;
312-
notifications.notificationsPanel = notificationsPanel;
313-
} else {
314-
Log.log(LOGGER::debug, project, "showAllNotifications was called but notificationsPanel is null. it may happen if the runtime JVM does not support JCEF");
315-
}
316-
}
317-
318-
319-
public void closeAllNotificationsIfShowing() {
320-
if (notifications.isOn()) {
321-
closeAllNotifications();
322-
}
323-
}
324-
325-
326-
public void closeAllNotifications() {
327-
Log.log(LOGGER::debug, "closeAllNotifications called");
328-
329-
EDT.ensureEDT(() -> {
330-
if (notifications.isOn()) {
331-
toolWindow.getContentManager().removeContent(notifications.notificationsContent, true);
332-
toolWindow.getContentManager().addContent(mainContent);
333-
//dispose the notifications panel which will dispose the jcef browser
334-
notifications.notificationsPanel.dispose();
335-
notifications.notificationsContent = null;
336-
notifications.notificationsPanel = null;
337-
338-
} else {
339-
Log.log(LOGGER::debug, project, "closeAllNotifications was called but notifications is not on.");
340-
}
341-
});
342-
343-
}
344-
345-
346-
347-
348281
/**
349282
* it may happen that user clicks a span link while the troubleshooting or wizard are on.
350283
* it can happen if user opens troubleshooting or the wizard and then clicks a link in recent activity,
@@ -366,7 +299,6 @@ public void closeCoveringViewsIfNecessary() {
366299
}
367300
wizardFinished();
368301
troubleshootingFinished();
369-
closeAllNotificationsIfShowing();
370302
}
371303

372304
public void showMainPanel() {
@@ -472,13 +404,5 @@ public boolean isOn() {
472404
}
473405
}
474406

475-
private static class NotificationsComponents {
476-
Content notificationsContent;
477-
DisposablePanel notificationsPanel;
478-
479-
public boolean isOn() {
480-
return notificationsContent != null && notificationsPanel != null;
481-
}
482-
}
483407

484408
}

ide-common/src/main/kotlin/org/digma/intellij/plugin/analytics/EnvUtils.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ fun setCurrentEnvironmentById(project: Project, envId: String) {
4343
AnalyticsService.getInstance(project).environment.setCurrentById(envId)
4444
}
4545

46-
fun setCurrentEnvironmentById(project: Project, envId: String, taskToRunAfterChange: Runnable) {
47-
AnalyticsService.getInstance(project).environment.setCurrentById(envId, taskToRunAfterChange)
48-
}
49-
5046
fun refreshEnvironmentsNowOnBackground(project: Project) {
5147
AnalyticsService.getInstance(project).environment.refreshNowOnBackground()
5248
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.digma.intellij.plugin.codelens
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator
4+
import org.digma.intellij.plugin.model.lens.CodeLens
5+
import java.beans.ConstructorProperties
6+
7+
data class ChangeScopeMessagePayload
8+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
9+
@ConstructorProperties("codeLens")
10+
constructor(val codeLens: CodeLens)

ide-common/src/main/kotlin/org/digma/intellij/plugin/codelens/CodeLensService.kt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ import com.intellij.psi.PsiFile
1616
import com.intellij.psi.SmartPointerManager
1717
import com.jetbrains.rd.util.ConcurrentHashMap
1818
import org.digma.intellij.plugin.common.Backgroundable
19+
import org.digma.intellij.plugin.common.objectToJsonNode
1920
import org.digma.intellij.plugin.document.CodeLensChanged
2021
import org.digma.intellij.plugin.document.CodeLensProvider
2122
import org.digma.intellij.plugin.document.CodeLensUtils.psiFileToKey
2223
import org.digma.intellij.plugin.errorreporting.ErrorReporter
2324
import org.digma.intellij.plugin.log.Log
2425
import org.digma.intellij.plugin.model.lens.CodeLens
25-
import org.digma.intellij.plugin.navigation.View
2626
import org.digma.intellij.plugin.posthog.ActivityMonitor
2727
import org.digma.intellij.plugin.psi.LanguageService
28+
import org.digma.intellij.plugin.scope.ScopeContext
2829
import org.digma.intellij.plugin.scope.ScopeManager
2930
import org.digma.intellij.plugin.scope.SpanScope
3031
import java.awt.event.MouseEvent
@@ -223,16 +224,9 @@ class CodeLensService(private val project: Project) : Disposable {
223224
}
224225
}
225226
Backgroundable.ensurePooledThreadWithoutReadAccess {
226-
if (lens.scopeCodeObjectId.startsWith("span:")) {
227-
//order must be first change scope then change view, UI relies on this order
228-
if (lens.importance <= 4) {
229-
ScopeManager.getInstance(project).changeScope(SpanScope(lens.scopeCodeObjectId), preferredView = View.Insights)
230-
} else if (lens.lensTitle.contains("runtime data", false)) {
231-
ScopeManager.getInstance(project).changeScope(SpanScope(lens.scopeCodeObjectId), preferredView = View.Highlights)
232-
} else {
233-
ScopeManager.getInstance(project).changeScope(SpanScope(lens.scopeCodeObjectId))
234-
}
235-
}
227+
val contextPayload = objectToJsonNode(ChangeScopeMessagePayload(lens))
228+
val scopeContext = ScopeContext("IDE/CODE_LENS_CLICKED",contextPayload)
229+
ScopeManager.getInstance(project).changeScope(SpanScope(lens.scopeCodeObjectId),false,null,scopeContext,null)
236230
}
237231

238232
} catch (e: Exception) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ fun objectToJson(value: Any): String {
1111
return sharedObjectMapper.writeValueAsString(value)
1212
}
1313

14+
@Throws(JsonProcessingException::class)
15+
fun objectToJsonNode(value: Any): JsonNode {
16+
return sharedObjectMapper.valueToTree(value)
17+
}
18+
1419
@Throws(JsonProcessingException::class)
1520
fun readTree(tree: String): JsonNode {
1621
return sharedObjectMapper.readTree(tree)

ide-common/src/main/kotlin/org/digma/intellij/plugin/scope/ScopeChangedEvent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ interface ScopeChangedEvent {
1616
}
1717

1818

19-
fun scopeChanged(scope: SpanScope?, codeLocation: CodeLocation, hasErrors: Boolean)
19+
fun scopeChanged(scope: SpanScope?, codeLocation: CodeLocation, hasErrors: Boolean, scopeContext: ScopeContext?, environmentId: String?)
2020
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.digma.intellij.plugin.scope
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator
4+
import com.fasterxml.jackson.databind.JsonNode
5+
import java.beans.ConstructorProperties
6+
7+
data class ScopeContext
8+
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
9+
@ConstructorProperties(
10+
"event",
11+
"payload"
12+
)
13+
constructor(
14+
val event: String? = null,
15+
val payload: JsonNode? = null
16+
)

0 commit comments

Comments
 (0)