@@ -5,18 +5,37 @@ import {
55} from "../../../containers/Admin/hooks" ;
66import { useMount } from "../../../hooks/useMount" ;
77import { useStableSearchParams } from "../../../hooks/useStableSearchParams" ;
8+ import { useGetSpanByIdQuery } from "../../../redux/services/digma" ;
89import { InsightsSortingCriterion } from "../../../redux/services/types" ;
910import {
1011 setSelectedEnvironmentId ,
1112 setSelectedServices
1213} from "../../../redux/slices/issuesReportSlice" ;
1314import { RepositorySidebarOverlay } from "../common/RepositorySidebarOverlay" ;
14- import type { RepositorySidebarQuery } from "../common/RepositorySidebarOverlay/types" ;
15+ import type {
16+ RepositorySidebarQuery ,
17+ TabLocation
18+ } from "../common/RepositorySidebarOverlay/types" ;
1519import { Environments } from "./Environments" ;
1620import { Overview } from "./Overview" ;
1721import { Reports } from "./Reports" ;
1822import * as s from "./styles" ;
1923
24+ const getRepositorySidebarLocation = (
25+ locationParam : string | null
26+ ) : TabLocation | undefined => {
27+ if ( ! locationParam ) {
28+ return undefined ;
29+ }
30+
31+ try {
32+ const parsedLocation = JSON . parse ( locationParam ) as TabLocation ;
33+ return parsedLocation ;
34+ } catch {
35+ return undefined ;
36+ }
37+ } ;
38+
2039export const Home = ( ) => {
2140 const environmentId = useAdminSelector (
2241 ( state ) => state . codeIssuesReport . selectedEnvironmentId
@@ -29,11 +48,26 @@ export const Home = () => {
2948 const [ searchParams , setSearchParams ] = useStableSearchParams ( ) ;
3049 const environmentParam = searchParams . get ( "environment" ) ;
3150 const issuesParam = searchParams . get ( "issues" ) ;
51+ const [ sidebarScope , setSidebarScope ] = useState (
52+ searchParams . get ( "sidebar-scope" ) ?? undefined
53+ ) ;
54+ const [ sidebarLocation , setSidebarLocation ] = useState (
55+ getRepositorySidebarLocation ( searchParams . get ( "sidebar-view" ) )
56+ ) ;
3257 const servicesParam = useMemo (
3358 ( ) => searchParams . getAll ( "services" ) ,
3459 [ searchParams ]
3560 ) ;
3661
62+ const { data : spanInfo } = useGetSpanByIdQuery (
63+ {
64+ id : sidebarScope ?? ""
65+ } ,
66+ {
67+ skip : ! sidebarScope
68+ }
69+ ) ;
70+
3771 const queries : Record < string , RepositorySidebarQuery > = useMemo (
3872 ( ) => ( {
3973 "top-criticality" : {
@@ -64,6 +98,8 @@ export const Home = () => {
6498
6599 const handleRepositorySidebarClose = ( ) => {
66100 setIssuesQuery ( undefined ) ;
101+ setSidebarScope ( undefined ) ;
102+ setSidebarLocation ( undefined ) ;
67103 } ;
68104
69105 // TODO: replace with useEffect
@@ -112,7 +148,48 @@ export const Home = () => {
112148 } ) ;
113149 } , [ setSearchParams , issuesQuery ] ) ;
114150
115- const repositorySidebarQuery = issuesQuery ? queries [ issuesQuery ] : undefined ;
151+ useEffect ( ( ) => {
152+ setSearchParams ( ( params ) => {
153+ if ( sidebarScope ) {
154+ params . set ( "sidebar-scope" , sidebarScope ) ;
155+ } else {
156+ params . delete ( "sidebar-scope" ) ;
157+ }
158+ return params ;
159+ } ) ;
160+ } , [ setSearchParams , sidebarScope ] ) ;
161+
162+ useEffect ( ( ) => {
163+ setSearchParams ( ( params ) => {
164+ if ( sidebarLocation ) {
165+ params . set ( "sidebar-view" , JSON . stringify ( sidebarLocation ) ) ;
166+ } else {
167+ params . delete ( "sidebar-view" ) ;
168+ }
169+ return params ;
170+ } ) ;
171+ } , [ setSearchParams , sidebarLocation ] ) ;
172+
173+ const repositorySidebarQuery : RepositorySidebarQuery | undefined =
174+ sidebarScope && spanInfo
175+ ? {
176+ query : {
177+ environment : environmentId ?? undefined ,
178+ scopedSpanCodeObjectId : spanInfo ?. spanCodeObjectId
179+ }
180+ }
181+ : sidebarLocation
182+ ? {
183+ query : {
184+ environment : environmentId ?? undefined
185+ }
186+ }
187+ : issuesQuery
188+ ? queries [ issuesQuery ]
189+ : undefined ;
190+ const isRepositorySidebarOpen = Boolean (
191+ repositorySidebarQuery ?? sidebarLocation
192+ ) ;
116193
117194 return (
118195 < s . Container >
@@ -124,7 +201,8 @@ export const Home = () => {
124201 < Environments />
125202 < RepositorySidebarOverlay
126203 sidebarQuery = { repositorySidebarQuery }
127- isSidebarOpen = { Boolean ( repositorySidebarQuery ) }
204+ sidebarLocation = { sidebarLocation }
205+ isSidebarOpen = { isRepositorySidebarOpen }
128206 onSidebarClose = { handleRepositorySidebarClose }
129207 />
130208 </ s . Container >
0 commit comments