1- import { useCallback , useRef } from 'react' ;
1+ import { useCallback , useEffect , useRef } from 'react' ;
22import styled from '@emotion/styled' ;
33
44import { Button } from 'sentry/components/core/button' ;
@@ -11,13 +11,16 @@ import type {Group} from 'sentry/types/group';
1111import type { Project } from 'sentry/types/project' ;
1212import { trackAnalytics } from 'sentry/utils/analytics' ;
1313import { LogsAnalyticsPageSource } from 'sentry/utils/analytics/logsAnalyticsEvent' ;
14+ import { useLocation } from 'sentry/utils/useLocation' ;
15+ import { useNavigate } from 'sentry/utils/useNavigate' ;
1416import useOrganization from 'sentry/utils/useOrganization' ;
1517import { TableBody } from 'sentry/views/explore/components/table' ;
1618import {
1719 LogsPageDataProvider ,
1820 useLogsPageDataQueryResult ,
1921} from 'sentry/views/explore/contexts/logs/logsPageData' ;
2022import { TraceItemAttributeProvider } from 'sentry/views/explore/contexts/traceItemAttributeContext' ;
23+ import { LOGS_DRAWER_QUERY_PARAM } from 'sentry/views/explore/logs/constants' ;
2124import { LogsQueryParamsProvider } from 'sentry/views/explore/logs/logsQueryParamsProvider' ;
2225import { LogRowContent } from 'sentry/views/explore/logs/tables/logsTableRow' ;
2326import { useQueryParamsSearch } from 'sentry/views/explore/queryParams/context' ;
@@ -58,6 +61,8 @@ function OurlogsSectionContent({
5861 project : Project ;
5962} ) {
6063 const organization = useOrganization ( ) ;
64+ const navigate = useNavigate ( ) ;
65+ const location = useLocation ( ) ;
6166 const feature = organization . features . includes ( 'ourlogs-enabled' ) ;
6267 const tableData = useLogsPageDataQueryResult ( ) ;
6368 const logsSearch = useQueryParamsSearch ( ) ;
@@ -73,6 +78,34 @@ function OurlogsSectionContent({
7378 trackAnalytics ( 'logs.issue_details.drawer_opened' , {
7479 organization,
7580 } ) ;
81+
82+ navigate (
83+ {
84+ ...location ,
85+ query : {
86+ ...location . query ,
87+ [ LOGS_DRAWER_QUERY_PARAM ] : 'true' ,
88+ ...( expandedLogId && { expandedLogId} ) ,
89+ } ,
90+ } ,
91+ { replace : true }
92+ ) ;
93+ } ,
94+ [ navigate , location , organization ]
95+ ) ;
96+
97+ const onEmbeddedRowClick = useCallback (
98+ ( logItemId : string , clickEvent : React . MouseEvent ) => {
99+ onOpenLogsDrawer ( clickEvent , logItemId ) ;
100+ } ,
101+ [ onOpenLogsDrawer ]
102+ ) ;
103+
104+ useEffect ( ( ) => {
105+ const shouldOpenDrawer = location . query [ LOGS_DRAWER_QUERY_PARAM ] === 'true' ;
106+ if ( shouldOpenDrawer && traceId ) {
107+ const expandedLogId = location . query . expandedLogId as string | undefined ;
108+
76109 openDrawer (
77110 ( ) => (
78111 < LogsQueryParamsProvider
@@ -89,6 +122,10 @@ function OurlogsSectionContent({
89122 embeddedOptions = {
90123 expandedLogId ? { openWithExpandedIds : [ expandedLogId ] } : undefined
91124 }
125+ additionalData = { {
126+ event,
127+ scrollToDisabled : ! ! expandedLogId ,
128+ } }
92129 />
93130 </ TraceItemAttributeProvider >
94131 </ LogsPageDataProvider >
@@ -97,23 +134,27 @@ function OurlogsSectionContent({
97134 {
98135 ariaLabel : 'logs drawer' ,
99136 drawerKey : 'logs-issue-drawer' ,
100-
101137 shouldCloseOnInteractOutside : element => {
102138 const viewAllButton = viewAllButtonRef . current ;
103139 return ! viewAllButton ?. contains ( element ) ;
104140 } ,
141+ onClose : ( ) => {
142+ navigate (
143+ {
144+ ...location ,
145+ query : {
146+ ...location . query ,
147+ [ LOGS_DRAWER_QUERY_PARAM ] : undefined ,
148+ expandedLogId : undefined ,
149+ } ,
150+ } ,
151+ { replace : true }
152+ ) ;
153+ } ,
105154 }
106155 ) ;
107- } ,
108- [ group , event , project , openDrawer , organization , traceId ]
109- ) ;
110-
111- const onEmbeddedRowClick = useCallback (
112- ( logItemId : string , clickEvent : React . MouseEvent ) => {
113- onOpenLogsDrawer ( clickEvent , logItemId ) ;
114- } ,
115- [ onOpenLogsDrawer ]
116- ) ;
156+ }
157+ } , [ location . query , traceId , group , event , project , openDrawer , navigate , location ] ) ;
117158 if ( ! feature ) {
118159 return null ;
119160 }
0 commit comments