mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
undo unrelated changes
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
9847d1ef78
commit
64991721a9
@ -1,7 +1,5 @@
|
||||
// Common utils (main OR renderer)
|
||||
|
||||
export const noop: any = () => { /* */ };
|
||||
|
||||
export * from "./app-version";
|
||||
export * from "./autobind";
|
||||
export * from "./base64";
|
||||
|
||||
@ -2,19 +2,19 @@
|
||||
import { action, observable } from "mobx";
|
||||
import { LensExtension } from "../lens-extension";
|
||||
|
||||
export class BaseRegistry<T> {
|
||||
export class BaseRegistry<T = object, I extends T = T> {
|
||||
private items = observable<T>([], { deep: false });
|
||||
|
||||
getItems(): T[] {
|
||||
return this.items.toJS();
|
||||
getItems(): I[] {
|
||||
return this.items.toJS() as I[];
|
||||
}
|
||||
|
||||
add(items: T | T[], ext?: LensExtension): () => void; // allow method overloading with required "ext"
|
||||
@action
|
||||
add(items: T | T[]) {
|
||||
const itemArray: T[] = Array.isArray(items) ? items : [items];
|
||||
this.items.push(...itemArray);
|
||||
return () => this.remove(...itemArray);
|
||||
const normalizedItems = (Array.isArray(items) ? items : [items]);
|
||||
this.items.push(...normalizedItems);
|
||||
return () => this.remove(...normalizedItems);
|
||||
}
|
||||
|
||||
@action
|
||||
|
||||
@ -14,10 +14,15 @@ export interface KubeObjectDetailRegistration {
|
||||
|
||||
export class KubeObjectDetailRegistry extends BaseRegistry<KubeObjectDetailRegistration> {
|
||||
getItemsForKind(kind: string, apiVersion: string) {
|
||||
return this.getItems()
|
||||
.filter(item => item.kind === kind && item.apiVersions.includes(apiVersion))
|
||||
.map(item => (item.priority ??= 50, item))
|
||||
.sort((a, b) => b.priority - a.priority);
|
||||
const items = this.getItems().filter((item) => {
|
||||
return item.kind === kind && item.apiVersions.includes(apiVersion);
|
||||
}).map((item) => {
|
||||
if (item.priority === null) {
|
||||
item.priority = 50;
|
||||
}
|
||||
return item;
|
||||
});
|
||||
return items.sort((a, b) => b.priority - a.priority);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -13,8 +13,9 @@ export interface KubeObjectMenuRegistration {
|
||||
|
||||
export class KubeObjectMenuRegistry extends BaseRegistry<KubeObjectMenuRegistration> {
|
||||
getItemsForKind(kind: string, apiVersion: string) {
|
||||
return this.getItems()
|
||||
.filter(item => item.kind === kind && item.apiVersions.includes(apiVersion));
|
||||
return this.getItems().filter((item) => {
|
||||
return item.kind === kind && item.apiVersions.includes(apiVersion);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -9,8 +9,9 @@ export interface KubeObjectStatusRegistration {
|
||||
|
||||
export class KubeObjectStatusRegistry extends BaseRegistry<KubeObjectStatusRegistration> {
|
||||
getItemsForKind(kind: string, apiVersion: string) {
|
||||
return this.getItems()
|
||||
.filter(item => item.kind === kind && item.apiVersions.includes(apiVersion));
|
||||
return this.getItems().filter((item) => {
|
||||
return item.kind === kind && item.apiVersions.includes(apiVersion);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -30,16 +30,28 @@ export interface PageMenuComponents {
|
||||
export class GlobalPageMenuRegistry extends BaseRegistry<PageMenuRegistration> {
|
||||
@action
|
||||
add(items: PageMenuRegistration[], ext: LensExtension) {
|
||||
const norm = items.map(item => ((item.target ??= {}).extensionId = ext.name, item));
|
||||
return super.add(norm);
|
||||
const normalizedItems = items.map(menuItem => {
|
||||
menuItem.target = {
|
||||
extensionId: ext.name,
|
||||
...(menuItem.target || {}),
|
||||
};
|
||||
return menuItem;
|
||||
});
|
||||
return super.add(normalizedItems);
|
||||
}
|
||||
}
|
||||
|
||||
export class ClusterPageMenuRegistry extends BaseRegistry<ClusterPageMenuRegistration> {
|
||||
@action
|
||||
add(items: PageMenuRegistration[], ext: LensExtension) {
|
||||
const norm = items.map(item => ((item.target ??= {}).extensionId = ext.name, item));
|
||||
return super.add(norm);
|
||||
const normalizedItems = items.map(menuItem => {
|
||||
menuItem.target = {
|
||||
extensionId: ext.name,
|
||||
...(menuItem.target || {}),
|
||||
};
|
||||
return menuItem;
|
||||
});
|
||||
return super.add(normalizedItems);
|
||||
}
|
||||
|
||||
getRootItems() {
|
||||
|
||||
@ -7,7 +7,6 @@ import { compile } from "path-to-regexp";
|
||||
import { BaseRegistry } from "./base-registry";
|
||||
import { LensExtension } from "../lens-extension";
|
||||
import logger from "../../main/logger";
|
||||
import { noop } from "../../common/utils";
|
||||
|
||||
export interface PageRegistration {
|
||||
/**
|
||||
@ -60,27 +59,24 @@ export function getExtensionPageUrl<P extends object>({ extensionId, pageId = ""
|
||||
return extPageRoutePath;
|
||||
}
|
||||
|
||||
export class PageRegistry extends BaseRegistry<RegisteredPage> {
|
||||
export class PageRegistry extends BaseRegistry<PageRegistration, RegisteredPage> {
|
||||
@action
|
||||
add(items: PageRegistration | PageRegistration[], ext: LensExtension) {
|
||||
const itemArray = Array.isArray(items) ? items : [items];
|
||||
add(items: PageRegistration[], ext: LensExtension) {
|
||||
let registeredPages: RegisteredPage[] = [];
|
||||
try {
|
||||
const pages = itemArray.map(page => ({
|
||||
registeredPages = items.map(page => ({
|
||||
...page,
|
||||
extensionId: ext.name,
|
||||
routePath: getExtensionPageUrl({ extensionId: ext.name, pageId: page.id ?? page.routePath }),
|
||||
}));
|
||||
|
||||
return super.add(pages);
|
||||
} catch (err) {
|
||||
logger.error(`[EXTENSION]: page-registration failed`, {
|
||||
items,
|
||||
extension: ext,
|
||||
error: String(err),
|
||||
});
|
||||
|
||||
return noop;
|
||||
}
|
||||
return super.add(registeredPages);
|
||||
}
|
||||
|
||||
getUrl<P extends object>({ extensionId, id: pageId }: RegisteredPage, params?: P) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user