-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add onRenderRangeChange and release version patch
- Loading branch information
1 parent
a587aa8
commit 6a00d4c
Showing
7 changed files
with
186 additions
and
1 deletion.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
examples/src/pages/tests/table/props/scrolling/onRenderRangeChange.page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import * as React from 'react'; | ||
|
||
import { | ||
InfiniteTable, | ||
InfiniteTablePropColumns, | ||
DataSourceData, | ||
ScrollStopInfo, | ||
debounce, | ||
} from '@infinite-table/infinite-react'; | ||
import { DataSource } from '@infinite-table/infinite-react'; | ||
import { TableRenderRange } from '@src/components/VirtualBrain/MatrixBrain'; | ||
|
||
type Developer = { | ||
id: number; | ||
firstName: string; | ||
lastName: string; | ||
country: string; | ||
city: string; | ||
currency: string; | ||
|
||
email: string; | ||
preferredLanguage: string; | ||
stack: string; | ||
canDesign: 'yes' | 'no'; | ||
hobby: string; | ||
salary: number; | ||
age: number; | ||
}; | ||
|
||
const columns: InfiniteTablePropColumns<Developer> = { | ||
index: { | ||
renderValue: ({ rowInfo }) => { | ||
return `${rowInfo.indexInAll}`; | ||
}, | ||
}, | ||
preferredLanguage: { | ||
field: 'preferredLanguage', | ||
}, | ||
salary: { | ||
field: 'salary', | ||
type: 'number', | ||
}, | ||
age: { field: 'age' }, | ||
city: { field: 'city' }, | ||
email: { field: 'email' }, | ||
canDesign: { field: 'canDesign' }, | ||
stack: { field: 'stack' }, | ||
}; | ||
|
||
const dataSource: DataSourceData<Developer> = ({}) => { | ||
return fetch(process.env.NEXT_PUBLIC_BASE_URL + `/developers10k-sql`) | ||
.then((r) => r.json()) | ||
.then((data: Developer[]) => data); | ||
}; | ||
|
||
const sinon = require('sinon'); | ||
|
||
const onRenderRangeChange = sinon.spy((_scrollInfo: ScrollStopInfo) => {}); | ||
|
||
(globalThis as any).onRenderRangeChange = onRenderRangeChange; | ||
|
||
export default () => { | ||
const fn = React.useMemo(() => { | ||
return debounce( | ||
(range: TableRenderRange) => { | ||
console.log(range); | ||
onRenderRangeChange(range); | ||
}, | ||
{ wait: 10 }, | ||
); | ||
}, []); | ||
return ( | ||
<React.StrictMode> | ||
<> | ||
<DataSource<Developer> data={dataSource} primaryKey="id"> | ||
<InfiniteTable<Developer> | ||
domProps={{ | ||
style: { | ||
margin: '5px', | ||
height: '60vh', | ||
width: '80vw', | ||
border: '1px solid gray', | ||
position: 'relative', | ||
}, | ||
}} | ||
columnMinWidth={50} | ||
columnDefaultWidth={350} | ||
onRenderRangeChange={fn} | ||
columns={columns} | ||
/> | ||
</DataSource> | ||
</> | ||
</React.StrictMode> | ||
); | ||
}; |
29 changes: 29 additions & 0 deletions
29
examples/src/pages/tests/table/props/scrolling/onRenderRangeChange.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { getFnCalls } from '../../../testUtils/getFnCalls'; | ||
import { test, expect } from '@testing'; | ||
|
||
export default test.describe.parallel('onRenderRangeChange', () => { | ||
test('should correctly be called', async ({ page, apiModel }) => { | ||
await page.waitForInfinite(); | ||
|
||
let calls = await getFnCalls('onRenderRangeChange', { page }); | ||
expect(calls.length).toEqual(1); | ||
|
||
await apiModel.evaluate((api) => { | ||
return api.scrollRowIntoView(100); | ||
}); | ||
await page.waitForTimeout(50); | ||
|
||
calls = await getFnCalls('onRenderRangeChange', { page }); | ||
expect(calls.length).toEqual(2); | ||
|
||
await page.setViewportSize({ | ||
width: 500, | ||
height: 500, | ||
}); | ||
|
||
await page.waitForTimeout(100); | ||
|
||
calls = await getFnCalls('onRenderRangeChange', { page }); | ||
expect(calls.length).toEqual(3); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters