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

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 2022-12-20 15:38:20 +02:00 committed by GitHub
parent 257582df76
commit e36f3d2d70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 9 deletions

View File

@ -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;
},
});

View File

@ -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;