Skip to content

Commit

Permalink
table header width
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi-sl committed Sep 11, 2024
1 parent f31df74 commit 23eabf9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
5 changes: 2 additions & 3 deletions examples/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 11 additions & 9 deletions src/Components/NetworkTable/NetworkTableBody.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,24 @@ const NetworkTableBody = ({ height }) => {
const totalNetworkTime = state.get('totalNetworkTime');
const selectedReqIndex = state.get('selectedReqIndex');

const ref = useRef(null);
const { elementDims } = useResizeObserver(ref?.current?._outerRef || ref?.current);
const listRef = useRef(null);
const { elementDims } = useResizeObserver(listRef);

useEffect(() => actions.setTableHeaderWidth(elementDims.width), [elementDims]);
useEffect(() => {
actions.setTableHeaderWidth(elementDims.width);
}, [elementDims]);

useEffect(() => {
if (enableAutoScroll && ref?.current?._outerRef) {
const outerRef = ref?.current?._outerRef;
if (enableAutoScroll && listRef?.current?._outerRef) {
const outerRef = listRef?.current?._outerRef;
const needToScroll = outerRef.scrollTop +
outerRef.offsetHeight +
(numberOfNewEntries * TABLE_ENTRY_HEIGHT) >= outerRef.scrollHeight;
if (needToScroll) {
ref.current._outerRef.scrollTop = outerRef.scrollHeight;
listRef.current._outerRef.scrollTop = outerRef.scrollHeight;
}
}
}, [data, ref]);
}, [data, listRef]);

const handleReqSelect = (payload) => {
if (selectedReqIndex === payload.index) {
Expand All @@ -80,7 +82,7 @@ const NetworkTableBody = ({ height }) => {
if (actualData.size === 0) {
return (
<div
ref={ref}
ref={listRef}
className={Styles['no-data']}
>
<IconNetworkRequest className={Styles['network-icon']} />
Expand All @@ -98,7 +100,7 @@ const NetworkTableBody = ({ height }) => {
return (
<>
<FixedSizeList
ref={ref}
ref={listRef}
className={Styles['network-table-body']}
height={height}
itemCount={data.size}
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useResizeObserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const useResizeObserver = (elementRef) => {
});

useEffect(() => {
ref = elementRef?.current;
ref = elementRef?.current?._outerRef || elementRef?.current;
const onResize = () => {
if (ref) {
setElementDims({
Expand Down

0 comments on commit 23eabf9

Please sign in to comment.