diff --git a/gallery/src/GalleryNav/GalleryNav.tsx b/gallery/src/GalleryNav/GalleryNav.tsx index 90d6874095..fe794a5059 100644 --- a/gallery/src/GalleryNav/GalleryNav.tsx +++ b/gallery/src/GalleryNav/GalleryNav.tsx @@ -110,7 +110,8 @@ function GalleryNav() { [openTreeViews, setOpenTreeViews] = useState(initialOpenTreeViews), isFiltering = !!filter, filteredConfig: PageConfig = isFiltering ? pipe<[PageConfig], PageConfig, PageConfig>( - map(pickBy((_, pageName) => matchesFilter(filter, pageName))), + map(pickBy((pageInfo, pageName) => + matchesFilter(filter, pageName, pageInfo.tags))), pickBy(complement(isEmpty)) )(pageConfig) : pageConfig, filteredCategories = pipe<[PageConfig], [string, PageMapping][], ReactNode[]>( diff --git a/gallery/src/filterUtil.tsx b/gallery/src/filterUtil.tsx index 80ef9e50d7..b27a7c3c0d 100644 --- a/gallery/src/filterUtil.tsx +++ b/gallery/src/filterUtil.tsx @@ -4,7 +4,7 @@ * the terms of the Eclipse Public License 2.0 which accompanies this * distribution and is available at https://www.eclipse.org/legal/epl-2.0/. */ -import { reduce, head, tail, toLower, isEmpty, splitAt, drop, join } from 'ramda'; +import {reduce, head, tail, toLower, isEmpty, splitAt, drop, join, map} from 'ramda'; import React, { ReactNode } from 'react'; /** @@ -67,14 +67,22 @@ export function markByFilter(filter: string | undefined, text: string): ReactNod /** * @return true if the pageName contains every character present in the filter in the same order, case insensitive */ -export function matchesFilter(filter: string, pageName: string) { +export function matchesFilter(filter: string, pageName: string, tags: string[] = []): boolean { + const matchesPageName = isStringIncludedInSecondStringCaseInsensitive(filter, pageName); + const matchesAnyTags: boolean = map((tag: string) => { + return isStringIncludedInSecondStringCaseInsensitive(filter, tag); + }, tags).reduce((acc, val) => acc || val, false); + + return matchesPageName || matchesAnyTags; +} + +function isStringIncludedInSecondStringCaseInsensitive(search: string, fullValue: string): boolean { const unmatchedFilterChars = reduce( (remainingFilter, pageNameChar) => head(remainingFilter) === pageNameChar ? tail(remainingFilter) : remainingFilter, - Array.from(toLower(filter)), - Array.from(toLower(pageName)) + Array.from(toLower(search)), + Array.from(toLower(fullValue)) ); return isEmpty(unmatchedFilterChars); } - diff --git a/gallery/src/pageConfig.ts b/gallery/src/pageConfig.ts index 8ca38be856..399ba7b26d 100644 --- a/gallery/src/pageConfig.ts +++ b/gallery/src/pageConfig.ts @@ -161,9 +161,9 @@ import DarkModeMixinPage from './styles/DarkMode/DarkModeMixinPage'; const pageConfig: PageConfig = { 'Alerts and Indicators': { - 'Alert': { content: NxAlertComponentsPage, type: 'react' }, - 'Stateful Alert': { content: NxStatefulAlertComponentsPage, type: 'react' }, - 'Counter': { content: NxCounterPage, type: 'html' }, + 'Alert': { content: NxAlertComponentsPage, type: 'react', tags: ['NxAlert'] }, + 'Stateful Alert': { content: NxStatefulAlertComponentsPage, type: 'react', tags: ['NxStatefulAlert'] }, + 'Counter': { content: NxCounterPage, type: 'html', tags: ['NxCounter'] }, 'Load Error': { content: NxLoadErrorPage, type: 'react' }, 'Load Wrapper': { content: NxLoadWrapperPage, type: 'react' }, 'Loading Spinner': { content: NxLoadingSpinnerPage, type: 'react' }, @@ -282,7 +282,7 @@ const pageConfig: PageConfig = { 'Code': { content: NxCodePage, type: 'html' }, 'Font Awesome Icon': { content: NxFontAwesomeIconPage, type: 'react' }, 'H*': { content: NxHPage, type: 'html' }, - 'P': { content: NxPPage, type: 'html' }, + 'P': { content: NxPPage, type: 'html', tags: ['NxP'] }, 'Pre': { content: NxPrePage, type: 'html' } }, 'HTML Variants': { diff --git a/gallery/src/pageConfigTypes.ts b/gallery/src/pageConfigTypes.ts index cd1c7bd801..3c0019e3ad 100644 --- a/gallery/src/pageConfigTypes.ts +++ b/gallery/src/pageConfigTypes.ts @@ -21,6 +21,8 @@ export type PageType = typeof PAGE_TYPES[number]; export interface PageContentDescription { content: ComponentType; type: PageType; + + tags?: string [] } export type PageConfig = Record;