fix: ability to fetch separators by id (#15290)
This commit is contained in:
		
					parent
					
						
							
								6d844a0b67
							
						
					
				
			
			
				commit
				
					
						f9f34fd628
					
				
			
		
					 2 changed files with 29 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -17,10 +17,15 @@ function splitArray (arr, predicate) {
 | 
			
		|||
  return result
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function joinArrays (arrays, joiner) {
 | 
			
		||||
function joinArrays (arrays, joinIDs) {
 | 
			
		||||
  return arrays.reduce((joined, arr, i) => {
 | 
			
		||||
    if (i > 0 && arr.length) {
 | 
			
		||||
      joined.push(joiner)
 | 
			
		||||
      if (joinIDs.length > 0) {
 | 
			
		||||
        joined.push(joinIDs[0])
 | 
			
		||||
        joinIDs.splice(0, 1)
 | 
			
		||||
      } else {
 | 
			
		||||
        joined.push({ type: 'separator' })
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    return joined.concat(arr)
 | 
			
		||||
  }, [])
 | 
			
		||||
| 
						 | 
				
			
			@ -156,6 +161,7 @@ function sortGroups (groups) {
 | 
			
		|||
 | 
			
		||||
function sortMenuItems (menuItems) {
 | 
			
		||||
  const isSeparator = (item) => item.type === 'separator'
 | 
			
		||||
  const separators = menuItems.filter(i => i.type === 'separator')
 | 
			
		||||
 | 
			
		||||
  // Split the items into their implicit groups based upon separators.
 | 
			
		||||
  const groups = splitArray(menuItems, isSeparator)
 | 
			
		||||
| 
						 | 
				
			
			@ -163,7 +169,7 @@ function sortMenuItems (menuItems) {
 | 
			
		|||
  const mergedGroupsWithSortedItems = mergedGroups.map(sortItemsInGroup)
 | 
			
		||||
  const sortedGroups = sortGroups(mergedGroupsWithSortedItems)
 | 
			
		||||
 | 
			
		||||
  const joined = joinArrays(sortedGroups, { type: 'separator' })
 | 
			
		||||
  const joined = joinArrays(sortedGroups, separators)
 | 
			
		||||
  return joined
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue