1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix type errors and remove dead code

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-11-28 10:34:00 -05:00
parent 986cf869ae
commit 00a8b81df4
5 changed files with 29 additions and 27 deletions

View File

@ -8,7 +8,6 @@ import type { ApiManager } from "../api-manager";
import { Ingress, IngressApi } from "../endpoints"; import { Ingress, IngressApi } from "../endpoints";
import { getDiForUnitTesting } from "../../../renderer/getDiForUnitTesting"; import { getDiForUnitTesting } from "../../../renderer/getDiForUnitTesting";
import apiManagerInjectable from "../api-manager/manager.injectable"; import apiManagerInjectable from "../api-manager/manager.injectable";
import autoRegistrationInjectable from "../api-manager/auto-registration.injectable";
import type { Fetch } from "../../fetch/fetch.injectable"; import type { Fetch } from "../../fetch/fetch.injectable";
import fetchInjectable from "../../fetch/fetch.injectable"; import fetchInjectable from "../../fetch/fetch.injectable";
import type { AsyncFnMock } from "@async-fn/jest"; import type { AsyncFnMock } from "@async-fn/jest";
@ -16,6 +15,7 @@ import asyncFn from "@async-fn/jest";
import { flushPromises } from "../../test-utils/flush-promises"; import { flushPromises } from "../../test-utils/flush-promises";
import createKubeJsonApiInjectable from "../create-kube-json-api.injectable"; import createKubeJsonApiInjectable from "../create-kube-json-api.injectable";
import type { Response, Headers as NodeFetchHeaders } from "node-fetch"; import type { Response, Headers as NodeFetchHeaders } from "node-fetch";
import setupAutoRegistrationInjectable from "../../../renderer/before-frame-starts/runnables/setup-auto-registration.injectable";
const createMockResponseFromString = (url: string, data: string, statusCode = 200) => { const createMockResponseFromString = (url: string, data: string, statusCode = 200) => {
const res: jest.Mocked<Response> = { const res: jest.Mocked<Response> = {
@ -60,7 +60,9 @@ describe("KubeApi", () => {
}); });
registerApiSpy = jest.spyOn(di.inject(apiManagerInjectable), "registerApi"); registerApiSpy = jest.spyOn(di.inject(apiManagerInjectable), "registerApi");
di.inject(autoRegistrationInjectable); const setupAutoRegistration = di.inject(setupAutoRegistrationInjectable);
setupAutoRegistration.run();
}); });
describe("on first call to IngressApi.get()", () => { describe("on first call to IngressApi.get()", () => {

View File

@ -8,7 +8,6 @@ import type { KubeJsonApi, KubeJsonApiData } from "../kube-json-api";
import { PassThrough } from "stream"; import { PassThrough } from "stream";
import { Deployment, DeploymentApi, NamespaceApi, Pod, PodApi } from "../endpoints"; import { Deployment, DeploymentApi, NamespaceApi, Pod, PodApi } from "../endpoints";
import { getDiForUnitTesting } from "../../../renderer/getDiForUnitTesting"; import { getDiForUnitTesting } from "../../../renderer/getDiForUnitTesting";
import autoRegistrationInjectable from "../api-manager/auto-registration.injectable";
import type { Fetch } from "../../fetch/fetch.injectable"; import type { Fetch } from "../../fetch/fetch.injectable";
import fetchInjectable from "../../fetch/fetch.injectable"; import fetchInjectable from "../../fetch/fetch.injectable";
import type { CreateKubeApiForRemoteCluster } from "../create-kube-api-for-remote-cluster.injectable"; import type { CreateKubeApiForRemoteCluster } from "../create-kube-api-for-remote-cluster.injectable";
@ -21,6 +20,7 @@ import type { IKubeWatchEvent } from "../kube-watch-event";
import type { KubeJsonApiDataFor } from "../kube-object"; import type { KubeJsonApiDataFor } from "../kube-object";
import type { Response, Headers as NodeFetchHeaders } from "node-fetch"; import type { Response, Headers as NodeFetchHeaders } from "node-fetch";
import AbortController from "abort-controller"; import AbortController from "abort-controller";
import setupAutoRegistrationInjectable from "../../../renderer/before-frame-starts/runnables/setup-auto-registration.injectable";
const createMockResponseFromString = (url: string, data: string, statusCode = 200) => { const createMockResponseFromString = (url: string, data: string, statusCode = 200) => {
const res: jest.Mocked<Response> = { const res: jest.Mocked<Response> = {
@ -184,7 +184,9 @@ describe("KubeApi", () => {
apiBase: "/api-kube", apiBase: "/api-kube",
}); });
di.inject(autoRegistrationInjectable); const setupAutoRegistration = di.inject(setupAutoRegistrationInjectable);
setupAutoRegistration.run();
}); });
describe("patching deployments", () => { describe("patching deployments", () => {

View File

@ -6,21 +6,6 @@
// App's common configuration for any process (main, renderer, build pipeline, etc.) // App's common configuration for any process (main, renderer, build pipeline, etc.)
import type { ThemeId } from "../renderer/themes/lens-theme"; import type { ThemeId } from "../renderer/themes/lens-theme";
/**
* @deprecated Switch to using isWindowsInjectable
*/
export const isWindows = process.platform === "win32";
/**
* @deprecated Switch to using isLinuxInjectable
*/
export const isLinux = process.platform === "linux";
/**
* @deprecated switch to using `isDebuggingInjectable`
*/
export const isDebugging = ["true", "1", "yes", "y", "on"].includes((process.env.DEBUG ?? "").toLowerCase());
/** /**
* @deprecated Switch to using isTestEnvInjectable * @deprecated Switch to using isTestEnvInjectable
*/ */

View File

@ -3,22 +3,23 @@
* 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 configurePackages from "./common/configure-packages";
import { configure } from "mobx"; import { configure } from "mobx";
import { setImmediate } from "timers"; import { setImmediate } from "timers";
import { TextEncoder, TextDecoder as TextDecoderNode } from "util"; import { TextEncoder, TextDecoder as TextDecoderNode } from "util";
import glob from "glob"; import glob from "glob";
import path from "path"; import path from "path";
import { enableMapSet, setAutoFreeze } from "immer";
// setup default configuration for external npm-packages
configurePackages();
configure({ configure({
// Needed because we want to use jest.spyOn() // Needed because we want to use jest.spyOn()
// ref https://github.com/mobxjs/mobx/issues/2784 // ref https://github.com/mobxjs/mobx/issues/2784
safeDescriptors: false, safeDescriptors: false,
enforceActions: "never",
}); });
setAutoFreeze(false); // allow to merge mobx observables
enableMapSet(); // allow to merge maps and sets
// Mock __non_webpack_require__ for tests // Mock __non_webpack_require__ for tests
globalThis.__non_webpack_require__ = jest.fn(); globalThis.__non_webpack_require__ = jest.fn();

View File

@ -11,7 +11,8 @@ import { cssNames, autoBind } from "../../utils";
import { Icon } from "../icon"; import { Icon } from "../icon";
import type { InputProps } from "./input"; import type { InputProps } from "./input";
import { Input } from "./input"; import { Input } from "./input";
import { isMac } from "../../../common/vars"; import { withInjectables } from "@ogre-tools/injectable-react";
import isMacInjectable from "../../../common/vars/is-mac.injectable";
export interface SearchInputProps extends InputProps { export interface SearchInputProps extends InputProps {
compact?: boolean; // show only search-icon when not focused compact?: boolean; // show only search-icon when not focused
@ -27,13 +28,17 @@ const defaultProps: Partial<SearchInputProps> = {
placeholder: "Search...", placeholder: "Search...",
}; };
interface Dependencies {
isMac: boolean;
}
@observer @observer
export class SearchInput extends React.Component<SearchInputProps> { class NonInjectedSearchInput extends React.Component<SearchInputProps & Dependencies> {
static defaultProps = defaultProps as object; static defaultProps = defaultProps as object;
private inputRef = createRef<Input>(); private inputRef = createRef<Input>();
constructor(props: SearchInputProps) { constructor(props: SearchInputProps & Dependencies) {
super(props); super(props);
autoBind(this); autoBind(this);
} }
@ -48,7 +53,7 @@ export class SearchInput extends React.Component<SearchInputProps> {
} }
onGlobalKey(evt: KeyboardEvent) { onGlobalKey(evt: KeyboardEvent) {
if (evt.key === "f" && (isMac ? evt.metaKey : evt.ctrlKey)) { if (evt.key === "f" && (this.props.isMac ? evt.metaKey : evt.ctrlKey)) {
this.inputRef.current?.focus(); this.inputRef.current?.focus();
} }
} }
@ -97,3 +102,10 @@ export class SearchInput extends React.Component<SearchInputProps> {
); );
} }
} }
export const SearchInput = withInjectables<Dependencies, SearchInputProps>(NonInjectedSearchInput, {
getProps: (di, props) => ({
...props,
isMac: di.inject(isMacInjectable),
}),
});