11/**
22 * The marketplace catalog's facet filters: solution type as a segment (one
33 * value or All), business function and industry as toggle rows (any number of
4- * values, OR inside the row). The rows combine with AND. Each value carries
5- * the count of loaded listings that hold it under the other facets' selection .
4+ * values, OR inside the row). The rows combine with AND. The server applies
5+ * the selection: the page sends it with the list read and draws the answer .
66 *
7- * `facetOptions` (`marketplaceTaxonomy.ts`) decides what is drawn: a facet no
8- * loaded listing carries is empty and its row is not drawn, so a catalog that
7+ * A drawn facet offers every value the spec declares, in the spec's order: the
8+ * page holds one page of the filtered catalog, so the values its rows carry
9+ * are not the values a selection can add. `ServedFacets`
10+ * (`marketplaceTaxonomy.ts`) decides which facets are drawn, so a catalog that
911 * does not serve the taxonomy yet draws no filter at all.
1012 */
1113
1214import type { ReactNode } from 'react' ;
1315import { Button } from '@object-ui/components' ;
1416import { useObjectTranslation } from '@object-ui/i18n' ;
15- import type { FacetOptions , FacetSelection } from './marketplaceTaxonomy.js' ;
17+ import {
18+ BUSINESS_FUNCTIONS ,
19+ INDUSTRIES ,
20+ SOLUTION_TYPES ,
21+ type FacetSelection ,
22+ type ServedFacets ,
23+ } from './marketplaceTaxonomy.js' ;
1624
1725function toggled < T > ( set : ReadonlySet < T > , value : T ) : Set < T > {
1826 const next = new Set ( set ) ;
@@ -30,9 +38,8 @@ function FacetRow({ label, testId, children }: { label: string; testId: string;
3038 ) ;
3139}
3240
33- function FacetButton ( { label, count , pressed, onClick, testId } : {
41+ function FacetButton ( { label, pressed, onClick, testId } : {
3442 label : string ;
35- count ?: number ;
3643 pressed : boolean ;
3744 onClick : ( ) => void ;
3845 testId : string ;
@@ -46,65 +53,57 @@ function FacetButton({ label, count, pressed, onClick, testId }: {
4653 data-testid = { testId }
4754 >
4855 { label }
49- { count !== undefined && (
50- < span className = "ml-1.5 text-xs tabular-nums opacity-70" data-testid = { `${ testId } -count` } > { count } </ span >
51- ) }
5256 </ Button >
5357 ) ;
5458}
5559
56- export function MarketplaceFacetFilters ( { options , selection, onChange } : {
57- options : FacetOptions ;
60+ export function MarketplaceFacetFilters ( { served , selection, onChange } : {
61+ served : ServedFacets ;
5862 selection : FacetSelection ;
5963 onChange : ( next : FacetSelection ) => void ;
6064} ) {
6165 const { t } = useObjectTranslation ( ) ;
62- if ( options . solutionType . length === 0 && options . businessFunctions . length === 0 && options . industries . length === 0 ) {
63- return null ;
64- }
66+ if ( ! served . solutionType && ! served . businessFunctions && ! served . industries ) return null ;
6567 return (
6668 < div className = "flex flex-col gap-2" data-testid = "marketplace-facets" >
67- { options . solutionType . length > 0 && (
69+ { served . solutionType && (
6870 < FacetRow label = { t ( 'marketplace.facet.solutionType' ) } testId = "marketplace-facet-solutionType" >
6971 < FacetButton
7072 label = { t ( 'marketplace.all' ) }
7173 pressed = { selection . solutionType === null }
7274 onClick = { ( ) => onChange ( { ...selection , solutionType : null } ) }
7375 testId = "marketplace-facet-solutionType-all"
7476 />
75- { options . solutionType . map ( ( { value, count } ) => (
77+ { SOLUTION_TYPES . map ( ( value ) => (
7678 < FacetButton
7779 key = { value }
7880 label = { t ( `marketplace.solutionType.${ value } ` ) }
79- count = { count }
8081 pressed = { selection . solutionType === value }
8182 onClick = { ( ) => onChange ( { ...selection , solutionType : value } ) }
8283 testId = { `marketplace-facet-solutionType-${ value } ` }
8384 />
8485 ) ) }
8586 </ FacetRow >
8687 ) }
87- { options . businessFunctions . length > 0 && (
88+ { served . businessFunctions && (
8889 < FacetRow label = { t ( 'marketplace.facet.businessFunction' ) } testId = "marketplace-facet-businessFunction" >
89- { options . businessFunctions . map ( ( { value, count } ) => (
90+ { BUSINESS_FUNCTIONS . map ( ( value ) => (
9091 < FacetButton
9192 key = { value }
9293 label = { t ( `marketplace.businessFunction.${ value } ` ) }
93- count = { count }
9494 pressed = { selection . businessFunctions . has ( value ) }
9595 onClick = { ( ) => onChange ( { ...selection , businessFunctions : toggled ( selection . businessFunctions , value ) } ) }
9696 testId = { `marketplace-facet-businessFunction-${ value } ` }
9797 />
9898 ) ) }
9999 </ FacetRow >
100100 ) }
101- { options . industries . length > 0 && (
101+ { served . industries && (
102102 < FacetRow label = { t ( 'marketplace.facet.industry' ) } testId = "marketplace-facet-industry" >
103- { options . industries . map ( ( { value, count } ) => (
103+ { INDUSTRIES . map ( ( value ) => (
104104 < FacetButton
105105 key = { value }
106106 label = { t ( `marketplace.industry.${ value } ` ) }
107- count = { count }
108107 pressed = { selection . industries . has ( value ) }
109108 onClick = { ( ) => onChange ( { ...selection , industries : toggled ( selection . industries , value ) } ) }
110109 testId = { `marketplace-facet-industry-${ value } ` }
0 commit comments