File tree Expand file tree Collapse file tree 4 files changed +31
-4
lines changed
Expand file tree Collapse file tree 4 files changed +31
-4
lines changed Original file line number Diff line number Diff line change 1212
1313### 🐞 Fixes
1414
15+ - [ #895 ] ( https://github.com/estruyf/vscode-front-matter/issues/895 ) : Fix issue with array values in filters
16+
1517## [ 10.6.0] - 2024-11-06 - [ Release notes] ( https://beta.frontmatter.codes/updates/v10.6.0 )
1618
1719### 🎨 Enhancements
Original file line number Diff line number Diff line change @@ -24,17 +24,35 @@ export const Filters: React.FunctionComponent<IFiltersProps> = () => {
2424 return otherFilters ?. map ( ( filter ) => {
2525 const filterName = typeof filter === "string" ? filter : filter . name ;
2626 const filterTitle = typeof filter === "string" ? firstToUpper ( filter ) : filter . title ;
27- const values = filterValues ?. [ filterName ] ;
27+ let values = filterValues ?. [ filterName ] ;
2828 if ( ! values || values . length === 0 ) {
2929 return null ;
3030 }
3131
32+ // Get all the unique values
33+ const individualValues = new Set < string > ( ) ;
34+ values . forEach ( ( value ) => {
35+ if ( value . length === 0 ) {
36+ return ;
37+ }
38+
39+ if ( Array . isArray ( value ) ) {
40+ value . forEach ( ( v ) => individualValues . add ( v ) ) ;
41+ }
42+
43+ if ( typeof value === "string" ) {
44+ individualValues . add ( value ) ;
45+ }
46+ } ) ;
47+
48+ values = Array . from ( individualValues ) ;
49+
3250 return (
3351 < Filter
3452 key = { filterName }
3553 label = { filterTitle }
3654 activeItem = { crntFilters [ filterName ] }
37- items = { values }
55+ items = { values as string [ ] }
3856 onClick = { ( value ) => setCrntFilters ( ( prev ) => {
3957 const clone = Object . assign ( { } , prev ) ;
4058 if ( ! clone [ filterName ] && value ) {
Original file line number Diff line number Diff line change @@ -107,7 +107,14 @@ export default function usePages(pages: Page[]) {
107107 for ( const filter of filterNames ) {
108108 const filterValue = filters [ filter ] ;
109109 if ( filterValue ) {
110- pagesSorted = pagesSorted . filter ( ( page ) => page [ filter ] === filterValue ) ;
110+ pagesSorted = pagesSorted . filter ( ( page ) => {
111+ const value = page [ filter ] ;
112+ if ( Array . isArray ( value ) ) {
113+ return value . includes ( filterValue ) ;
114+ } else {
115+ return value === filterValue ;
116+ }
117+ } ) ;
111118 }
112119 }
113120 }
Original file line number Diff line number Diff line change 11import { atom } from 'recoil' ;
22
3- export const FilterValuesAtom = atom < { [ filter : string ] : string [ ] } > ( {
3+ export const FilterValuesAtom = atom < { [ filter : string ] : string [ ] | string [ ] [ ] } > ( {
44 key : 'FilterValuesAtom' ,
55 default : { }
66} ) ;
You can’t perform that action at this time.
0 commit comments