From 09fe2c3498e119bf0998c2ab8db2d8f0cf77dbd6 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Tue, 3 Mar 2020 10:56:17 +0100 Subject: [PATCH] CHANGE exactMatch to case insensitive && ADD safety to parameters check --- .../src/components/sidebar/treeview/utils.ts | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/ui/src/components/sidebar/treeview/utils.ts b/lib/ui/src/components/sidebar/treeview/utils.ts index 8c95643d3e4..e369678a60c 100644 --- a/lib/ui/src/components/sidebar/treeview/utils.ts +++ b/lib/ui/src/components/sidebar/treeview/utils.ts @@ -14,7 +14,6 @@ export const prevent = (e: SyntheticEvent) => { const toList = memoize(1)((dataset: Dataset) => Object.values(dataset)); export type Item = StoriesHash[keyof StoriesHash]; - export type Dataset = Record; export type SelectedSet = Record; export type ExpandedSet = Record; @@ -192,12 +191,20 @@ const fuse = memoize(5)( }) ); -const exactMatch = memoize(1)(filter => (i: Item) => - (isStory(i) && i.kind.includes(filter)) || - (i.name && i.name.includes(filter)) || - (i.parameters && i.parameters.fileName && i.parameters.fileName.includes(filter)) || - (i.parameters && typeof i.parameters.notes === 'string' && i.parameters.notes.includes(filter)) -); +const exactMatch = memoize(1)((filter: string) => (i: Item) => { + const reg = new RegExp(filter, 'i'); + return ( + i.isLeaf && + ((isStory(i) && reg.test(i.kind)) || + (i.name && reg.test(i.name)) || + (i.parameters && + typeof i.parameters.fileName === 'string' && + reg.test(i.parameters.fileName.toString())) || + (i.parameters && + typeof i.parameters.notes === 'string' && + reg.test(i.parameters.notes.toString()))) + ); +}); export const toId = (base: string, addition: string) => base === '' ? `${addition}` : `${base}-${addition}`;