Skip to content

Commit

Permalink
Auto scroll to bottom for dynamic data (#140)
Browse files Browse the repository at this point in the history
* auto scroll to bottom if at the bottom

* adjust scroll check
  • Loading branch information
yuyi-sl authored Aug 10, 2024
1 parent 7c0da02 commit ab6170a
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/Components/Common/Checkbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const Checkbox = ({
<input
checked={isChecked}
className={Styles.checkbox}
name="checkbox"
onChange={onChange}
type="checkbox"
/>
Expand Down
1 change: 1 addition & 0 deletions src/Components/Filters/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const Search = ({
return (
<input
className={Styles['search-input']}
name="search"
onChange={handleInputChange}
placeholder="Search by URL"
type="text"
Expand Down
1 change: 1 addition & 0 deletions src/Components/Import/URLInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const URLInput = ({ onSubmit }) => {
/>
<input
className={Styles.input}
name="har-url"
onChange={handleInputChange}
placeholder="HAR file URL"
type="text"
Expand Down
40 changes: 26 additions & 14 deletions src/Components/NetworkTable/NetworkTableBody.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import NetworkTableRow from './NetworkTableRow';
import { TABLE_ENTRY_HEIGHT } from '../../constants';
import { useResizeObserver } from '../../hooks/useResizeObserver';

/* eslint no-underscore-dangle: 0 */

const virtualizedTableRow = ({
data,
index,
Expand Down Expand Up @@ -44,29 +46,39 @@ const NetworkTableBody = ({ height }) => {

const ref = useRef(null);
const { elementDims } = useResizeObserver(ref);

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

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

const handleReqSelect = (payload) => {
actions.updateScrollToIndex(payload.index);
actions.selectRequest(payload);
callbacks.onRequestSelect(payload);
};

return (
<FixedSizeList
ref={ref}
height={height}
itemCount={data.size}
itemData={{
listData: data,
totalNetworkTime,
handleReqSelect,
selectedReqIndex,
}}
itemSize={TABLE_ENTRY_HEIGHT}
>
{virtualizedTableRow}
</FixedSizeList>
<>
<FixedSizeList
ref={ref}
height={height}
itemCount={data.size}
itemData={{
listData: data,
totalNetworkTime,
handleReqSelect,
selectedReqIndex,
}}
itemSize={TABLE_ENTRY_HEIGHT}
>
{virtualizedTableRow}
</FixedSizeList>
</>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ exports[`Search renders without crashing 1`] = `
value="test"
>
<input
name="search"
onChange={[Function]}
placeholder="Search by URL"
type="text"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ exports[`FilterContainer renders without crashing 1`] = `
value=""
>
<input
name="search"
onChange={[Function]}
placeholder="Search by URL"
type="text"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ exports[`MainContainer renders without crashing 1`] = `
value=""
>
<input
name="search"
onChange={[Function]}
placeholder="Search by URL"
type="text"
Expand Down Expand Up @@ -584,6 +585,7 @@ exports[`MainContainer renders without crashing 1`] = `
>
<input
checked={false}
name="checkbox"
onChange={[Function]}
type="checkbox"
/>
Expand All @@ -593,6 +595,7 @@ exports[`MainContainer renders without crashing 1`] = `
</Checkbox>
</CORSCheckbox>
<input
name="har-url"
onChange={[Function]}
placeholder="HAR file URL"
type="text"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ exports[`NetworkTableContainer renders without crashing 1`] = `
>
<input
checked={false}
name="checkbox"
onChange={[Function]}
type="checkbox"
/>
Expand All @@ -132,6 +133,7 @@ exports[`NetworkTableContainer renders without crashing 1`] = `
</Checkbox>
</CORSCheckbox>
<input
name="har-url"
onChange={[Function]}
placeholder="HAR file URL"
type="text"
Expand Down

0 comments on commit ab6170a

Please sign in to comment.