From bc6c9c8a250ba5b41e778f790e3ea87b59444b1a Mon Sep 17 00:00:00 2001 From: Kyrylo Shmidt Date: Fri, 13 Jun 2025 02:12:55 +0200 Subject: [PATCH] Fix tab navigation --- .../Insights/InsightsCatalog/styles.ts | 1 + .../Navigation/HistoryNavigation/index.tsx | 31 ++----------------- src/redux/utils/getRememberEnhancer.ts | 22 ++++++------- 3 files changed, 14 insertions(+), 40 deletions(-) diff --git a/src/components/Insights/InsightsCatalog/styles.ts b/src/components/Insights/InsightsCatalog/styles.ts index a7b910bae..5852fb3e5 100644 --- a/src/components/Insights/InsightsCatalog/styles.ts +++ b/src/components/Insights/InsightsCatalog/styles.ts @@ -15,6 +15,7 @@ export const Container = styled.div` padding: 8px 0; gap: 8px; box-sizing: border-box; + overflow: auto; `; export const Footer = styled.div` diff --git a/src/components/Navigation/HistoryNavigation/index.tsx b/src/components/Navigation/HistoryNavigation/index.tsx index bdd59a1bd..d0539015e 100644 --- a/src/components/Navigation/HistoryNavigation/index.tsx +++ b/src/components/Navigation/HistoryNavigation/index.tsx @@ -1,7 +1,4 @@ import { useEffect } from "react"; -import type { Location } from "react-router"; -import { useLocation, useNavigate } from "react-router"; -import { history } from "../../../containers/Main/history"; import type { HistoryEntry } from "../../../history/History"; import { useConfigSelector } from "../../../store/config/useConfigSelector"; import { isBoolean } from "../../../typeGuards/isBoolean"; @@ -12,7 +9,7 @@ import { ScopeChangeEvent } from "../../../types"; import { changeScope } from "../../../utils/actions/changeScope"; import { sendUserActionTrackingEvent } from "../../../utils/actions/sendUserActionTrackingEvent"; import { HistoryNavigationPanel } from "../../common/HistoryNavigationPanel"; -import type { HistoryState, ReactRouterLocationState } from "../../Main/types"; +import type { HistoryState } from "../../Main/types"; import { useBrowserLocationUpdater } from "../../Main/updateBrowserLocationUpdater"; import { useHistory } from "../../Main/useHistory"; import { trackingEvents } from "../tracking"; @@ -35,32 +32,10 @@ const isHistoryEntryWithHistoryState = ( (isHistoryState(obj.state) || isUndefined(obj.state)); export const HistoryNavigation = () => { - const { goBack, goForward, goTo, canGoBack, canGoForward } = useHistory(); - const navigate = useNavigate(); + const { goBack, goForward, canGoBack, canGoForward } = useHistory(); const { environments, environment, scope } = useConfigSelector(); - const location = useLocation() as Location; const updateBrowserLocation = useBrowserLocationUpdater(); - useEffect(() => { - // Initialize history with the current state - if (!location.state?.navigatedWithCustomHistory) { - goTo( - { - pathname: location.pathname, - search: location.search - }, - { - replace: history.historyStack.length > 0, - state: { - environmentId: environment?.id, - spanCodeObjectId: scope?.span?.spanCodeObjectId, - spanDisplayName: scope?.span?.displayName - } - } - ); - } - }, [location, goTo, environment?.id, scope?.span]); - useEffect(() => { const handleHistoryChange = (e: Event) => { if ( @@ -131,7 +106,7 @@ export const HistoryNavigation = () => { return () => { window.removeEventListener("history:navigate", handleHistoryNavigate); }; - }, [navigate]); + }, []); const handleBackButtonClick = () => { sendUserActionTrackingEvent(trackingEvents.BACK_BUTTON_CLICKED); diff --git a/src/redux/utils/getRememberEnhancer.ts b/src/redux/utils/getRememberEnhancer.ts index fbd78db61..d8df5cd48 100644 --- a/src/redux/utils/getRememberEnhancer.ts +++ b/src/redux/utils/getRememberEnhancer.ts @@ -1,4 +1,5 @@ import { rememberEnhancer } from "redux-remember"; +import { isObject } from "../../typeGuards/isObject"; interface RememberEnhancerProps { rememberedKeys: string[]; @@ -6,18 +7,19 @@ interface RememberEnhancerProps { version: number; } -const rehydrateState = >( - rehydratedState: Record, - version: number -) => { +const rehydrateState = (rehydratedState: unknown, version: number) => { + if (!isObject(rehydratedState)) { + return undefined; + } + if (rehydratedState.version !== version) { return undefined; } - return rehydratedState as T; + return rehydratedState; }; -export const getRememberEnhancer = >({ +export const getRememberEnhancer = ({ rememberedKeys, prefix, version @@ -26,12 +28,8 @@ export const getRememberEnhancer = >({ prefix, unserialize: (stateString: string) => { try { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - const rehydratedState = JSON.parse(stateString); - return rehydrateState( - rehydratedState as Record, - version - ); + const rehydratedState = JSON.parse(stateString) as unknown; + return rehydrateState(rehydratedState, version); } catch (error) { // eslint-disable-next-line no-console console.error("Failed to parse persisted state:", error);