@@ -26,13 +26,84 @@ export function CollectionsPanel({
26
26
} )
27
27
28
28
// Group collections by type
29
- const standardCollections = createMemo ( ( ) =>
30
- sortedCollections ( ) . filter ( ( c ) => c . type === `collection` )
31
- )
29
+ const groupedCollections = createMemo ( ( ) => {
30
+ const groups : Record < string , Array < CollectionMetadata > > = {
31
+ "live-query" : [ ] ,
32
+ electric : [ ] ,
33
+ query : [ ] ,
34
+ "local-only" : [ ] ,
35
+ "local-storage" : [ ] ,
36
+ generic : [ ] ,
37
+ }
32
38
33
- const liveCollections = createMemo ( ( ) =>
34
- sortedCollections ( ) . filter ( ( c ) => c . type === `live-query` )
35
- )
39
+ sortedCollections ( ) . forEach ( ( collection ) => {
40
+ const type = collection . type
41
+ const targetGroup = ( groups as any ) [ type ] || groups [ `generic` ]
42
+ targetGroup . push ( collection )
43
+ } )
44
+
45
+ // Sort collections within each group alphabetically
46
+ Object . keys ( groups ) . forEach ( ( key ) => {
47
+ const group = groups [ key ]
48
+ if ( group ) {
49
+ group . sort ( ( a , b ) =>
50
+ a . id . toLowerCase ( ) . localeCompare ( b . id . toLowerCase ( ) )
51
+ )
52
+ }
53
+ } )
54
+
55
+ return groups
56
+ } )
57
+
58
+ const getGroupDisplayName = ( type : string ) : string => {
59
+ switch ( type ) {
60
+ case `live-query` :
61
+ return `Live Queries`
62
+ case `electric` :
63
+ return `Electric Collections`
64
+ case `query` :
65
+ return `Query Collections`
66
+ case `local-only` :
67
+ return `Local-Only Collections`
68
+ case `local-storage` :
69
+ return `Local Storage Collections`
70
+ case `generic` :
71
+ return `Generic Collections`
72
+ default :
73
+ return `${ type . charAt ( 0 ) . toUpperCase ( ) + type . slice ( 1 ) } Collections`
74
+ }
75
+ }
76
+
77
+ const getGroupStats = ( type : string ) : Array < string > => {
78
+ switch ( type ) {
79
+ case `live-query` :
80
+ return [ `Items` , `/` , `GC` , `/` , `Status` ]
81
+ case `electric` :
82
+ return [ `Items` , `/` , `Txn` , `/` , `GC` , `/` , `Status` ]
83
+ case `query` :
84
+ return [ `Items` , `/` , `Txn` , `/` , `GC` , `/` , `Status` ]
85
+ case `local-only` :
86
+ return [ `Items` , `/` , `Txn` , `/` , `GC` , `/` , `Status` ]
87
+ case `local-storage` :
88
+ return [ `Items` , `/` , `Txn` , `/` , `GC` , `/` , `Status` ]
89
+ case `generic` :
90
+ return [ `Items` , `/` , `Txn` , `/` , `GC` , `/` , `Status` ]
91
+ default :
92
+ return [ `Items` , `/` , `Txn` , `/` , `GC` , `/` , `Status` ]
93
+ }
94
+ }
95
+
96
+ // Get sorted group entries with live-query first, then alphabetical
97
+ const sortedGroupEntries = createMemo ( ( ) => {
98
+ const entries = Object . entries ( groupedCollections ( ) )
99
+ return entries . sort ( ( [ a ] , [ b ] ) => {
100
+ // Live-query always comes first
101
+ if ( a === `live-query` ) return - 1
102
+ if ( b === `live-query` ) return 1
103
+ // Others are sorted alphabetically
104
+ return a . localeCompare ( b )
105
+ } )
106
+ } )
36
107
37
108
return (
38
109
< div class = { styles ( ) . collectionsExplorer } >
@@ -45,57 +116,33 @@ export function CollectionsPanel({
45
116
</ div >
46
117
}
47
118
>
48
- { /* Standard Collections */ }
49
- < Show when = { standardCollections ( ) . length > 0 } >
50
- < div class = { styles ( ) . collectionGroup } >
51
- < div class = { styles ( ) . collectionGroupHeader } >
52
- < div > Standard Collections ({ standardCollections ( ) . length } )</ div >
53
- < div class = { styles ( ) . collectionGroupStats } >
54
- < span > Items</ span >
55
- < span > /</ span >
56
- < span > Txn</ span >
57
- < span > /</ span >
58
- < span > GC</ span >
59
- < span > /</ span >
60
- < span > Status</ span >
61
- </ div >
62
- </ div >
63
- < For each = { standardCollections ( ) } >
64
- { ( collection ) => (
65
- < CollectionItem
66
- collection = { collection }
67
- isActive = { ( ) => collection . id === activeCollectionId ( ) }
68
- onSelect = { onSelectCollection }
69
- />
70
- ) }
71
- </ For >
72
- </ div >
73
- </ Show >
74
-
75
- { /* Live Collections */ }
76
- < Show when = { liveCollections ( ) . length > 0 } >
77
- < div class = { styles ( ) . collectionGroup } >
78
- < div class = { styles ( ) . collectionGroupHeader } >
79
- < div > Live Collections ({ liveCollections ( ) . length } )</ div >
80
- < div class = { styles ( ) . collectionGroupStats } >
81
- < span > Items</ span >
82
- < span > /</ span >
83
- < span > GC</ span >
84
- < span > /</ span >
85
- < span > Status</ span >
119
+ < For each = { sortedGroupEntries ( ) } >
120
+ { ( [ type , collections ] ) => (
121
+ < Show when = { collections . length > 0 } >
122
+ < div class = { styles ( ) . collectionGroup } >
123
+ < div class = { styles ( ) . collectionGroupHeader } >
124
+ < div >
125
+ { getGroupDisplayName ( type ) } ({ collections . length } )
126
+ </ div >
127
+ < div class = { styles ( ) . collectionGroupStats } >
128
+ < For each = { getGroupStats ( type ) } >
129
+ { ( stat ) => < span > { stat } </ span > }
130
+ </ For >
131
+ </ div >
132
+ </ div >
133
+ < For each = { collections } >
134
+ { ( collection ) => (
135
+ < CollectionItem
136
+ collection = { collection }
137
+ isActive = { ( ) => collection . id === activeCollectionId ( ) }
138
+ onSelect = { onSelectCollection }
139
+ />
140
+ ) }
141
+ </ For >
86
142
</ div >
87
- </ div >
88
- < For each = { liveCollections ( ) } >
89
- { ( collection ) => (
90
- < CollectionItem
91
- collection = { collection }
92
- isActive = { ( ) => collection . id === activeCollectionId ( ) }
93
- onSelect = { onSelectCollection }
94
- />
95
- ) }
96
- </ For >
97
- </ div >
98
- </ Show >
143
+ </ Show >
144
+ ) }
145
+ </ For >
99
146
</ Show >
100
147
</ div >
101
148
</ div >
0 commit comments