Navigation logging injectable (#6797)

Move navigation logging to `setupLoggingForNavigationInjectable` to prevent cycle of injectables from occurring. Wasn't eventually needed for #6795 but still an improvement.

Credit for the implementation goes to @Nokel81 , thanks!

Signed-off-by: Sami Tiilikainen <97873007+samitiilikainen@users.noreply.github.com>

Signed-off-by: Sami Tiilikainen <97873007+samitiilikainen@users.noreply.github.com>
This commit is contained in:
Sami Tiilikainen authored and GitHub committed 2022-12-20 08:38:20 -05:00
1 parent 257582df76
commit e36f3d2d70
2 files changed
+33 -9

No files matched your search

@@ -4,7 +4,6 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import { createObservableHistory } from "mobx-observable-history";
import loggerInjectable from "../../common/logger.injectable";
import { searchParamsOptions } from "./search-params";
import historyInjectable from "./history.injectable";
@@ -13,18 +12,10 @@ const observableHistoryInjectable = getInjectable({
instantiate: (di) => {
const history = di.inject(historyInjectable);
const logger = di.inject(loggerInjectable);
const navigation = createObservableHistory(history, {
searchParams: searchParamsOptions,
});
navigation.listen((location, action) => {
const isClusterView = !process.isMainFrame;
const domain = global.location.href;
logger.debug(`[NAVIGATION]: ${action}-ing. Current is now:`, { isClusterView, domain, location });
});
return navigation;
},
});
@@ -0,0 +1,33 @@
/**
* 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 loggerInjectable from "../../common/logger.injectable";
import { beforeFrameStartsInjectionToken } from "../before-frame-starts/tokens";
import observableHistoryInjectable from "./observable-history.injectable";
const setupLoggingForNavigationInjectable = getInjectable({
id: "setup-logging-for-navigation",
instantiate: (di) => ({
id: "setup-logging-for-navigation",
run: () => {
const logger = di.inject(loggerInjectable);
const observableHistory = di.inject(observableHistoryInjectable);
observableHistory.listen((location, action) => {
const isClusterView = !process.isMainFrame;
const domain = global.location.href;
logger.debug(`[NAVIGATION]: ${action}-ing. Current is now:`, {
isClusterView,
domain,
location,
});
});
},
}),
injectionToken: beforeFrameStartsInjectionToken,
});
export default setupLoggingForNavigationInjectable;