mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix finding the current route component
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
a7121d2cbe
commit
9ac417bce5
@ -25,6 +25,10 @@
|
|||||||
grid-area: menu;
|
grid-area: menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
#lens-views {
|
#lens-views {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0;
|
left: 0;
|
||||||
|
|||||||
@ -21,12 +21,14 @@ import { buildURL } from "../../../common/utils/buildUrl";
|
|||||||
import type { StorageLayer } from "../../utils";
|
import type { StorageLayer } from "../../utils";
|
||||||
import type { WatchForGeneralEntityNavigation } from "../../api/helpers/watch-for-general-entity-navigation.injectable";
|
import type { WatchForGeneralEntityNavigation } from "../../api/helpers/watch-for-general-entity-navigation.injectable";
|
||||||
import watchForGeneralEntityNavigationInjectable from "../../api/helpers/watch-for-general-entity-navigation.injectable";
|
import watchForGeneralEntityNavigationInjectable from "../../api/helpers/watch-for-general-entity-navigation.injectable";
|
||||||
|
import currentPathInjectable from "../../routes/current-path.injectable";
|
||||||
|
|
||||||
interface Dependencies {
|
interface Dependencies {
|
||||||
catalogPreviousActiveTabStorage: StorageLayer<string | null>;
|
catalogPreviousActiveTabStorage: StorageLayer<string | null>;
|
||||||
currentRouteComponent: IComputedValue<React.ElementType | undefined>;
|
currentRouteComponent: IComputedValue<React.ElementType | undefined>;
|
||||||
welcomeUrl: string;
|
welcomeUrl: string;
|
||||||
watchForGeneralEntityNavigation: WatchForGeneralEntityNavigation;
|
watchForGeneralEntityNavigation: WatchForGeneralEntityNavigation;
|
||||||
|
currentPath: IComputedValue<string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
@ -37,19 +39,40 @@ class NonInjectedClusterManager extends React.Component<Dependencies> {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
renderMainComponent() {
|
||||||
const Component = this.props.currentRouteComponent.get();
|
const Component = this.props.currentRouteComponent.get();
|
||||||
|
|
||||||
if (!Component) {
|
if (Component) {
|
||||||
|
return <Component />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentPath = this.props.currentPath.get();
|
||||||
|
|
||||||
|
if (currentPath !== this.props.welcomeUrl) {
|
||||||
return <Redirect exact to={this.props.welcomeUrl} />;
|
return <Redirect exact to={this.props.welcomeUrl} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="error">
|
||||||
|
<h2>ERROR!!</h2>
|
||||||
|
<p>
|
||||||
|
No matching route for the current path:
|
||||||
|
{" "}
|
||||||
|
<code>{currentPath}</code>
|
||||||
|
{" "}
|
||||||
|
which is the welcomeUrl. This is a bug.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="ClusterManager">
|
<div className="ClusterManager">
|
||||||
<TopBar />
|
<TopBar />
|
||||||
<main>
|
<main>
|
||||||
<div id="lens-views" />
|
<div id="lens-views" />
|
||||||
<Component />
|
{this.renderMainComponent()}
|
||||||
</main>
|
</main>
|
||||||
<HotbarMenu />
|
<HotbarMenu />
|
||||||
<StatusBar />
|
<StatusBar />
|
||||||
@ -65,5 +88,6 @@ export const ClusterManager = withInjectables<Dependencies>(NonInjectedClusterMa
|
|||||||
currentRouteComponent: di.inject(currentRouteComponentInjectable),
|
currentRouteComponent: di.inject(currentRouteComponentInjectable),
|
||||||
welcomeUrl: buildURL(di.inject(welcomeRouteInjectable).path),
|
welcomeUrl: buildURL(di.inject(welcomeRouteInjectable).path),
|
||||||
watchForGeneralEntityNavigation: di.inject(watchForGeneralEntityNavigationInjectable),
|
watchForGeneralEntityNavigation: di.inject(watchForGeneralEntityNavigationInjectable),
|
||||||
|
currentPath: di.inject(currentPathInjectable),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx";
|
import { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx";
|
||||||
import { matches } from "lodash/fp";
|
|
||||||
import { computed } from "mobx";
|
import { computed } from "mobx";
|
||||||
import currentRouteInjectable from "./current-route.injectable";
|
import currentRouteInjectable from "./current-route.injectable";
|
||||||
import { routeSpecificComponentInjectionToken } from "./route-specific-component-injection-token";
|
import { routeSpecificComponentInjectionToken } from "./route-specific-component-injection-token";
|
||||||
@ -24,11 +23,13 @@ const currentRouteComponentInjectable = getInjectable({
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const routeSpecificComponent = routeComponents
|
return routeComponents
|
||||||
.get()
|
.get()
|
||||||
.find(matches({ route: currentRoute }));
|
.find(({ route }) => (
|
||||||
|
route.path === currentRoute.path
|
||||||
return routeSpecificComponent?.Component;
|
&& route.clusterFrame === currentRoute.clusterFrame
|
||||||
|
))
|
||||||
|
?.Component;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user