-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat: support search alias matching and refactor duplicate code
1 parent
74071ed
commit 3e3c248
Showing
4 changed files
with
112 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...rm/create/builder-and-design/BuilderAndDesignDrawer/FieldListDrawer/field-panels/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { BasicField, MyInfoAttribute } from '~shared/types' | ||
|
||
import { BuilderSidebarFieldMeta } from '~features/admin-form/create/constants' | ||
|
||
const checkSearchValueMatchesFieldMeta = ( | ||
searchValue: string, | ||
fieldMeta: BuilderSidebarFieldMeta, | ||
) => { | ||
const lowerCaseSearchValue = searchValue.toLowerCase() | ||
return ( | ||
fieldMeta.label.toLowerCase().includes(lowerCaseSearchValue) || | ||
fieldMeta.alias?.some((alias) => | ||
alias.toLowerCase().includes(lowerCaseSearchValue), | ||
) | ||
) | ||
} | ||
|
||
export const filterFieldsBySearchValue = < | ||
T extends BasicField | MyInfoAttribute, | ||
>( | ||
searchValue: string, | ||
fields: T[], | ||
fieldsMeta: { | ||
[key in T]: BuilderSidebarFieldMeta | ||
}, | ||
) => { | ||
return fields.filter((fieldType) => { | ||
const fieldMeta = fieldsMeta[fieldType] | ||
return checkSearchValueMatchesFieldMeta(searchValue, fieldMeta) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters