From b8f48420de03409ec67cce2685be827e05156dc2 Mon Sep 17 00:00:00 2001 From: Charlie Drage Date: Tue, 28 May 2024 11:31:33 -0400 Subject: [PATCH] chore: add unsubscribe for k8s deployments (#7337) ### What does this PR do? Adds the missing unsubscribe for deployments. ### Screenshot / video of UI N/A ### What issues does this PR fix or reference? Closes https://github.com/containers/podman-desktop/issues/7336 ### How to test this PR? - [X] Tests are covering the bug fix or the new feature Tests cover the feature. Ex. `(window as any).window.kubernetesUnregisterGetCurrentContextResources = () => Promise.resolve(undefined);` is added. If that was not there, it would fail (it will try and call unsubscribe). Signed-off-by: Charlie Drage --- packages/renderer/src/lib/deployments/DeploymentsList.spec.ts | 1 + packages/renderer/src/stores/kubernetes-contexts-state.ts | 3 +++ 2 files changed, 4 insertions(+) diff --git a/packages/renderer/src/lib/deployments/DeploymentsList.spec.ts b/packages/renderer/src/lib/deployments/DeploymentsList.spec.ts index 69a44977802ea..7e124ff79ef8a 100644 --- a/packages/renderer/src/lib/deployments/DeploymentsList.spec.ts +++ b/packages/renderer/src/lib/deployments/DeploymentsList.spec.ts @@ -40,6 +40,7 @@ beforeEach(() => { vi.clearAllMocks(); (window as any).kubernetesGetContextsGeneralState = () => Promise.resolve(new Map()); (window as any).kubernetesGetCurrentContextGeneralState = () => Promise.resolve({}); + (window as any).window.kubernetesUnregisterGetCurrentContextResources = () => Promise.resolve(undefined); }); async function waitRender(customProperties: object): Promise { diff --git a/packages/renderer/src/stores/kubernetes-contexts-state.ts b/packages/renderer/src/stores/kubernetes-contexts-state.ts index 49e3203f05647..abcd561816e75 100644 --- a/packages/renderer/src/stores/kubernetes-contexts-state.ts +++ b/packages/renderer/src/stores/kubernetes-contexts-state.ts @@ -48,6 +48,9 @@ export const kubernetesCurrentContextDeployments = readable( window.events?.receive('kubernetes-current-context-deployments-update', (value: unknown) => { set(value as KubernetesObject[]); }); + return () => { + window.kubernetesUnregisterGetCurrentContextResources('deployments'); + }; }); export const deploymentSearchPattern = writable('');