@@ -140,6 +140,25 @@ const useValues = ({
140
140
} ;
141
141
} ;
142
142
143
+ const useGetCount = ( modal : boolean , path : string ) => {
144
+ const isFilterMode = useRecoilValue ( fos . isSidebarFilterMode ) ;
145
+ const keypoints = useRecoilValue ( isInKeypointsField ( path ) ) ;
146
+ const lightning = useRecoilValue ( fos . isLightningPath ( path ) ) ;
147
+ return ( count : number | null , value : string | null ) => {
148
+ // show no count for the 'points' field of a Keypoint, and visibility mode
149
+ if ( ! isFilterMode || keypoints ) {
150
+ return undefined ;
151
+ }
152
+
153
+ // request subcount for non-lightning paths
154
+ if ( typeof count !== "number" && ! lightning ) {
155
+ return pathSearchCount ( { modal, path, value : value as string } ) ;
156
+ }
157
+
158
+ return count ?? undefined ;
159
+ } ;
160
+ } ;
161
+
143
162
const Checkboxes = ( {
144
163
results,
145
164
selectedAtom,
@@ -150,7 +169,6 @@ const Checkboxes = ({
150
169
} : CheckboxesProps ) => {
151
170
const [ selected , setSelected ] = useRecoilState ( selectedAtom ) ;
152
171
const color = useRecoilValue ( fos . pathColor ( path ) ) ;
153
- const isFilterMode = useRecoilValue ( fos . isSidebarFilterMode ) ;
154
172
155
173
const { loading, name, selectedSet, sorting, values } = useValues ( {
156
174
modal,
@@ -160,8 +178,7 @@ const Checkboxes = ({
160
178
} ) ;
161
179
162
180
const show = useRecoilValue ( showSearchSelector ( { modal, path } ) ) ;
163
- const keypoints = useRecoilValue ( isInKeypointsField ( path ) ) ;
164
- const lightning = useRecoilValue ( fos . isLightningPath ( path ) ) ;
181
+ const getCount = useGetCount ( modal , path ) ;
165
182
166
183
if ( loading ) {
167
184
return < LoadingDots text = { "Loading" } /> ;
@@ -186,13 +203,7 @@ const Checkboxes = ({
186
203
forceColor = { value === null }
187
204
name = { value === null ? "None" : value }
188
205
loading = { loading }
189
- count = {
190
- ( typeof count !== "number" || ! isFilterMode || keypoints ) &&
191
- ! lightning
192
- ? // only string and id fields use pathSearchCount
193
- pathSearchCount ( { modal, path, value : value as string } )
194
- : count
195
- }
206
+ count = { getCount ( count , value ) }
196
207
setValue = { ( checked : boolean ) => {
197
208
if ( checked ) {
198
209
selectedSet . add ( value ) ;
0 commit comments