mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Implement API ResourceStatusText extension
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
parent
d7c7593c0d
commit
db9a6b1e41
@ -8,7 +8,7 @@ import logger from "../main/logger"
|
||||
import { app, ipcRenderer, remote } from "electron"
|
||||
import {
|
||||
appPreferenceRegistry, clusterFeatureRegistry, clusterPageRegistry, globalPageRegistry,
|
||||
kubeObjectDetailRegistry, kubeObjectMenuRegistry, menuRegistry, statusBarRegistry
|
||||
kubeObjectDetailRegistry, kubeObjectMenuRegistry, menuRegistry, statusBarRegistry, resourceStatusRegistry
|
||||
} from "./registries";
|
||||
|
||||
export interface InstalledExtension extends ExtensionModel {
|
||||
@ -59,7 +59,11 @@ export class ExtensionLoader {
|
||||
this.autoloadExtensions((extension: LensRendererExtension) => {
|
||||
extension.registerTo(clusterPageRegistry, extension.clusterPages)
|
||||
extension.registerTo(kubeObjectMenuRegistry, extension.kubeObjectMenuItems)
|
||||
<<<<<<< HEAD
|
||||
extension.registerTo(kubeObjectDetailRegistry, extension.kubeObjectDetailItems)
|
||||
=======
|
||||
extension.registerTo(resourceStatusRegistry, extension.resourceStatusTexts)
|
||||
>>>>>>> 4f6b790d... Implement API ResourceStatusText extension
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import type {
|
||||
AppPreferenceRegistration, ClusterFeatureRegistration,
|
||||
KubeObjectMenuRegistration, KubeObjectDetailRegistration,
|
||||
PageRegistration, StatusBarRegistration
|
||||
PageRegistration, StatusBarRegistration, ResourceStatusRegistration
|
||||
} from "./registries"
|
||||
import { observable } from "mobx";
|
||||
import { LensExtension } from "./lens-extension"
|
||||
@ -9,6 +9,7 @@ import { LensExtension } from "./lens-extension"
|
||||
export class LensRendererExtension extends LensExtension {
|
||||
@observable.shallow globalPages: PageRegistration[] = []
|
||||
@observable.shallow clusterPages: PageRegistration[] = []
|
||||
@observable.shallow resourceStatusTexts: ResourceStatusRegistration[] = []
|
||||
@observable.shallow appPreferences: AppPreferenceRegistration[] = []
|
||||
@observable.shallow clusterFeatures: ClusterFeatureRegistration[] = []
|
||||
@observable.shallow statusBarItems: StatusBarRegistration[] = []
|
||||
|
||||
@ -7,3 +7,4 @@ export * from "./status-bar-registry"
|
||||
export * from "./kube-object-detail-registry";
|
||||
export * from "./kube-object-menu-registry";
|
||||
export * from "./cluster-feature-registry"
|
||||
export * from "./resource-status-registry"
|
||||
|
||||
36
src/extensions/registries/resource-status-registry.ts
Normal file
36
src/extensions/registries/resource-status-registry.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { KubeObject } from "../renderer-api/k8s-api";
|
||||
|
||||
import { BaseRegistry } from "./base-registry";
|
||||
|
||||
export enum ResourceStatusColor {
|
||||
INFO = "info",
|
||||
SUCCESS = "success",
|
||||
ERROR = "error"
|
||||
}
|
||||
|
||||
export abstract class ResourceStatusResolver {
|
||||
protected object: KubeObject
|
||||
|
||||
constructor(object: KubeObject) {
|
||||
this.object = object
|
||||
}
|
||||
|
||||
public abstract getStatusText(): string
|
||||
public abstract getStatusColor(): string
|
||||
}
|
||||
|
||||
export interface ResourceStatusRegistration {
|
||||
kind: string;
|
||||
apiVersions: string[];
|
||||
resolver: (object: KubeObject) => ResourceStatusResolver;
|
||||
}
|
||||
|
||||
export class ResourceStatusRegistry extends BaseRegistry<ResourceStatusRegistration> {
|
||||
getItemsForKind(kind: string, apiVersion: string) {
|
||||
return this.items.filter((item) => {
|
||||
return item.kind === kind && item.apiVersions.includes(apiVersion)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const resourceStatusRegistry = new ResourceStatusRegistry();
|
||||
@ -4,9 +4,11 @@
|
||||
import * as Component from "./components"
|
||||
import * as K8sApi from "./k8s-api"
|
||||
import * as Navigation from "./navigation"
|
||||
import * as ResourceStatus from "./resource-status"
|
||||
|
||||
export {
|
||||
Component,
|
||||
K8sApi,
|
||||
Navigation,
|
||||
ResourceStatus
|
||||
}
|
||||
|
||||
1
src/extensions/renderer-api/resource-status.ts
Normal file
1
src/extensions/renderer-api/resource-status.ts
Normal file
@ -0,0 +1 @@
|
||||
export { ResourceStatusResolver as Resolver, ResourceStatusColor as Color } from "../registries/resource-status-registry"
|
||||
@ -1,6 +1,6 @@
|
||||
import "./pods.scss"
|
||||
|
||||
import React, { Fragment } from "react";
|
||||
import React, { Children, Fragment } from "react";
|
||||
import { observer } from "mobx-react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { Trans } from "@lingui/macro";
|
||||
@ -19,6 +19,8 @@ import toPairs from "lodash/toPairs";
|
||||
import startCase from "lodash/startCase";
|
||||
import kebabCase from "lodash/kebabCase";
|
||||
import { lookupApiLink } from "../../api/kube-api";
|
||||
import { resourceStatusRegistry } from "../../../extensions/registries/resource-status-registry";
|
||||
import { ResourceStatus } from "../resource-status";
|
||||
|
||||
enum sortBy {
|
||||
name = "name",
|
||||
@ -67,6 +69,25 @@ export class Pods extends React.Component<Props> {
|
||||
});
|
||||
}
|
||||
|
||||
renderPodStatus(pod: Pod) {
|
||||
const podStatusTextsFromExtensions = resourceStatusRegistry.getItemsForKind(pod.kind, pod.apiVersion).map((item, index) => {
|
||||
const podStatusResolver = item.resolver(pod)
|
||||
return (
|
||||
<span key={`resource-status-${index}`} className={podStatusResolver.getStatusColor()}>
|
||||
{podStatusResolver.getStatusText()}
|
||||
</span>
|
||||
)
|
||||
});
|
||||
return {
|
||||
className: kebabCase(pod.getStatusMessage()),
|
||||
children: (
|
||||
<span>
|
||||
{pod.getStatusMessage()} {podStatusTextsFromExtensions}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<KubeObjectListLayout
|
||||
@ -115,7 +136,7 @@ export class Pods extends React.Component<Props> {
|
||||
}),
|
||||
pod.getQosClass(),
|
||||
pod.getAge(),
|
||||
{ title: pod.getStatusMessage(), className: kebabCase(pod.getStatusMessage()) }
|
||||
this.renderPodStatus(pod)
|
||||
]}
|
||||
/>
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user