Skip to content

Commit b89ef20

Browse files
committed
Add lazy load
Signed-off-by: Lan Xia <[email protected]>
1 parent b6415a5 commit b89ef20

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

test-result-summary-client/src/Build/TopLevelBuildTable.jsx

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { params } from '../utils/query';
77
import { fetchData, setBuildsStatus } from '../utils/Utils';
88
import BuildLink from './BuildLink';
99
import BuildStatus from './Summary/BuildStatus';
10+
import { useVisibility } from 'reactjs-visibility';
1011

1112
// Set the page size for the table.
1213
const pageSize = 5;
@@ -18,11 +19,12 @@ function TopLevelBuildTable(props) {
1819
// Declare two state variables, currentPage and buildInfo, using the useState hook.
1920
const [currentPage, setCurrentPage] = useState(1);
2021
const [buildInfo, setBuildInfo] = useState([]);
22+
const { ref, visible } = useVisibility();
2123

2224
// Use the useEffect hook to fetch data and update the component state when certain props or state variables change.
2325
useEffect(() => {
24-
fetchDataAndUpdate();
25-
}, [buildName, url, currentPage]);
26+
if (visible && !buildInfo.length) fetchDataAndUpdate();
27+
}, [buildName, url, currentPage, visible]);
2628

2729
// Declare a function that updates the totals for each build.
2830
async function updateTotals(buildInfo) {
@@ -415,27 +417,30 @@ function TopLevelBuildTable(props) {
415417
];
416418

417419
return (
418-
<Table
419-
columns={columns}
420-
dataSource={buildInfo}
421-
title={() => (
422-
<div>
423-
<Link
424-
to={{
425-
pathname: '/builds',
426-
search: params({
427-
buildName,
428-
url,
429-
type,
430-
}),
431-
}}
432-
>
433-
<b>{buildName}</b> in server {url}
434-
</Link>
435-
</div>
436-
)}
437-
pagination={{ pageSize, onChange }}
438-
/>
420+
<div ref={ref}>
421+
<Table
422+
columns={columns}
423+
dataSource={buildInfo}
424+
title={() => (
425+
<div>
426+
<Link
427+
to={{
428+
pathname: '/builds',
429+
search: params({
430+
buildName,
431+
url,
432+
type,
433+
}),
434+
}}
435+
>
436+
<b>{buildName}</b> in server {url}
437+
</Link>
438+
</div>
439+
)}
440+
pagination={{ pageSize, onChange }}
441+
/>
442+
{!buildInfo.length && <div style={{ height: 1000 }} />}
443+
</div>
439444
);
440445
}
441446
}

0 commit comments

Comments
 (0)