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

chore: Extract an injectionToken

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
Iku-turso 2023-04-25 15:52:35 +03:00 committed by Sebastian Malton
parent 0dae1594ba
commit db9a3675e1
7 changed files with 19 additions and 14 deletions

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 "@k8slens/routing";
import { historyInjectionToken } from "@k8slens/routing";
import type { History } from "history";
import type { StorageLayer } from "../../utils/storage-helper";
@ -251,7 +251,7 @@ class NonInjectedDrawer extends React.Component<DrawerProps & Dependencies & typ
export const Drawer = withInjectables<Dependencies, DrawerProps>(NonInjectedDrawer as React.ElementType<DrawerProps & Dependencies>, {
getProps: (di, props) => ({
...props,
history: di.inject(historyInjectable),
history: di.inject(historyInjectionToken),
drawerStorage: di.inject(drawerStorageInjectable),
}),
});

View File

@ -24,7 +24,6 @@ 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 "@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";
@ -71,6 +70,7 @@ import { applicationFeature, startApplicationInjectionToken } from "@k8slens/app
import { testUsingFakeTime } from "../../../test-utils/use-fake-time";
import { sendMessageToChannelInjectionToken } from "@k8slens/messaging";
import { getMessageBridgeFake } from "@k8slens/messaging-fake-bridge";
import { historyInjectionToken } from "@k8slens/routing";
type MainDiCallback = (container: { mainDi: DiContainer }) => void | Promise<void>;
type WindowDiCallback = (container: { windowDi: DiContainer }) => void | Promise<void>;
@ -292,7 +292,7 @@ export const getApplicationBuilder = () => {
await callback({ windowDi });
}
const history = windowDi.inject(historyInjectable);
const history = windowDi.inject(historyInjectionToken);
const render = renderFor(windowDi);

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 "@k8slens/routing";
import { historyInjectionToken } from "@k8slens/routing";
import { computed } from "mobx";
import { Cluster } from "../../../common/cluster/cluster";
import subscribeStoresInjectable from "../../kube-watch-api/subscribe-stores.injectable";
@ -34,7 +34,7 @@ describe("<ClusterFrame />", () => {
di = getDiForUnitTesting();
render = () => testingLibraryRender((
<DiContextProvider value={{ di }}>
<Router history={di.inject(historyInjectable)}>
<Router history={di.inject(historyInjectionToken)}>
{DefaultProps(ClusterFrame)}
</Router>
</DiContextProvider>

View File

@ -4,7 +4,7 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import { Router } from "react-router";
import { historyInjectable } from "@k8slens/routing";
import { historyInjectionToken } from "@k8slens/routing";
import React from "react";
import {
@ -15,7 +15,7 @@ const routingReactApplicationHocInjectable = getInjectable({
id: "routing-react-application-hoc",
instantiate: (di) => {
const history = di.inject(historyInjectable);
const history = di.inject(historyInjectionToken);
return ({ children }) =>
(

View File

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

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
export { historyInjectable } from "./src/history.injectable";
export { historyInjectionToken } from "./src/history.injectable";
export { observableHistoryInjectable } from "./src/observable-history.injectable";
export { searchParamsOptions } from "./src/search-params";
export { routingFeature } from "./src/feature";

View File

@ -2,11 +2,16 @@
* 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 { getInjectable, getInjectionToken } from "@ogre-tools/injectable";
import type { History } from "history";
import { createBrowserHistory } from "history";
export const historyInjectionToken = getInjectionToken<History>({
id: "history-injection-token",
});
export const historyInjectable = getInjectable({
id: "history",
instantiate: (): History => createBrowserHistory(),
instantiate: () => createBrowserHistory(),
injectionToken: historyInjectionToken,
});