@@ -21,14 +21,16 @@ import { Group } from "@/interfaces/Group";
21
21
22
22
interface MultiSelectProps {
23
23
values : string [ ] ;
24
- onChange : ( items : string [ ] ) => void ;
24
+ exactValue ?: string ;
25
+ onChange : ( items : string [ ] , exactItem ?: string ) => void ;
25
26
disabled ?: boolean ;
26
27
popoverWidth ?: "auto" | number ;
27
28
groups : Group [ ] | undefined ;
28
29
}
29
30
export function GroupSelector ( {
30
31
onChange,
31
32
values,
33
+ exactValue : exactValues ,
32
34
disabled = false ,
33
35
popoverWidth = 400 ,
34
36
groups,
@@ -40,9 +42,20 @@ export function GroupSelector({
40
42
const toggle = ( code : string ) => {
41
43
const isSelected = values . find ( ( c ) => c == code ) != undefined ;
42
44
if ( isSelected ) {
43
- onChange && onChange ( values . filter ( ( c ) => c != code ) ) ;
45
+ onChange && onChange ( values . filter ( ( c ) => c != code ) , undefined ) ;
44
46
} else {
45
- onChange && onChange ( [ ...values , code ] ) ;
47
+ onChange && onChange ( [ ...values , code ] , undefined ) ;
48
+ setSearch ( "" ) ;
49
+ }
50
+ } ;
51
+
52
+ const toggleExactGroup = ( code : string ) => {
53
+ const isSelected = exactValues == code ;
54
+ if ( isSelected ) {
55
+ onChange && onChange ( [ ] , undefined ) ;
56
+ setSearch ( "" ) ;
57
+ } else {
58
+ onChange && onChange ( [ ] , code ) ;
46
59
setSearch ( "" ) ;
47
60
}
48
61
} ;
@@ -65,11 +78,13 @@ export function GroupSelector({
65
78
< Button variant = { "secondary" } disabled = { disabled } ref = { inputRef } >
66
79
< FolderGit2 size = { 16 } className = { "shrink-0" } />
67
80
< div className = { "w-full flex justify-between" } >
68
- { values . length > 0 ? (
69
- < div > { values . length } Group(s)</ div >
70
- ) : (
71
- "All Groups"
72
- ) }
81
+ {
82
+ exactValues != undefined
83
+ ? ( "Unassigned peers" )
84
+ : values . length > 0
85
+ ? ( `${ values . length } Group(s)` )
86
+ : ( "All Groups" )
87
+ }
73
88
< div className = { "pl-2" } >
74
89
< ChevronsUpDown size = { 18 } className = { "shrink-0" } />
75
90
</ div >
@@ -132,7 +147,6 @@ export function GroupSelector({
132
147
</ div >
133
148
</ div >
134
149
</ div >
135
-
136
150
< ScrollArea
137
151
className = {
138
152
"max-h-[380px] overflow-y-auto flex flex-col gap-1 pl-2 py-2 pr-3"
@@ -141,7 +155,42 @@ export function GroupSelector({
141
155
< CommandGroup >
142
156
< div className = { "" } >
143
157
< div className = { "grid grid-cols-1 gap-1" } >
144
- { orderBy ( groups , "name" ) ?. map ( ( item ) => {
158
+ < CommandItem
159
+ key = { "_All" }
160
+ value = { "All" }
161
+ className = { "p-1" }
162
+ onSelect = { ( ) => {
163
+ toggleExactGroup ( "All" ) ;
164
+ searchRef . current ?. focus ( ) ;
165
+ } }
166
+ onClick = { ( e ) => e . preventDefault ( ) }
167
+ >
168
+ < div
169
+ className = {
170
+ "text-neutral-500 dark:text-nb-gray-300 font-medium flex items-center gap-3 py-1 px-1 w-full"
171
+ }
172
+ >
173
+ < Checkbox checked = { exactValues == "All" } />
174
+ < div
175
+ className = {
176
+ "flex justify-between items-center w-full"
177
+ }
178
+ >
179
+ < div
180
+ className = {
181
+ "flex items-center gap-2 whitespace-nowrap text-sm"
182
+ }
183
+ >
184
+ < FolderGit2 size = { 13 } className = { "shrink-0" } />
185
+ < TextWithTooltip text = { "Unassigned peers" } />
186
+ </ div >
187
+ </ div >
188
+ </ div >
189
+ </ CommandItem >
190
+ < hr />
191
+ { orderBy ( groups , "name" )
192
+ ?. filter ( ( group ) => group . name != "All" ) // Ignore All group
193
+ ?. map ( ( item ) => {
145
194
const value = item ?. name || "" ;
146
195
if ( value === "" ) return null ;
147
196
const isSelected =
0 commit comments