-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show toasts for notifications and notification banner on critical not…
…ifications(#5097) * Display toast notifications with actions * Condition matcher for displaying notifications * Show notification banner * feedback 1 * Modified deserialization cases and added tests * not required file change * feedback 1 * feedback 1 * modified the base class * merge conflicts resolved * rearranged call site * show notifications when panel is opened * fixed tests * detekt * feedback * convert panels into wrappers * fixed test
- Loading branch information
Showing
17 changed files
with
449 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...nity/src/software/aws/toolkits/jetbrains/services/amazonq/toolwindow/OuterAmazonQPanel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.jetbrains.services.amazonq.toolwindow | ||
|
||
import com.intellij.openapi.project.Project | ||
import com.intellij.ui.components.panels.Wrapper | ||
import com.intellij.util.ui.components.BorderLayoutPanel | ||
import software.aws.toolkits.core.utils.error | ||
import software.aws.toolkits.core.utils.getLogger | ||
import software.aws.toolkits.jetbrains.core.webview.BrowserState | ||
import software.aws.toolkits.jetbrains.services.amazonq.QWebviewPanel | ||
import software.aws.toolkits.jetbrains.utils.isQConnected | ||
import software.aws.toolkits.jetbrains.utils.isQExpired | ||
import software.aws.toolkits.telemetry.FeatureId | ||
import javax.swing.JComponent | ||
|
||
class OuterAmazonQPanel(val project: Project) : BorderLayoutPanel() { | ||
private val wrapper = Wrapper() | ||
init { | ||
isOpaque = false | ||
addToCenter(wrapper) | ||
val component = if (isQConnected(project) && !isQExpired(project)) { | ||
AmazonQToolWindow.getInstance(project).component | ||
} else { | ||
QWebviewPanel.getInstance(project).browser?.prepareBrowser(BrowserState(FeatureId.AmazonQ)) | ||
QWebviewPanel.getInstance(project).component | ||
} | ||
updateQPanel(component) | ||
} | ||
|
||
fun updateQPanel(content: JComponent) { | ||
try { | ||
wrapper.setContent(content) | ||
} catch (e: Exception) { | ||
getLogger<OuterAmazonQPanel>().error { "Error while creating window" } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...ins-community/src/software/aws/toolkits/jetbrains/core/notifications/NotificationPanel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.jetbrains.core.notifications | ||
|
||
import com.intellij.icons.AllIcons | ||
import com.intellij.openapi.application.runInEdt | ||
import com.intellij.ui.EditorNotificationPanel | ||
import com.intellij.ui.components.panels.Wrapper | ||
import com.intellij.util.ui.components.BorderLayoutPanel | ||
import software.aws.toolkits.resources.AwsCoreBundle | ||
|
||
class NotificationPanel : BorderLayoutPanel() { | ||
private val wrapper = Wrapper() | ||
init { | ||
isOpaque = false | ||
addToCenter(wrapper) | ||
ProcessNotificationsBase.showBannerNotification.forEach { | ||
updateNotificationPanel(it.value) | ||
} | ||
} | ||
|
||
private fun removeNotificationPanel(notificationId: String) = runInEdt { | ||
ProcessNotificationsBase.showBannerNotification.remove(notificationId) // TODO: add id to dismissed notification list | ||
wrapper.removeAll() | ||
} | ||
|
||
fun updateNotificationPanel(bannerContent: BannerContent) { | ||
val panel = EditorNotificationPanel() | ||
panel.text = bannerContent.title | ||
panel.icon(AllIcons.General.Error) | ||
val panelWithActions = NotificationManager.buildBannerPanel(panel, bannerContent.actions) | ||
panelWithActions.createActionLabel(AwsCoreBundle.message("general.dismiss")) { | ||
removeNotificationPanel(bannerContent.id) | ||
} | ||
|
||
wrapper.setContent(panelWithActions) | ||
} | ||
} |
Oops, something went wrong.