mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Release/v5.4.4 (#5099)
* Emit AppEvent when opening Catalog and changing Catalog Category (#5071) * Emit AppEvent when opening Catalog and changing Catalog Category. Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com> * Add getName method to CatalogCategory Signed-off-by: Panu Horsmalahti <phorsmalahti@mirantis.com> * Fix winston logger missing splat format (#5070) * Fix KubeJsonApi.forCluster throwing on renderer (#5034) * test relied on typing of newer version of ogre-tools Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com> * release v5.4.4 Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com> Co-authored-by: Panu Horsmalahti <phorsmalahti@mirantis.com> Co-authored-by: Jari Kolehmainen <jari.kolehmainen@gmail.com> Co-authored-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
87e870b5b9
commit
adcf87e939
@ -3,7 +3,7 @@
|
|||||||
"productName": "OpenLens",
|
"productName": "OpenLens",
|
||||||
"description": "OpenLens - Open Source IDE for Kubernetes",
|
"description": "OpenLens - Open Source IDE for Kubernetes",
|
||||||
"homepage": "https://github.com/lensapp/lens",
|
"homepage": "https://github.com/lensapp/lens",
|
||||||
"version": "5.4.3",
|
"version": "5.4.4",
|
||||||
"main": "static/build/main.js",
|
"main": "static/build/main.js",
|
||||||
"copyright": "© 2021 OpenLens Authors",
|
"copyright": "© 2021 OpenLens Authors",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
30
src/common/__tests__/catalog-entity.test.ts
Normal file
30
src/common/__tests__/catalog-entity.test.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { CatalogCategory, CatalogCategorySpec } from "../catalog";
|
||||||
|
|
||||||
|
class TestCatalogCategory extends CatalogCategory {
|
||||||
|
public readonly apiVersion = "catalog.k8slens.dev/v1alpha1";
|
||||||
|
public readonly kind = "CatalogCategory";
|
||||||
|
public metadata = {
|
||||||
|
name: "Test Category",
|
||||||
|
icon: "",
|
||||||
|
};
|
||||||
|
public spec: CatalogCategorySpec = {
|
||||||
|
group: "entity.k8slens.dev",
|
||||||
|
versions: [],
|
||||||
|
names: {
|
||||||
|
kind: "Test",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("CatalogCategory", () => {
|
||||||
|
it("returns name", () => {
|
||||||
|
const category = new TestCatalogCategory();
|
||||||
|
|
||||||
|
expect(category.getName()).toEqual("Test Category");
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -173,6 +173,13 @@ export abstract class CatalogCategory extends (EventEmitter as new () => TypedEm
|
|||||||
return `${this.spec.group}/${this.spec.names.kind}`;
|
return `${this.spec.group}/${this.spec.names.kind}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of this category
|
||||||
|
*/
|
||||||
|
public getName(): string {
|
||||||
|
return this.metadata.name;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a filter for menu items of catalogAddMenu
|
* Add a filter for menu items of catalogAddMenu
|
||||||
* @param fn The function that should return a truthy value if that menu item should be displayed
|
* @param fn The function that should return a truthy value if that menu item should be displayed
|
||||||
|
|||||||
40
src/common/k8s-api/api-base.ts
Normal file
40
src/common/k8s-api/api-base.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { JsonApi } from "./json-api";
|
||||||
|
import { apiPrefix, isDebugging, isDevelopment } from "../vars";
|
||||||
|
import { appEventBus } from "../app-event-bus/event-bus";
|
||||||
|
|
||||||
|
export let apiBase: JsonApi;
|
||||||
|
|
||||||
|
if (typeof window === "undefined") {
|
||||||
|
appEventBus.addListener((event) => {
|
||||||
|
if (event.name !== "lens-proxy" && event.action !== "listen") return;
|
||||||
|
|
||||||
|
const params = event.params as { port?: number };
|
||||||
|
|
||||||
|
if (!params.port) return;
|
||||||
|
|
||||||
|
apiBase = new JsonApi({
|
||||||
|
serverAddress: `http://127.0.0.1:${params.port}`,
|
||||||
|
apiBase: apiPrefix,
|
||||||
|
debug: isDevelopment || isDebugging,
|
||||||
|
}, {
|
||||||
|
headers: {
|
||||||
|
"Host": `localhost:${params.port}`,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
apiBase = new JsonApi({
|
||||||
|
serverAddress: `http://127.0.0.1:${window.location.port}`,
|
||||||
|
apiBase: apiPrefix,
|
||||||
|
debug: isDevelopment || isDebugging,
|
||||||
|
}, {
|
||||||
|
headers: {
|
||||||
|
"Host": window.location.host,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
20
src/common/k8s-api/api-kube.ts
Normal file
20
src/common/k8s-api/api-kube.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { isClusterPageContext } from "../utils";
|
||||||
|
import { KubeJsonApi } from "./kube-json-api";
|
||||||
|
import { apiKubePrefix, isDevelopment } from "../vars";
|
||||||
|
|
||||||
|
export const apiKube = isClusterPageContext()
|
||||||
|
? new KubeJsonApi({
|
||||||
|
serverAddress: `http://127.0.0.1:${window.location.port}`,
|
||||||
|
apiBase: apiKubePrefix,
|
||||||
|
debug: isDevelopment,
|
||||||
|
}, {
|
||||||
|
headers: {
|
||||||
|
"Host": window.location.host,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
: undefined;
|
||||||
@ -3,58 +3,5 @@
|
|||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { JsonApi } from "./json-api";
|
export { apiBase } from "./api-base";
|
||||||
import { KubeJsonApi } from "./kube-json-api";
|
export { apiKube } from "./api-kube";
|
||||||
import { apiKubePrefix, apiPrefix, isDebugging, isDevelopment } from "../../common/vars";
|
|
||||||
import { isClusterPageContext } from "../utils/cluster-id-url-parsing";
|
|
||||||
import { appEventBus } from "../app-event-bus/event-bus";
|
|
||||||
|
|
||||||
let apiBase: JsonApi;
|
|
||||||
let apiKube: KubeJsonApi;
|
|
||||||
|
|
||||||
if (typeof window === "undefined") {
|
|
||||||
appEventBus.addListener((event) => {
|
|
||||||
if (event.name !== "lens-proxy" && event.action !== "listen") return;
|
|
||||||
|
|
||||||
const params = event.params as { port?: number };
|
|
||||||
|
|
||||||
if (!params.port) return;
|
|
||||||
|
|
||||||
apiBase = new JsonApi({
|
|
||||||
serverAddress: `http://127.0.0.1:${params.port}`,
|
|
||||||
apiBase: apiPrefix,
|
|
||||||
debug: isDevelopment || isDebugging,
|
|
||||||
}, {
|
|
||||||
headers: {
|
|
||||||
"Host": `localhost:${params.port}`,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
apiBase = new JsonApi({
|
|
||||||
serverAddress: `http://127.0.0.1:${window.location.port}`,
|
|
||||||
apiBase: apiPrefix,
|
|
||||||
debug: isDevelopment || isDebugging,
|
|
||||||
}, {
|
|
||||||
headers: {
|
|
||||||
"Host": window.location.host,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isClusterPageContext()) {
|
|
||||||
apiKube = new KubeJsonApi({
|
|
||||||
serverAddress: `http://127.0.0.1:${window.location.port}`,
|
|
||||||
apiBase: apiKubePrefix,
|
|
||||||
debug: isDevelopment,
|
|
||||||
}, {
|
|
||||||
headers: {
|
|
||||||
"Host": window.location.host,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export {
|
|
||||||
apiBase,
|
|
||||||
apiKube,
|
|
||||||
};
|
|
||||||
|
|||||||
@ -5,8 +5,8 @@
|
|||||||
|
|
||||||
import { JsonApi, JsonApiData, JsonApiError } from "./json-api";
|
import { JsonApi, JsonApiData, JsonApiError } from "./json-api";
|
||||||
import type { Response } from "node-fetch";
|
import type { Response } from "node-fetch";
|
||||||
import { LensProxy } from "../../main/lens-proxy";
|
|
||||||
import { apiKubePrefix, isDebugging } from "../vars";
|
import { apiKubePrefix, isDebugging } from "../vars";
|
||||||
|
import { apiBase } from "./api-base";
|
||||||
|
|
||||||
export interface KubeJsonApiListMetadata {
|
export interface KubeJsonApiListMetadata {
|
||||||
resourceVersion: string;
|
resourceVersion: string;
|
||||||
@ -57,15 +57,15 @@ export interface KubeJsonApiError extends JsonApiError {
|
|||||||
|
|
||||||
export class KubeJsonApi extends JsonApi<KubeJsonApiData> {
|
export class KubeJsonApi extends JsonApi<KubeJsonApiData> {
|
||||||
static forCluster(clusterId: string): KubeJsonApi {
|
static forCluster(clusterId: string): KubeJsonApi {
|
||||||
const port = LensProxy.getInstance().port;
|
const url = new URL(apiBase.config.serverAddress);
|
||||||
|
|
||||||
return new this({
|
return new this({
|
||||||
serverAddress: `http://127.0.0.1:${port}`,
|
serverAddress: apiBase.config.serverAddress,
|
||||||
apiBase: apiKubePrefix,
|
apiBase: apiKubePrefix,
|
||||||
debug: isDebugging,
|
debug: isDebugging,
|
||||||
}, {
|
}, {
|
||||||
headers: {
|
headers: {
|
||||||
"Host": `${clusterId}.localhost:${port}`,
|
"Host": `${clusterId}.localhost:${url.port}`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -65,6 +65,9 @@ if (ipcMain) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default winston.createLogger({
|
export default winston.createLogger({
|
||||||
format: format.simple(),
|
format: format.combine(
|
||||||
|
format.splat(),
|
||||||
|
format.simple(),
|
||||||
|
),
|
||||||
transports,
|
transports,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -20,6 +20,7 @@ jest.mock("winston", () => ({
|
|||||||
label: jest.fn(),
|
label: jest.fn(),
|
||||||
timestamp: jest.fn(),
|
timestamp: jest.fn(),
|
||||||
printf: jest.fn(),
|
printf: jest.fn(),
|
||||||
|
splat: jest.fn(),
|
||||||
},
|
},
|
||||||
createLogger: jest.fn().mockReturnValue(logger),
|
createLogger: jest.fn().mockReturnValue(logger),
|
||||||
transports: {
|
transports: {
|
||||||
|
|||||||
@ -15,6 +15,7 @@ jest.mock("winston", () => ({
|
|||||||
printf: jest.fn(),
|
printf: jest.fn(),
|
||||||
padLevels: jest.fn(),
|
padLevels: jest.fn(),
|
||||||
ms: jest.fn(),
|
ms: jest.fn(),
|
||||||
|
splat: jest.fn(),
|
||||||
},
|
},
|
||||||
createLogger: jest.fn().mockReturnValue({
|
createLogger: jest.fn().mockReturnValue({
|
||||||
silly: jest.fn(),
|
silly: jest.fn(),
|
||||||
|
|||||||
@ -21,6 +21,7 @@ jest.mock("winston", () => ({
|
|||||||
padLevels: jest.fn(),
|
padLevels: jest.fn(),
|
||||||
ms: jest.fn(),
|
ms: jest.fn(),
|
||||||
printf: jest.fn(),
|
printf: jest.fn(),
|
||||||
|
splat: jest.fn(),
|
||||||
},
|
},
|
||||||
createLogger: jest.fn().mockReturnValue(logger),
|
createLogger: jest.fn().mockReturnValue(logger),
|
||||||
transports: {
|
transports: {
|
||||||
|
|||||||
@ -52,10 +52,10 @@ function handleAutoUpdateBackChannel(event: Electron.IpcMainEvent, ...[arg]: Upd
|
|||||||
}
|
}
|
||||||
|
|
||||||
autoUpdater.logger = {
|
autoUpdater.logger = {
|
||||||
info: message => logger.info(`[AUTO-UPDATE]: electron-updater:`, message),
|
info: message => logger.info(`[AUTO-UPDATE]: electron-updater: %s`, message),
|
||||||
warn: message => logger.warn(`[AUTO-UPDATE]: electron-updater:`, message),
|
warn: message => logger.warn(`[AUTO-UPDATE]: electron-updater: %s`, message),
|
||||||
error: message => logger.error(`[AUTO-UPDATE]: electron-updater:`, message),
|
error: message => logger.error(`[AUTO-UPDATE]: electron-updater: %s`, message),
|
||||||
debug: message => logger.debug(`[AUTO-UPDATE]: electron-updater:`, message),
|
debug: message => logger.debug(`[AUTO-UPDATE]: electron-updater: %s`, message),
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -25,6 +25,9 @@ import { UserStore } from "../../../common/user-store";
|
|||||||
import mockFs from "mock-fs";
|
import mockFs from "mock-fs";
|
||||||
import directoryForUserDataInjectable
|
import directoryForUserDataInjectable
|
||||||
from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
from "../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||||
|
import type { AppEvent } from "../../../common/app-event-bus/event-bus";
|
||||||
|
import appEventBusInjectable from "../../../common/app-event-bus/app-event-bus.injectable";
|
||||||
|
import { EventEmitter } from "../../../common/event-emitter";
|
||||||
|
|
||||||
mockWindow();
|
mockWindow();
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
@ -98,6 +101,7 @@ describe("<Catalog />", () => {
|
|||||||
let di: DependencyInjectionContainer;
|
let di: DependencyInjectionContainer;
|
||||||
let catalogEntityStore: CatalogEntityStore;
|
let catalogEntityStore: CatalogEntityStore;
|
||||||
let catalogEntityRegistry: CatalogEntityRegistry;
|
let catalogEntityRegistry: CatalogEntityRegistry;
|
||||||
|
let emitEvent: (event: AppEvent) => void;
|
||||||
let render: DiRender;
|
let render: DiRender;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
@ -121,6 +125,14 @@ describe("<Catalog />", () => {
|
|||||||
|
|
||||||
di.override(catalogEntityRegistryInjectable, () => catalogEntityRegistry);
|
di.override(catalogEntityRegistryInjectable, () => catalogEntityRegistry);
|
||||||
|
|
||||||
|
emitEvent = jest.fn();
|
||||||
|
|
||||||
|
const source = new EventEmitter();
|
||||||
|
|
||||||
|
source.emit = emitEvent;
|
||||||
|
|
||||||
|
di.override(appEventBusInjectable, () => source);
|
||||||
|
|
||||||
catalogEntityStore = di.inject(catalogEntityStoreInjectable);
|
catalogEntityStore = di.inject(catalogEntityStoreInjectable);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -316,4 +328,39 @@ describe("<Catalog />", () => {
|
|||||||
|
|
||||||
userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon"));
|
userEvent.click(screen.getByTestId("detail-panel-hot-bar-icon"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("emits catalog open AppEvent", () => {
|
||||||
|
render(
|
||||||
|
<Catalog
|
||||||
|
history={history}
|
||||||
|
location={mockLocation}
|
||||||
|
match={mockMatch}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(emitEvent).toHaveBeenCalledWith( {
|
||||||
|
action: "open",
|
||||||
|
name: "catalog",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("emits catalog change AppEvent when changing the category", () => {
|
||||||
|
render(
|
||||||
|
<Catalog
|
||||||
|
history={history}
|
||||||
|
location={mockLocation}
|
||||||
|
match={mockMatch}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
userEvent.click(screen.getByText("Web Links"));
|
||||||
|
|
||||||
|
expect(emitEvent).toHaveBeenLastCalledWith({
|
||||||
|
action: "change-category",
|
||||||
|
name: "catalog",
|
||||||
|
params: {
|
||||||
|
category: "Web Links",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -36,6 +36,8 @@ import getCategoryColumnsInjectable from "./get-category-columns.injectable";
|
|||||||
import type { RegisteredCustomCategoryViewDecl } from "./custom-views.injectable";
|
import type { RegisteredCustomCategoryViewDecl } from "./custom-views.injectable";
|
||||||
import customCategoryViewsInjectable from "./custom-views.injectable";
|
import customCategoryViewsInjectable from "./custom-views.injectable";
|
||||||
import type { CustomCategoryViewComponents } from "./custom-views";
|
import type { CustomCategoryViewComponents } from "./custom-views";
|
||||||
|
import type { AppEvent } from "../../../common/app-event-bus/event-bus";
|
||||||
|
import appEventBusInjectable from "../../../common/app-event-bus/app-event-bus.injectable";
|
||||||
|
|
||||||
interface Props extends RouteComponentProps<CatalogViewRouteParam> {}
|
interface Props extends RouteComponentProps<CatalogViewRouteParam> {}
|
||||||
|
|
||||||
@ -44,6 +46,7 @@ interface Dependencies {
|
|||||||
catalogEntityStore: CatalogEntityStore;
|
catalogEntityStore: CatalogEntityStore;
|
||||||
getCategoryColumns: (params: GetCategoryColumnsParams) => CategoryColumns;
|
getCategoryColumns: (params: GetCategoryColumnsParams) => CategoryColumns;
|
||||||
customCategoryViews: IComputedValue<Map<string, Map<string, RegisteredCustomCategoryViewDecl>>>;
|
customCategoryViews: IComputedValue<Map<string, Map<string, RegisteredCustomCategoryViewDecl>>>;
|
||||||
|
emitEvent: (event: AppEvent) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
@ -104,6 +107,11 @@ class NonInjectedCatalog extends React.Component<Props & Dependencies> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
this.props.emitEvent({
|
||||||
|
name: "catalog",
|
||||||
|
action: "open",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addToHotbar(entity: CatalogEntity): void {
|
addToHotbar(entity: CatalogEntity): void {
|
||||||
@ -146,6 +154,14 @@ class NonInjectedCatalog extends React.Component<Props & Dependencies> {
|
|||||||
onTabChange = action((tabId: string | null) => {
|
onTabChange = action((tabId: string | null) => {
|
||||||
const activeCategory = this.categories.find(category => category.getId() === tabId);
|
const activeCategory = this.categories.find(category => category.getId() === tabId);
|
||||||
|
|
||||||
|
this.props.emitEvent({
|
||||||
|
name: "catalog",
|
||||||
|
action: "change-category",
|
||||||
|
params: {
|
||||||
|
category: activeCategory ? activeCategory.getName() : "Browse",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (activeCategory) {
|
if (activeCategory) {
|
||||||
navigate(catalogURL({ params: { group: activeCategory.spec.group, kind: activeCategory.spec.names.kind }}));
|
navigate(catalogURL({ params: { group: activeCategory.spec.group, kind: activeCategory.spec.names.kind }}));
|
||||||
} else {
|
} else {
|
||||||
@ -311,6 +327,7 @@ export const Catalog = withInjectables<Dependencies, Props>( NonInjectedCatalog,
|
|||||||
catalogPreviousActiveTabStorage: di.inject(catalogPreviousActiveTabStorageInjectable),
|
catalogPreviousActiveTabStorage: di.inject(catalogPreviousActiveTabStorageInjectable),
|
||||||
getCategoryColumns: di.inject(getCategoryColumnsInjectable),
|
getCategoryColumns: di.inject(getCategoryColumnsInjectable),
|
||||||
customCategoryViews: di.inject(customCategoryViewsInjectable),
|
customCategoryViews: di.inject(customCategoryViewsInjectable),
|
||||||
|
emitEvent: di.inject(appEventBusInjectable).emit,
|
||||||
...props,
|
...props,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user