@@ -27,6 +27,26 @@ export const Default: Story<NavigationTreeProps> = () => {
27
27
) ;
28
28
} ;
29
29
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
+
30
50
const sleep = ( ms : number ) => new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
31
51
32
52
async function fetchPath ( path : string ) {
@@ -92,6 +112,68 @@ async function fetchPath(path: string) {
92
112
return items ;
93
113
}
94
114
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
+
95
177
function getActions ( path : string , type : NavigationTreeNodeType ) {
96
178
if ( type === 'directory' ) {
97
179
return [ { text : 'Show Directory' , action : ( ) => alert ( `Directory path is "${ path } "` ) } ] ;
0 commit comments