|  | 
| 1 | 1 | 'use client' | 
| 2 | 2 | 
 | 
|  | 3 | +import { useMemo } from 'react' | 
|  | 4 | + | 
| 3 | 5 | import { isThisFieldShapeFilterable, isThisFilterAllowed } from './components/filter/filter-helper' | 
| 4 | 6 | import { | 
| 5 | 7 |   CollectionListFilterPanel, | 
| @@ -32,16 +34,20 @@ export function CollectionListFilter(props: CollectionListFilterProps) { | 
| 32 | 34 | 
 | 
| 33 | 35 |   const filterable = props.filterOptions.filter((e) => isThisFieldShapeFilterable(e.fieldShape)) | 
| 34 | 36 | 
 | 
| 35 |  | -  const whatFilterCanIFetch = [] // use this to fetch for optionsName | 
| 36 |  | -  const whatFilterCanIFormulate = [] // these you will have to create a component to handle the filter value(s) yourself | 
|  | 37 | +  const { whatFilterCanIFetch, whatFilterCanIFormulate } = useMemo(() => { | 
|  | 38 | +    const fetchList: typeof filterable = [] // this is those "select" options, will have to fetch for choices | 
|  | 39 | +    const formulateList: typeof filterable = [] // this is other types, create a filter component to handle each type separately | 
| 37 | 40 | 
 | 
| 38 |  | -  for (const e of filterable) { | 
| 39 |  | -    if (e.optionsName) { | 
| 40 |  | -      whatFilterCanIFetch.push(e) | 
| 41 |  | -    } else if (isThisFilterAllowed(e.fieldShape.$client.fieldName, props.allowedFilters)) { | 
| 42 |  | -      whatFilterCanIFormulate.push(e) | 
|  | 41 | +    for (const e of filterable) { | 
|  | 42 | +      if (e.optionsName) { | 
|  | 43 | +        fetchList.push(e) | 
|  | 44 | +      } else if (isThisFilterAllowed(e.fieldShape.$client.fieldName, props.allowedFilters)) { | 
|  | 45 | +        formulateList.push(e) | 
|  | 46 | +      } | 
| 43 | 47 |     } | 
| 44 |  | -  } | 
|  | 48 | + | 
|  | 49 | +    return { whatFilterCanIFetch: fetchList, whatFilterCanIFormulate: formulateList } | 
|  | 50 | +  }, [filterable, props.allowedFilters]) | 
| 45 | 51 | 
 | 
| 46 | 52 |   return ( | 
| 47 | 53 |     <CollectionListFilterPanel | 
|  | 
0 commit comments