Skip to content

Commit fbedc50

Browse files
committed
extract state since it can change upon 2nd access (redhat-developer#619)
Signed-off-by: Andre Dietisheim <[email protected]>
1 parent 6437bb8 commit fbedc50

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/PushNotification.kt

+12-4
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,20 @@ class PushNotification(private val editor: FileEditor, private val project: Proj
3333

3434
fun show(showPull: Boolean, editorResources: Collection<EditorResource>) {
3535
val toCreateOrUpdate = editorResources
36-
.filter { editorResource ->
37-
editorResource.getState() is Different
36+
.map { editorResource ->
37+
// extract state, it may change when accessed again
38+
Pair(editorResource.getState(), editorResource)
3839
}
39-
.groupBy { editorResource ->
40-
(editorResource.getState() as Different).exists
40+
.filter { resourceByState ->
41+
resourceByState.first is Different
4142
}
43+
.groupBy(
44+
{ resourceByState ->
45+
(resourceByState.first as Different).exists
46+
}, { resourceByState ->
47+
resourceByState.second
48+
}
49+
)
4250
val toCreate = toCreateOrUpdate[false] ?: emptyList()
4351
val toUpdate = toCreateOrUpdate[true] ?: emptyList()
4452
if (toCreate.isEmpty()

src/main/kotlin/com/redhat/devtools/intellij/kubernetes/editor/notification/PushedNotification.kt

+13-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import com.intellij.openapi.util.Key
1616
import com.intellij.ui.EditorNotificationPanel
1717
import com.intellij.util.containers.isNullOrEmpty
1818
import com.redhat.devtools.intellij.kubernetes.editor.EditorResource
19-
import com.redhat.devtools.intellij.kubernetes.editor.FILTER_PUSHED
2019
import com.redhat.devtools.intellij.kubernetes.editor.Pushed
2120
import com.redhat.devtools.intellij.kubernetes.editor.hideNotification
2221
import com.redhat.devtools.intellij.kubernetes.editor.showNotification
@@ -46,10 +45,20 @@ class PushedNotification(private val editor: FileEditor, private val project: Pr
4645
private fun createPanel(editorResources: Collection<EditorResource>): EditorNotificationPanel {
4746
val panel = EditorNotificationPanel()
4847
val createdOrUpdated = editorResources
49-
.filter(FILTER_PUSHED)
50-
.groupBy { editorResource ->
51-
(editorResource.getState() as Pushed).updated
48+
.map { editorResource ->
49+
Pair(editorResource.getState(), editorResource)
5250
}
51+
.filter { resourceByState ->
52+
resourceByState.first is Pushed
53+
}
54+
.groupBy(
55+
{ resourceByState ->
56+
(resourceByState.first as Pushed).updated
57+
},
58+
{ resourceByState ->
59+
resourceByState.second
60+
}
61+
)
5362
val created = createdOrUpdated[false]
5463
val updated = createdOrUpdated[true]
5564
panel.text = createText(created, updated)

0 commit comments

Comments
 (0)