@@ -10,7 +10,7 @@ import { MdBubbleChart } from "react-icons/md";
1010import { RiFilterOffFill } from "react-icons/ri" ;
1111
1212import { RangeMetric , SearchMetrics , TermsMetric } from "../lib/computedData" ;
13- import { MAX_PALETTE_SIZE , RANGE_STYLE } from "../lib/consts" ;
13+ import { MAX_PALETTE_SIZE , EXPAND_STEP_SIZE , RANGE_STYLE } from "../lib/consts" ;
1414import { GraphContext } from "../lib/context" ;
1515import { ContentField , QualiField , QuantiField , getFilterableFields , getValue } from "../lib/data" ;
1616import { Filter , RangeFilter , SearchFilter , TermsFilter } from "../lib/navState" ;
@@ -38,11 +38,11 @@ const SearchFilterComponent: FC<{
3838 setFilter (
3939 value
4040 ? {
41- type : "search" ,
42- field : field . id ,
43- value : value ,
44- normalizedValue : normalize ( value ) ,
45- }
41+ type : "search" ,
42+ field : field . id ,
43+ value : value ,
44+ normalizedValue : normalize ( value ) ,
45+ }
4646 : null ,
4747 ) ;
4848 } }
@@ -73,17 +73,30 @@ const TermsFilterComponent: FC<{
7373 const { data : graphData , setHovered } = useContext ( GraphContext ) ;
7474 const [ alphaSort , setAlphaSort ] = useState ( false ) ;
7575 const [ expanded , setExpanded ] = useState ( false ) ;
76+ const [ currentLimit , setCurrentLimit ] = useState ( MAX_PALETTE_SIZE ) ;
7677 const maxCount = max ( data . values . map ( ( v ) => v . globalCount ) ) as number ;
7778 const filteredValues = filter ?. values ? new Set ( filter . values ) : null ;
7879
7980 const showExpandToggle = data . values . length > MAX_PALETTE_SIZE ;
81+
82+ const handleExpand = ( ) => {
83+ const newLimit = Math . min ( currentLimit + EXPAND_STEP_SIZE , data . values . length ) ;
84+ setCurrentLimit ( newLimit ) ;
85+ setExpanded ( true ) ;
86+ } ;
87+
88+ const handleCollapse = ( ) => {
89+ setCurrentLimit ( MAX_PALETTE_SIZE ) ;
90+ setExpanded ( false ) ;
91+ } ;
92+
8093 const values = useMemo (
8194 ( ) =>
8295 take (
8396 alphaSort ? sortBy ( data . values , ( value ) => value . label . toLowerCase ( ) ) : data . values ,
84- showExpandToggle && ! expanded ? MAX_PALETTE_SIZE : Infinity ,
97+ currentLimit ,
8598 ) ,
86- [ showExpandToggle , expanded , alphaSort , data . values ] ,
99+ [ currentLimit , alphaSort , data . values ] ,
87100 ) ;
88101
89102 return (
@@ -172,17 +185,21 @@ const TermsFilterComponent: FC<{
172185 } ) }
173186 </ ul >
174187 { showExpandToggle && (
175- < button className = "btn btn-link p-0 btn-sm" onClick = { ( ) => setExpanded ( ( v ) => ! v ) } >
176- { expanded ? (
177- < >
178- < FiMinus /> Only show { MAX_PALETTE_SIZE } first values
179- </ >
180- ) : (
181- < >
182- < FiPlus /> Show all values ({ data . values . length - values . length } more)
183- </ >
188+ < div className = "d-flex flex-column gap-2 mt-2" >
189+ < div className = "text-muted small" >
190+ Showing { currentLimit } of { data . values . length } values
191+ </ div >
192+ { currentLimit < data . values . length && (
193+ < button className = "btn btn-link p-0 btn-sm" onClick = { handleExpand } >
194+ < FiPlus /> Show { Math . min ( EXPAND_STEP_SIZE , data . values . length - currentLimit ) } more values ({ data . values . length - currentLimit } remaining)
195+ </ button >
184196 ) }
185- </ button >
197+ { expanded && (
198+ < button className = "btn btn-link p-0 btn-sm text-muted" onClick = { handleCollapse } >
199+ < FiMinus /> Collapse to { MAX_PALETTE_SIZE } values
200+ </ button >
201+ ) }
202+ </ div >
186203 ) }
187204 </ >
188205 ) ;
@@ -207,9 +224,9 @@ const RangeFilterComponent: FC<{
207224 ( v ) =>
208225 v === currentMin || v === currentMax
209226 ? {
210- label : shortenNumber ( v ) ,
211- style : { fontWeight : "bold" , background : "white" , padding : "0 0.2em" , zIndex : 1 } ,
212- }
227+ label : shortenNumber ( v ) ,
228+ style : { fontWeight : "bold" , background : "white" , padding : "0 0.2em" , zIndex : 1 } ,
229+ }
213230 : shortenNumber ( v ) ,
214231 ) ;
215232 const [ inputValues , setInputValues ] = useState < { min : number ; max : number } > ( { min : currentMin , max : currentMax } ) ;
0 commit comments