Allow extensions to control status bar item visibility (#6178)

* Allow extensions to control status bar item visibility.

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>

* Move visible to StatusBarRegistration

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>

Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com>
This commit is contained in:
Panu Horsmalahti authored and GitHub committed 2022-09-07 08:41:50 -04:00
1 parent 4a033a49f0
commit 78b771d03b
3 files changed
+32 -7

No files matched your search

@@ -4,6 +4,7 @@
*/
import type { Injectable } from "@ogre-tools/injectable";
import { getInjectable } from "@ogre-tools/injectable";
import type { IComputedValue } from "mobx";
import { computed } from "mobx";
import { extensionRegistratorInjectionToken } from "../../../extensions/extension-loader/extension-registrator-injection-token";
import type { LensRendererExtension } from "../../../extensions/lens-renderer-extension";
@@ -38,6 +39,7 @@ const toItemInjectableFor = (extension: LensRendererExtension, getRandomId: () =
const id = `${getRandomId()}-status-bar-item-for-extension-${extension.sanitizedExtensionId}`;
let component: React.ComponentType;
let position: "left" | "right";
const visible: IComputedValue<boolean> | undefined = registration?.visible;
if (registration?.item) {
const { item } = registration;
@@ -74,7 +76,7 @@ const toItemInjectableFor = (extension: LensRendererExtension, getRandomId: () =
instantiate: () => ({
component,
position,
visible: computed(() => true),
visible: visible ?? computed(() => true),
}),
injectionToken: statusBarItemInjectionToken,
@@ -3,6 +3,8 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { IComputedValue } from "mobx";
/**
* The props for StatusBar item component
*/
@@ -38,4 +40,9 @@ export interface StatusBarRegistration {
* The newer API, allows for registering a component instead of a ReactNode
*/
components?: StatusBarComponents;
/**
* If specified, controls item visibility
*/
visible?: IComputedValue<boolean>;
}