mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Expose a way to control cluster page menu visibility through Extension API
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
ba5d76a49f
commit
e377cfedee
@ -19,6 +19,8 @@ import assert from "assert";
|
|||||||
import hostedClusterIdInjectable from "../../renderer/cluster-frame-context/hosted-cluster-id.injectable";
|
import hostedClusterIdInjectable from "../../renderer/cluster-frame-context/hosted-cluster-id.injectable";
|
||||||
import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time";
|
import { advanceFakeTime, useFakeTime } from "../../common/test-utils/use-fake-time";
|
||||||
import { getExtensionFakeFor } from "../../renderer/components/test-utils/get-extension-fake";
|
import { getExtensionFakeFor } from "../../renderer/components/test-utils/get-extension-fake";
|
||||||
|
import type { IObservableValue } from "mobx";
|
||||||
|
import { runInAction, computed, observable } from "mobx";
|
||||||
|
|
||||||
// TODO: Make tooltips free of side effects by making it deterministic
|
// TODO: Make tooltips free of side effects by making it deterministic
|
||||||
jest.mock("../../renderer/components/tooltip/withTooltip", () => ({
|
jest.mock("../../renderer/components/tooltip/withTooltip", () => ({
|
||||||
@ -49,7 +51,11 @@ describe("cluster - sidebar and tab navigation for extensions", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("given extension with cluster pages and cluster page menus", () => {
|
describe("given extension with cluster pages and cluster page menus", () => {
|
||||||
|
let someObservable: IObservableValue<boolean>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
someObservable = observable.box(false);
|
||||||
|
|
||||||
const getExtensionFake = getExtensionFakeFor(applicationBuilder);
|
const getExtensionFake = getExtensionFakeFor(applicationBuilder);
|
||||||
|
|
||||||
const testExtension = getExtensionFake({
|
const testExtension = getExtensionFake({
|
||||||
@ -114,6 +120,16 @@ describe("cluster - sidebar and tab navigation for extensions", () => {
|
|||||||
Icon: null as never,
|
Icon: null as never,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
id: "some-menu-with-controlled-visibility",
|
||||||
|
title: "Some menu with controlled visibility",
|
||||||
|
visible: computed(() => someObservable.get()),
|
||||||
|
|
||||||
|
components: {
|
||||||
|
Icon: () => <div>Some icon</div>,
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -276,6 +292,26 @@ describe("cluster - sidebar and tab navigation for extensions", () => {
|
|||||||
expect(child).toBeNull();
|
expect(child).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("does not show the sidebar item that should be hidden", () => {
|
||||||
|
const child = rendered.queryByTestId(
|
||||||
|
"sidebar-item-some-extension-name-some-menu-with-controlled-visibility",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(child).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("when sidebar item becomes visible, shows the sidebar item", () => {
|
||||||
|
runInAction(() => {
|
||||||
|
someObservable.set(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
const child = rendered.queryByTestId(
|
||||||
|
"sidebar-item-some-extension-name-some-menu-with-controlled-visibility",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(child).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
describe("when a parent sidebar item is expanded", () => {
|
describe("when a parent sidebar item is expanded", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const parentLink = rendered.getByTestId(
|
const parentLink = rendered.getByTestId(
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
import type { IconProps } from "../../renderer/components/icon";
|
import type { IconProps } from "../../renderer/components/icon";
|
||||||
import type React from "react";
|
import type React from "react";
|
||||||
import type { PageTarget } from "./page-registry";
|
import type { PageTarget } from "./page-registry";
|
||||||
|
import type { IComputedValue } from "mobx";
|
||||||
|
|
||||||
export interface ClusterPageMenuRegistration {
|
export interface ClusterPageMenuRegistration {
|
||||||
id?: string;
|
id?: string;
|
||||||
@ -14,6 +15,7 @@ export interface ClusterPageMenuRegistration {
|
|||||||
target?: PageTarget;
|
target?: PageTarget;
|
||||||
title: React.ReactNode;
|
title: React.ReactNode;
|
||||||
components: ClusterPageMenuComponents;
|
components: ClusterPageMenuComponents;
|
||||||
|
visible?: IComputedValue<boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ClusterPageMenuComponents {
|
export interface ClusterPageMenuComponents {
|
||||||
|
|||||||
@ -49,6 +49,8 @@ const extensionSidebarItemRegistratorInjectable = getInjectable({
|
|||||||
? `${extension.sanitizedExtensionId}-${registration.parentId}`
|
? `${extension.sanitizedExtensionId}-${registration.parentId}`
|
||||||
: null,
|
: null,
|
||||||
|
|
||||||
|
...(registration.visible ? { isVisible: registration.visible } : {}),
|
||||||
|
|
||||||
title: registration.title,
|
title: registration.title,
|
||||||
getIcon: registration.components.Icon
|
getIcon: registration.components.Icon
|
||||||
? () => <registration.components.Icon />
|
? () => <registration.components.Icon />
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user