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 <sven.grossmann@grafana.com>

---------

Co-authored-by: Sven Grossmann <sven.grossmann@grafana.com>
This commit is contained in:
Andrej Ocenas 2024-11-07 11:50:05 +01:00 committed by GitHub
parent bee29c14c6
commit e55100fa90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)
);
}
}