-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix(ourlogs): Add drawer QP and fix scroll #103979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import {useCallback, useRef} from 'react'; | ||
| import {useCallback, useEffect, useRef} from 'react'; | ||
| import styled from '@emotion/styled'; | ||
|
|
||
| import {Button} from 'sentry/components/core/button'; | ||
|
|
@@ -11,13 +11,16 @@ import type {Group} from 'sentry/types/group'; | |
| import type {Project} from 'sentry/types/project'; | ||
| import {trackAnalytics} from 'sentry/utils/analytics'; | ||
| import {LogsAnalyticsPageSource} from 'sentry/utils/analytics/logsAnalyticsEvent'; | ||
| import {useLocation} from 'sentry/utils/useLocation'; | ||
| import {useNavigate} from 'sentry/utils/useNavigate'; | ||
| import useOrganization from 'sentry/utils/useOrganization'; | ||
| import {TableBody} from 'sentry/views/explore/components/table'; | ||
| import { | ||
| LogsPageDataProvider, | ||
| useLogsPageDataQueryResult, | ||
| } from 'sentry/views/explore/contexts/logs/logsPageData'; | ||
| import {TraceItemAttributeProvider} from 'sentry/views/explore/contexts/traceItemAttributeContext'; | ||
| import {LOGS_DRAWER_QUERY_PARAM} from 'sentry/views/explore/logs/constants'; | ||
| import {LogsQueryParamsProvider} from 'sentry/views/explore/logs/logsQueryParamsProvider'; | ||
| import {LogRowContent} from 'sentry/views/explore/logs/tables/logsTableRow'; | ||
| import {useQueryParamsSearch} from 'sentry/views/explore/queryParams/context'; | ||
|
|
@@ -58,6 +61,8 @@ function OurlogsSectionContent({ | |
| project: Project; | ||
| }) { | ||
| const organization = useOrganization(); | ||
| const navigate = useNavigate(); | ||
| const location = useLocation(); | ||
| const feature = organization.features.includes('ourlogs-enabled'); | ||
| const tableData = useLogsPageDataQueryResult(); | ||
| const logsSearch = useQueryParamsSearch(); | ||
|
|
@@ -73,6 +78,34 @@ function OurlogsSectionContent({ | |
| trackAnalytics('logs.issue_details.drawer_opened', { | ||
| organization, | ||
| }); | ||
|
|
||
| navigate( | ||
| { | ||
| ...location, | ||
| query: { | ||
| ...location.query, | ||
| [LOGS_DRAWER_QUERY_PARAM]: 'true', | ||
| ...(expandedLogId && {expandedLogId}), | ||
| }, | ||
| }, | ||
| {replace: true} | ||
| ); | ||
| }, | ||
| [navigate, location, organization] | ||
| ); | ||
|
|
||
| const onEmbeddedRowClick = useCallback( | ||
| (logItemId: string, clickEvent: React.MouseEvent) => { | ||
| onOpenLogsDrawer(clickEvent, logItemId); | ||
| }, | ||
| [onOpenLogsDrawer] | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| const shouldOpenDrawer = location.query[LOGS_DRAWER_QUERY_PARAM] === 'true'; | ||
| if (shouldOpenDrawer && traceId) { | ||
| const expandedLogId = location.query.expandedLogId as string | undefined; | ||
|
|
||
| openDrawer( | ||
| () => ( | ||
| <LogsQueryParamsProvider | ||
|
|
@@ -89,6 +122,10 @@ function OurlogsSectionContent({ | |
| embeddedOptions={ | ||
| expandedLogId ? {openWithExpandedIds: [expandedLogId]} : undefined | ||
| } | ||
| additionalData={{ | ||
| event, | ||
| scrollToDisabled: !!expandedLogId, | ||
| }} | ||
| /> | ||
| </TraceItemAttributeProvider> | ||
| </LogsPageDataProvider> | ||
|
|
@@ -97,23 +134,27 @@ function OurlogsSectionContent({ | |
| { | ||
| ariaLabel: 'logs drawer', | ||
| drawerKey: 'logs-issue-drawer', | ||
|
|
||
| shouldCloseOnInteractOutside: element => { | ||
| const viewAllButton = viewAllButtonRef.current; | ||
| return !viewAllButton?.contains(element); | ||
| }, | ||
| onClose: () => { | ||
| navigate( | ||
| { | ||
| ...location, | ||
| query: { | ||
| ...location.query, | ||
| [LOGS_DRAWER_QUERY_PARAM]: undefined, | ||
| expandedLogId: undefined, | ||
| }, | ||
| }, | ||
| {replace: true} | ||
| ); | ||
| }, | ||
| } | ||
| ); | ||
| }, | ||
| [group, event, project, openDrawer, organization, traceId] | ||
| ); | ||
|
|
||
| const onEmbeddedRowClick = useCallback( | ||
| (logItemId: string, clickEvent: React.MouseEvent) => { | ||
| onOpenLogsDrawer(clickEvent, logItemId); | ||
| }, | ||
| [onOpenLogsDrawer] | ||
| ); | ||
| } | ||
| }, [location.query, traceId, group, event, project, openDrawer, navigate, location]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Drawer opens even when feature flag is disabledThe |
||
| if (!feature) { | ||
| return null; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Race condition in
onOpenLogsDrawercan causeexpandedLogIdto persist in URL due to stalelocation.queryafter drawer close.Severity: HIGH | Confidence: High
🔍 Detailed Analysis
When
onOpenLogsDraweris called afteronClosehas been triggered but before thelocationobject has fully updated to reflectexpandedLogId: undefined, the...location.queryspread will include the staleexpandedLogIdfrom the previous navigation. This occurs if a user closes the drawer and immediately clicks "View more" again. The drawer then opens withscrollToDisabled: trueeven though no specific log was selected, breaking the intended scroll behavior for the pseudo event.💡 Suggested Fix
Modify
onOpenLogsDrawerto explicitly setexpandedLogId: undefinedin the new query object when noexpandedLogIdis passed, instead of relying on...location.queryto implicitly remove it. This ensures the parameter is cleared regardless oflocationobject staleness.🤖 Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID:
3557864