mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add behaviour for tray menu items originating from extensions (#5609)
This commit is contained in:
1 parent
2a5b4af344
commit
10ba9ef853
10 files changed
+248
-196
No files matched your search
@@ -55,20 +55,27 @@ const toItemInjectablesFor = (extension: LensMainExtension, installationCounter:
|
||||
label: computed(() => registration.label || ""),
|
||||
tooltip: registration.toolTip,
|
||||
|
||||
click: pipeline(
|
||||
() => {
|
||||
registration.click?.(registration);
|
||||
},
|
||||
click: () => {
|
||||
const decorated = pipeline(
|
||||
registration.click || (() => {}),
|
||||
|
||||
withErrorLoggingFor(() => `[TRAY]: Clicking of tray item "${trayItemId}" from extension "${extension.sanitizedExtensionId}" failed.`),
|
||||
withErrorLoggingFor(
|
||||
() =>
|
||||
`[TRAY]: Clicking of tray item "${trayItemId}" from extension "${extension.sanitizedExtensionId}" failed.`,
|
||||
),
|
||||
|
||||
// TODO: Find out how to improve typing so that instead of
|
||||
// x => withErrorSuppression(x) there could only be withErrorSuppression
|
||||
(x) => withErrorSuppression(x),
|
||||
),
|
||||
// TODO: Find out how to improve typing so that instead of
|
||||
// x => withErrorSuppression(x) there could only be withErrorSuppression
|
||||
x => withErrorSuppression(x),
|
||||
);
|
||||
|
||||
return decorated(registration);
|
||||
},
|
||||
|
||||
enabled: computed(() => !!registration.enabled),
|
||||
visible: computed(() => true),
|
||||
|
||||
extension,
|
||||
}),
|
||||
|
||||
injectionToken: trayMenuItemInjectionToken,
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { computed } from "mobx";
|
||||
import mainExtensionsInjectable from "../../extensions/main-extensions.injectable";
|
||||
|
||||
const trayItemsInjectable = getInjectable({
|
||||
id: "tray-items",
|
||||
|
||||
instantiate: (di) => {
|
||||
const extensions = di.inject(mainExtensionsInjectable);
|
||||
|
||||
return computed(() => extensions.get().flatMap(extension => extension.trayMenus));
|
||||
},
|
||||
});
|
||||
|
||||
export default trayItemsInjectable;
|
||||
@@ -1,120 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import { LensMainExtension } from "../../extensions/lens-main-extension";
|
||||
import trayItemsInjectable from "./tray-menu-items.injectable";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import { computed, ObservableMap, runInAction } from "mobx";
|
||||
import { getDiForUnitTesting } from "../getDiForUnitTesting";
|
||||
import mainExtensionsInjectable from "../../extensions/main-extensions.injectable";
|
||||
import type { TrayMenuRegistration } from "./tray-menu-registration";
|
||||
|
||||
describe("tray-menu-items", () => {
|
||||
let di: DiContainer;
|
||||
let trayMenuItems: IComputedValue<TrayMenuRegistration[]>;
|
||||
let extensionsStub: ObservableMap<string, LensMainExtension>;
|
||||
|
||||
beforeEach(async () => {
|
||||
di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
|
||||
extensionsStub = new ObservableMap();
|
||||
|
||||
di.override(
|
||||
mainExtensionsInjectable,
|
||||
() => computed(() => [...extensionsStub.values()]),
|
||||
);
|
||||
|
||||
trayMenuItems = di.inject(trayItemsInjectable);
|
||||
});
|
||||
|
||||
it("does not have any items yet", () => {
|
||||
expect(trayMenuItems.get()).toHaveLength(0);
|
||||
});
|
||||
|
||||
describe("when extension is enabled", () => {
|
||||
beforeEach(() => {
|
||||
const someExtension = new SomeTestExtension({
|
||||
id: "some-extension-id",
|
||||
trayMenus: [{ label: "tray-menu-from-some-extension" }],
|
||||
});
|
||||
|
||||
runInAction(() => {
|
||||
extensionsStub.set("some-extension-id", someExtension);
|
||||
});
|
||||
});
|
||||
|
||||
it("has tray menu items", () => {
|
||||
expect(trayMenuItems.get()).toEqual([
|
||||
{
|
||||
label: "tray-menu-from-some-extension",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("when disabling extension, does not have tray menu items", () => {
|
||||
runInAction(() => {
|
||||
extensionsStub.delete("some-extension-id");
|
||||
});
|
||||
|
||||
expect(trayMenuItems.get()).toHaveLength(0);
|
||||
});
|
||||
|
||||
describe("when other extension is enabled", () => {
|
||||
beforeEach(() => {
|
||||
const someOtherExtension = new SomeTestExtension({
|
||||
id: "some-extension-id",
|
||||
trayMenus: [{ label: "some-label-from-second-extension" }],
|
||||
});
|
||||
|
||||
runInAction(() => {
|
||||
extensionsStub.set("some-other-extension-id", someOtherExtension);
|
||||
});
|
||||
});
|
||||
|
||||
it("has tray menu items for both extensions", () => {
|
||||
expect(trayMenuItems.get()).toEqual([
|
||||
{
|
||||
label: "tray-menu-from-some-extension",
|
||||
},
|
||||
|
||||
{
|
||||
label: "some-label-from-second-extension",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("when extension is disabled, still returns tray menu items for extensions that are enabled", () => {
|
||||
runInAction(() => {
|
||||
extensionsStub.delete("some-other-extension-id");
|
||||
});
|
||||
|
||||
expect(trayMenuItems.get()).toEqual([
|
||||
{
|
||||
label: "tray-menu-from-some-extension",
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
class SomeTestExtension extends LensMainExtension {
|
||||
constructor({ id, trayMenus }: {
|
||||
id: string;
|
||||
trayMenus: TrayMenuRegistration[];
|
||||
}) {
|
||||
super({
|
||||
id,
|
||||
absolutePath: "irrelevant",
|
||||
isBundled: false,
|
||||
isCompatible: false,
|
||||
isEnabled: false,
|
||||
manifest: { name: id, version: "some-version", engines: { lens: "^5.5.0" }},
|
||||
manifestPath: "irrelevant",
|
||||
});
|
||||
|
||||
this.trayMenus = trayMenus;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user