Skip to content

Commit e1d765a

Browse files
committed
docs(NavigationTree): virtualized render in storyboook
1 parent 7388ff5 commit e1d765a

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

src/components/NavigationTree/__stories__/NavigationTree.stories.tsx

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@ export const Default: Story<NavigationTreeProps> = () => {
2727
);
2828
};
2929

30+
export const Virtualized: Story<NavigationTreeProps> = () => {
31+
const [activePath, setActivePath] = React.useState('');
32+
33+
return (
34+
<NavigationTree
35+
rootState={{
36+
path: '',
37+
name: 'ru/maps/maps_prod',
38+
type: 'database',
39+
collapsed: false,
40+
}}
41+
fetchPath={fetchPathWithLargeResults}
42+
getActions={getActions}
43+
activePath={activePath}
44+
onActivePathUpdate={setActivePath}
45+
virtualize
46+
/>
47+
);
48+
};
49+
3050
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
3151

3252
async function fetchPath(path: string) {
@@ -92,6 +112,68 @@ async function fetchPath(path: string) {
92112
return items;
93113
}
94114

115+
async function fetchPathWithLargeResults(path: string) {
116+
let items: NavigationTreeDataItem[] = [];
117+
console.log(`Fetching "${path}"...`);
118+
119+
await sleep(1000);
120+
121+
if (path === '') {
122+
items = [
123+
{
124+
name: '200_items',
125+
type: 'directory',
126+
},
127+
{
128+
name: 'folder_with_error',
129+
type: 'directory',
130+
},
131+
{
132+
name: '10000_items',
133+
type: 'directory',
134+
},
135+
{
136+
name: 'table_1',
137+
type: 'table',
138+
},
139+
{
140+
name: 'table_2',
141+
type: 'table',
142+
},
143+
{
144+
name: 'table_3',
145+
type: 'table',
146+
},
147+
];
148+
}
149+
150+
if (path === '/200_items') {
151+
items = [];
152+
for (let i = 1; i < 200; i++) {
153+
items.push({
154+
name: `item_${i}`,
155+
type: 'table',
156+
});
157+
}
158+
}
159+
160+
if (path === '/folder_with_error') {
161+
throw new Error('Ошибка');
162+
}
163+
164+
if (path === '/10000_items') {
165+
items = [];
166+
for (let i = 1; i < 10000; i++) {
167+
items.push({
168+
name: `item_${i}`,
169+
type: 'table',
170+
});
171+
}
172+
}
173+
174+
return items;
175+
}
176+
95177
function getActions(path: string, type: NavigationTreeNodeType) {
96178
if (type === 'directory') {
97179
return [{text: 'Show Directory', action: () => alert(`Directory path is "${path}"`)}];

0 commit comments

Comments
 (0)