Skip to content

Commit

Permalink
feat(website): fix components explorer filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
plouc committed Jan 12, 2022
1 parent 16f89bb commit bda98c8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions website/src/components/components/explorer/ComponentsGrid.tsx
Expand Up @@ -3,7 +3,7 @@ import styled from 'styled-components'
import { ComponentsGridItem } from './ComponentsGridItem'
import * as nav from '../../../data/nav'
import media from '../../../theming/mediaQueries'
import { ChartNavData } from '../../../types'
import { ChartNavData, Flavor } from '../../../types'

type FilterFunction = (item: ChartNavData) => boolean

Expand All @@ -13,9 +13,11 @@ const getFilterFunction = (term?: string | null, filter?: string | null): Filter
predicates.push(({ name }) => name.toLowerCase().includes(term.toLowerCase()))
}
if (filter) {
// @ts-ignore
predicates.push(({ flavors }) => flavors[filter.toLowerCase()] === true)
predicates.push(({ tags }) => tags.includes(filter))
const normalizedFilter = filter.toLowerCase()
predicates.push(({ tags, flavors }) => {
if (tags.includes(normalizedFilter)) return true
return !!(normalizedFilter in flavors && flavors[normalizedFilter as Flavor])
})
}

return item => predicates.every(predicate => predicate(item))
Expand Down

0 comments on commit bda98c8

Please sign in to comment.