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