-
Notifications
You must be signed in to change notification settings - Fork 274
Show notification banner #5097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show notification banner #5097
Changes from 10 commits
c3cc2bf
09729c7
885f3f0
f0aca38
e909a0e
5a84e39
56c1888
a981227
682897f
adb6ec7
dbfcefc
823ea7f
218c8ed
b684a01
368fd25
57fb2ef
a5126d1
22f9438
87ec1d9
24a2f65
78f8c6b
bfc1077
1a83a40
9e8b0af
1b12854
e7d8594
bbf6779
a8fa482
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // 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.icons.AllIcons | ||
| import com.intellij.openapi.application.runInEdt | ||
| import com.intellij.openapi.components.Service | ||
| import com.intellij.openapi.components.service | ||
| import com.intellij.openapi.project.Project | ||
| import com.intellij.ui.EditorNotificationPanel | ||
| import com.intellij.ui.components.panels.Wrapper | ||
| import com.intellij.util.ui.components.BorderLayoutPanel | ||
| import software.aws.toolkits.jetbrains.core.notifications.NotificationActionList | ||
| import software.aws.toolkits.jetbrains.core.notifications.NotificationManager | ||
| import software.aws.toolkits.resources.AwsCoreBundle | ||
|
|
||
| @Service(Service.Level.PROJECT) | ||
| class NotificationPanel : BorderLayoutPanel() { | ||
| private val wrapper = Wrapper() | ||
| init { | ||
| isOpaque = false | ||
| addToCenter(wrapper) | ||
| } | ||
|
|
||
| private fun removeNotificationPanel() = runInEdt { | ||
| wrapper.removeAll() | ||
| } | ||
|
|
||
| fun updateNotificationPanel(title: String, message: String, notificationActionList: List<NotificationActionList>) { | ||
| val panel = EditorNotificationPanel() | ||
| panel.text = title | ||
| panel.icon(AllIcons.General.Error) | ||
| val panelWithActions = NotificationManager.buildBannerPanel(panel, notificationActionList) | ||
| panelWithActions.createActionLabel(AwsCoreBundle.message("general.dismiss")) { | ||
| removeNotificationPanel() | ||
| } | ||
|
|
||
| wrapper.setContent(panelWithActions) | ||
| } | ||
|
|
||
| companion object { | ||
| fun getInstance(project: Project): NotificationPanel = project.service() | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // 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.components.Service | ||
| import com.intellij.openapi.components.service | ||
| 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.getLogger | ||
| import javax.swing.JComponent | ||
|
|
||
| @Service(Service.Level.PROJECT) | ||
manodnyab marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| class OuterAmazonQPanel : BorderLayoutPanel() { | ||
| private val wrapper = Wrapper() | ||
| init { | ||
| isOpaque = false | ||
| addToCenter(wrapper) | ||
| } | ||
|
|
||
| fun updateQPanel(content: JComponent) { | ||
Check noticeCode scanning / QDJVMC Class member can have 'private' visibility Note
Function 'updateQPanel' could be private
|
||
| try { | ||
| wrapper.setContent(content) | ||
| } catch (e: Exception) { | ||
| getLogger<OuterAmazonQPanel>().error("Error while creating window") | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| fun getInstance(project: Project): OuterAmazonQPanel = project.service() | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // 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.ide.BrowserUtil | ||
| import com.intellij.openapi.actionSystem.AnAction | ||
| import com.intellij.openapi.actionSystem.AnActionEvent | ||
| import com.intellij.openapi.ui.Messages | ||
| import com.intellij.ui.EditorNotificationPanel | ||
| import software.aws.toolkits.jetbrains.AwsToolkit | ||
| import software.aws.toolkits.resources.AwsCoreBundle | ||
|
|
||
| fun checkSeverity(notificationSeverity: String): NotificationSeverity = when (notificationSeverity) { | ||
| "Critical" -> NotificationSeverity.CRITICAL | ||
| "Warning" -> NotificationSeverity.WARNING | ||
| "Info" -> NotificationSeverity.INFO | ||
| else -> NotificationSeverity.INFO | ||
| } | ||
|
|
||
| object NotificationManager { | ||
| fun createActions( | ||
| followupActions: List<NotificationFollowupActions>?, | ||
| message: String, | ||
| title: String, | ||
|
|
||
| ): List<NotificationActionList> = buildList { | ||
| add( | ||
| NotificationActionList(AwsCoreBundle.message("notification.expand")) { | ||
| Messages.showYesNoDialog( | ||
| null, | ||
| message, | ||
| title, | ||
| AwsCoreBundle.message("general.ok"), | ||
| AwsCoreBundle.message("general.cancel"), | ||
| AllIcons.General.Error | ||
| ) | ||
| } | ||
| ) | ||
|
|
||
| followupActions?.forEach { action -> | ||
| if (action.type == "ShowUrl") { | ||
| add( | ||
| NotificationActionList(AwsCoreBundle.message("notification.learn_more")) { | ||
| action.content.locale.url?.let { url -> BrowserUtil.browse(url) } | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| if (action.type == "UpdateExtension") { | ||
| add( | ||
| NotificationActionList(AwsCoreBundle.message("notification.update")) { | ||
| // TODO: Add update logic | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| if (action.type == "OpenChangelog") { | ||
| add( | ||
| NotificationActionList(AwsCoreBundle.message("notification.changelog")) { | ||
| BrowserUtil.browse(AwsToolkit.GITHUB_CHANGELOG) | ||
| } | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun buildNotificationActions(actions: List<NotificationActionList>): List<AnAction> = actions.map { (title, block) -> | ||
| object : AnAction(title) { | ||
| override fun actionPerformed(e: AnActionEvent) { | ||
| block() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fun buildBannerPanel(panel: EditorNotificationPanel, actions: List<NotificationActionList>): EditorNotificationPanel { | ||
| actions.forEach { (actionTitle, block) -> | ||
| panel.createActionLabel(actionTitle) { | ||
| block() | ||
| } | ||
| } | ||
|
|
||
| return panel | ||
| } | ||
| } | ||
|
|
||
| data class NotificationActionList( | ||
| val title: String, | ||
| val blockToExecute: () -> Unit, | ||
| ) |
| 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.notification.NotificationType | ||
| import com.intellij.openapi.actionSystem.AnAction | ||
| import com.intellij.openapi.project.Project | ||
| import software.aws.toolkits.jetbrains.utils.notifyStickyWithData | ||
|
|
||
| object DisplayToastNotifications { | ||
| fun showToast(title: String, message: String, action: List<AnAction>, notificationType: NotificationSeverity, notificationId: String) { | ||
|
Check notice on line 12 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/DisplayToastNotifications.kt
|
||
|
||
| val notifyType = when (notificationType) { | ||
| NotificationSeverity.CRITICAL -> NotificationType.ERROR | ||
| NotificationSeverity.WARNING -> NotificationType.WARNING | ||
| NotificationSeverity.INFO -> NotificationType.INFORMATION | ||
| } | ||
| notifyStickyWithData(notifyType, title, message, null, action, notificationId) | ||
| } | ||
|
|
||
| fun shouldShowNotification(project: Project, notificationData: NotificationData) { | ||
|
||
| if (RulesEngine.displayNotification(notificationData, project)) { | ||
| val notificationContent = notificationData.content.locale | ||
| val severity = notificationData.severity | ||
| val followupActions = NotificationManager.createActions(notificationData.actions, notificationContent.description, notificationContent.title) | ||
| showToast( | ||
| notificationContent.title, | ||
| notificationContent.description, | ||
| NotificationManager.buildNotificationActions(followupActions), | ||
| checkSeverity(severity), | ||
| notificationData.id | ||
| ) | ||
|
|
||
| if (severity == "Critical") { | ||
| ShowCriticalNotificationBannerListener.showBanner(notificationContent.title, notificationContent.description, followupActions) | ||
| } | ||
| } | ||
| } | ||
| } | ||
manodnyab marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // 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.openapi.actionSystem.AnAction | ||
| import com.intellij.openapi.actionSystem.AnActionEvent | ||
| import com.intellij.openapi.util.registry.Registry | ||
|
|
||
| class DummyNotificationAction : AnAction("Show notif") { | ||
|
Check warning on line 10 in plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/DummyNotificationAction.kt
|
||
|
||
| override fun actionPerformed(e: AnActionEvent) { | ||
| if (!Registry.`is`("aws.toolkit.developerMode")) return | ||
| ShowCriticalNotificationBannerListener.showBanner( | ||
| "hello hello", | ||
| "This is a bug", | ||
| NotificationManager.createActions(emptyList(), "This is a bug", "hello hello") | ||
| ) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.