Group items by source type for display, sorted by tokens descending within each group
(items: T[])
| 75 | |
| 76 | /** Group items by source type for display, sorted by tokens descending within each group */ |
| 77 | function groupBySource<T extends { |
| 78 | source: SettingSource | 'plugin' | 'built-in'; |
| 79 | tokens: number; |
| 80 | }>(items: T[]): Map<string, T[]> { |
| 81 | const groups = new Map<string, T[]>(); |
| 82 | for (const item of items) { |
| 83 | const key = getSourceDisplayName(item.source); |
| 84 | const existing = groups.get(key) || []; |
| 85 | existing.push(item); |
| 86 | groups.set(key, existing); |
| 87 | } |
| 88 | // Sort each group by tokens descending |
| 89 | for (const [key, group] of groups.entries()) { |
| 90 | groups.set(key, group.sort((a, b) => b.tokens - a.tokens)); |
| 91 | } |
| 92 | // Return groups in consistent order |
| 93 | const orderedGroups = new Map<string, T[]>(); |
| 94 | for (const source of SOURCE_DISPLAY_ORDER) { |
| 95 | const group = groups.get(source); |
| 96 | if (group) { |
| 97 | orderedGroups.set(source, group); |
| 98 | } |
| 99 | } |
| 100 | return orderedGroups; |
| 101 | } |
| 102 | interface Props { |
| 103 | data: ContextData; |
| 104 | } |
no test coverage detected