Skip to content

Commit d81e15b

Browse files
authored
Add custom tracks for chrome devtools
1 parent babad28 commit d81e15b

File tree

12 files changed

+708
-69
lines changed

12 files changed

+708
-69
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import * as React from 'react';
2+
3+
import {
4+
InfiniteTable,
5+
DataSource,
6+
InfiniteTablePropColumns,
7+
} from '@infinite-table/infinite-react';
8+
import { useState } from 'react';
9+
10+
type Developer = {
11+
id: number;
12+
firstName: string;
13+
lastName: string;
14+
country: string;
15+
city: string;
16+
currency: string;
17+
preferredLanguage: string;
18+
stack: string;
19+
canDesign: 'yes' | 'no';
20+
hobby: string;
21+
salary: number;
22+
age: number;
23+
streetName: string;
24+
streetNo: number;
25+
streetPrefix: string;
26+
};
27+
28+
const dataSource: () => Promise<Developer[]> = () => {
29+
return fetch(`${process.env.NEXT_PUBLIC_BASE_URL}/developers10k-sql`)
30+
.then((r) => r.json())
31+
.then((data: Developer[]) => {
32+
// random delay between 100 and 1000ms
33+
const delay = Math.floor(Math.random() * 900) + 100;
34+
return new Promise((resolve) => {
35+
setTimeout(() => {
36+
resolve(data);
37+
}, delay);
38+
});
39+
});
40+
};
41+
42+
const columns: InfiniteTablePropColumns<Developer> = {
43+
id: { field: 'id' },
44+
firstName: { field: 'firstName' },
45+
age: {
46+
field: 'age',
47+
type: ['number'],
48+
},
49+
salary: {
50+
field: 'salary',
51+
type: ['number', 'currency'],
52+
style: {
53+
color: 'red',
54+
},
55+
},
56+
57+
currency: { field: 'currency' },
58+
};
59+
60+
export default function DataTestPage() {
61+
const [data, setData] = useState<typeof dataSource>(() => dataSource);
62+
return (
63+
<>
64+
<button
65+
onClick={() => {
66+
setData(() => dataSource.bind(null));
67+
}}
68+
>
69+
reload
70+
</button>
71+
<React.StrictMode>
72+
<DataSource<Developer>
73+
data={data}
74+
primaryKey="id"
75+
defaultGroupBy={[{ field: 'age' }]}
76+
>
77+
<InfiniteTable<Developer>
78+
debugId="test"
79+
domProps={{
80+
style: {
81+
margin: '5px',
82+
height: '80vh',
83+
border: '1px solid gray',
84+
position: 'relative',
85+
},
86+
}}
87+
columns={columns}
88+
>
89+
<InfiniteTable.GroupingToolbar />
90+
<InfiniteTable.Header />
91+
<InfiniteTable.Body />
92+
</InfiniteTable>
93+
</DataSource>
94+
</React.StrictMode>
95+
</>
96+
);
97+
}

examples/src/pages/tests/table/props/group-by/server-side-group-and-agg-with-child-dataset.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default test.describe
2828
// wait for Canada to be loaded as well, from the remote location
2929
await page.waitForRequest(condition);
3030
// also wait for node to be expanded
31-
await page.waitForTimeout(80);
31+
await page.waitForTimeout(150);
3232

3333
const queryStrings = urls.map((url) => url.slice(url.indexOf('?')));
3434

source/src/components/DataSource/privateHooks/useLoadData.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333

3434
import { getChangeDetect } from './getChangeDetect';
3535
import { logDevToolsWarning } from '../../../utils/debugModeUtils';
36+
import { DevToolsMarker, getMarker } from '../../../utils/devTools';
3637

3738
const CACHE_DEFAULT = true;
3839

@@ -694,6 +695,13 @@ export function useLoadData<T>(options: LoadDataOptions<T>) {
694695

695696
const componentState = getComponentState();
696697
if (typeof componentState.data === 'function') {
698+
let marker: DevToolsMarker | undefined;
699+
700+
if (componentState.debugId) {
701+
marker = getMarker(
702+
componentState.debugId,
703+
).track.DataSource.label.RemoteDataLoad.start();
704+
}
697705
loadData(
698706
componentState.data,
699707
componentState,
@@ -702,7 +710,9 @@ export function useLoadData<T>(options: LoadDataOptions<T>) {
702710
append: appendWhenLivePagination,
703711
},
704712
masterContext,
705-
);
713+
).then(() => {
714+
marker?.end();
715+
});
706716
}
707717
},
708718
{ ...depsObject, data },

0 commit comments

Comments
 (0)