Skip to content

Commit edb8184

Browse files
fix(logs): adjust back-to-top containers to window width resize
1 parent 4d90122 commit edb8184

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type {RefObject} from 'react';
2+
import {useLayoutEffect, useState} from 'react';
3+
4+
import {useWindowSize} from 'sentry/utils/window/useWindowSize';
5+
6+
export function useElementWidth<Element extends HTMLElement>(
7+
elementRef: RefObject<Element | null>
8+
) {
9+
const [width, setWidth] = useState(elementRef.current?.getBoundingClientRect().width);
10+
const {innerWidth} = useWindowSize();
11+
12+
useLayoutEffect(() => {
13+
setWidth(elementRef.current?.getBoundingClientRect().width);
14+
}, [elementRef, innerWidth]);
15+
16+
return width;
17+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {t, tct} from 'sentry/locale';
3030
import type {Event} from 'sentry/types/event';
3131
import type {TagCollection} from 'sentry/types/group';
3232
import {defined} from 'sentry/utils';
33+
import {useElementWidth} from 'sentry/utils/useElementWidth';
3334
import {
3435
TableBodyCell,
3536
TableHead,
@@ -220,6 +221,7 @@ export function LogsInfiniteTable({
220221

221222
const tableRef = useRef<HTMLTableElement>(null);
222223
const tableBodyRef = useRef<HTMLTableSectionElement>(null);
224+
const tableWidth = useElementWidth(tableRef);
223225
const [expandedLogRows, setExpandedLogRows] = useState<Set<string>>(
224226
new Set(embeddedOptions?.openWithExpandedIds ?? [])
225227
);
@@ -556,7 +558,7 @@ export function LogsInfiniteTable({
556558
<FloatingBackToTopContainer
557559
position={expanded === undefined ? 'fixed' : 'absolute'}
558560
inReplay={!!embeddedOptions?.replay}
559-
tableWidth={tableRef.current?.getBoundingClientRect().width ?? 0}
561+
tableWidth={tableWidth}
560562
>
561563
{!embeddedOptions?.replay && (
562564
<BackToTopButton
@@ -571,9 +573,7 @@ export function LogsInfiniteTable({
571573
<JumpButtons jump="up" onClick={onClickToJump} tableHeaderHeight={0} />
572574
) : null}
573575
</FloatingBackToTopContainer>
574-
<FloatingBottomContainer
575-
tableWidth={tableRef.current?.getBoundingClientRect().width ?? 0}
576-
>
576+
<FloatingBottomContainer tableWidth={tableWidth}>
577577
{embeddedOptions?.replay && showJumpDownButton ? (
578578
<JumpButtons jump="down" onClick={onClickToJump} tableHeaderHeight={0} />
579579
) : null}

0 commit comments

Comments
 (0)