@@ -11,7 +11,7 @@ import { partition, throttle } from 'lodash';
1111import React , { Fragment , useCallback , useEffect , useMemo , useState } from 'react' ;
1212import useLocalStorage from 'react-use/lib/useLocalStorage' ;
1313import { i18n } from '@kbn/i18n' ;
14- import { EuiScreenReaderOnly , EuiSpacer } from '@elastic/eui' ;
14+ import { EuiScreenReaderOnly , EuiSpacer , EuiSkipLink , useGeneratedHtmlId } from '@elastic/eui' ;
1515import { type DataViewField } from '@kbn/data-views-plugin/common' ;
1616import { NoFieldsCallout } from './no_fields_callout' ;
1717import { FieldsAccordion , type FieldsAccordionProps , getFieldKey } from './fields_accordion' ;
@@ -59,6 +59,8 @@ function InnerFieldListGrouped<T extends FieldListItem = DataViewField>({
5959 const hasSyncedExistingFields =
6060 fieldsExistenceStatus && fieldsExistenceStatus !== ExistenceFetchStatus . unknown ;
6161
62+ const buttonIdPrefix = useGeneratedHtmlId ( { prefix : 'fieldListGroupedButton' } ) ;
63+
6264 const [ fieldGroupsToShow , fieldGroupsToCollapse ] = partition (
6365 Object . entries ( fieldGroups ) ,
6466 ( [ , { showInAccordion } ] ) => showInAccordion
@@ -243,66 +245,83 @@ function InnerFieldListGrouped<T extends FieldListItem = DataViewField>({
243245 < EuiSpacer size = "s" />
244246 </ >
245247 ) }
246- { fieldGroupsToShow . map ( ( [ key , fieldGroup ] , index ) => {
247- const hidden = Boolean ( fieldGroup . hideIfEmpty ) && ! fieldGroup . fields . length ;
248- if ( hidden ) {
249- return null ;
250- }
251- return (
252- < Fragment key = { key } >
253- < FieldsAccordion < T >
254- id = { `${ dataTestSubject } ${ key } ` }
255- initialIsOpen = { Boolean ( accordionState [ key ] ) }
256- label = { fieldGroup . title }
257- helpTooltip = { fieldGroup . helpText }
258- hideDetails = { fieldGroup . hideDetails }
259- hasLoaded = { hasSyncedExistingFields }
260- fieldsCount = { fieldGroup . fields . length }
261- isFiltered = { fieldGroup . fieldCount !== fieldGroup . fields . length }
262- fieldSearchHighlight = { fieldGroup . fieldSearchHighlight }
263- paginatedFields = { paginatedFields [ key ] }
264- groupIndex = { index + 1 }
265- groupName = { key as FieldsGroupNames }
266- onToggle = { ( open ) => {
267- setAccordionState ( ( s ) => ( {
268- ...s ,
269- [ key ] : open ,
270- } ) ) ;
271- const displayedFieldLength = getDisplayedFieldsLength ( fieldGroups , {
272- ...accordionState ,
273- [ key ] : open ,
274- } ) ;
275- setPageSize (
276- Math . max (
277- PAGINATION_SIZE ,
278- Math . min ( Math . ceil ( pageSize * 1.5 ) , displayedFieldLength )
279- )
280- ) ;
281- if ( localStorageKeyPrefix ) {
282- storeInitiallyOpenSections ( {
283- ...storedInitiallyOpenSections ,
248+ { fieldGroupsToShow
249+ . filter ( ( [ _ , fieldGroup ] ) => {
250+ if ( fieldGroup . fields . length ) return true ;
251+ return ! Boolean ( fieldGroup . hideIfEmpty ) ;
252+ } )
253+ . map ( ( [ key , fieldGroup ] , index , _fieldGroupsToShow ) => {
254+ const nextFieldGroup = _fieldGroupsToShow . at ( index + 1 ) ;
255+
256+ return (
257+ < Fragment key = { key } >
258+ < FieldsAccordion < T >
259+ id = { `${ dataTestSubject } ${ key } ` }
260+ buttonId = { `${ buttonIdPrefix } ${ key } ` }
261+ initialIsOpen = { Boolean ( accordionState [ key ] ) }
262+ label = { fieldGroup . title }
263+ helpTooltip = { fieldGroup . helpText }
264+ hideDetails = { fieldGroup . hideDetails }
265+ hasLoaded = { hasSyncedExistingFields }
266+ fieldsCount = { fieldGroup . fields . length }
267+ isFiltered = { fieldGroup . fieldCount !== fieldGroup . fields . length }
268+ fieldSearchHighlight = { fieldGroup . fieldSearchHighlight }
269+ paginatedFields = { paginatedFields [ key ] }
270+ groupIndex = { index + 1 }
271+ groupName = { key as FieldsGroupNames }
272+ onToggle = { ( open ) => {
273+ setAccordionState ( ( s ) => ( {
274+ ...s ,
275+ [ key ] : open ,
276+ } ) ) ;
277+ const displayedFieldLength = getDisplayedFieldsLength ( fieldGroups , {
278+ ...accordionState ,
284279 [ key ] : open ,
285280 } ) ;
281+ setPageSize (
282+ Math . max (
283+ PAGINATION_SIZE ,
284+ Math . min ( Math . ceil ( pageSize * 1.5 ) , displayedFieldLength )
285+ )
286+ ) ;
287+ if ( localStorageKeyPrefix ) {
288+ storeInitiallyOpenSections ( {
289+ ...storedInitiallyOpenSections ,
290+ [ key ] : open ,
291+ } ) ;
292+ }
293+ } }
294+ showExistenceFetchError = { fieldsExistenceStatus === ExistenceFetchStatus . failed }
295+ showExistenceFetchTimeout = { fieldsExistenceStatus === ExistenceFetchStatus . failed } // TODO: deprecate timeout logic?
296+ renderCallout = { ( ) => (
297+ < NoFieldsCallout
298+ isAffectedByGlobalFilter = { fieldGroup . isAffectedByGlobalFilter }
299+ isAffectedByTimerange = { fieldGroup . isAffectedByTimeFilter }
300+ isAffectedByFieldFilter = { fieldGroup . fieldCount !== fieldGroup . fields . length }
301+ fieldsExistInIndex = { ! ! fieldsExistInIndex }
302+ defaultNoFieldsMessage = { fieldGroup . defaultNoFieldsMessage }
303+ data-test-subj = { `${ dataTestSubject } ${ key } NoFieldsCallout` }
304+ />
305+ ) }
306+ renderFieldItem = { renderFieldItem }
307+ extraAction = {
308+ nextFieldGroup ? (
309+ < EuiSkipLink
310+ overrideLinkBehavior
311+ destinationId = { `${ buttonIdPrefix } ${ nextFieldGroup [ 0 ] } ` }
312+ >
313+ { i18n . translate ( 'unifiedFieldList.fieldListGrouped.goToNextGroupLink' , {
314+ defaultMessage : 'Go to {nextFieldGroup}' ,
315+ values : { nextFieldGroup : nextFieldGroup [ 1 ] . title } ,
316+ } ) }
317+ </ EuiSkipLink >
318+ ) : null
286319 }
287- } }
288- showExistenceFetchError = { fieldsExistenceStatus === ExistenceFetchStatus . failed }
289- showExistenceFetchTimeout = { fieldsExistenceStatus === ExistenceFetchStatus . failed } // TODO: deprecate timeout logic?
290- renderCallout = { ( ) => (
291- < NoFieldsCallout
292- isAffectedByGlobalFilter = { fieldGroup . isAffectedByGlobalFilter }
293- isAffectedByTimerange = { fieldGroup . isAffectedByTimeFilter }
294- isAffectedByFieldFilter = { fieldGroup . fieldCount !== fieldGroup . fields . length }
295- fieldsExistInIndex = { ! ! fieldsExistInIndex }
296- defaultNoFieldsMessage = { fieldGroup . defaultNoFieldsMessage }
297- data-test-subj = { `${ dataTestSubject } ${ key } NoFieldsCallout` }
298- />
299- ) }
300- renderFieldItem = { renderFieldItem }
301- />
302- < EuiSpacer size = "m" />
303- </ Fragment >
304- ) ;
305- } ) }
320+ />
321+ < EuiSpacer size = "m" />
322+ </ Fragment >
323+ ) ;
324+ } ) }
306325 </ div >
307326 </ div >
308327 ) ;
0 commit comments