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

chore: gather injectables import

Signed-off-by: Gabriel <gaccettola@mirantis.com>
This commit is contained in:
Gabriel 2023-04-24 19:30:12 +02:00
parent 5381c90232
commit 116f1e796a
35 changed files with 32 additions and 225 deletions

View File

@ -12,13 +12,13 @@ import { frontEndRouteInjectionToken } from "../../common/front-end-routing/fron
import { computed, runInAction } from "mobx";
import React from "react";
import { routeSpecificComponentInjectionToken } from "../../renderer/routes/route-specific-component-injection-token";
import observableHistoryInjectable from "../../renderer/navigation/observable-history.injectable";
import observableHistoryInjectable from "@k8slens/routing";
import { createMemoryHistory } from "history";
import { createObservableHistory } from "mobx-observable-history";
import navigateToFrontPageInjectable from "../../common/front-end-routing/navigate-to-front-page.injectable";
import { navigateToRouteInjectionToken } from "../../common/front-end-routing/navigate-to-route-injection-token";
import { preferenceItemInjectionToken } from "./renderer/preference-items/preference-item-injection-token";
import { searchParamsOptions } from "../../renderer/navigation/search-params";
import { searchParamsOptions } from "@k8slens/routing";
describe("preferences - closing-preferences", () => {
let builder: ApplicationBuilder;

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import observableHistoryInjectable from "../../../../renderer/navigation/observable-history.injectable";
import observableHistoryInjectable from "@k8slens/routing";
import navigateToFrontPageInjectable from "../../../../common/front-end-routing/navigate-to-front-page.injectable";
const closePreferencesInjectable = getInjectable({

View File

@ -7,7 +7,7 @@ import { reaction, when } from "mobx";
import type { GeneralEntity } from "../../../common/catalog-entities";
import generalCategoryInjectable from "../../../common/catalog/categories/general.injectable";
import isActiveRouteInjectable from "../../navigation/is-route-active.injectable";
import observableHistoryInjectable from "../../navigation/observable-history.injectable";
import observableHistoryInjectable from "@k8slens/routing";
import type { Disposer } from "@k8slens/utilities";
import { disposer } from "@k8slens/utilities";
import catalogEntityRegistryInjectable from "../catalog/entity/registry.injectable";

View File

@ -6,7 +6,7 @@ import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
import { action } from "mobx";
import { byOrderNumber } from "../../../common/utils/composable-responsibilities/orderable/orderable";
import type { CatalogEntity } from "../../api/catalog-entity";
import observableHistoryInjectable from "../../navigation/observable-history.injectable";
import observableHistoryInjectable from "@k8slens/routing";
import type { RegisteredEntitySetting } from "./extension-registrator.injectable";
import catalogEntitySettingItemsInjectable from "./settings.injectable";

View File

@ -7,7 +7,7 @@ import { getInjectable } from "@ogre-tools/injectable";
import { rootFrameChildComponentInjectionToken } from "../../frames/root-frame/root-frame-child-component-injection-token";
import { ClusterManager } from "./cluster-manager";
import { computed } from "mobx";
import { ErrorBoundary } from "../error-boundary";
import { ErrorBoundary } from "@k8slens/error-boundary";
const clusterManagerRootFrameChildComponentInjectable = getInjectable({
id: "cluster-manager-root-frame-child-component",

View File

@ -13,7 +13,7 @@ import { Animate } from "../animate";
import { cssNames, noop, stopPropagation } from "@k8slens/utilities";
import type { ObservableHistory } from "mobx-observable-history";
import { withInjectables } from "@ogre-tools/injectable-react";
import observableHistoryInjectable from "../../navigation/observable-history.injectable";
import observableHistoryInjectable from "@k8slens/routing";
import requestAnimationFrameInjectable from "../animate/request-animation-frame.injectable";
// todo: refactor + handle animation-end in props.onClose()?

View File

@ -24,7 +24,7 @@ import { withInjectables } from "@ogre-tools/injectable-react";
import createResourceTabInjectable from "./create-resource/create-resource-tab.injectable";
import dockStoreInjectable from "./dock/store.injectable";
import createTerminalTabInjectable from "./terminal/create-terminal-tab.injectable";
import { ErrorBoundary } from "../error-boundary";
import { ErrorBoundary } from "@k8slens/error-boundary";
export interface DockProps {
className?: string;

View File

@ -16,7 +16,7 @@ import { Animate } from "../animate";
import { ResizeDirection, ResizeGrowthDirection, ResizeSide, ResizingAnchor } from "../resizing-anchor";
import drawerStorageInjectable, { defaultDrawerWidth } from "./drawer-storage/drawer-storage.injectable";
import { withInjectables } from "@ogre-tools/injectable-react";
import historyInjectable from "../../navigation/history.injectable";
import historyInjectable from "@k8slens/routing";
import type { History } from "history";
import type { StorageLayer } from "../../utils/storage-helper";

View File

@ -1,34 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
.ErrorBoundary {
--flex-gap: #{$padding * 2};
padding: var(--flex-gap);
word-break: break-all;
.wrapper {
display: grid;
grid-template-columns: minmax(300px, 1fr) minmax(300px, 1fr);
column-gap: 12px;
row-gap: 12px;
@media screen and (max-width: 900px) {
grid-template-columns: auto;
}
}
code {
max-height: none;
border: 5px solid var(--borderFaintColor);
white-space: pre-wrap;
background: var(--contentColor);
color: var(--textColorSecondary);
}
a {
color: var(--colorInfo);
}
}

View File

@ -1,103 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import "./error-boundary.scss";
import type { ErrorInfo } from "react";
import React from "react";
import { observer } from "mobx-react";
import { Button } from "@k8slens/button";
import { issuesTrackerUrl, forumsUrl } from "../../../common/vars";
import type { SingleOrMany } from "@k8slens/utilities";
import type { ObservableHistory } from "mobx-observable-history";
import { withInjectables } from "@ogre-tools/injectable-react";
import observableHistoryInjectable from "../../navigation/observable-history.injectable";
export interface ErrorBoundaryProps {
children?: SingleOrMany<React.ReactNode>;
}
interface State {
error?: Error;
errorInfo?: ErrorInfo;
}
interface Dependencies {
observableHistory: ObservableHistory<unknown>;
}
@observer
class NonInjectedErrorBoundary extends React.Component<ErrorBoundaryProps & Dependencies, State> {
public state: State = {};
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
this.setState({ error, errorInfo });
}
back = () => {
this.setState({ error: undefined, errorInfo: undefined });
this.props.observableHistory.goBack();
};
render() {
const { error, errorInfo } = this.state;
if (error) {
return (
<div className="ErrorBoundary flex column gaps">
<h5>
{"App crash at "}
<span className="contrast">{location.pathname}</span>
</h5>
<p>
{"To help us improve the product please report bugs on"}
<a
href={forumsUrl}
rel="noreferrer"
target="_blank"
>
Lens Forums
</a>
{" or on our"}
<a
href={issuesTrackerUrl}
rel="noreferrer"
target="_blank"
>
Github
</a>
{" issues tracker."}
</p>
<div className="wrapper">
<code className="block">
<p className="contrast">Component stack:</p>
{errorInfo?.componentStack}
</code>
<code className="block">
<p className="contrast">Error stack:</p>
{error.stack}
</code>
</div>
<Button
className="box self-flex-start"
primary
label="Back"
onClick={this.back}
/>
</div>
);
}
return this.props.children;
}
}
export const ErrorBoundary = withInjectables<Dependencies, ErrorBoundaryProps>(NonInjectedErrorBoundary, {
getProps: (di, props) => ({
...props,
observableHistory: di.inject(observableHistoryInjectable),
}),
});

View File

@ -1,6 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
export * from "./error-boundary";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import observableHistoryInjectable from "../../navigation/observable-history.injectable";
import observableHistoryInjectable from "@k8slens/routing";
import kubeDetailsUrlParamInjectable from "./kube-details-url.injectable";
import kubeSelectedUrlParamInjectable from "./kube-selected-url.injectable";

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import observableHistoryInjectable from "../../navigation/observable-history.injectable";
import observableHistoryInjectable from "@k8slens/routing";
import getDetailsUrlInjectable from "./get-details-url.injectable";
/**

View File

@ -8,7 +8,7 @@ import styles from "./main-layout.module.scss";
import React from "react";
import { observer } from "mobx-react";
import { cssNames } from "@k8slens/utilities";
import { ErrorBoundary } from "../error-boundary";
import { ErrorBoundary } from "@k8slens/error-boundary";
import { ResizeDirection, ResizeGrowthDirection, ResizeSide, ResizingAnchor } from "../resizing-anchor";
import { withInjectables } from "@ogre-tools/injectable-react";
import type { SidebarStorageState } from "./sidebar-storage/sidebar-storage.injectable";

View File

@ -12,7 +12,7 @@ import { cssNames } from "@k8slens/utilities";
import { CloseButton } from "./close-button";
import { getLegacyGlobalDiForExtensionApi } from "../../../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
import navigateToCatalogInjectable from "../../../common/front-end-routing/routes/catalog/navigate-to-catalog.injectable";
import observableHistoryInjectable from "../../navigation/observable-history.injectable";
import observableHistoryInjectable from "@k8slens/routing";
export interface SettingLayoutProps extends React.DOMAttributes<any> {
className?: IClassName;

View File

@ -9,7 +9,7 @@ import React from "react";
import { observer } from "mobx-react";
import { cssNames } from "@k8slens/utilities";
import { Tab, Tabs } from "../tabs";
import { ErrorBoundary } from "../error-boundary";
import { ErrorBoundary } from "@k8slens/error-boundary";
import type { HierarchicalSidebarItem } from "./sidebar-items.injectable";
export interface TabLayoutProps {

View File

@ -12,10 +12,10 @@ import { observer } from "mobx-react";
import type { IClassName } from "@k8slens/utilities";
import { cssNames } from "@k8slens/utilities";
import { Tab, Tabs } from "../tabs";
import { ErrorBoundary } from "../error-boundary";
import { ErrorBoundary } from "@k8slens/error-boundary";
import type { ObservableHistory } from "mobx-observable-history";
import { withInjectables } from "@ogre-tools/injectable-react";
import observableHistoryInjectable from "../../navigation/observable-history.injectable";
import observableHistoryInjectable from "@k8slens/routing";
import type { Navigate } from "../../navigation/navigate.injectable";
import navigateInjectable from "../../navigation/navigate.injectable";

View File

@ -24,7 +24,7 @@ import navigateToHelmChartsInjectable from "../../../common/front-end-routing/ro
import hostedClusterInjectable from "../../cluster-frame-context/hosted-cluster.injectable";
import { Cluster } from "../../../common/cluster/cluster";
import type { NamespaceStore } from "../+namespaces/store";
import historyInjectable from "../../navigation/history.injectable";
import historyInjectable from "@k8slens/routing";
import type { MinimalTrayMenuItem } from "../../../main/tray/electron-tray/electron-tray.injectable";
import electronTrayInjectable from "../../../main/tray/electron-tray/electron-tray.injectable";
import { getDiForUnitTesting as getRendererDi } from "../../getDiForUnitTesting";

View File

@ -12,7 +12,7 @@ import { DiContextProvider } from "@ogre-tools/injectable-react";
import { Router } from "react-router";
import { DefaultProps } from "../../mui-base-theme";
import { ClusterFrame } from "./cluster-frame";
import historyInjectable from "../../navigation/history.injectable";
import historyInjectable from "@k8slens/routing";
import { computed } from "mobx";
import { Cluster } from "../../../common/cluster/cluster";
import subscribeStoresInjectable from "../../kube-watch-api/subscribe-stores.injectable";

View File

@ -4,7 +4,7 @@
*/
import React, { useEffect } from "react";
import { Observer, observer } from "mobx-react";
import { ErrorBoundary } from "../../components/error-boundary";
import { ErrorBoundary } from "@k8slens/error-boundary";
import type { NamespaceStore } from "../../components/+namespaces/store";
import { withInjectables } from "@ogre-tools/injectable-react";
import namespaceStoreInjectable from "../../components/+namespaces/store.injectable";

View File

@ -4,7 +4,7 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import { Router } from "react-router";
import historyInjectable from "../navigation/history.injectable";
import historyInjectable from "@k8slens/routing";
import React from "react";
import {

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import observableHistoryInjectable from "./observable-history.injectable";
import observableHistoryInjectable from "@k8slens/routing";
import type { PageParamDependencies, PageParamInit } from "./page-param";
import { PageParam } from "./page-param";

View File

@ -5,6 +5,6 @@
import { createMemoryHistory } from "history";
import { getGlobalOverride } from "@k8slens/test-utils";
import historyInjectable from "./history.injectable";
import historyInjectable from "@k8slens/routing";
export default getGlobalOverride(historyInjectable, () => createMemoryHistory());

View File

@ -1,14 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { createBrowserHistory } from "history";
import type { History } from "history";
const historyInjectable = getInjectable({
id: "history",
instantiate: (): History => createBrowserHistory(),
});
export default historyInjectable;

View File

@ -5,7 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable";
import type { match, RouteProps } from "react-router";
import { matchPath } from "react-router";
import observableHistoryInjectable from "./observable-history.injectable";
import observableHistoryInjectable from "@k8slens/routing";
export type MatchRoute = <Params extends { [K in keyof Params]?: string }>(route: string | string[] | RouteProps) => match<Params> | null;

View File

@ -5,7 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable";
import type { LocationDescriptor } from "history";
import { action } from "mobx";
import observableHistoryInjectable from "./observable-history.injectable";
import observableHistoryInjectable from "@k8slens/routing";
import { createPath } from "history";
export type Navigate = (location: LocationDescriptor) => void;

View File

@ -1,23 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import { createObservableHistory } from "mobx-observable-history";
import { searchParamsOptions } from "./search-params";
import historyInjectable from "./history.injectable";
const observableHistoryInjectable = getInjectable({
id: "observable-history",
instantiate: (di) => {
const history = di.inject(historyInjectable);
const navigation = createObservableHistory(history, {
searchParams: searchParamsOptions,
});
return navigation;
},
});
export default observableHistoryInjectable;

View File

@ -1,12 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import type { ObservableSearchParamsOptions } from "mobx-observable-history";
export const searchParamsOptions: ObservableSearchParamsOptions = {
skipEmpty: true, // skip empty params, e.g. "?x=&y2=" will be "?y=2"
joinArrays: false, // join multiple params with same name, e.g. "?x=1&x=2" => "?x=1,2"
joinArraysWith: ",", // param values splitter, applicable only with {joinArrays:true}
};

View File

@ -5,7 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable";
import loggerInjectable from "../../common/logger.injectable";
import { beforeFrameStartsSecondInjectionToken } from "../before-frame-starts/tokens";
import observableHistoryInjectable from "./observable-history.injectable";
import observableHistoryInjectable from "@k8slens/routing";
const setupLoggingForNavigationInjectable = getInjectable({
id: "setup-logging-for-navigation",

View File

@ -6,7 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable";
import { emitWindowLocationChanged } from "../ipc";
import { reaction } from "mobx";
import observableHistoryInjectable from "../navigation/observable-history.injectable";
import observableHistoryInjectable from "@k8slens/routing";
const watchHistoryStateInjectable = getInjectable({
id: "watch-history-state",

View File

@ -4,7 +4,7 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx";
import observableHistoryInjectable from "../navigation/observable-history.injectable";
import observableHistoryInjectable from "@k8slens/routing";
const currentPathInjectable = getInjectable({
id: "current-path",

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import observableHistoryInjectable from "../navigation/observable-history.injectable";
import observableHistoryInjectable from "@k8slens/routing";
import { runInAction } from "mobx";
import type { NavigateToUrl } from "../../common/front-end-routing/navigate-to-url-injection-token";
import { navigateToUrlInjectionToken } from "../../common/front-end-routing/navigate-to-url-injection-token";

View File

@ -5,7 +5,7 @@
import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx";
import { parse as parseQueryString } from "query-string";
import observableHistoryInjectable from "../navigation/observable-history.injectable";
import observableHistoryInjectable from "@k8slens/routing";
const queryParametersInjectable = getInjectable({
id: "query-parameters",

View File

@ -5,6 +5,8 @@
import observableHistoryInjectable from "./src/observable-history.injectable";
export * from "./src/history.injectable";
export * from "./src/observable-history.injectable";
export * from "./src/search-params";
export default observableHistoryInjectable;

View File

@ -3,8 +3,5 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import observableHistoryInjectable from "./routing/observable-history.injectable";
export * from "./error-boundary";
export * from "./routing/observable-history.injectable";
export default observableHistoryInjectable;