MCPcopy Index your code
hub / github.com/codeaashu/claude-code / groupBySource

Function groupBySource

src/components/ContextVisualization.tsx:77–101  ·  view source on GitHub ↗

Group items by source type for display, sorted by tokens descending within each group

(items: T[])

Source from the content-addressed store, hash-verified

75
76/** Group items by source type for display, sorted by tokens descending within each group */
77function 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}
102interface Props {
103 data: ContextData;
104}

Callers 1

ContextVisualizationFunction · 0.85

Calls 5

getSourceDisplayNameFunction · 0.85
entriesMethod · 0.80
getMethod · 0.65
pushMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected