mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Turn on strict mode in tsconfig.json
- Add route, clusterRoute, and payloadValidatedClusterRoute helper functions to improve types with backend routes - Turn on the following new lints: - react/jsx-first-prop-new-line - react/jsx-wrap-multilines - react/jsx-one-expression-per-line - react/jsx-max-props-per-line - react/jsx-indent - react/jsx-indent-props Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
e532b90b72
commit
f594bf03f3
689 files changed
+14529
-11302
No files matched your search
@@ -9,7 +9,7 @@ import { stdout, stderr } from "process";
|
||||
|
||||
console = new Console(stdout, stderr);
|
||||
|
||||
let ext: LensExtension = null;
|
||||
let ext: LensExtension;
|
||||
|
||||
describe("lens extension", () => {
|
||||
beforeEach(async () => {
|
||||
|
||||
+16
-10
@@ -7,17 +7,23 @@ import { asLegacyGlobalForExtensionApi } from "./as-legacy-global-object-for-ext
|
||||
import { getLegacyGlobalDiForExtensionApi } from "./legacy-global-di-for-extension-api";
|
||||
import loggerInjectable from "../../common/logger.injectable";
|
||||
|
||||
export const asLegacyGlobalSingletonForExtensionApi = <
|
||||
Instance,
|
||||
InstantiationParameter = void,
|
||||
>(
|
||||
injectable: Injectable<Instance, unknown, InstantiationParameter>,
|
||||
instantiationParameter?: InstantiationParameter,
|
||||
) => {
|
||||
export interface LegacySingleton<T> {
|
||||
createInstance(): T;
|
||||
getInstance(): T;
|
||||
resetInstance(): void;
|
||||
}
|
||||
|
||||
export function asLegacyGlobalSingletonForExtensionApi<Instance>(injectable: Injectable<Instance, unknown, void>): LegacySingleton<Instance>;
|
||||
export function asLegacyGlobalSingletonForExtensionApi<Instance, InstantiationParameter>(injectable: Injectable<Instance, unknown, InstantiationParameter>, param: InstantiationParameter): LegacySingleton<Instance>;
|
||||
|
||||
export function asLegacyGlobalSingletonForExtensionApi<Instance, InstantiationParameter>(
|
||||
injectable: Injectable<Instance, unknown, InstantiationParameter>,
|
||||
instantiationParameter?: InstantiationParameter,
|
||||
): LegacySingleton<Instance> {
|
||||
const instance = asLegacyGlobalForExtensionApi(
|
||||
injectable,
|
||||
injectable as never,
|
||||
instantiationParameter,
|
||||
);
|
||||
) as Instance;
|
||||
|
||||
return {
|
||||
createInstance: () => instance,
|
||||
@@ -33,4 +39,4 @@ export const asLegacyGlobalSingletonForExtensionApi = <
|
||||
);
|
||||
},
|
||||
};
|
||||
};
|
||||
}
|
||||
+8
-2
@@ -3,6 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import assert from "assert";
|
||||
|
||||
const legacyGlobalDis = new Map<Environments, DiContainer>();
|
||||
|
||||
@@ -28,5 +29,10 @@ export const getLegacyGlobalDiForExtensionApi = () => {
|
||||
return globalDis[0];
|
||||
};
|
||||
|
||||
export const getEnvironmentSpecificLegacyGlobalDiForExtensionApi = (environment: Environments) =>
|
||||
legacyGlobalDis.get(environment);
|
||||
export function getEnvironmentSpecificLegacyGlobalDiForExtensionApi(environment: Environments) {
|
||||
const di = legacyGlobalDis.get(environment);
|
||||
|
||||
assert(di, `missing di for environment=${Environments[environment]}`);
|
||||
|
||||
return di;
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { FSWatcher } from "chokidar";
|
||||
import { watch } from "chokidar";
|
||||
import path from "path";
|
||||
import os from "os";
|
||||
@@ -66,7 +67,7 @@ describe("ExtensionDiscovery", () => {
|
||||
});
|
||||
|
||||
it("emits add for added extension", async (done) => {
|
||||
let addHandler: (filePath: string) => void;
|
||||
let addHandler!: (filePath: string) => void;
|
||||
|
||||
mockedFse.readJson.mockImplementation((p) => {
|
||||
expect(p).toBe(path.join(os.homedir(), ".k8slens/extensions/my-extension/package.json"));
|
||||
@@ -79,7 +80,7 @@ describe("ExtensionDiscovery", () => {
|
||||
|
||||
mockedFse.pathExists.mockImplementation(() => true);
|
||||
|
||||
const mockWatchInstance: any = {
|
||||
const mockWatchInstance = {
|
||||
on: jest.fn((event: string, handler: typeof addHandler) => {
|
||||
if (event === "add") {
|
||||
addHandler = handler;
|
||||
@@ -87,11 +88,9 @@ describe("ExtensionDiscovery", () => {
|
||||
|
||||
return mockWatchInstance;
|
||||
}),
|
||||
};
|
||||
} as unknown as FSWatcher;
|
||||
|
||||
mockedWatch.mockImplementationOnce(() =>
|
||||
(mockWatchInstance) as any,
|
||||
);
|
||||
mockedWatch.mockImplementationOnce(() => mockWatchInstance);
|
||||
|
||||
// Need to force isLoaded to be true so that the file watching is started
|
||||
extensionDiscovery.isLoaded = true;
|
||||
@@ -118,9 +117,9 @@ describe("ExtensionDiscovery", () => {
|
||||
});
|
||||
|
||||
it("doesn't emit add for added file under extension", async done => {
|
||||
let addHandler: (filePath: string) => void;
|
||||
let addHandler!: (filePath: string) => void;
|
||||
|
||||
const mockWatchInstance: any = {
|
||||
const mockWatchInstance = {
|
||||
on: jest.fn((event: string, handler: typeof addHandler) => {
|
||||
if (event === "add") {
|
||||
addHandler = handler;
|
||||
@@ -128,11 +127,9 @@ describe("ExtensionDiscovery", () => {
|
||||
|
||||
return mockWatchInstance;
|
||||
}),
|
||||
};
|
||||
} as unknown as FSWatcher;
|
||||
|
||||
mockedWatch.mockImplementationOnce(() =>
|
||||
(mockWatchInstance) as any,
|
||||
);
|
||||
mockedWatch.mockImplementationOnce(() => mockWatchInstance);
|
||||
|
||||
// Need to force isLoaded to be true so that the file watching is started
|
||||
extensionDiscovery.isLoaded = true;
|
||||
|
||||
@@ -11,7 +11,7 @@ import { makeObservable, observable, reaction, when } from "mobx";
|
||||
import os from "os";
|
||||
import path from "path";
|
||||
import { broadcastMessage, ipcMainHandle, ipcRendererOn } from "../../common/ipc";
|
||||
import { toJS } from "../../common/utils";
|
||||
import { isErrnoException, toJS } from "../../common/utils";
|
||||
import logger from "../../main/logger";
|
||||
import type { ExtensionsStore } from "../extensions-store/extensions-store";
|
||||
import type { ExtensionLoader } from "../extension-loader";
|
||||
@@ -81,7 +81,7 @@ interface LoadFromFolderOptions {
|
||||
* - "remove": When extension is removed. The event is of type LensExtensionId
|
||||
*/
|
||||
export class ExtensionDiscovery {
|
||||
protected bundledFolderPath: string;
|
||||
protected bundledFolderPath!: string;
|
||||
|
||||
private loadStarted = false;
|
||||
private extensions: Map<string, InstalledExtension> = new Map();
|
||||
@@ -271,7 +271,13 @@ export class ExtensionDiscovery {
|
||||
* @param extensionId The ID of the extension to uninstall.
|
||||
*/
|
||||
async uninstallExtension(extensionId: LensExtensionId): Promise<void> {
|
||||
const { manifest, absolutePath } = this.extensions.get(extensionId) ?? this.dependencies.extensionLoader.getExtension(extensionId);
|
||||
const extension = this.extensions.get(extensionId) ?? this.dependencies.extensionLoader.getExtension(extensionId);
|
||||
|
||||
if (!extension) {
|
||||
return void logger.warn(`${logModule} could not uninstall extension, not found`, { id: extensionId });
|
||||
}
|
||||
|
||||
const { manifest, absolutePath } = extension;
|
||||
|
||||
logger.info(`${logModule} Uninstalling ${manifest.name}`);
|
||||
|
||||
@@ -369,7 +375,7 @@ export class ExtensionDiscovery {
|
||||
isCompatible,
|
||||
};
|
||||
} catch (error) {
|
||||
if (error.code === "ENOTDIR") {
|
||||
if (isErrnoException(error) && error.code === "ENOTDIR") {
|
||||
// ignore this error, probably from .DS_Store file
|
||||
logger.debug(`${logModule}: failed to load extension manifest through a not-dir-like at ${manifestPath}`);
|
||||
} else {
|
||||
@@ -392,10 +398,12 @@ export class ExtensionDiscovery {
|
||||
try {
|
||||
await this.dependencies.installExtension(extension.absolutePath);
|
||||
} catch (error) {
|
||||
const message = error.message || error || "unknown error";
|
||||
const message = error instanceof Error
|
||||
? error.message
|
||||
: String(error || "unknown error");
|
||||
const { name, version } = extension.manifest;
|
||||
|
||||
logger.error(`${logModule}: failed to install user extension ${name}@${version}`, message);
|
||||
logger.error(`${logModule}: failed to install user extension ${name}@${version}: ${message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ export class ExtensionInstaller {
|
||||
});
|
||||
let stderr = "";
|
||||
|
||||
child.stderr.on("data", data => {
|
||||
child.stderr?.on("data", data => {
|
||||
stderr += String(data);
|
||||
});
|
||||
|
||||
|
||||
+4
-8
@@ -10,7 +10,7 @@ import { action, makeObservable, observable } from "mobx";
|
||||
import path from "path";
|
||||
import { BaseStore } from "../../../../common/base-store";
|
||||
import type { LensExtensionId } from "../../../lens-extension";
|
||||
import { toJS } from "../../../../common/utils";
|
||||
import { getOrInsertWith, toJS } from "../../../../common/utils";
|
||||
|
||||
interface FSProvisionModel {
|
||||
extensions: Record<string, string>; // extension names to paths
|
||||
@@ -41,16 +41,12 @@ export class FileSystemProvisionerStore extends BaseStore<FSProvisionModel> {
|
||||
* @returns path to the folder that the extension can safely write files to.
|
||||
*/
|
||||
async requestDirectory(extensionName: string): Promise<string> {
|
||||
if (!this.registeredExtensions.has(extensionName)) {
|
||||
const dirPath = getOrInsertWith(this.registeredExtensions, extensionName, () => {
|
||||
const salt = randomBytes(32).toString("hex");
|
||||
const hashedName = SHA256(`${extensionName}/${salt}`).toString();
|
||||
|
||||
const dirPath = path.resolve(this.dependencies.directoryForExtensionData, hashedName);
|
||||
|
||||
this.registeredExtensions.set(extensionName, dirPath);
|
||||
}
|
||||
|
||||
const dirPath = this.registeredExtensions.get(extensionName);
|
||||
return path.resolve(this.dependencies.directoryForExtensionData, hashedName);
|
||||
});
|
||||
|
||||
await fse.ensureDir(dirPath);
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ import { action, computed, makeObservable, observable, observe, reaction, when }
|
||||
import path from "path";
|
||||
import { broadcastMessage, ipcMainOn, ipcRendererOn, ipcMainHandle } from "../../common/ipc";
|
||||
import type { Disposer } from "../../common/utils";
|
||||
import { toJS } from "../../common/utils";
|
||||
import { isDefined, toJS } from "../../common/utils";
|
||||
import logger from "../../main/logger";
|
||||
import type { KubernetesCluster } from "../common-api/catalog";
|
||||
import type { CatalogEntity, KubernetesCluster } from "../common-api/catalog";
|
||||
import type { InstalledExtension } from "../extension-discovery/extension-discovery";
|
||||
import type { LensExtension, LensExtensionConstructor, LensExtensionId } from "../lens-extension";
|
||||
import type { LensRendererExtension } from "../lens-renderer-extension";
|
||||
@@ -20,6 +20,7 @@ import * as registries from "../registries";
|
||||
import type { LensExtensionState } from "../extensions-store/extensions-store";
|
||||
import { extensionLoaderFromMainChannel, extensionLoaderFromRendererChannel } from "../../common/ipc/extension-handling";
|
||||
import { requestExtensionLoaderInitialState } from "../../renderer/ipc";
|
||||
import assert from "assert";
|
||||
|
||||
const logModule = "[EXTENSIONS-LOADER]";
|
||||
|
||||
@@ -152,7 +153,7 @@ export class ExtensionLoader {
|
||||
);
|
||||
}
|
||||
|
||||
initExtensions(extensions?: Map<LensExtensionId, InstalledExtension>) {
|
||||
initExtensions(extensions: Map<LensExtensionId, InstalledExtension>) {
|
||||
this.extensions.replace(extensions);
|
||||
}
|
||||
|
||||
@@ -188,7 +189,11 @@ export class ExtensionLoader {
|
||||
}
|
||||
|
||||
setIsEnabled(lensExtensionId: LensExtensionId, isEnabled: boolean) {
|
||||
this.extensions.get(lensExtensionId).isEnabled = isEnabled;
|
||||
const extension = this.extensions.get(lensExtensionId);
|
||||
|
||||
assert(extension, `Must register extension ${lensExtensionId} with before enabling it`);
|
||||
|
||||
extension.isEnabled = isEnabled;
|
||||
}
|
||||
|
||||
protected async initMain() {
|
||||
@@ -248,7 +253,8 @@ export class ExtensionLoader {
|
||||
loadOnClusterManagerRenderer = () => {
|
||||
logger.debug(`${logModule}: load on main renderer (cluster manager)`);
|
||||
|
||||
return this.autoInitExtensions(async (extension: LensRendererExtension) => {
|
||||
return this.autoInitExtensions(async (ext) => {
|
||||
const extension = ext as LensRendererExtension;
|
||||
const removeItems = [
|
||||
registries.EntitySettingRegistry.getInstance().add(extension.entitySettings),
|
||||
registries.CatalogEntityDetailRegistry.getInstance().add(extension.catalogEntityDetailItems),
|
||||
@@ -266,12 +272,15 @@ export class ExtensionLoader {
|
||||
});
|
||||
};
|
||||
|
||||
loadOnClusterRenderer = (getCluster: () => KubernetesCluster) => {
|
||||
loadOnClusterRenderer = (getCluster: () => CatalogEntity) => {
|
||||
logger.debug(`${logModule}: load on cluster renderer (dashboard)`);
|
||||
|
||||
this.autoInitExtensions(async (extension: LensRendererExtension) => {
|
||||
this.autoInitExtensions(async (ext) => {
|
||||
const entity = getCluster() as KubernetesCluster;
|
||||
const extension = ext as LensRendererExtension;
|
||||
|
||||
// getCluster must be a callback, as the entity might be available only after an extension has been loaded
|
||||
if ((await extension.isEnabledForCluster(getCluster())) === false) {
|
||||
if ((await extension.isEnabledForCluster(entity)) === false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -332,7 +341,9 @@ export class ExtensionLoader {
|
||||
}
|
||||
|
||||
return null;
|
||||
}).filter(extension => Boolean(extension));
|
||||
})
|
||||
// Remove null values
|
||||
.filter(isDefined);
|
||||
|
||||
// We first need to wait until each extension's `onActivate` is resolved or rejected,
|
||||
// as this might register new catalog categories. Afterwards we can safely .enable the extension.
|
||||
@@ -346,7 +357,7 @@ export class ExtensionLoader {
|
||||
);
|
||||
|
||||
extensions.forEach(({ instance }) => {
|
||||
const installationCount = (this.dependencies.extensionInstallationCounter.get(instance.sanitizedExtensionId) | 0) + 1;
|
||||
const installationCount = (this.dependencies.extensionInstallationCounter.get(instance.sanitizedExtensionId) ?? 0) + 1;
|
||||
|
||||
this.dependencies.extensionInstallationCounter.set(instance.sanitizedExtensionId, installationCount);
|
||||
|
||||
@@ -389,7 +400,7 @@ export class ExtensionLoader {
|
||||
try {
|
||||
return __non_webpack_require__(extAbsolutePath).default;
|
||||
} catch (error) {
|
||||
if (ipcRenderer) {
|
||||
if (window && error instanceof window.Error) {
|
||||
console.error(`${logModule}: can't load ${entryPointName} for "${extension.manifest.name}": ${error.stack || error}`, extension);
|
||||
} else {
|
||||
logger.error(`${logModule}: can't load ${entryPointName} for "${extension.manifest.name}": ${error}`, { extension });
|
||||
@@ -399,12 +410,12 @@ export class ExtensionLoader {
|
||||
return null;
|
||||
}
|
||||
|
||||
getExtension(extId: LensExtensionId): InstalledExtension {
|
||||
getExtension(extId: LensExtensionId) {
|
||||
return this.extensions.get(extId);
|
||||
}
|
||||
|
||||
getInstanceById<E extends LensExtension>(extId: LensExtensionId): E {
|
||||
return this.instances.get(extId) as E;
|
||||
getInstanceById(extId: LensExtensionId) {
|
||||
return this.instances.get(extId);
|
||||
}
|
||||
|
||||
toJSON(): Map<LensExtensionId, InstalledExtension> {
|
||||
|
||||
@@ -6,10 +6,11 @@
|
||||
import { BaseStore } from "../common/base-store";
|
||||
import * as path from "path";
|
||||
import type { LensExtension } from "./lens-extension";
|
||||
import assert from "assert";
|
||||
|
||||
export abstract class ExtensionStore<T> extends BaseStore<T> {
|
||||
readonly displayName = "ExtensionStore<T>";
|
||||
protected extension: LensExtension;
|
||||
protected extension?: LensExtension;
|
||||
|
||||
loadExtension(extension: LensExtension) {
|
||||
this.extension = extension;
|
||||
@@ -24,6 +25,8 @@ export abstract class ExtensionStore<T> extends BaseStore<T> {
|
||||
}
|
||||
|
||||
protected cwd() {
|
||||
assert(this.extension, "must call this.load() first");
|
||||
|
||||
return path.join(super.cwd(), "extension-store", this.extension.name);
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ export class ExtensionsStore extends BaseStore<LensExtensionsStoreModel> {
|
||||
return isBundled || Boolean(this.state.get(id)?.enabled);
|
||||
}
|
||||
|
||||
mergeState = action((extensionsState: Record<LensExtensionId, LensExtensionState>) => {
|
||||
mergeState = action((extensionsState: Record<LensExtensionId, LensExtensionState> | [LensExtensionId, LensExtensionState][]) => {
|
||||
this.state.merge(extensionsState);
|
||||
});
|
||||
|
||||
|
||||
@@ -68,10 +68,10 @@ export class LensExtension {
|
||||
return this.manifest.description;
|
||||
}
|
||||
|
||||
private dependencies: LensExtensionDependencies;
|
||||
private readonly dependencies!: LensExtensionDependencies;
|
||||
|
||||
[setLensExtensionDependencies] = (dependencies: LensExtensionDependencies) => {
|
||||
this.dependencies = dependencies;
|
||||
(this as unknown as { dependencies: LensExtensionDependencies }).dependencies = dependencies;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -86,7 +86,7 @@ export class LensExtension {
|
||||
}
|
||||
|
||||
@action
|
||||
async enable(register: (ext: LensExtension) => Promise<Disposer[]>) {
|
||||
async enable(register: (ext: this) => Promise<Disposer[]>) {
|
||||
if (this._isEnabled) {
|
||||
return;
|
||||
}
|
||||
@@ -136,11 +136,13 @@ export function sanitizeExtensionName(name: string) {
|
||||
return name.replace("@", "").replace("/", "--");
|
||||
}
|
||||
|
||||
export const getSanitizedPath = (...parts: string[]) => parts
|
||||
.filter(Boolean)
|
||||
.join("/")
|
||||
.replace(/\/+/g, "/")
|
||||
.replace(/\/$/, ""); // normalize multi-slashes (e.g. coming from page.id)
|
||||
export function getSanitizedPath(...parts: string[]) {
|
||||
return parts
|
||||
.filter(Boolean)
|
||||
.join("/")
|
||||
.replace(/\/+/g, "/")
|
||||
.replace(/\/$/, "");
|
||||
} // normalize multi-slashes (e.g. coming from page.id)
|
||||
|
||||
export function extensionDisplayName(name: string, version: string) {
|
||||
return `${name}@${version}`;
|
||||
|
||||
@@ -28,8 +28,8 @@ import routesInjectable from "../renderer/routes/routes.injectable";
|
||||
import { fromPairs, map, matches, toPairs } from "lodash/fp";
|
||||
import extensionPageParametersInjectable from "../renderer/routes/extension-page-parameters.injectable";
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import { getExtensionRoutePath } from "../renderer/routes/get-extension-route-path";
|
||||
import { navigateToRouteInjectionToken } from "../common/front-end-routing/navigate-to-route-injection-token";
|
||||
import { getExtensionRoutePath } from "../renderer/routes/for-extension";
|
||||
|
||||
export class LensRendererExtension extends LensExtension {
|
||||
globalPages: registries.PageRegistration[] = [];
|
||||
@@ -50,49 +50,41 @@ export class LensRendererExtension extends LensExtension {
|
||||
additionalCategoryColumns: AdditionalCategoryColumnRegistration[] = [];
|
||||
customCategoryViews: CustomCategoryViewRegistration[] = [];
|
||||
|
||||
async navigate<P extends object>(pageId?: string, params?: P) {
|
||||
const di = getEnvironmentSpecificLegacyGlobalDiForExtensionApi(
|
||||
Environments.renderer,
|
||||
);
|
||||
|
||||
async navigate(pageId?: string, params: object = {}) {
|
||||
const di = getEnvironmentSpecificLegacyGlobalDiForExtensionApi(Environments.renderer);
|
||||
const navigateToRoute = di.inject(navigateToRouteInjectionToken);
|
||||
const routes = di.inject(routesInjectable).get();
|
||||
const targetRegistration = [...this.globalPages, ...this.clusterPages]
|
||||
.find(registration => registration.id === (pageId || undefined));
|
||||
|
||||
const targetRegistration = [...this.globalPages, ...this.clusterPages].find(
|
||||
registration => registration.id === (pageId || undefined),
|
||||
);
|
||||
if (!targetRegistration) {
|
||||
return;
|
||||
}
|
||||
|
||||
const targetRoutePath = getExtensionRoutePath(this, targetRegistration.id);
|
||||
|
||||
const targetRoute = routes.find(matches({ path: targetRoutePath }));
|
||||
|
||||
if (targetRoute) {
|
||||
const normalizedParams = di.inject(extensionPageParametersInjectable, {
|
||||
extension: this,
|
||||
registration: targetRegistration,
|
||||
});
|
||||
|
||||
const query = pipeline(
|
||||
params,
|
||||
|
||||
toPairs,
|
||||
|
||||
map(([key, value]) => {
|
||||
const normalizedParam = normalizedParams[key];
|
||||
|
||||
return [
|
||||
key,
|
||||
normalizedParam.stringify(value),
|
||||
];
|
||||
}),
|
||||
|
||||
fromPairs,
|
||||
);
|
||||
|
||||
navigateToRoute(targetRoute, {
|
||||
query,
|
||||
});
|
||||
if (!targetRoute) {
|
||||
return;
|
||||
}
|
||||
|
||||
const normalizedParams = di.inject(extensionPageParametersInjectable, {
|
||||
extension: this,
|
||||
registration: targetRegistration,
|
||||
});
|
||||
const query = pipeline(
|
||||
params,
|
||||
toPairs,
|
||||
map(([key, value]) => [
|
||||
key,
|
||||
normalizedParams[key].stringify(value),
|
||||
]),
|
||||
fromPairs,
|
||||
);
|
||||
|
||||
navigateToRoute(targetRoute, {
|
||||
query,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,10 +8,16 @@ import { catalogEntityRegistry as registry } from "../../main/catalog";
|
||||
|
||||
export { catalogCategoryRegistry as catalogCategories } from "../../common/catalog/catalog-category-registry";
|
||||
|
||||
export class CatalogEntityRegistry {
|
||||
getItemsForApiKind<T extends CatalogEntity>(apiVersion: string, kind: string): T[] {
|
||||
return registry.getItemsForApiKind<T>(apiVersion, kind);
|
||||
}
|
||||
export interface CatalogEntityRegistry {
|
||||
getItemsForApiKind(apiVersion: string, kind: string): CatalogEntity[];
|
||||
/**
|
||||
* @deprecated use a cast instead of a unbounded type parameter
|
||||
*/
|
||||
getItemsForApiKind<T extends CatalogEntity>(apiVersion: string, kind: string): T[];
|
||||
}
|
||||
|
||||
export const catalogEntities = new CatalogEntityRegistry();
|
||||
export const catalogEntities: CatalogEntityRegistry = {
|
||||
getItemsForApiKind(apiVersion: string, kind: string) {
|
||||
return registry.filterItemsForApiKind(apiVersion, kind);
|
||||
},
|
||||
};
|
||||
@@ -16,30 +16,30 @@ export { apiManager } from "../../common/k8s-api/api-manager";
|
||||
export { KubeApi, forCluster, forRemoteCluster } from "../../common/k8s-api/kube-api";
|
||||
export { KubeObject, KubeStatus } from "../../common/k8s-api/kube-object";
|
||||
export { KubeObjectStore } from "../../common/k8s-api/kube-object.store";
|
||||
export { Pod, podsApi, PodsApi } from "../../common/k8s-api/endpoints/pods.api";
|
||||
export { Node, nodesApi, NodesApi } from "../../common/k8s-api/endpoints/nodes.api";
|
||||
export { Pod, podApi as podsApi, PodApi as PodsApi } from "../../common/k8s-api/endpoints/pods.api";
|
||||
export { Node, nodeApi as nodesApi, NodeApi as NodesApi } from "../../common/k8s-api/endpoints/nodes.api";
|
||||
export { Deployment, deploymentApi, DeploymentApi } from "../../common/k8s-api/endpoints/deployment.api";
|
||||
export { DaemonSet, daemonSetApi } from "../../common/k8s-api/endpoints/daemon-set.api";
|
||||
export { StatefulSet, statefulSetApi } from "../../common/k8s-api/endpoints/stateful-set.api";
|
||||
export { Job, jobApi } from "../../common/k8s-api/endpoints/job.api";
|
||||
export { CronJob, cronJobApi } from "../../common/k8s-api/endpoints/cron-job.api";
|
||||
export { ConfigMap, configMapApi } from "../../common/k8s-api/endpoints/configmap.api";
|
||||
export { Secret, secretsApi } from "../../common/k8s-api/endpoints/secret.api";
|
||||
export { Secret, secretApi as secretsApi } from "../../common/k8s-api/endpoints/secret.api";
|
||||
export { ReplicaSet, replicaSetApi } from "../../common/k8s-api/endpoints/replica-set.api";
|
||||
export { ResourceQuota, resourceQuotaApi } from "../../common/k8s-api/endpoints/resource-quota.api";
|
||||
export { LimitRange, limitRangeApi } from "../../common/k8s-api/endpoints/limit-range.api";
|
||||
export { HorizontalPodAutoscaler, hpaApi } from "../../common/k8s-api/endpoints/hpa.api";
|
||||
export { PodDisruptionBudget, pdbApi } from "../../common/k8s-api/endpoints/poddisruptionbudget.api";
|
||||
export { HorizontalPodAutoscaler, horizontalPodAutoscalerApi as hpaApi } from "../../common/k8s-api/endpoints/hpa.api";
|
||||
export { PodDisruptionBudget, podDisruptionBudgetApi as pdbApi } from "../../common/k8s-api/endpoints/poddisruptionbudget.api";
|
||||
export { Service, serviceApi } from "../../common/k8s-api/endpoints/service.api";
|
||||
export { Endpoint, endpointApi } from "../../common/k8s-api/endpoints/endpoint.api";
|
||||
export { Endpoints as Endpoint, endpointsApi as endpointApi } from "../../common/k8s-api/endpoints/endpoint.api";
|
||||
export { Ingress, ingressApi, IngressApi } from "../../common/k8s-api/endpoints/ingress.api";
|
||||
export { NetworkPolicy, networkPolicyApi } from "../../common/k8s-api/endpoints/network-policy.api";
|
||||
export { PersistentVolume, persistentVolumeApi } from "../../common/k8s-api/endpoints/persistent-volume.api";
|
||||
export { PersistentVolumeClaim, pvcApi, PersistentVolumeClaimsApi } from "../../common/k8s-api/endpoints/persistent-volume-claims.api";
|
||||
export { PersistentVolumeClaim, persistentVolumeClaimApi as pvcApi, PersistentVolumeClaimApi as PersistentVolumeClaimsApi } from "../../common/k8s-api/endpoints/persistent-volume-claims.api";
|
||||
export { StorageClass, storageClassApi } from "../../common/k8s-api/endpoints/storage-class.api";
|
||||
export { Namespace, namespacesApi } from "../../common/k8s-api/endpoints/namespaces.api";
|
||||
export { KubeEvent, eventApi } from "../../common/k8s-api/endpoints/events.api";
|
||||
export { ServiceAccount, serviceAccountsApi } from "../../common/k8s-api/endpoints/service-accounts.api";
|
||||
export { ServiceAccount, serviceAccountApi as serviceAccountsApi } from "../../common/k8s-api/endpoints/service-accounts.api";
|
||||
export { Role, roleApi } from "../../common/k8s-api/endpoints/role.api";
|
||||
export { RoleBinding, roleBindingApi } from "../../common/k8s-api/endpoints/role-binding.api";
|
||||
export { ClusterRole, clusterRoleApi } from "../../common/k8s-api/endpoints/cluster-role.api";
|
||||
@@ -49,6 +49,6 @@ export { CustomResourceDefinition, crdApi } from "../../common/k8s-api/endpoints
|
||||
// types
|
||||
export type { ILocalKubeApiConfig, IRemoteKubeApiConfig, IKubeApiCluster } from "../../common/k8s-api/kube-api";
|
||||
export type { IPodContainer, IPodContainerStatus } from "../../common/k8s-api/endpoints/pods.api";
|
||||
export type { ISecretRef } from "../../common/k8s-api/endpoints/secret.api";
|
||||
export type { KubeObjectMetadata, KubeStatusData } from "../../common/k8s-api/kube-object";
|
||||
export type { SecretReference as ISecretRef } from "../../common/k8s-api/endpoints/secret.api";
|
||||
export type { KubeObjectMetadata, KubeJsonApiObjectMetadata, KubeStatusData } from "../../common/k8s-api/kube-object";
|
||||
export type { KubeObjectStoreLoadAllParams, KubeObjectStoreLoadingParams, KubeObjectStoreSubscribeParams } from "../../common/k8s-api/kube-object.store";
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
// Base class for extensions-api registries
|
||||
import { action, observable, makeObservable } from "mobx";
|
||||
import type { Disposer } from "../../common/utils";
|
||||
import { Singleton } from "../../common/utils";
|
||||
import type { LensExtension } from "../lens-extension";
|
||||
|
||||
@@ -21,7 +22,7 @@ export class BaseRegistry<T, I = T> extends Singleton {
|
||||
}
|
||||
|
||||
@action
|
||||
add(items: T | T[], extension?: LensExtension) {
|
||||
add(items: T | T[], extension?: LensExtension): Disposer {
|
||||
const itemArray = [items].flat() as T[];
|
||||
|
||||
itemArray.forEach(item => {
|
||||
@@ -33,7 +34,7 @@ export class BaseRegistry<T, I = T> extends Singleton {
|
||||
|
||||
// eslint-disable-next-line unused-imports/no-unused-vars-ts
|
||||
protected getRegisteredItem(item: T, extension?: LensExtension): I {
|
||||
return item as any;
|
||||
return item as never;
|
||||
}
|
||||
|
||||
@action
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
import type React from "react";
|
||||
import type { Disposer } from "../../common/utils";
|
||||
import type { CatalogEntity } from "../common-api/catalog";
|
||||
import { BaseRegistry } from "./base-registry";
|
||||
|
||||
@@ -23,6 +24,10 @@ export interface CatalogEntityDetailRegistration<T extends CatalogEntity> {
|
||||
}
|
||||
|
||||
export class CatalogEntityDetailRegistry extends BaseRegistry<CatalogEntityDetailRegistration<CatalogEntity>> {
|
||||
add<T extends CatalogEntity>(items: CatalogEntityDetailRegistration<T> | CatalogEntityDetailRegistration<T>[]): Disposer {
|
||||
return super.add(items as never);
|
||||
}
|
||||
|
||||
getItemsForKind(kind: string, apiVersion: string) {
|
||||
const items = this.getItems().filter((item) => {
|
||||
return item.kind === kind && item.apiVersions.includes(apiVersion);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
import type React from "react";
|
||||
import type { Disposer } from "../../common/utils";
|
||||
import type { KubeObjectDetailsProps } from "../renderer-api/components";
|
||||
import type { KubeObject } from "../renderer-api/k8s-api";
|
||||
import { BaseRegistry } from "./base-registry";
|
||||
@@ -12,14 +13,20 @@ export interface KubeObjectDetailComponents<T extends KubeObject = KubeObject> {
|
||||
Details: React.ComponentType<KubeObjectDetailsProps<T>>;
|
||||
}
|
||||
|
||||
export interface KubeObjectDetailRegistration {
|
||||
export interface KubeObjectDetailRegistration<T extends KubeObject = KubeObject> {
|
||||
kind: string;
|
||||
apiVersions: string[];
|
||||
components: KubeObjectDetailComponents<KubeObject>;
|
||||
components: KubeObjectDetailComponents<T>;
|
||||
priority?: number;
|
||||
}
|
||||
|
||||
export class KubeObjectDetailRegistry extends BaseRegistry<KubeObjectDetailRegistration> {
|
||||
add(items: KubeObjectDetailRegistration[]): Disposer;
|
||||
add<T extends KubeObject>(item: KubeObjectDetailRegistration<T>): Disposer;
|
||||
add(items: KubeObjectDetailRegistration | KubeObjectDetailRegistration[]): Disposer {
|
||||
return super.add(items);
|
||||
}
|
||||
|
||||
getItemsForKind(kind: string, apiVersion: string) {
|
||||
const items = this.getItems().filter((item) => {
|
||||
return item.kind === kind && item.apiVersions.includes(apiVersion);
|
||||
|
||||
@@ -20,12 +20,12 @@ export interface RouteParams {
|
||||
/**
|
||||
* the parts of the URI query string
|
||||
*/
|
||||
search: Record<string, string>;
|
||||
search: Record<string, string | undefined>;
|
||||
|
||||
/**
|
||||
* the matching parts of the path. The dynamic parts of the URI path.
|
||||
*/
|
||||
pathname: Record<string, string>;
|
||||
pathname: Record<string, string | undefined>;
|
||||
|
||||
/**
|
||||
* if the most specific path schema that is matched does not cover the whole
|
||||
|
||||
@@ -33,9 +33,7 @@ export * from "../../renderer/components/switch";
|
||||
export * from "../../renderer/components/input/input";
|
||||
|
||||
// command-overlay
|
||||
export const CommandOverlay = asLegacyGlobalForExtensionApi(
|
||||
commandOverlayInjectable,
|
||||
);
|
||||
export const CommandOverlay = asLegacyGlobalForExtensionApi(commandOverlayInjectable);
|
||||
|
||||
export type {
|
||||
CategoryColumnRegistration,
|
||||
@@ -81,39 +79,30 @@ export * from "../../renderer/components/+events/kube-event-details";
|
||||
// specific exports
|
||||
export * from "../../renderer/components/status-brick";
|
||||
|
||||
export const createTerminalTab = asLegacyGlobalFunctionForExtensionApi(
|
||||
createTerminalTabInjectable,
|
||||
export const createTerminalTab = asLegacyGlobalFunctionForExtensionApi(createTerminalTabInjectable);
|
||||
|
||||
export const terminalStore = asLegacyGlobalObjectForExtensionApiWithModifications(
|
||||
terminalStoreInjectable,
|
||||
{
|
||||
sendCommand: asLegacyGlobalFunctionForExtensionApi(sendCommandInjectable),
|
||||
},
|
||||
);
|
||||
|
||||
export const terminalStore =
|
||||
asLegacyGlobalObjectForExtensionApiWithModifications(
|
||||
terminalStoreInjectable,
|
||||
{
|
||||
sendCommand: asLegacyGlobalFunctionForExtensionApi(sendCommandInjectable),
|
||||
},
|
||||
);
|
||||
const renameTab = asLegacyGlobalFunctionForExtensionApi(renameTabInjectable);
|
||||
|
||||
export const logTabStore = asLegacyGlobalObjectForExtensionApiWithModifications(
|
||||
logTabStoreInjectable,
|
||||
{
|
||||
createPodTab: asLegacyGlobalFunctionForExtensionApi(
|
||||
createPodLogsTabInjectable,
|
||||
),
|
||||
|
||||
createWorkloadTab: asLegacyGlobalFunctionForExtensionApi(
|
||||
createWorkloadLogsTabInjectable,
|
||||
),
|
||||
|
||||
createPodTab: asLegacyGlobalFunctionForExtensionApi(createPodLogsTabInjectable),
|
||||
createWorkloadTab: asLegacyGlobalFunctionForExtensionApi(createWorkloadLogsTabInjectable),
|
||||
renameTab: (tabId: string): void => {
|
||||
const renameTab =
|
||||
asLegacyGlobalFunctionForExtensionApi(renameTabInjectable);
|
||||
|
||||
const tabData = logTabStore.getData(tabId);
|
||||
const pod = podsStore.getById(tabData.selectedPodId);
|
||||
const pod = podsStore.getById(tabData?.selectedPodId);
|
||||
|
||||
renameTab(tabId, `Pod ${pod.getName()}`);
|
||||
if (pod) {
|
||||
renameTab(tabId, `Pod ${pod.getName()}`);
|
||||
}
|
||||
},
|
||||
|
||||
tabs: undefined,
|
||||
},
|
||||
);
|
||||
|
||||
@@ -25,30 +25,30 @@ export { apiManager } from "../../common/k8s-api/api-manager";
|
||||
export { KubeObjectStore } from "../../common/k8s-api/kube-object.store";
|
||||
export { KubeApi, forCluster, forRemoteCluster } from "../../common/k8s-api/kube-api";
|
||||
export { KubeObject, KubeStatus } from "../../common/k8s-api/kube-object";
|
||||
export { Pod, podsApi, PodsApi } from "../../common/k8s-api/endpoints";
|
||||
export { Node, nodesApi, NodesApi } from "../../common/k8s-api/endpoints";
|
||||
export { Pod, podApi as podsApi, PodApi as PodsApi } from "../../common/k8s-api/endpoints";
|
||||
export { Node, nodeApi as nodesApi, NodeApi as NodesApi } from "../../common/k8s-api/endpoints";
|
||||
export { Deployment, deploymentApi, DeploymentApi } from "../../common/k8s-api/endpoints";
|
||||
export { DaemonSet, daemonSetApi } from "../../common/k8s-api/endpoints";
|
||||
export { StatefulSet, statefulSetApi } from "../../common/k8s-api/endpoints";
|
||||
export { Job, jobApi } from "../../common/k8s-api/endpoints";
|
||||
export { CronJob, cronJobApi } from "../../common/k8s-api/endpoints";
|
||||
export { ConfigMap, configMapApi } from "../../common/k8s-api/endpoints";
|
||||
export { Secret, secretsApi } from "../../common/k8s-api/endpoints";
|
||||
export { Secret, secretApi as secretsApi } from "../../common/k8s-api/endpoints";
|
||||
export { ReplicaSet, replicaSetApi } from "../../common/k8s-api/endpoints";
|
||||
export { ResourceQuota, resourceQuotaApi } from "../../common/k8s-api/endpoints";
|
||||
export { LimitRange, limitRangeApi } from "../../common/k8s-api/endpoints";
|
||||
export { HorizontalPodAutoscaler, hpaApi } from "../../common/k8s-api/endpoints";
|
||||
export { PodDisruptionBudget, pdbApi } from "../../common/k8s-api/endpoints";
|
||||
export { HorizontalPodAutoscaler, horizontalPodAutoscalerApi as hpaApi } from "../../common/k8s-api/endpoints";
|
||||
export { PodDisruptionBudget, podDisruptionBudgetApi as pdbApi } from "../../common/k8s-api/endpoints";
|
||||
export { Service, serviceApi } from "../../common/k8s-api/endpoints";
|
||||
export { Endpoint, endpointApi } from "../../common/k8s-api/endpoints";
|
||||
export { Endpoints as Endpoint, endpointsApi as endpointApi } from "../../common/k8s-api/endpoints";
|
||||
export { Ingress, ingressApi, IngressApi } from "../../common/k8s-api/endpoints";
|
||||
export { NetworkPolicy, networkPolicyApi } from "../../common/k8s-api/endpoints";
|
||||
export { PersistentVolume, persistentVolumeApi } from "../../common/k8s-api/endpoints";
|
||||
export { PersistentVolumeClaim, pvcApi, PersistentVolumeClaimsApi } from "../../common/k8s-api/endpoints";
|
||||
export { PersistentVolumeClaim, persistentVolumeClaimApi as pvcApi, PersistentVolumeClaimApi as PersistentVolumeClaimsApi } from "../../common/k8s-api/endpoints";
|
||||
export { StorageClass, storageClassApi } from "../../common/k8s-api/endpoints";
|
||||
export { Namespace, namespacesApi } from "../../common/k8s-api/endpoints";
|
||||
export { KubeEvent, eventApi } from "../../common/k8s-api/endpoints";
|
||||
export { ServiceAccount, serviceAccountsApi } from "../../common/k8s-api/endpoints";
|
||||
export { ServiceAccount, serviceAccountApi as serviceAccountsApi } from "../../common/k8s-api/endpoints";
|
||||
export { Role, roleApi } from "../../common/k8s-api/endpoints";
|
||||
export { RoleBinding, roleBindingApi } from "../../common/k8s-api/endpoints";
|
||||
export { ClusterRole, clusterRoleApi } from "../../common/k8s-api/endpoints";
|
||||
@@ -60,9 +60,9 @@ export { KubeJsonApi } from "../../common/k8s-api/kube-json-api";
|
||||
// types
|
||||
export type { ILocalKubeApiConfig, IRemoteKubeApiConfig, IKubeApiCluster } from "../../common/k8s-api/kube-api";
|
||||
export type { IPodContainer, IPodContainerStatus } from "../../common/k8s-api/endpoints";
|
||||
export type { ISecretRef } from "../../common/k8s-api/endpoints";
|
||||
export type { SecretReference as ISecretRef } from "../../common/k8s-api/endpoints";
|
||||
export type { KubeObjectStatus } from "./kube-object-status";
|
||||
export type { KubeObjectMetadata, KubeStatusData } from "../../common/k8s-api/kube-object";
|
||||
export type { KubeJsonApiObjectMetadata as KubeObjectMetadata, KubeStatusData } from "../../common/k8s-api/kube-object";
|
||||
export type { KubeObjectStoreLoadAllParams, KubeObjectStoreLoadingParams, KubeObjectStoreSubscribeParams } from "../../common/k8s-api/kube-object.store";
|
||||
|
||||
// stores
|
||||
@@ -74,23 +74,23 @@ export type { DaemonSetStore } from "../../renderer/components/+workloads-daemon
|
||||
export type { StatefulSetStore } from "../../renderer/components/+workloads-statefulsets/statefulset.store";
|
||||
export type { JobStore } from "../../renderer/components/+workloads-jobs/job.store";
|
||||
export type { CronJobStore } from "../../renderer/components/+workloads-cronjobs/cronjob.store";
|
||||
export type { ConfigMapsStore } from "../../renderer/components/+config-maps/config-maps.store";
|
||||
export type { SecretsStore } from "../../renderer/components/+config-secrets/secrets.store";
|
||||
export type { ConfigMapStore as ConfigMapsStore } from "../../renderer/components/+config-maps/config-maps.store";
|
||||
export type { SecretStore as SecretsStore } from "../../renderer/components/+config-secrets/secrets.store";
|
||||
export type { ReplicaSetStore } from "../../renderer/components/+workloads-replicasets/replicasets.store";
|
||||
export type { ResourceQuotasStore } from "../../renderer/components/+config-resource-quotas/resource-quotas.store";
|
||||
export type { LimitRangesStore } from "../../renderer/components/+config-limit-ranges/limit-ranges.store";
|
||||
export type { HPAStore } from "../../renderer/components/+config-autoscalers/hpa.store";
|
||||
export type { PodDisruptionBudgetsStore } from "../../renderer/components/+config-pod-disruption-budgets/pod-disruption-budgets.store";
|
||||
export type { ResourceQuotaStore as ResourceQuotasStore } from "../../renderer/components/+config-resource-quotas/resource-quotas.store";
|
||||
export type { LimitRangeStore as LimitRangesStore } from "../../renderer/components/+config-limit-ranges/limit-ranges.store";
|
||||
export type { HorizontalPodAutoscalerStore as HPAStore } from "../../renderer/components/+config-autoscalers/hpa.store";
|
||||
export type { PodDisruptionBudgetStore as PodDisruptionBudgetsStore } from "../../renderer/components/+config-pod-disruption-budgets/pod-disruption-budgets.store";
|
||||
export type { ServiceStore } from "../../renderer/components/+network-services/services.store";
|
||||
export type { EndpointStore } from "../../renderer/components/+network-endpoints/endpoints.store";
|
||||
export type { IngressStore } from "../../renderer/components/+network-ingresses/ingress.store";
|
||||
export type { NetworkPolicyStore } from "../../renderer/components/+network-policies/network-policy.store";
|
||||
export type { PersistentVolumesStore } from "../../renderer/components/+storage-volumes/volumes.store";
|
||||
export type { VolumeClaimStore } from "../../renderer/components/+storage-volume-claims/volume-claim.store";
|
||||
export type { PersistentVolumeClaimStore as VolumeClaimStore } from "../../renderer/components/+storage-volume-claims/volume-claim.store";
|
||||
export type { StorageClassStore } from "../../renderer/components/+storage-classes/storage-class.store";
|
||||
export type { NamespaceStore } from "../../renderer/components/+namespaces/namespace-store/namespace.store";
|
||||
export type { ServiceAccountsStore } from "../../renderer/components/+user-management/+service-accounts/store";
|
||||
export type { RolesStore } from "../../renderer/components/+user-management/+roles/store";
|
||||
export type { RoleBindingsStore } from "../../renderer/components/+user-management/+role-bindings/store";
|
||||
export type { RoleBindingStore as RoleBindingsStore } from "../../renderer/components/+user-management/+role-bindings/store";
|
||||
export type { CRDStore } from "../../renderer/components/+custom-resources/crd.store";
|
||||
export type { CRDResourceStore } from "../../renderer/components/+custom-resources/crd-resource.store";
|
||||
Reference in new issue
Block a user