From a7c3225c73498f607adfc753a0d695492d31ccca Mon Sep 17 00:00:00 2001 From: Kyrylo Shmidt Date: Mon, 19 May 2025 15:24:44 +0200 Subject: [PATCH] Fix sidebar tab selection --- .../common/RepositorySidebarOverlay/index.tsx | 35 +++++++++---------- .../InsightHeader/InsightIcon/index.tsx | 2 +- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/components/Admin/common/RepositorySidebarOverlay/index.tsx b/src/components/Admin/common/RepositorySidebarOverlay/index.tsx index 35a458236..da4f21a43 100644 --- a/src/components/Admin/common/RepositorySidebarOverlay/index.tsx +++ b/src/components/Admin/common/RepositorySidebarOverlay/index.tsx @@ -7,6 +7,7 @@ import History, { type HistoryEntry, type HistoryEntryLocation } from "../../../../history/History"; +import { usePrevious } from "../../../../hooks/usePrevious"; import { digmaApi, useGetSpanInfoQuery @@ -70,18 +71,10 @@ export const RepositorySidebarOverlay = ({ ); const { resetInsights, resetAssets, resetGlobalErrors } = useStore.getState(); const dispatch = useAdminDispatch(); - const [history] = useState( - () => - new History([ - { - location: window.location, - state: { - spanCodeObjectId: currentSpanCodeObjectId, - tabLocation: currentTabLocation - } - } - ]) + const [history, setHistory] = useState( + () => new History([]) ); + const previousIsSidebarOpen = usePrevious(isSidebarOpen); const { data: spanInfo } = useGetSpanInfoQuery( { spanCodeObjectId: currentSpanCodeObjectId ?? "" }, @@ -172,17 +165,21 @@ export const RepositorySidebarOverlay = ({ resetInsights(); resetAssets(); resetGlobalErrors(); - history.clear(); - setCurrentTabLocation(initialTabLocation); setCurrentSpanCodeObjectId(undefined); + setCurrentTabLocation(initialTabLocation); onSidebarClose(); + }, [dispatch, onSidebarClose, resetAssets, resetGlobalErrors, resetInsights]); + + // Reset history on sidebar open + useEffect(() => { + if (!previousIsSidebarOpen && isSidebarOpen) { + setHistory(new History([])); + } }, [ - dispatch, - onSidebarClose, - resetAssets, - resetGlobalErrors, - resetInsights, - history + previousIsSidebarOpen, + isSidebarOpen, + currentSpanCodeObjectId, + currentTabLocation ]); useEffect(() => { diff --git a/src/components/Insights/InsightsCatalog/InsightsPage/InsightCardRenderer/insightCards/common/InsightCard/InsightHeader/InsightIcon/index.tsx b/src/components/Insights/InsightsCatalog/InsightsPage/InsightCardRenderer/insightCards/common/InsightCard/InsightHeader/InsightIcon/index.tsx index c3ac38630..871f66f95 100644 --- a/src/components/Insights/InsightsCatalog/InsightsPage/InsightCardRenderer/insightCards/common/InsightCard/InsightHeader/InsightIcon/index.tsx +++ b/src/components/Insights/InsightsCatalog/InsightsPage/InsightCardRenderer/insightCards/common/InsightCard/InsightHeader/InsightIcon/index.tsx @@ -27,7 +27,7 @@ export const InsightIcon = ({ return ( } - titlePlacement={"bottom"} + titlePlacement={"bottom-start"} type={tagType} content={