Skip to content

Commit f04e637

Browse files
committed
update docs
1 parent e470b77 commit f04e637

3 files changed

Lines changed: 170 additions & 0 deletions

File tree

.github/workflows/rebuild-website.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
GITHUB_PAT: ${{ secrets.DEPLOY_GITHUB_TOKEN }}
3030
READ_GITHUB_ISSUES_TOKEN: ${{ secrets.READ_GITHUB_ISSUES_TOKEN }}
3131
NEXT_PUBLIC_INFINITE_LICENSE_KEY: ${{ secrets.NEXT_PUBLIC_INFINITE_LICENSE_KEY }}
32+
NEXT_PUBLIC_INFINITE_ALLOW_CANARY_IN_DOCS: ${{ secrets.NEXT_PUBLIC_INFINITE_ALLOW_CANARY_IN_DOCS }}
3233
NEXT_PUBLIC_PADDLE_SUBSCRIPTION_PLAIN_ID: ${{ secrets.NEXT_PUBLIC_PADDLE_SUBSCRIPTION_PLAIN_ID }}
3334
NEXT_PUBLIC_PADDLE_VENDOR_ID: ${{ secrets.NEXT_PUBLIC_PADDLE_VENDOR_ID }}
3435
NEXT_PUBLIC_PADDLE_VOLUME_DISCOUNT_TEST_3_LINK: ${{ secrets.NEXT_PUBLIC_PADDLE_VOLUME_DISCOUNT_TEST_3_LINK }}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import * as React from 'react';
2+
3+
import {
4+
InfiniteTable,
5+
DataSource,
6+
InfiniteTableColumn,
7+
useDataSourceState,
8+
DataSourceState,
9+
DataSourceProps,
10+
} from '@infinite-table/infinite-react';
11+
import { CarSale } from '@examples/datasets/CarSale';
12+
13+
const carsales: CarSale[] = [
14+
{
15+
category: '1 - Category 1 Truck',
16+
make: 'Acura',
17+
model: 'RDX 2WD',
18+
year: 2010,
19+
sales: 15,
20+
color: 'red',
21+
id: 0,
22+
},
23+
{
24+
category: '1 - Category 1 Truck',
25+
make: 'Acura',
26+
model: 'RDX 4WD',
27+
year: 2007,
28+
sales: 1,
29+
color: 'red',
30+
id: 1,
31+
},
32+
{
33+
category: '1 - Category 1 Truck',
34+
make: 'Acura',
35+
model: 'RDX 4WD',
36+
year: 2008,
37+
sales: 2,
38+
color: 'magenta',
39+
id: 2,
40+
},
41+
{
42+
category: '1 - Category 1 Truck',
43+
make: 'Acura',
44+
model: 'RDX 4WD',
45+
year: 2009,
46+
sales: 136,
47+
color: 'blue',
48+
id: 3,
49+
},
50+
{
51+
category: '1 - Category 1 Truck',
52+
make: 'Acura',
53+
model: 'RDX 4WD',
54+
year: 2010,
55+
color: 'blue',
56+
sales: 30,
57+
id: 4,
58+
},
59+
{
60+
category: '1 - Category 1 Truck',
61+
make: 'Acura',
62+
model: 'TSX',
63+
year: 2009,
64+
sales: 14,
65+
color: 'yellow',
66+
id: 5,
67+
},
68+
{
69+
category: '1 - Category 1 Truck',
70+
make: 'Acura',
71+
model: 'TSX',
72+
year: 2010,
73+
sales: 14,
74+
color: 'red',
75+
id: 6,
76+
},
77+
{
78+
category: '1 - Category 1 Truck',
79+
make: 'Audi',
80+
model: 'A3',
81+
year: 2009,
82+
sales: 2,
83+
color: 'magenta',
84+
id: 7,
85+
},
86+
];
87+
88+
(globalThis as any).carsales = carsales;
89+
90+
const columns: Record<string, InfiniteTableColumn<CarSale>> = {
91+
make: { field: 'make' },
92+
model: { field: 'model' },
93+
94+
category: {
95+
field: 'category',
96+
},
97+
count: {
98+
field: 'sales',
99+
},
100+
year: {
101+
field: 'year',
102+
type: 'number',
103+
},
104+
};
105+
106+
function AppGrid() {
107+
const dataArrayLength = useDataSourceState(
108+
(state: DataSourceState<CarSale>) => state.dataArray.length,
109+
);
110+
return (
111+
<div>
112+
<p data-name="test">Showing {dataArrayLength} rows.</p>
113+
<InfiniteTable<CarSale>
114+
debugId="test"
115+
domProps={{
116+
style: {
117+
margin: '5px',
118+
height: 900,
119+
border: '1px solid gray',
120+
position: 'relative',
121+
},
122+
}}
123+
columns={columns}
124+
/>
125+
</div>
126+
);
127+
}
128+
129+
const groupRowsState: DataSourceProps<CarSale>['defaultGroupRowsState'] = {
130+
expandedRows: true,
131+
collapsedRows: [[2010]],
132+
};
133+
134+
export default function DataTestPage() {
135+
return (
136+
<React.StrictMode>
137+
<DataSource<CarSale>
138+
data={carsales}
139+
primaryKey="id"
140+
defaultGroupBy={[{ field: 'year' }]}
141+
defaultGroupRowsState={groupRowsState}
142+
>
143+
<AppGrid />
144+
</DataSource>
145+
</React.StrictMode>
146+
);
147+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { test, expect } from '@testing';
2+
3+
export default test.describe.parallel('DataSource hook', () => {
4+
test('should properly update component when state changes', async ({
5+
page,
6+
rowModel,
7+
}) => {
8+
await page.waitForInfinite();
9+
10+
const p = page.locator('p[data-name="test"]');
11+
12+
expect(await p.innerText()).toBe('Showing 9 rows.');
13+
14+
expect(await rowModel.getRenderedRowCount()).toBe(9);
15+
16+
await rowModel.toggleGroupRow(0);
17+
18+
expect(await p.innerText()).toBe('Showing 12 rows.');
19+
20+
expect(await rowModel.getRenderedRowCount()).toBe(12);
21+
});
22+
});

0 commit comments

Comments
 (0)