1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/routes/current-route-component.injectable.ts
Jim Ehrismann a2d52fa6b8
Made welcome page configurable (#6232)
Co-authored-by: Sebastian Malton <sebastian@malton.name>
2022-09-14 09:07:44 -04:00

38 lines
1.2 KiB
TypeScript

/**
* 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 { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx";
import { computed } from "mobx";
import currentRouteInjectable from "./current-route.injectable";
import { routeSpecificComponentInjectionToken } from "./route-specific-component-injection-token";
const currentRouteComponentInjectable = getInjectable({
id: "current-route-component",
instantiate: (di) => {
const route = di.inject(currentRouteInjectable);
const computedInjectMany = di.inject(computedInjectManyInjectable);
const routeComponents = computedInjectMany(routeSpecificComponentInjectionToken);
return computed(() => {
const currentRoute = route.get();
if (!currentRoute) {
return undefined;
}
return routeComponents
.get()
.find(({ route }) => (
route.path === currentRoute.path
&& route.clusterFrame === currentRoute.clusterFrame
))
?.Component;
});
},
});
export default currentRouteComponentInjectable;