@@ -2,7 +2,7 @@ import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useRef,
2
2
import { useDispatch , useSelector } from 'react-redux'
3
3
import cx from 'classnames'
4
4
import { useParams } from 'react-router-dom'
5
- import { debounce , isUndefined , reject } from 'lodash'
5
+ import { debounce , findIndex , isUndefined , reject } from 'lodash'
6
6
7
7
import {
8
8
EuiText ,
@@ -189,39 +189,25 @@ const KeyList = forwardRef((props: Props, ref) => {
189
189
const isSomeNotUndefined = ( { type, size, length } : GetKeyInfoResponse ) =>
190
190
! isUndefined ( type ) || ! isUndefined ( size ) || ! isUndefined ( length )
191
191
192
- const emptyItems = reject ( itemsInit , isSomeNotUndefined )
192
+ const firstEmptyItemIndex = findIndex ( itemsInit , ( item ) => ! isSomeNotUndefined ( item ) )
193
+ if ( firstEmptyItemIndex === - 1 ) return
193
194
194
- if ( ! emptyItems . length ) return
195
+ const emptyItems = reject ( itemsInit , isSomeNotUndefined )
195
196
196
197
dispatch ( fetchKeysMetadata (
197
198
emptyItems . map ( ( { name } ) => name ) ,
198
199
( loadedItems ) =>
199
- onSuccessFetchedMetadata ( {
200
- startIndex,
201
- lastIndex,
202
- loadedItems,
203
- isFirstEmpty : ! isSomeNotUndefined ( itemsInit [ 0 ] ) ,
204
- } ) ,
200
+ onSuccessFetchedMetadata ( startIndex + firstEmptyItemIndex , loadedItems ) ,
205
201
( ) => { rerender ( { } ) }
206
202
) )
207
203
}
208
204
209
- const onSuccessFetchedMetadata = ( data : {
205
+ const onSuccessFetchedMetadata = (
210
206
startIndex : number ,
211
- lastIndex : number ,
212
- isFirstEmpty : boolean
213
207
loadedItems : GetKeyInfoResponse [ ] ,
214
- } ) => {
215
- const {
216
- startIndex,
217
- lastIndex,
218
- isFirstEmpty,
219
- loadedItems,
220
- } = data
208
+ ) => {
221
209
const items = loadedItems . map ( formatItem )
222
- const startIndexDel = isFirstEmpty ? startIndex : lastIndex - items . length + 1
223
-
224
- itemsRef . current . splice ( startIndexDel , items . length , ...items )
210
+ itemsRef . current . splice ( startIndex , items . length , ...items )
225
211
226
212
rerender ( { } )
227
213
}
0 commit comments