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:
parent
257582df76
commit
e36f3d2d70
@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import { createObservableHistory } from "mobx-observable-history";
|
import { createObservableHistory } from "mobx-observable-history";
|
||||||
import loggerInjectable from "../../common/logger.injectable";
|
|
||||||
import { searchParamsOptions } from "./search-params";
|
import { searchParamsOptions } from "./search-params";
|
||||||
import historyInjectable from "./history.injectable";
|
import historyInjectable from "./history.injectable";
|
||||||
|
|
||||||
@ -13,18 +12,10 @@ const observableHistoryInjectable = getInjectable({
|
|||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const history = di.inject(historyInjectable);
|
const history = di.inject(historyInjectable);
|
||||||
const logger = di.inject(loggerInjectable);
|
|
||||||
const navigation = createObservableHistory(history, {
|
const navigation = createObservableHistory(history, {
|
||||||
searchParams: searchParamsOptions,
|
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;
|
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;
|
||||||
Loading…
Reference in New Issue
Block a user