Skip to content

Commit c505461

Browse files
committed
move everything around, fix many bugs
1 parent 39f9329 commit c505461

File tree

7 files changed

+124
-159
lines changed

7 files changed

+124
-159
lines changed

static/app/components/events/breadcrumbs/combinedBreadcrumbsAndLogsSection.tsx

Lines changed: 0 additions & 66 deletions
This file was deleted.

static/app/views/explore/logs/logsIssueDrawer.tsx renamed to static/app/components/events/ourlogs/ourlogsDrawer.tsx

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,21 @@ import {
99
NavigationCrumbs,
1010
ShortId,
1111
} from 'sentry/components/events/eventDrawer';
12+
import {SearchQueryBuilderProvider} from 'sentry/components/searchQueryBuilder/context';
1213
import {t} from 'sentry/locale';
1314
import {space} from 'sentry/styles/space';
1415
import type {Event} from 'sentry/types/event';
1516
import type {Group} from 'sentry/types/group';
1617
import type {Project} from 'sentry/types/project';
1718
import {getShortEventId} from 'sentry/utils/events';
18-
import {TraceItemSearchQueryBuilder} from 'sentry/views/explore/components/traceItemSearchQueryBuilder';
19+
import {MutableSearch} from 'sentry/utils/tokenizeSearch';
20+
import {
21+
TraceItemSearchQueryBuilder,
22+
useSearchQueryBuilderProps,
23+
} from 'sentry/views/explore/components/traceItemSearchQueryBuilder';
1924
import {
2025
useLogsSearch,
21-
useSetLogsQuery,
26+
useSetLogsSearch,
2227
} from 'sentry/views/explore/contexts/logs/logsPageParams';
2328
import {useTraceItemAttributes} from 'sentry/views/explore/contexts/traceItemAttributeContext';
2429
import {LogsTable} from 'sentry/views/explore/logs/logsTable';
@@ -31,12 +36,24 @@ interface LogIssueDrawerProps {
3136
project: Project;
3237
}
3338

34-
export function LogsIssueDrawer({event, project, group}: LogIssueDrawerProps) {
35-
const setLogsQuery = useSetLogsQuery();
39+
export function OurlogsDrawer({event, project, group}: LogIssueDrawerProps) {
40+
const setLogsSearch = useSetLogsSearch();
3641
const logsSearch = useLogsSearch();
3742
const tableData = useExploreLogsTable({});
38-
const {attributes: stringTags} = useTraceItemAttributes('string');
39-
const {attributes: numberTags} = useTraceItemAttributes('number');
43+
const {attributes: stringAttributes} = useTraceItemAttributes('string');
44+
const {attributes: numberAttributes} = useTraceItemAttributes('number');
45+
46+
const tracesItemSearchQueryBuilderProps = {
47+
initialQuery: logsSearch.formatString(),
48+
searchSource: 'ourlogs',
49+
onSearch: (query: string) => setLogsSearch(new MutableSearch(query)),
50+
numberAttributes,
51+
stringAttributes,
52+
itemType: TraceItemDataset.LOGS,
53+
};
54+
const searchQueryBuilderProps = useSearchQueryBuilderProps(
55+
tracesItemSearchQueryBuilderProps
56+
);
4057

4158
return (
4259
<EventDrawerContainer>
@@ -57,17 +74,12 @@ export function LogsIssueDrawer({event, project, group}: LogIssueDrawerProps) {
5774
/>
5875
</EventDrawerHeader>
5976
<EventDrawerBody>
60-
<LogsTableContainer>
61-
<TraceItemSearchQueryBuilder
62-
initialQuery={logsSearch.formatString()}
63-
searchSource="ourlogs"
64-
onSearch={setLogsQuery}
65-
numberAttributes={numberTags}
66-
stringAttributes={stringTags}
67-
itemType={TraceItemDataset.LOGS}
68-
/>
69-
<LogsTable showHeader={false} allowPagination tableData={tableData} />
70-
</LogsTableContainer>
77+
<SearchQueryBuilderProvider {...searchQueryBuilderProps}>
78+
<LogsTableContainer>
79+
<TraceItemSearchQueryBuilder {...tracesItemSearchQueryBuilderProps} />
80+
<LogsTable showHeader={false} allowPagination tableData={tableData} />
81+
</LogsTableContainer>
82+
</SearchQueryBuilderProvider>
7183
</EventDrawerBody>
7284
</EventDrawerContainer>
7385
);

static/app/views/explore/logs/logsIssuesSection.tsx renamed to static/app/components/events/ourlogs/ourlogsSection.tsx

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {useCallback} from 'react';
22
import styled from '@emotion/styled';
33

44
import {Button} from 'sentry/components/core/button';
5+
import {OurlogsDrawer} from 'sentry/components/events/ourlogs/ourlogsDrawer';
56
import useDrawer from 'sentry/components/globalDrawer';
67
import {IconChevron} from 'sentry/icons';
78
import {t} from 'sentry/locale';
@@ -14,36 +15,53 @@ import {LogsAnalyticsPageSource} from 'sentry/utils/analytics/logsAnalyticsEvent
1415
import useOrganization from 'sentry/utils/useOrganization';
1516
import {
1617
LogsPageParamsProvider,
17-
type LogsPageParamsProviderProps,
18+
useLogsSearch,
1819
} from 'sentry/views/explore/contexts/logs/logsPageParams';
1920
import {TraceItemAttributeProvider} from 'sentry/views/explore/contexts/traceItemAttributeContext';
20-
import {LogsIssueDrawer} from 'sentry/views/explore/logs/logsIssueDrawer';
2121
import {LogsTable} from 'sentry/views/explore/logs/logsTable';
22-
import {
23-
useExploreLogsTable,
24-
type UseExploreLogsTableResult,
25-
} from 'sentry/views/explore/logs/useLogsQuery';
22+
import {useExploreLogsTable} from 'sentry/views/explore/logs/useLogsQuery';
2623
import {TraceItemDataset} from 'sentry/views/explore/types';
2724
import {SectionKey} from 'sentry/views/issueDetails/streamline/context';
2825
import {InterimSection} from 'sentry/views/issueDetails/streamline/interimSection';
2926

30-
export function LogsIssuesSection({
31-
initialCollapse,
32-
limitToTraceId,
27+
export function OurlogsSection({
3328
event,
3429
project,
3530
group,
3631
}: {
3732
event: Event;
3833
group: Group;
39-
initialCollapse: boolean;
4034
project: Project;
41-
} & Omit<LogsPageParamsProviderProps, 'children' | 'analyticsPageSource'>) {
35+
}) {
36+
return (
37+
<LogsPageParamsProvider
38+
analyticsPageSource={LogsAnalyticsPageSource.ISSUE_DETAILS}
39+
isTableFrozen
40+
blockRowExpanding
41+
limitToTraceId={event.contexts?.trace?.trace_id}
42+
>
43+
<OurlogsSectionContent event={event} group={group} project={project} />
44+
</LogsPageParamsProvider>
45+
);
46+
}
47+
48+
function OurlogsSectionContent({
49+
event,
50+
project,
51+
group,
52+
}: {
53+
event: Event;
54+
group: Group;
55+
project: Project;
56+
}) {
4257
const organization = useOrganization();
4358
const feature = organization.features.includes('ourlogs-enabled');
4459
const tableData = useExploreLogsTable({enabled: feature, limit: 10});
60+
const logsSearch = useLogsSearch();
61+
const abbreviatedTableData = {...tableData, data: (tableData.data ?? []).slice(0, 5)};
4562
const {openDrawer} = useDrawer();
4663

64+
const limitToTraceId = event.contexts?.trace?.trace_id;
4765
const onOpenLogsDrawer = useCallback(() => {
4866
trackAnalytics('logs.issue_details.drawer_opened', {
4967
organization,
@@ -56,7 +74,7 @@ export function LogsIssuesSection({
5674
limitToTraceId={limitToTraceId}
5775
>
5876
<TraceItemAttributeProvider traceItemType={TraceItemDataset.LOGS} enabled>
59-
<LogsIssueDrawer group={group} event={event} project={project} />
77+
<OurlogsDrawer group={group} event={event} project={project} />
6078
</TraceItemAttributeProvider>
6179
</LogsPageParamsProvider>
6280
),
@@ -73,7 +91,7 @@ export function LogsIssuesSection({
7391
// We may change this in the future if we have a trace-group or we generate trace sids for these issue types.
7492
return null;
7593
}
76-
if (tableData?.data?.length === 0) {
94+
if (!tableData || (tableData.data?.length === 0 && logsSearch.isEmpty())) {
7795
// Like breadcrumbs, we don't show the logs section if there are no logs.
7896
return null;
7997
}
@@ -83,53 +101,40 @@ export function LogsIssuesSection({
83101
type={SectionKey.LOGS}
84102
title={t('Logs')}
85103
data-test-id="logs-data-section"
86-
initialCollapse={initialCollapse}
87104
>
88-
<LogsPageParamsProvider
89-
analyticsPageSource={LogsAnalyticsPageSource.ISSUE_DETAILS}
90-
isTableFrozen
91-
blockRowExpanding
92-
limitToTraceId={limitToTraceId}
93-
>
94-
<LogsSectionContent tableData={tableData} openDrawer={onOpenLogsDrawer} />
95-
</LogsPageParamsProvider>
105+
<LogContentWrapper onClick={() => onOpenLogsDrawer()}>
106+
<LogsTable
107+
showHeader={false}
108+
allowPagination={false}
109+
tableData={abbreviatedTableData}
110+
/>
111+
{tableData.data?.length > 5 ? (
112+
<div>
113+
<Button
114+
icon={<IconChevron direction="right" />}
115+
aria-label={t('View more')}
116+
size="md"
117+
onClick={() => onOpenLogsDrawer()}
118+
>
119+
{t('View more')}
120+
</Button>
121+
</div>
122+
) : null}
123+
</LogContentWrapper>
96124
</InterimSection>
97125
);
98126
}
99127

100-
function LogsSectionContent({
101-
tableData,
102-
openDrawer,
103-
}: {
104-
openDrawer: () => void;
105-
tableData: UseExploreLogsTableResult;
106-
}) {
107-
const abbreviatedTableData = {...tableData, data: (tableData.data ?? []).slice(0, 5)};
108-
return (
109-
<LogContentWrapper>
110-
<LogsTable
111-
showHeader={false}
112-
allowPagination={false}
113-
tableData={abbreviatedTableData}
114-
/>
115-
{tableData.data?.length > 5 ? (
116-
<div>
117-
<Button
118-
icon={<IconChevron direction="right" />}
119-
aria-label={t('View more')}
120-
size="md"
121-
onClick={() => openDrawer()}
122-
>
123-
{t('View more')}
124-
</Button>
125-
</div>
126-
) : null}
127-
</LogContentWrapper>
128-
);
129-
}
130-
131-
const LogContentWrapper = styled('div')`
128+
const LogContentWrapper = styled('button')`
129+
all: unset;
132130
display: flex;
133131
flex-direction: column;
134132
gap: ${space(1)};
133+
pointer-events: auto;
134+
cursor: pointer;
135+
136+
* {
137+
pointer-events: none !important;
138+
cursor: inherit !important;
139+
}
135140
`;

static/app/views/explore/contexts/logs/logsPageParams.tsx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {useCallback, useLayoutEffect} from 'react';
1+
import {useCallback, useLayoutEffect, useState} from 'react';
22
import type {Location} from 'history';
33

44
import type {CursorHandler} from 'sentry/components/pagination';
@@ -36,9 +36,14 @@ interface LogsPageParams {
3636
readonly fields: string[];
3737
readonly isTableFrozen: boolean | undefined;
3838
readonly search: MutableSearch;
39+
/**
40+
* On frozen pages (like the issues page), we don't want to store the search in the URL
41+
* Instead, use a useState in the context, so that it's dropped if you navigate away or refresh.
42+
*/
43+
readonly setSearchForFrozenPages: (val: MutableSearch) => void;
3944
readonly sortBys: Sort[];
4045
/**
41-
* The base search, which doesn't appear in the URL or the search bar, used for adding traceid etc..
46+
* The base search, which doesn't appear in the URL or the search bar, used for adding traceid etc.
4247
*/
4348
readonly baseSearch?: MutableSearch;
4449
/**
@@ -76,7 +81,11 @@ export function LogsPageParamsProvider({
7681
}: LogsPageParamsProviderProps) {
7782
const location = useLocation();
7883
const logsQuery = decodeLogsQuery(location);
79-
const search = new MutableSearch(logsQuery);
84+
85+
// on embedded pages with search bars, use a useState instead of a URL parameter
86+
const [searchForFrozenPages, setSearchForFrozenPages] = useState(new MutableSearch(''));
87+
88+
const search = isTableFrozen ? searchForFrozenPages : new MutableSearch(logsQuery);
8089
let baseSearch: MutableSearch | undefined = undefined;
8190
if (limitToSpanId && limitToTraceId) {
8291
baseSearch = baseSearch ?? new MutableSearch('');
@@ -103,6 +112,7 @@ export function LogsPageParamsProvider({
103112
value={{
104113
fields,
105114
search,
115+
setSearchForFrozenPages,
106116
sortBys,
107117
cursor,
108118
isTableFrozen,
@@ -184,24 +194,19 @@ export function useLogsBaseSearch(): MutableSearch | undefined {
184194
return baseSearch;
185195
}
186196

187-
export function useSetLogsQuery() {
188-
const setPageParams = useSetLogsPageParams();
189-
return useCallback(
190-
(query: string) => {
191-
setPageParams({search: new MutableSearch(query)});
192-
},
193-
[setPageParams]
194-
);
195-
}
196-
197197
export function useSetLogsSearch() {
198198
const setPageParams = useSetLogsPageParams();
199-
return useCallback(
199+
const {setSearchForFrozenPages, isTableFrozen} = useLogsPageParams();
200+
const setPageParamsCallback = useCallback(
200201
(search: MutableSearch) => {
201202
setPageParams({search});
202203
},
203204
[setPageParams]
204205
);
206+
if (isTableFrozen) {
207+
return setSearchForFrozenPages;
208+
}
209+
return setPageParamsCallback;
205210
}
206211

207212
export function useLogsIsTableFrozen() {

0 commit comments

Comments
 (0)