mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Expose reactive ways to hide items in cluster frame using Extension API - PART 7 (#5824)
* Kludge "isEnabledForCluster" work again for cluster pages Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Kludge "isEnabledForCluster" work again for kube object details Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Expose reactive way to hide kube object detail items in Extension API Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Expose reactive way to hide kube object menu items in Extension API Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Expose reactive way to hide kube object status items in Extension API Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Expose reactive way to hide workload overview detail items in Extension API Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Expose reactive way to disable pages in Extension API Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Expose a way to access active cluster from Extension API Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Deprecate "isEnabledForCluster" in favor of individual enabled or visible properties for each registration Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
1 parent
ca40c51117
commit
d66e6c23c5
19 files changed
+679
-33
No files matched your search
+7
-3
@@ -38,9 +38,13 @@ const workloadOverviewDetailRegistratorInjectable = getInjectable({
|
||||
instantiate: () => ({
|
||||
Component: registration.components.Details,
|
||||
|
||||
enabled: computed(() =>
|
||||
extensionShouldBeEnabledForClusterFrame.value.get(),
|
||||
),
|
||||
enabled: computed(() => {
|
||||
if (!extensionShouldBeEnabledForClusterFrame.value.get()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return registration.visible ? registration.visible.get() : true;
|
||||
}),
|
||||
|
||||
orderNumber:
|
||||
0.5 + (registration.priority ? 100 - registration.priority : 50),
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { IComputedValue } from "mobx";
|
||||
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
@@ -9,4 +15,5 @@ interface WorkloadsOverviewDetailComponents {
|
||||
export interface WorkloadsOverviewDetailRegistration {
|
||||
components: WorkloadsOverviewDetailComponents;
|
||||
priority?: number;
|
||||
visible?: IComputedValue<boolean>;
|
||||
}
|
||||
+13
-11
@@ -10,9 +10,7 @@ import extensionShouldBeEnabledForClusterFrameInjectable from "../../../extensio
|
||||
import { kubeObjectDetailItemInjectionToken } from "./kube-object-detail-item-injection-token";
|
||||
import { extensionRegistratorInjectionToken } from "../../../../extensions/extension-loader/extension-registrator-injection-token";
|
||||
import currentKubeObjectInDetailsInjectable from "../current-kube-object-in-details.injectable";
|
||||
import {
|
||||
kubeObjectMatchesToKindAndApiVersion,
|
||||
} from "./kube-object-matches-to-kind-and-api-version";
|
||||
import { kubeObjectMatchesToKindAndApiVersion } from "./kube-object-matches-to-kind-and-api-version";
|
||||
|
||||
const kubeObjectDetailItemRegistratorInjectable = getInjectable({
|
||||
id: "kube-object-detail-item-registrator",
|
||||
@@ -45,20 +43,24 @@ const kubeObjectDetailItemRegistratorInjectable = getInjectable({
|
||||
id,
|
||||
|
||||
instantiate: (di) => {
|
||||
const kubeObject = di.inject(
|
||||
currentKubeObjectInDetailsInjectable,
|
||||
);
|
||||
const kubeObject = di.inject(currentKubeObjectInDetailsInjectable);
|
||||
|
||||
return {
|
||||
kind: registration.kind,
|
||||
apiVersions: registration.apiVersions,
|
||||
Component: registration.components.Details,
|
||||
|
||||
enabled: computed(
|
||||
() =>
|
||||
extensionShouldBeEnabledForClusterFrame.value.get() &&
|
||||
isRelevantKubeObject(kubeObject.get()),
|
||||
),
|
||||
enabled: computed(() => {
|
||||
if (!extensionShouldBeEnabledForClusterFrame.value.get()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isRelevantKubeObject(kubeObject.get())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return registration.visible ? registration.visible.get() : true;
|
||||
}),
|
||||
|
||||
orderNumber: 300 - (registration.priority || 50),
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import type { KubeObject } from "../../../common/k8s-api/kube-object";
|
||||
import type { KubeObjectDetailsProps } from "./kube-object-details";
|
||||
import type React from "react";
|
||||
import type { IComputedValue } from "mobx";
|
||||
|
||||
export interface KubeObjectDetailComponents<T extends KubeObject = KubeObject> {
|
||||
Details: React.ComponentType<KubeObjectDetailsProps<T>>;
|
||||
@@ -15,4 +16,5 @@ export interface KubeObjectDetailRegistration<T extends KubeObject = KubeObject>
|
||||
apiVersions: string[];
|
||||
components: KubeObjectDetailComponents<T>;
|
||||
priority?: number;
|
||||
visible?: IComputedValue<boolean>;
|
||||
}
|
||||
+7
-3
@@ -40,9 +40,13 @@ const kubeObjectMenuItemRegistratorInjectable = getInjectable({
|
||||
apiVersions: registration.apiVersions,
|
||||
Component: registration.components.MenuItem,
|
||||
|
||||
enabled: computed(() =>
|
||||
extensionShouldBeEnabledForClusterFrame.value.get(),
|
||||
),
|
||||
enabled: computed(() => {
|
||||
if (!extensionShouldBeEnabledForClusterFrame.value.get()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return registration.visible ? registration.visible.get() : true;
|
||||
}),
|
||||
|
||||
orderNumber: 100,
|
||||
}),
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { IComputedValue } from "mobx";
|
||||
import type React from "react";
|
||||
import type { KubeObject } from "../../../common/k8s-api/kube-object";
|
||||
|
||||
@@ -19,4 +20,5 @@ export interface KubeObjectMenuRegistration {
|
||||
kind: string;
|
||||
apiVersions: string[];
|
||||
components: KubeObjectMenuComponents;
|
||||
visible?: IComputedValue<boolean>;
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { IComputedValue } from "mobx";
|
||||
import type { KubeObject } from "../../../common/k8s-api/kube-object";
|
||||
import type { KubeObjectStatus } from "../../../common/k8s-api/kube-object-status";
|
||||
|
||||
@@ -9,4 +10,5 @@ export interface KubeObjectStatusRegistration {
|
||||
kind: string;
|
||||
apiVersions: string[];
|
||||
resolve: (object: KubeObject) => KubeObjectStatus;
|
||||
visible?: IComputedValue<boolean>;
|
||||
}
|
||||
+7
-3
@@ -38,9 +38,13 @@ const kubeObjectStatusTextRegistratorInjectable = getInjectable({
|
||||
instantiate: () => ({
|
||||
...registration,
|
||||
|
||||
enabled: computed(() =>
|
||||
extensionShouldBeEnabledForClusterFrame.value.get(),
|
||||
),
|
||||
enabled: computed(() => {
|
||||
if (!extensionShouldBeEnabledForClusterFrame.value.get()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return registration.visible ? registration.visible.get() : true;
|
||||
}),
|
||||
}),
|
||||
|
||||
injectionToken: kubeObjectStatusTextInjectionToken,
|
||||
|
||||
@@ -35,16 +35,22 @@ const extensionRouteRegistratorInjectable = getInjectable({
|
||||
|
||||
return [
|
||||
...extension.globalPages.map(
|
||||
toRouteInjectable(
|
||||
false,
|
||||
computed(() => true),
|
||||
toRouteInjectable(false, (registration) =>
|
||||
computed(() =>
|
||||
registration.enabled ? registration.enabled.get() : true,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
...extension.clusterPages.map(
|
||||
toRouteInjectable(
|
||||
true,
|
||||
computed(() => extensionShouldBeEnabledForClusterFrame.value.get()),
|
||||
toRouteInjectable(true, (registration) =>
|
||||
computed(() => {
|
||||
if (!extensionShouldBeEnabledForClusterFrame.value.get()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return registration.enabled ? registration.enabled.get() : true;
|
||||
}),
|
||||
),
|
||||
),
|
||||
].flat();
|
||||
@@ -61,7 +67,7 @@ const toRouteInjectableFor =
|
||||
di: DiContainerForInjection,
|
||||
extension: LensRendererExtension,
|
||||
) =>
|
||||
(clusterFrame: boolean, isEnabled: IComputedValue<boolean>) =>
|
||||
(clusterFrame: boolean, getIsEnabled: (registration: PageRegistration) => IComputedValue<boolean>) =>
|
||||
(registration: PageRegistration) => {
|
||||
const routeInjectable = getInjectable({
|
||||
id: `route-${registration.id}-for-extension-${extension.sanitizedExtensionId}`,
|
||||
@@ -69,7 +75,7 @@ const toRouteInjectableFor =
|
||||
instantiate: () => ({
|
||||
path: getExtensionRoutePath(extension, registration.id),
|
||||
clusterFrame,
|
||||
isEnabled,
|
||||
isEnabled: getIsEnabled(registration),
|
||||
extension,
|
||||
}),
|
||||
|
||||
|
||||
Reference in new issue
Block a user