-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for controlling entity settings visibility during runtime #7816
base: master
Are you sure you want to change the base?
Changes from all commits
e81824e
0b70957
9911449
de3db05
053a5d7
f91e360
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ import { extensionRegistratorInjectionToken } from "../../../extensions/extensio | |
import type { LensRendererExtension } from "../../../extensions/lens-renderer-extension"; | ||
import type { CatalogEntity } from "../../api/catalog-entity"; | ||
import { entitySettingInjectionToken } from "./token"; | ||
import type { IComputedValue } from "mobx"; | ||
import { computed } from "mobx"; | ||
|
||
export interface EntitySettingViewProps { | ||
entity: CatalogEntity; | ||
|
@@ -25,6 +27,7 @@ export interface EntitySettingRegistration { | |
id?: string; | ||
priority?: number; | ||
group?: string; | ||
visible?: IComputedValue<boolean>; | ||
} | ||
|
||
export interface RegisteredEntitySetting { | ||
|
@@ -36,6 +39,7 @@ export interface RegisteredEntitySetting { | |
components: EntitySettingComponents; | ||
source?: string; | ||
group: string; | ||
isShown: IComputedValue<boolean>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if this should be optional to not break something.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
} | ||
|
||
const entitySettingExtensionRegistratorInjectable = getInjectable({ | ||
|
@@ -59,6 +63,7 @@ const getInjectableForEntitySettingRegistrationFor = (extension: LensRendererExt | |
id = btoa(title), | ||
priority, | ||
source, | ||
visible, | ||
}: EntitySettingRegistration) => getInjectable({ | ||
id: `${extension.manifest.name}:${group}/${kind}:${id}`, | ||
instantiate: () => ({ | ||
|
@@ -70,6 +75,7 @@ const getInjectableForEntitySettingRegistrationFor = (extension: LensRendererExt | |
title, | ||
group, | ||
source, | ||
isShown: computed(() => visible?.get() ?? true), | ||
}), | ||
injectionToken: entitySettingInjectionToken, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/** | ||
* Copyright (c) OpenLens Authors. All rights reserved. | ||
* Licensed under MIT License. See LICENSE in root directory for more information. | ||
*/ | ||
|
||
import type { ApplicationBuilder } from "../test-utils/get-application-builder"; | ||
import { getApplicationBuilder } from "../test-utils/get-application-builder"; | ||
import type { FakeExtensionOptions } from "../test-utils/get-extension-fake"; | ||
import type { EntitySettingRegistration, RegisteredEntitySetting } from "./extension-registrator.injectable"; | ||
import type { DiContainer } from "@ogre-tools/injectable"; | ||
import catalogEntitySettingItemsInjectable from "./settings.injectable"; | ||
import { KubernetesCluster } from "../../../common/catalog-entities"; | ||
import type { IComputedValue, IObservableValue } from "mobx"; | ||
import { observable } from "mobx"; | ||
|
||
describe("entity-settings", () => { | ||
let builder: ApplicationBuilder; | ||
let windowDi: DiContainer; | ||
let items: IComputedValue<RegisteredEntitySetting[]>; | ||
|
||
beforeEach(async () => { | ||
builder = getApplicationBuilder(); | ||
|
||
await builder.render(); | ||
|
||
windowDi = builder.applicationWindow.only.di; | ||
|
||
const entity = new KubernetesCluster({ | ||
metadata: { | ||
labels: {}, | ||
name: "some-kubernetes-cluster", | ||
uid: "some-entity-id", | ||
}, | ||
spec: { | ||
kubeconfigContext: "some-context", | ||
kubeconfigPath: "/some/path/to/kubeconfig", | ||
}, | ||
status: { | ||
phase: "connecting", | ||
}, | ||
}); | ||
|
||
items = windowDi.inject(catalogEntitySettingItemsInjectable, entity); | ||
|
||
}); | ||
|
||
it("given extension does not specify entity settings visibility, it will be shown by default", () => { | ||
const entitySetting: EntitySettingRegistration = { | ||
title: "some-title", | ||
kind: "KubernetesCluster", | ||
apiVersions: ["entity.k8slens.dev/v1alpha1"], | ||
components: { | ||
View: () => null, | ||
}, | ||
}; | ||
|
||
const testExtensionOptions: FakeExtensionOptions = { | ||
id: "some-extension", | ||
name: "some-extension-name", | ||
|
||
rendererOptions: { | ||
entitySettings: [entitySetting], | ||
}, | ||
}; | ||
const itemCountBefore = items.get().length; | ||
|
||
builder.extensions.enable(testExtensionOptions); | ||
|
||
expect(items.get().length).toBe(itemCountBefore + 1); | ||
}); | ||
|
||
describe("given extension entity settings has visibility set to false", () => { | ||
let settingVisible: IObservableValue<boolean>; | ||
|
||
beforeEach(() => { | ||
settingVisible = observable.box(false); | ||
const entitySetting: EntitySettingRegistration = { | ||
title: "some-title", | ||
kind: "KubernetesCluster", | ||
apiVersions: ["entity.k8slens.dev/v1alpha1"], | ||
components: { | ||
View: () => null, | ||
}, | ||
visible: settingVisible, | ||
}; | ||
|
||
const testExtensionOptions: FakeExtensionOptions = { | ||
id: "some-extension", | ||
name: "some-extension-name", | ||
|
||
rendererOptions: { | ||
entitySettings: [entitySetting], | ||
}, | ||
}; | ||
|
||
builder.extensions.enable(testExtensionOptions); | ||
}); | ||
|
||
it("it won't be shown initially", () => { | ||
const settingsItem = items.get().find(item => item.title === "some-title"); | ||
|
||
expect(settingsItem).toBe(undefined); | ||
}); | ||
|
||
it("visibility is changed, it is shown", () => { | ||
settingVisible.set(true); | ||
const settingsItem = items.get().find(item => item.title === "some-title"); | ||
|
||
expect(settingsItem).toBeDefined(); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not call this also
visible
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to replicate the existing behavior that was implemented with
AppPreferenceTabRegistration
. I think it's a convention in this code base forShowable
and such