@@ -198,13 +198,38 @@ const inferSelectOneByTypeReturnStatus = (
198198
199199const inferSelectAllByTypeReturnStatus = (
200200 _guide : KnockGuide ,
201- _snapshot : StoreStateSnapshot ,
201+ snapshot : StoreStateSnapshot ,
202202 _stage : KnockGuideClientGroupStage ,
203- _query : SelectionResultByQuery ,
203+ query : SelectionResultByQuery ,
204204) : SelectableStatusPresent [ "status" ] => {
205- // If queried with useGuides/selectGuides (i.e. can return multiple guides),
206- // then we need to look up the actual query results to figure out how this
207- // guide may or may not be included in the result.
205+ const result = query . type ! . all ! ;
206+ if ( result . size === 0 ) {
207+ // This should not happen but here for completeness.
208+ return "queried" ;
209+ }
210+
211+ // If queried with useGuides (i.e. can return multiple guides), then we need
212+ // to look up the actual query results to figure out how this guide may or
213+ // may not be included in the result.
214+
215+ // If explicitly given the option to ignore throttling, then all guides
216+ // selected in this query should return.
217+ const includeThrottled = ! ! query . type ?. one ?. metadata ?. opts ?. includeThrottled ;
218+ if ( includeThrottled ) {
219+ return "returned" ;
220+ }
221+
222+ const guides = [ ...result . values ( ) ]
223+ const first = guides [ 0 ] ! ;
224+
225+ // If not throttled, then all guides in the query result should be returned.
226+ if ( ! snapshot . throttled ) {
227+ return "returned"
228+ }
229+
230+ // If being throttled, then all guides in the query result should be returned.
231+ // const guides = [...result.values()];
232+
208233
209234 // TODO: Placeholder to follow up.
210235 return "returned" ;
@@ -229,6 +254,7 @@ const inferSelectReturnStatus = (
229254 return inferSelectAllByTypeReturnStatus ( guide , snapshot , stage , query ) ;
230255 }
231256
257+ // Should not happen but just for completeness.
232258 return undefined ;
233259} ;
234260
@@ -246,6 +272,7 @@ const toSelectableStatus = (
246272 type : ( stage . results . type || { } ) [ guide . type ] ,
247273 } ;
248274
275+ // There is no query in the current location that can select this guide.
249276 const queried = Boolean ( query . key || query . type ) ;
250277 if ( ! queried ) {
251278 return { status : undefined } ;
0 commit comments