Skip to content

Commit 606ee67

Browse files
switch to button in the tabs above the table
1 parent 6a29ef1 commit 606ee67

File tree

3 files changed

+63
-37
lines changed

3 files changed

+63
-37
lines changed

static/app/views/explore/logs/logsTab.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ import {useRawCounts} from 'sentry/views/explore/useRawCounts';
9494
// eslint-disable-next-line boundaries/element-types
9595
import QuotaExceededAlert from 'getsentry/components/performance/quotaExceededAlert';
9696

97+
import {useExpandoButton} from './tables/useExpandoButton';
98+
9799
type LogsTabProps = {
98100
datePageFilterProps: DatePageFilterProps;
99101
};
@@ -329,6 +331,8 @@ export function LogsTabContent({datePageFilterProps}: LogsTabProps) {
329331

330332
const {infiniteLogsQueryResult} = useLogsPageData();
331333

334+
const {expansion, expando} = useExpandoButton();
335+
332336
return (
333337
<SearchQueryBuilderProvider
334338
enableAISearch={areAiFeaturesAllowed}
@@ -467,12 +471,14 @@ export function LogsTabContent({datePageFilterProps}: LogsTabProps) {
467471
</Button>
468472
}
469473
/>
474+
{tableTab === 'logs' && expando}
470475
</TableActionsContainer>
471476
)}
472477
</LogsTableActionsContainer>
473478
<LogsItemContainer>
474479
{tableTab === 'logs' ? (
475480
<LogsInfiniteTable
481+
expansion={expansion}
476482
stringAttributes={stringAttributes}
477483
numberAttributes={numberAttributes}
478484
/>

static/app/views/explore/logs/tables/logsInfiniteTable.tsx

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
import type {CSSProperties, RefObject} from 'react';
2-
import {Fragment, useCallback, useEffect, useMemo, useRef, useState} from 'react';
1+
import {
2+
Fragment,
3+
useCallback,
4+
useEffect,
5+
useLayoutEffect,
6+
useMemo,
7+
useRef,
8+
useState,
9+
type CSSProperties,
10+
type RefObject,
11+
} from 'react';
312
import styled from '@emotion/styled';
413
import * as Sentry from '@sentry/react';
514
import type {Virtualizer} from '@tanstack/react-virtual';
@@ -49,7 +58,7 @@ import {
4958
LogTableRow,
5059
} from 'sentry/views/explore/logs/styles';
5160
import {LogRowContent} from 'sentry/views/explore/logs/tables/logsTableRow';
52-
import {useExpandoButton} from 'sentry/views/explore/logs/tables/useExpandoButton';
61+
import type {ExpansionState} from 'sentry/views/explore/logs/tables/useExpandoButton';
5362
import {
5463
OurLogKnownFieldKey,
5564
type OurLogsResponseItem,
@@ -75,6 +84,7 @@ import {
7584
import {EmptyStateText} from 'sentry/views/explore/tables/tracesTable/styles';
7685

7786
type LogsTableProps = {
87+
expansion: ExpansionState;
7888
additionalData?: {
7989
event?: Event;
8090
scrollToDisabled?: boolean;
@@ -107,6 +117,7 @@ export function LogsInfiniteTable({
107117
embedded = false,
108118
localOnlyItemFilters,
109119
emptyRenderer,
120+
expansion,
110121
numberAttributes,
111122
stringAttributes,
112123
booleanAttributes,
@@ -252,18 +263,18 @@ export function LogsInfiniteTable({
252263
return terms;
253264
}, [search, localOnlyItemFilters?.filterText]);
254265

255-
const {expanded, expando} = useExpandoButton(() => {
256-
virtualizer.measure();
257-
});
258-
259266
const virtualizer = useVirtualizer<HTMLElement, Element>({
260267
count: data?.length ?? 0,
261268
estimateSize,
262-
overscan: expanded ? 25 : 10,
269+
overscan: expansion.expanded ? 25 : 10,
263270
getScrollElement: () => tableBodyRef?.current,
264271
getItemKey: (index: number) => data?.[index]?.[OurLogKnownFieldKey.ID] ?? index,
265272
});
266273

274+
useLayoutEffect(() => {
275+
virtualizer.measure();
276+
}, [expansion.expanded, virtualizer]);
277+
267278
const virtualItems = virtualizer.getVirtualItems();
268279

269280
const firstItem = virtualItems[0]?.start;
@@ -386,13 +397,19 @@ export function LogsInfiniteTable({
386397
}
387398
}, [hasReplay, firstItemIndex, lastItemIndex, onRowsRendered]);
388399

389-
const handleExpand = useCallback((logItemId: string) => {
390-
setExpandedLogRows(prev => {
391-
const newSet = new Set(prev);
392-
newSet.add(logItemId);
393-
return newSet;
394-
});
395-
}, []);
400+
const handleExpand = useCallback(
401+
(logItemId: string) => {
402+
setExpandedLogRows(prev => {
403+
const newSet = new Set(prev);
404+
newSet.add(logItemId);
405+
return newSet;
406+
});
407+
if (!expansion.expanded) {
408+
expansion.toggle();
409+
}
410+
},
411+
[expansion]
412+
);
396413
const handleExpandHeight = useCallback((logItemId: string, estimatedHeight: number) => {
397414
setExpandedLogRowsHeights(prev => ({...prev, [logItemId]: estimatedHeight}));
398415
}, []);
@@ -441,7 +458,6 @@ export function LogsInfiniteTable({
441458

442459
return (
443460
<Fragment>
444-
{expando}
445461
<Table
446462
ref={tableRef}
447463
style={initialTableStyles}
@@ -463,7 +479,7 @@ export function LogsInfiniteTable({
463479
showHeader={!embedded}
464480
ref={tableBodyRef}
465481
disableBodyPadding={embeddedStyling?.disableBodyPadding}
466-
expanded={expanded}
482+
expanded={expansion.expanded}
467483
>
468484
{paddingTop > 0 && (
469485
<TableRow>
@@ -530,7 +546,7 @@ export function LogsInfiniteTable({
530546
)}
531547
</LogTableBody>
532548
</Table>
533-
{expanded && (
549+
{expansion.expanded && (
534550
<FloatingBackToTopContainer
535551
inReplay={!!embeddedOptions?.replay}
536552
tableLeft={tableRef.current?.getBoundingClientRect().left ?? 0}
Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
1-
import {useLayoutEffect, useRef, useState} from 'react';
1+
import {useCallback, useLayoutEffect, useMemo, useRef, useState} from 'react';
22
import styled from '@emotion/styled';
33

44
import {Button} from '@sentry/scraps/button';
55

6-
import {IconContract, IconExpand} from 'sentry/icons';
6+
import {IconFocus} from 'sentry/icons';
77
import {t} from 'sentry/locale';
88
import {TableActionButton} from 'sentry/views/explore/components/tableActionButton';
99

10-
export function useExpandoButton(onToggle: () => void) {
10+
export interface ExpansionState {
11+
expanded: boolean;
12+
toggle: () => void;
13+
}
14+
15+
interface UsedExpandoButton {
16+
expando: React.ReactNode;
17+
expansion: ExpansionState;
18+
}
19+
20+
export function useExpandoButton(): UsedExpandoButton {
1121
const [expanded, setExpanded] = useState(false);
1222
const ref = useRef<HTMLButtonElement>(null);
1323

14-
const [Icon, text] = expanded
15-
? [IconContract, t('Collapse')]
16-
: [IconExpand, t('Expand')];
17-
18-
const toggleExpanded = () => {
24+
const toggle = useCallback(() => {
1925
setExpanded(!expanded);
20-
onToggle();
21-
};
26+
}, [expanded]);
27+
28+
const expansion = useMemo(() => ({expanded, toggle}), [expanded, toggle]);
2229

2330
useLayoutEffect(() => {
2431
if (expanded) {
@@ -28,16 +35,17 @@ export function useExpandoButton(onToggle: () => void) {
2835
}
2936
}, [expanded]);
3037

38+
const text = expanded ? t('Collapse') : t('Expand');
39+
3140
const buttonProps = {
3241
'aria-label': text,
33-
icon: <Icon />,
34-
onClick: toggleExpanded,
42+
icon: <IconFocus isFocused={!expanded} />,
43+
onClick: toggle,
3544
ref,
3645
size: 'sm',
3746
} as const;
3847

3948
return {
40-
expanded,
4149
expando: (
4250
<ExpandoContainer>
4351
<TableActionButton
@@ -46,16 +54,12 @@ export function useExpandoButton(onToggle: () => void) {
4654
/>
4755
</ExpandoContainer>
4856
),
57+
expansion,
4958
};
5059
}
5160

5261
const ExpandoButton = styled(Button)`
5362
scroll-margin-top: 0.75rem;
5463
`;
5564

56-
const ExpandoContainer = styled('div')`
57-
position: absolute;
58-
top: 0.5rem;
59-
right: 0.5rem;
60-
z-index: 1;
61-
`;
65+
const ExpandoContainer = styled('div')``;

0 commit comments

Comments
 (0)