From a3cad405e857af379a33e5ecaf9478adb71a86cb Mon Sep 17 00:00:00 2001 From: Andre Dietisheim Date: Fri, 20 Dec 2024 17:21:20 +0100 Subject: [PATCH] fix: allow to refresh all contexts (#809) Signed-off-by: Andre Dietisheim --- .../kubernetes/actions/RefreshAction.kt | 33 +++++++++++++++---- .../kubernetes/model/ResourceModel.kt | 3 +- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/actions/RefreshAction.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/actions/RefreshAction.kt index c20bf268b..d839b42e9 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/actions/RefreshAction.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/actions/RefreshAction.kt @@ -23,15 +23,36 @@ import javax.swing.tree.TreePath class RefreshAction : StructureTreeAction(IActiveContext::class.java) { override fun actionPerformed(event: AnActionEvent?, path: TreePath?, selectedNode: Any?) { - val descriptor = selectedNode?.getDescriptor() ?: return - run("Refreshing $selectedNode...", true, + val descriptor = selectedNode?.getDescriptor() + run("Refreshing ${ selectedNode ?: "all contexts" }...", true, Progressive { - val telemetry = TelemetryService.instance.action("refresh resource") + val telemetry = TelemetryService.instance.action( + "refresh ${ + if (descriptor != null) { + "resource" + } else { + "all contexts" + } + } " + ) try { - descriptor.invalidate() - sendTelemetry(getResourceKind(descriptor.element), telemetry) + if (descriptor != null) { + descriptor.invalidate() + sendTelemetry(getResourceKind(descriptor.element), telemetry) + } else { + getResourceModel()?.invalidate(); + telemetry.send() + } } catch (e: Exception) { - logger().warn("Could not refresh $descriptor resources.", e) + logger().warn( + "Could not refresh ${ + if (descriptor != null) { + "$descriptor resources" + } else { + "all contexts." + } + }", e + ) telemetry.error(e).send() } }) diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/ResourceModel.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/ResourceModel.kt index 87779eac1..ba042cc21 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/ResourceModel.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/ResourceModel.kt @@ -50,6 +50,7 @@ interface IResourceModel { fun watch(definition: CustomResourceDefinition) fun stopWatch(kind: ResourceKind) fun stopWatch(definition: CustomResourceDefinition) + fun invalidate() fun invalidate(element: Any?) fun delete(resources: List, force: Boolean) fun canWatchLog(resource: HasMetadata): Boolean @@ -171,7 +172,7 @@ open class ResourceModel : IResourceModel { modelChange.removeListener(listener) } - private fun invalidate() { + override fun invalidate() { logger().debug("Invalidating all contexts.") allContexts.refresh() }