import { SelectableField } from '../column-selector' ; function getInnerFields ( childFields , parentPath , currentLevel = 1 ) { return childFields . reduce ( ( acc , cur ) => { const fieldPath = parentPath + '.' + cur . name ; const level = currentLevel + 1 ; const child = { field : cur , fieldPath , title : cur . type . title , level , sortable : true , } ; if ( cur . type ?. fields ?. length ) { child . sortable = false ; const children = cur . type . fields ; const innerFields = getInnerFields ( children , fieldPath , level ) ; if ( innerFields . length ) { return [ ... acc , child , ... innerFields ] ; } } return [ ... acc , child ] ; } , [ ] ) ; } export function getSelectableFields ( fields = [ ] ) { if ( ! fields . length ) return [ ] ; const selectable = fields . reduce ( ( acc , cur ) => { const fieldPath = cur . name ; const title = cur . type . title ; const parent = { field : cur , fieldPath , title , level : 0 , sortable : true } ; if ( cur . type ?. fields ?. length ) { parent . sortable = false ; const children = cur . type . fields ; const innerFields = getInnerFields ( children , fieldPath , 1 ) ; if ( innerFields . length ) { return [ ... acc , parent , ... innerFields ] ; } } return [ ... acc , parent ] ; } , [ ] ) ; return selectable ; }