Skip to content

Commit 77c3be8

Browse files
committed
Rename event. Test cleanup
1 parent e5d71cf commit 77c3be8

File tree

5 files changed

+46
-42
lines changed

5 files changed

+46
-42
lines changed

packages/x-data-grid-pro/src/hooks/features/infiniteLoader/useGridInfiniteLoader.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
useGridEventPriority,
55
gridVisibleColumnDefinitionsSelector,
66
useGridEvent,
7+
GridEventListener,
78
} from '@mui/x-data-grid';
89
import { useGridVisibleRows, runIf } from '@mui/x-data-grid/internals';
910
import useEventCallback from '@mui/utils/useEventCallback';
@@ -28,16 +29,18 @@ export const useGridInfiniteLoader = (
2829

2930
const isEnabled = props.rowsLoadingMode === 'client' && !!props.onRowsScrollEnd;
3031

31-
const handleLoadMoreRows = useEventCallback(() => {
32-
const viewportPageSize = apiRef.current.getViewportPageSize();
33-
const rowScrollEndParams: GridRowScrollEndParams = {
34-
visibleColumns,
35-
viewportPageSize,
36-
visibleRowsCount: currentPage.rows.length,
37-
};
38-
apiRef.current.publishEvent('rowsScrollEnd', rowScrollEndParams);
39-
});
32+
const handleLoadMoreRows: GridEventListener<'rowsScrollEndIntersection'> = useEventCallback(
33+
() => {
34+
const viewportPageSize = apiRef.current.getViewportPageSize();
35+
const rowScrollEndParams: GridRowScrollEndParams = {
36+
visibleColumns,
37+
viewportPageSize,
38+
visibleRowsCount: currentPage.rows.length,
39+
};
40+
apiRef.current.publishEvent('rowsScrollEnd', rowScrollEndParams);
41+
},
42+
);
4043

4144
useGridEventPriority(apiRef, 'rowsScrollEnd', props.onRowsScrollEnd);
42-
useGridEvent(apiRef, 'onIntersection', runIf(isEnabled, handleLoadMoreRows));
45+
useGridEvent(apiRef, 'rowsScrollEndIntersection', runIf(isEnabled, handleLoadMoreRows));
4346
};

packages/x-data-grid-pro/src/hooks/features/serverSideLazyLoader/useGridDataSourceLazyLoader.ts

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -347,32 +347,33 @@ export const useGridDataSourceLazyLoader = (
347347
privateApiRef.current.requestPipeProcessorsApplication('hydrateRows');
348348
}, [privateApiRef, updateLoadingTrigger, addSkeletonRows]);
349349

350-
const handleIntersection: GridEventListener<'onIntersection'> = React.useCallback(() => {
351-
if (rowsStale.current || loadingTrigger.current !== LoadingTrigger.SCROLL_END) {
352-
return;
353-
}
350+
const handleIntersection: GridEventListener<'rowsScrollEndIntersection'> =
351+
React.useCallback(() => {
352+
if (rowsStale.current || loadingTrigger.current !== LoadingTrigger.SCROLL_END) {
353+
return;
354+
}
354355

355-
const renderContext = gridRenderContextSelector(privateApiRef);
356-
if (previousLastRowIndex.current >= renderContext.lastRowIndex) {
357-
return;
358-
}
356+
const renderContext = gridRenderContextSelector(privateApiRef);
357+
if (previousLastRowIndex.current >= renderContext.lastRowIndex) {
358+
return;
359+
}
359360

360-
previousLastRowIndex.current = renderContext.lastRowIndex;
361+
previousLastRowIndex.current = renderContext.lastRowIndex;
361362

362-
const paginationModel = gridPaginationModelSelector(privateApiRef);
363-
const sortModel = gridSortModelSelector(privateApiRef);
364-
const filterModel = gridFilterModelSelector(privateApiRef);
365-
const getRowsParams: GridGetRowsParams = {
366-
start: renderContext.lastRowIndex,
367-
end: renderContext.lastRowIndex + paginationModel.pageSize - 1,
368-
sortModel,
369-
filterModel,
370-
};
363+
const paginationModel = gridPaginationModelSelector(privateApiRef);
364+
const sortModel = gridSortModelSelector(privateApiRef);
365+
const filterModel = gridFilterModelSelector(privateApiRef);
366+
const getRowsParams: GridGetRowsParams = {
367+
start: renderContext.lastRowIndex,
368+
end: renderContext.lastRowIndex + paginationModel.pageSize - 1,
369+
sortModel,
370+
filterModel,
371+
};
371372

372-
privateApiRef.current.setLoading(true);
373+
privateApiRef.current.setLoading(true);
373374

374-
fetchRows(adjustRowParams(getRowsParams));
375-
}, [privateApiRef, adjustRowParams, fetchRows]);
375+
fetchRows(adjustRowParams(getRowsParams));
376+
}, [privateApiRef, adjustRowParams, fetchRows]);
376377

377378
const handleRenderedRowsIntervalChange = React.useCallback<
378379
GridEventListener<'renderedRowsIntervalChange'>
@@ -504,7 +505,7 @@ export const useGridDataSourceLazyLoader = (
504505
);
505506
useGridEvent(
506507
privateApiRef,
507-
'onIntersection',
508+
'rowsScrollEndIntersection',
508509
runIf(lazyLoadingRowsUpdateStrategyActive, handleIntersection),
509510
);
510511
useGridEvent(

packages/x-data-grid-pro/src/hooks/features/serverSideLazyLoader/useGridIntersectionObserver.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const useGridIntersectionObserver = (
4646
observer.current?.disconnect();
4747
// do not observe this node anymore
4848
triggerElement.current = null;
49-
apiRef.current.publishEvent('onIntersection');
49+
apiRef.current.publishEvent('rowsScrollEndIntersection');
5050
}
5151
});
5252

packages/x-data-grid-pro/src/tests/dataSourceLazyLoader.DataGridPro.test.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ describeSkipIf(isJSDOM)('<DataGridPro /> - Data source lazy loader', () => {
254254
});
255255
});
256256

257-
it('should call make a new data source request when there is not enough rows to cover the viewport height', async () => {
257+
it('should make a new data source request when there is not enough rows to cover the viewport height', async () => {
258258
render(
259259
<TestDataSourceLazyLoader
260260
initialState={{
261-
pagination: { paginationModel: { page: 0, pageSize: 2 }, rowCount: undefined },
261+
pagination: { paginationModel: { page: 0, pageSize: 2 } },
262262
}}
263263
/>,
264264
);
@@ -270,12 +270,12 @@ describeSkipIf(isJSDOM)('<DataGridPro /> - Data source lazy loader', () => {
270270
expect(lastSearchParams.get('end')).to.equal('5'); // 6th row
271271
});
272272

273-
it('should call stop making data source requests if the new rows were not added on the last call', async () => {
273+
it('should stop making data source requests if the new rows were not added on the last call', async () => {
274274
render(
275275
<TestDataSourceLazyLoader
276276
mockServerRowCount={2}
277277
initialState={{
278-
pagination: { paginationModel: { page: 0, pageSize: 2 }, rowCount: undefined },
278+
pagination: { paginationModel: { page: 0, pageSize: 2 } },
279279
}}
280280
/>,
281281
);
@@ -344,7 +344,7 @@ describeSkipIf(isJSDOM)('<DataGridPro /> - Data source lazy loader', () => {
344344
describe('Row count updates', () => {
345345
it('should add skeleton rows once the rowCount becomes known', async () => {
346346
// override rowCount
347-
transformGetRowsResponse = (response) => ({ ...response, rowCount: undefined });
347+
transformGetRowsResponse = (response) => ({ ...response });
348348
const { setProps } = render(<TestDataSourceLazyLoader />);
349349
// wait until the rows are rendered
350350
await waitFor(() => expect(getRow(0)).not.to.be.undefined);
@@ -363,7 +363,7 @@ describeSkipIf(isJSDOM)('<DataGridPro /> - Data source lazy loader', () => {
363363

364364
it('should reset the grid if the rowCount becomes unknown', async () => {
365365
// override rowCount
366-
transformGetRowsResponse = (response) => ({ ...response, rowCount: undefined });
366+
transformGetRowsResponse = (response) => ({ ...response });
367367
const { setProps } = render(<TestDataSourceLazyLoader rowCount={100} />);
368368
// wait until the rows are rendered
369369
await waitFor(() => expect(getRow(0)).not.to.be.undefined);
@@ -380,7 +380,7 @@ describeSkipIf(isJSDOM)('<DataGridPro /> - Data source lazy loader', () => {
380380

381381
it('should reset the grid if the rowCount becomes smaller than the actual row count', async () => {
382382
// override rowCount
383-
transformGetRowsResponse = (response) => ({ ...response, rowCount: undefined });
383+
transformGetRowsResponse = (response) => ({ ...response });
384384
render(
385385
<TestDataSourceLazyLoader rowCount={100} paginationModel={{ page: 0, pageSize: 30 }} />,
386386
);
@@ -405,7 +405,7 @@ describeSkipIf(isJSDOM)('<DataGridPro /> - Data source lazy loader', () => {
405405

406406
it('should allow setting the row count via API', async () => {
407407
// override rowCount
408-
transformGetRowsResponse = (response) => ({ ...response, rowCount: undefined });
408+
transformGetRowsResponse = (response) => ({ ...response });
409409
render(<TestDataSourceLazyLoader />);
410410
// wait until the rows are rendered
411411
await waitFor(() => expect(getRow(0)).not.to.be.undefined);

packages/x-data-grid/src/models/events/gridEventLookup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ export interface GridEventLookup
577577
* Used to trigger infinite loading.
578578
* @ignore - do not document.
579579
*/
580-
onIntersection: {};
580+
rowsScrollEndIntersection: {};
581581

582582
// Selection
583583
/**

0 commit comments

Comments
 (0)