From e55100fa90848872eb1e31a75e3abee51fa9f480 Mon Sep 17 00:00:00 2001 From: Andrej Ocenas Date: Thu, 7 Nov 2024 11:50:05 +0100 Subject: [PATCH] Sidecar: isAppOpened returns true only if there are 2 apps rendered (#95978) * Check if sidecar is used * Update packages/grafana-runtime/src/services/SidecarService_EXPERIMENTAL.ts Co-authored-by: Sven Grossmann --------- Co-authored-by: Sven Grossmann --- .../services/SidecarService_EXPERIMENTAL.ts | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/grafana-runtime/src/services/SidecarService_EXPERIMENTAL.ts b/packages/grafana-runtime/src/services/SidecarService_EXPERIMENTAL.ts index dd7fa8bc6ee..67e8dd776f7 100644 --- a/packages/grafana-runtime/src/services/SidecarService_EXPERIMENTAL.ts +++ b/packages/grafana-runtime/src/services/SidecarService_EXPERIMENTAL.ts @@ -110,8 +110,19 @@ export class SidecarService_EXPERIMENTAL { } /** - * This is mainly useful inside an app extensions which are executed outside of the main app context but can work - * differently depending whether their app is currently rendered or not. + * This is mainly useful inside an app extensions which are executed outside the main app context but can work + * differently depending on whether their app is currently rendered or not. + * + * This is also true only in case a sidecar is opened. In other cases, just to check if a single app is opened + * probably does not make sense. + * + * This means these are the states and the result of this function: + * Single app is opened: false (may seem strange from considering the function name, but the main point of + * this is to recognize when the app needs to do specific alteration in context of running next to second app) + * 2 apps are opened and pluginId is the one in the main window: true + * 2 apps are opened and pluginId is the one in the sidecar window: true + * 2 apps are opened and pluginId is not one of those: false + * * @experimental */ isAppOpened(pluginId: string) { @@ -119,11 +130,10 @@ export class SidecarService_EXPERIMENTAL { return false; } - if (this._activePluginId.getValue() === pluginId || getMainAppPluginId() === pluginId) { - return true; - } - - return false; + return !!( + this._activePluginId.getValue() && + (this._activePluginId.getValue() === pluginId || getMainAppPluginId() === pluginId) + ); } }