Skip to content

Commit cc551ac

Browse files
fix: proper expando toggling
1 parent 7840d9a commit cc551ac

File tree

4 files changed

+72
-51
lines changed

4 files changed

+72
-51
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,10 @@ export const LogTableBody = styled(TableBody)<{
140140
padding-top: ${space(1)};
141141
padding-bottom: ${space(1)};
142142
`}
143-
${p =>
144-
p.expanded
145-
? ``
146-
: `
147-
overflow-y: scroll;
148-
max-height: 70vh;
149-
min-height: 5rem;`}
143+
overflow-y: scroll;
144+
max-height: ${p =>
145+
p.expanded ? `calc(100vh - ${GRID_BODY_ROW_HEIGHT * 1.5}px)` : '50vh'};
146+
min-height: 5rem;
150147
`;
151148

152149
export const LogDetailTableBodyCell = styled(TableBodyCell)`
@@ -303,6 +300,7 @@ export const LogsItemContainer = styled('div')`
303300
flex: 1 1 auto;
304301
margin-top: ${p => p.theme.space.md};
305302
margin-bottom: ${p => p.theme.space.md};
303+
position: relative;
306304
`;
307305

308306
export const LogsTableActionsContainer = styled(LogsItemContainer)`

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

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ type LogsTableProps = {
102102
const {info, fmt} = Sentry.logger;
103103

104104
const LOGS_GRID_SCROLL_PIXEL_REVERSE_THRESHOLD = LOGS_GRID_BODY_ROW_HEIGHT * 2; // If you are less than this number of pixels from the top of the table while scrolling backward, fetch the previous page.
105-
const LOGS_OVERSCAN_AMOUNT = 50; // How many items to render beyond the visible area.
106105

107106
export function LogsInfiniteTable({
108107
embedded = false,
@@ -253,10 +252,14 @@ export function LogsInfiniteTable({
253252
return terms;
254253
}, [search, localOnlyItemFilters?.filterText]);
255254

256-
const virtualizer = useVirtualizer({
255+
const {expanded, expando} = useExpandoButton(() => {
256+
virtualizer.measure();
257+
});
258+
259+
const virtualizer = useVirtualizer<HTMLElement, Element>({
257260
count: data?.length ?? 0,
258261
estimateSize,
259-
overscan: LOGS_OVERSCAN_AMOUNT,
262+
overscan: expanded ? 25 : 10,
260263
getScrollElement: () => tableBodyRef?.current,
261264
getItemKey: (index: number) => data?.[index]?.[OurLogKnownFieldKey.ID] ?? index,
262265
});
@@ -415,10 +418,6 @@ export function LogsInfiniteTable({
415418
};
416419
}, []);
417420

418-
const {expanded, expando} = useExpandoButton(() => {
419-
virtualizer.measure();
420-
});
421-
422421
// For replay context, render empty states outside the table for proper centering
423422
if (hasReplay && (isPending || isError || isEmpty)) {
424423
return (
@@ -442,6 +441,7 @@ export function LogsInfiniteTable({
442441

443442
return (
444443
<Fragment>
444+
{expando}
445445
<Table
446446
ref={tableRef}
447447
style={initialTableStyles}
@@ -459,7 +459,6 @@ export function LogsInfiniteTable({
459459
onResizeMouseDown={onResizeMouseDown}
460460
/>
461461
)}
462-
<div style={{position: 'absolute', top: 8, right: 8}}>{expando}</div>
463462
<LogTableBody
464463
showHeader={!embedded}
465464
ref={tableBodyRef}
@@ -532,24 +531,26 @@ export function LogsInfiniteTable({
532531
)}
533532
</LogTableBody>
534533
</Table>
535-
<FloatingBackToTopContainer
536-
inReplay={!!embeddedOptions?.replay}
537-
tableLeft={tableRef.current?.getBoundingClientRect().left ?? 0}
538-
tableWidth={tableRef.current?.getBoundingClientRect().width ?? 0}
539-
>
540-
{!embeddedOptions?.replay && (
541-
<BackToTopButton
542-
virtualizer={virtualizer}
543-
hidden={
544-
isPending || ((firstItemIndex ?? 0) === 0 && (scrollOffset ?? 0) < 550)
545-
}
546-
setIsFunctionScrolling={setIsFunctionScrolling}
547-
/>
548-
)}
549-
{embeddedOptions?.replay && showJumpUpButton ? (
550-
<JumpButtons jump="up" onClick={onClickToJump} tableHeaderHeight={0} />
551-
) : null}
552-
</FloatingBackToTopContainer>
534+
{expanded && (
535+
<FloatingBackToTopContainer
536+
inReplay={!!embeddedOptions?.replay}
537+
tableLeft={tableRef.current?.getBoundingClientRect().left ?? 0}
538+
tableWidth={tableRef.current?.getBoundingClientRect().width ?? 0}
539+
>
540+
{!embeddedOptions?.replay && (
541+
<BackToTopButton
542+
virtualizer={virtualizer}
543+
hidden={
544+
isPending || ((firstItemIndex ?? 0) === 0 && (scrollOffset ?? 0) < 550)
545+
}
546+
setIsFunctionScrolling={setIsFunctionScrolling}
547+
/>
548+
)}
549+
{embeddedOptions?.replay && showJumpUpButton ? (
550+
<JumpButtons jump="up" onClick={onClickToJump} tableHeaderHeight={0} />
551+
) : null}
552+
</FloatingBackToTopContainer>
553+
)}
553554
<FloatingBottomContainer
554555
tableWidth={tableRef.current?.getBoundingClientRect().width ?? 0}
555556
>
@@ -768,10 +769,7 @@ function BackToTopButton({
768769
}: {
769770
hidden: boolean;
770771
setIsFunctionScrolling: (isScrolling: boolean) => void;
771-
virtualizer:
772-
| Virtualizer<HTMLTableSectionElement, Element>
773-
| Virtualizer<HTMLElement, Element>
774-
| Virtualizer<Window, Element>;
772+
virtualizer: Virtualizer<HTMLElement, Element> | Virtualizer<Window, Element>;
775773
}) {
776774
if (hidden) {
777775
return null;
Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {useState} from 'react';
1+
import {useLayoutEffect, useRef, useState} from 'react';
2+
import styled from '@emotion/styled';
23

34
import {Button} from '@sentry/scraps/button';
45

@@ -8,29 +9,53 @@ import {TableActionButton} from 'sentry/views/explore/components/tableActionButt
89

910
export function useExpandoButton(onToggle: () => void) {
1011
const [expanded, setExpanded] = useState(false);
12+
const ref = useRef<HTMLButtonElement>(null);
1113

1214
const [Icon, text] = expanded
13-
? [IconContract, t('Collapse Table')]
14-
: [IconExpand, t('Expand Table')];
15+
? [IconContract, t('Collapse')]
16+
: [IconExpand, t('Expand')];
1517

1618
const toggleExpanded = () => {
1719
setExpanded(!expanded);
1820
onToggle();
1921
};
2022

23+
useLayoutEffect(() => {
24+
if (expanded) {
25+
ref.current?.scrollIntoView({
26+
block: 'start',
27+
});
28+
}
29+
}, [expanded]);
30+
31+
const buttonProps = {
32+
'aria-label': text,
33+
icon: <Icon />,
34+
onClick: toggleExpanded,
35+
ref,
36+
size: 'sm',
37+
} as const;
38+
2139
return {
2240
expanded,
2341
expando: (
24-
<TableActionButton
25-
mobile={
26-
<Button onClick={toggleExpanded} icon={<Icon />} size="sm" aria-label={text} />
27-
}
28-
desktop={
29-
<Button onClick={toggleExpanded} icon={<Icon />} size="sm" aria-label={text}>
30-
{text}
31-
</Button>
32-
}
33-
/>
42+
<ExpandoContainer>
43+
<TableActionButton
44+
mobile={<ExpandoButton {...buttonProps} />}
45+
desktop={<ExpandoButton {...buttonProps}>{text}</ExpandoButton>}
46+
/>
47+
</ExpandoContainer>
3448
),
3549
};
3650
}
51+
52+
const ExpandoButton = styled(Button)`
53+
scroll-margin-top: 0.75rem;
54+
`;
55+
56+
const ExpandoContainer = styled('div')`
57+
position: absolute;
58+
top: 0.5rem;
59+
right: 0.5rem;
60+
z-index: 1;
61+
`;

static/app/views/replays/detail/ourlogs/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {useCallback, useMemo, useRef} from 'react';
1+
import {useCallback, useMemo} from 'react';
22
import styled from '@emotion/styled';
33

44
import Placeholder from 'sentry/components/placeholder';

0 commit comments

Comments
 (0)