mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Reorganize stuff to prevent circular dependencies
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
d0ed4e46b1
commit
f7f973da45
@ -16,8 +16,8 @@ import { getApplicationBuilder } from "../renderer/components/test-utils/get-app
|
|||||||
import currentRouteInjectable from "../renderer/routes/current-route.injectable";
|
import currentRouteInjectable from "../renderer/routes/current-route.injectable";
|
||||||
import currentPathInjectable from "../renderer/routes/current-path.injectable";
|
import currentPathInjectable from "../renderer/routes/current-path.injectable";
|
||||||
import queryParametersInjectable from "../renderer/routes/query-parameters.injectable";
|
import queryParametersInjectable from "../renderer/routes/query-parameters.injectable";
|
||||||
import currentPathParametersInjectable from "../renderer/routes/current-path-parameters.injectable";
|
|
||||||
import { navigateToRouteInjectionToken } from "../common/front-end-routing/navigate-to-route-injection-token";
|
import { navigateToRouteInjectionToken } from "../common/front-end-routing/navigate-to-route-injection-token";
|
||||||
|
import routePathParametersInjectable from "../renderer/routes/route-path-parameters.injectable";
|
||||||
|
|
||||||
describe("navigating between routes", () => {
|
describe("navigating between routes", () => {
|
||||||
let rendererDi: DiContainer;
|
let rendererDi: DiContainer;
|
||||||
@ -73,7 +73,7 @@ describe("navigating between routes", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("does not have path parameters", () => {
|
it("does not have path parameters", () => {
|
||||||
const pathParameters = rendererDi.inject(currentPathParametersInjectable);
|
const pathParameters = rendererDi.inject(routePathParametersInjectable, route);
|
||||||
|
|
||||||
expect(pathParameters.get()).toEqual({});
|
expect(pathParameters.get()).toEqual({});
|
||||||
});
|
});
|
||||||
@ -101,7 +101,6 @@ describe("navigating between routes", () => {
|
|||||||
|
|
||||||
describe("given route with optional path parameters", () => {
|
describe("given route with optional path parameters", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
|
||||||
applicationBuilder.beforeApplicationStart(({ rendererDi }) => {
|
applicationBuilder.beforeApplicationStart(({ rendererDi }) => {
|
||||||
rendererDi.register(routeWithOptionalPathParametersInjectable);
|
rendererDi.register(routeWithOptionalPathParametersInjectable);
|
||||||
rendererDi.register(routeWithOptionalPathParametersComponentInjectable);
|
rendererDi.register(routeWithOptionalPathParametersComponentInjectable);
|
||||||
@ -146,7 +145,7 @@ describe("navigating between routes", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("knows path parameters", () => {
|
it("knows path parameters", () => {
|
||||||
const pathParameters = rendererDi.inject(currentPathParametersInjectable);
|
const pathParameters = rendererDi.inject(routePathParametersInjectable, route);
|
||||||
|
|
||||||
expect(pathParameters.get()).toEqual({
|
expect(pathParameters.get()).toEqual({
|
||||||
someParameter: "some-value",
|
someParameter: "some-value",
|
||||||
@ -179,7 +178,7 @@ describe("navigating between routes", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("knows path parameters", () => {
|
it("knows path parameters", () => {
|
||||||
const pathParameters = rendererDi.inject(currentPathParametersInjectable);
|
const pathParameters = rendererDi.inject(routePathParametersInjectable, route);
|
||||||
|
|
||||||
expect(pathParameters.get()).toEqual({
|
expect(pathParameters.get()).toEqual({
|
||||||
someParameter: undefined,
|
someParameter: undefined,
|
||||||
@ -227,10 +226,11 @@ const routeWithOptionalPathParametersComponentInjectable = getInjectable({
|
|||||||
id: "some-route-component",
|
id: "some-route-component",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const pathParameters = di.inject(currentPathParametersInjectable);
|
const route = di.inject(routeWithOptionalPathParametersInjectable);
|
||||||
|
const pathParameters = di.inject(routePathParametersInjectable, route);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
route: di.inject(routeWithOptionalPathParametersInjectable),
|
route,
|
||||||
|
|
||||||
Component: observer(() => (
|
Component: observer(() => (
|
||||||
<pre>{JSON.stringify(pathParameters.get(), null, 2)}</pre>
|
<pre>{JSON.stringify(pathParameters.get(), null, 2)}</pre>
|
||||||
|
|||||||
@ -8,10 +8,10 @@ import crdListRouteInjectable from "../../../common/front-end-routing/routes/clu
|
|||||||
import customResourceDefinitionsInjectable from "./custom-resources.injectable";
|
import customResourceDefinitionsInjectable from "./custom-resources.injectable";
|
||||||
import { groupBy, matches, noop, some, toPairs } from "lodash/fp";
|
import { groupBy, matches, noop, some, toPairs } from "lodash/fp";
|
||||||
import customResourcesRouteInjectable from "../../../common/front-end-routing/routes/cluster/custom-resources/custom-resources/custom-resources-route.injectable";
|
import customResourcesRouteInjectable from "../../../common/front-end-routing/routes/cluster/custom-resources/custom-resources/custom-resources-route.injectable";
|
||||||
import currentPathParametersInjectable from "../../routes/current-path-parameters.injectable";
|
|
||||||
import type { SidebarItemRegistration } from "../layout/sidebar-items.injectable";
|
import type { SidebarItemRegistration } from "../layout/sidebar-items.injectable";
|
||||||
import routeIsActiveInjectable from "../../routes/route-is-active.injectable";
|
import routeIsActiveInjectable from "../../routes/route-is-active.injectable";
|
||||||
import navigateToCustomResourcesInjectable from "../../../common/front-end-routing/routes/cluster/custom-resources/custom-resources/navigate-to-custom-resources.injectable";
|
import navigateToCustomResourcesInjectable from "../../../common/front-end-routing/routes/cluster/custom-resources/custom-resources/navigate-to-custom-resources.injectable";
|
||||||
|
import routePathParametersInjectable from "../../routes/route-path-parameters.injectable";
|
||||||
|
|
||||||
const sidebarItemsForDefinitionGroupsInjectable = getInjectable({
|
const sidebarItemsForDefinitionGroupsInjectable = getInjectable({
|
||||||
id: "sidebar-items-for-definition-groups",
|
id: "sidebar-items-for-definition-groups",
|
||||||
@ -24,7 +24,7 @@ const sidebarItemsForDefinitionGroupsInjectable = getInjectable({
|
|||||||
const crdRoute = di.inject(customResourcesRouteInjectable);
|
const crdRoute = di.inject(customResourcesRouteInjectable);
|
||||||
const crdRouteIsActive = di.inject(routeIsActiveInjectable, crdRoute);
|
const crdRouteIsActive = di.inject(routeIsActiveInjectable, crdRoute);
|
||||||
const crdListRoute = di.inject(crdListRouteInjectable);
|
const crdListRoute = di.inject(crdListRouteInjectable);
|
||||||
const pathParameters = di.inject(currentPathParametersInjectable);
|
const pathParameters = di.inject(routePathParametersInjectable, crdRoute);
|
||||||
const navigateToCustomResources = di.inject(navigateToCustomResourcesInjectable);
|
const navigateToCustomResources = di.inject(navigateToCustomResourcesInjectable);
|
||||||
|
|
||||||
return computed((): SidebarItemRegistration[] => {
|
return computed((): SidebarItemRegistration[] => {
|
||||||
|
|||||||
@ -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 { computed } from "mobx";
|
|
||||||
import matchingRouteInjectable from "./matching-route.injectable";
|
|
||||||
|
|
||||||
const currentPathParametersInjectable = getInjectable({
|
|
||||||
id: "current-path-parameters",
|
|
||||||
|
|
||||||
instantiate: (di) => {
|
|
||||||
const matchingRoute = di.inject(matchingRouteInjectable);
|
|
||||||
|
|
||||||
return computed((): Record<string, string> => {
|
|
||||||
const match = matchingRoute.get();
|
|
||||||
|
|
||||||
return match ? match.pathParameters: {};
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default currentPathParametersInjectable;
|
|
||||||
@ -4,16 +4,23 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||||
import { computed } from "mobx";
|
import { computed } from "mobx";
|
||||||
import currentRouteInjectable from "./current-route.injectable";
|
|
||||||
import type { Route } from "../../common/front-end-routing/front-end-route-injection-token";
|
import type { Route } from "../../common/front-end-routing/front-end-route-injection-token";
|
||||||
|
import currentPathInjectable from "./current-path.injectable";
|
||||||
|
import { matchPath } from "react-router-dom";
|
||||||
|
|
||||||
const routeIsActiveInjectable = getInjectable({
|
const routeIsActiveInjectable = getInjectable({
|
||||||
id: "route-is-active",
|
id: "route-is-active",
|
||||||
|
|
||||||
instantiate: (di, route: Route<unknown>) => {
|
instantiate: (di, route: Route<unknown>) => {
|
||||||
const currentRoute = di.inject(currentRouteInjectable);
|
const currentPath = di.inject(currentPathInjectable);
|
||||||
|
|
||||||
return computed(() => currentRoute.get() === route);
|
return computed(
|
||||||
|
() =>
|
||||||
|
!!matchPath(currentPath.get(), {
|
||||||
|
path: route.path,
|
||||||
|
exact: true,
|
||||||
|
}),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
lifecycle: lifecycleEnum.keyedSingleton({
|
lifecycle: lifecycleEnum.keyedSingleton({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user