Skip to content

Commit 09729c7

Browse files
committed
Condition matcher for displaying notifications
1 parent c3cc2bf commit 09729c7

File tree

7 files changed

+702
-9
lines changed

7 files changed

+702
-9
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.jetbrains.core.notifications
5+
6+
fun checkSeverity(notificationSeverity: String): NotificationSeverity = when (notificationSeverity) {
7+
"Critical" -> NotificationSeverity.CRITICAL
8+
"Warning" -> NotificationSeverity.WARNING
9+
"Info" -> NotificationSeverity.INFO
10+
else -> NotificationSeverity.INFO
11+
}
12+
13+
// TODO: Add actions that can be performed from the notifications here

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/DisplayToastNotifications.kt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,24 @@ package software.aws.toolkits.jetbrains.core.notifications
55

66
import com.intellij.notification.NotificationType
77
import com.intellij.openapi.actionSystem.AnAction
8+
import com.intellij.openapi.project.Project
89
import software.aws.toolkits.jetbrains.utils.notifySticky
910

1011
object DisplayToastNotifications {
11-
fun show(title: String, message: String, action: List<AnAction>, notificationType: ToastNotificationType) {
12+
fun show(title: String, message: String, action: List<AnAction>, notificationType: NotificationSeverity) {
1213
val notifyType = when (notificationType) {
13-
ToastNotificationType.CRITICAL -> NotificationType.ERROR
14-
ToastNotificationType.WARNING -> NotificationType.WARNING
15-
ToastNotificationType.PRODUCT_UPDATE -> NotificationType.INFORMATION
14+
NotificationSeverity.CRITICAL -> NotificationType.ERROR
15+
NotificationSeverity.WARNING -> NotificationType.WARNING
16+
NotificationSeverity.INFO -> NotificationType.INFORMATION
1617
}
1718
notifySticky(notifyType, title, message, null, action)
1819
}
19-
}
2020

21-
enum class ToastNotificationType {
22-
CRITICAL,
23-
WARNING,
24-
PRODUCT_UPDATE,
21+
fun shouldShow(project: Project, notificationData: NotificationData) {
22+
if (RulesEngine.displayNotification(notificationData, project)) {
23+
val notificationContent = notificationData.content.locale
24+
val severity = notificationData.severity
25+
show(notificationContent.title, notificationContent.description, emptyList(), checkSeverity(severity))
26+
}
27+
}
2528
}
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package software.aws.toolkits.jetbrains.core.notifications
5+
6+
import com.fasterxml.jackson.annotation.JsonProperty
7+
8+
data class NotificationsList(
9+
@JsonProperty("schema")
10+
val schema: Schema,
11+
@JsonProperty("notifications")
12+
val notifications: List<NotificationData>,
13+
)
14+
15+
data class Schema(
16+
@JsonProperty("version")
17+
val version: String,
18+
)
19+
20+
data class NotificationData(
21+
@JsonProperty("id")
22+
val id: String,
23+
@JsonProperty("schedule")
24+
val schedule: NotificationSchedule,
25+
@JsonProperty("severity")
26+
val severity: String,
27+
@JsonProperty("condition")
28+
val condition: NotificationDisplayCondition?,
29+
@JsonProperty("content")
30+
val content: NotificationContentDescriptionLocale,
31+
@JsonProperty("actions")
32+
val actions: List<NotificationFollowupActions>? = emptyList(),
33+
)
34+
35+
data class NotificationSchedule(
36+
@JsonProperty("type")
37+
val type: String,
38+
)
39+
40+
enum class NotificationSeverity {
41+
INFO,
42+
WARNING,
43+
CRITICAL,
44+
}
45+
46+
data class NotificationContentDescriptionLocale(
47+
@JsonProperty("en-US")
48+
val locale: NotificationContentDescription,
49+
)
50+
51+
data class NotificationContentDescription(
52+
@JsonProperty("title")
53+
val title: String,
54+
@JsonProperty("description")
55+
val description: String,
56+
)
57+
58+
data class NotificationFollowupActions(
59+
@JsonProperty("type")
60+
val type: String,
61+
@JsonProperty("content")
62+
val content: NotificationFollowupActionsContent,
63+
)
64+
65+
data class NotificationFollowupActionsContent(
66+
@JsonProperty("en-US")
67+
val locale: NotificationActionDescription,
68+
)
69+
70+
data class NotificationActionDescription(
71+
@JsonProperty("title")
72+
val title: String,
73+
@JsonProperty("url")
74+
val url: String?,
75+
)
76+
77+
data class NotificationDisplayCondition(
78+
@JsonProperty("compute")
79+
val compute: ComputeType?,
80+
@JsonProperty("os")
81+
val os: SystemType?,
82+
@JsonProperty("ide")
83+
val ide: SystemType?,
84+
@JsonProperty("extension")
85+
val extension: List<ExtensionType>?,
86+
@JsonProperty("authx")
87+
val authx: List<AuthxType>,
88+
)
89+
90+
data class ComputeType(
91+
@JsonProperty("type")
92+
val type: NotificationExpression?,
93+
@JsonProperty("architecture")
94+
val architecture: NotificationExpression?,
95+
)
96+
97+
data class SystemType(
98+
@JsonProperty("type")
99+
val type: NotificationExpression?,
100+
@JsonProperty("version")
101+
val version: NotificationExpression?,
102+
)
103+
104+
data class ExtensionType(
105+
@JsonProperty("id")
106+
val id: String?,
107+
@JsonProperty("version")
108+
val version: NotificationExpression?,
109+
)
110+
111+
open class NotificationExpression
112+
113+
open class NotificationOperation : NotificationExpression()
114+
115+
data class NotCondition(
116+
@JsonProperty("not")
117+
val expectedValue: NotificationExpression,
118+
) : NotificationExpression()
119+
120+
data class OrCondition(
121+
@JsonProperty("or")
122+
val expectedValueList: List<NotificationExpression>,
123+
) : NotificationExpression()
124+
125+
data class AndCondition(
126+
@JsonProperty("and")
127+
val expectedValueList: List<NotificationExpression>,
128+
) : NotificationExpression()
129+
130+
data class AuthxType(
131+
@JsonProperty("feature")
132+
val feature: String,
133+
@JsonProperty("type")
134+
val type: NotificationExpression?,
135+
@JsonProperty("region")
136+
val region: NotificationExpression?,
137+
@JsonProperty("connectionState")
138+
val connectionState: NotificationExpression?,
139+
@JsonProperty("ssoscopes")
140+
val ssoScopes: NotificationExpression?,
141+
)
142+
143+
data class ComparisonCondition(
144+
@JsonProperty("==")
145+
val expectedValue: String,
146+
) : NotificationOperation()
147+
148+
data class NotEqualsCondition(
149+
@JsonProperty("!=")
150+
val expectedValue: String,
151+
) : NotificationOperation()
152+
153+
data class GreaterThanCondition(
154+
@JsonProperty(">")
155+
val expectedValue: String,
156+
) : NotificationOperation()
157+
158+
data class GreaterThanOrEqualsCondition(
159+
@JsonProperty(">=")
160+
val expectedValue: String,
161+
) : NotificationOperation()
162+
163+
data class LessThanCondition(
164+
@JsonProperty("<")
165+
val expectedValue: String,
166+
) : NotificationOperation()
167+
168+
data class LessThanOrEqualsCondition(
169+
@JsonProperty("<=")
170+
val expectedValue: String,
171+
) : NotificationOperation()
172+
173+
data class InCondition(
174+
@JsonProperty("anyOf")
175+
val expectedValueList: List<String>,
176+
) : NotificationOperation()
177+
178+
data class NotInCondition(
179+
@JsonProperty("noneOf")
180+
val expectedValueList: List<String>,
181+
) : NotificationOperation()

0 commit comments

Comments
 (0)