-
Notifications
You must be signed in to change notification settings - Fork 336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Issue #2369 Regarding Fuzzy Search #2437
Open
wel013
wants to merge
3
commits into
h2oai:main
Choose a base branch
from
wel013:liwq-change
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+109
−6
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -17,7 +17,7 @@ import { B, Id, S, U } from './core' | |||||||||
import React from 'react' | ||||||||||
import { stylesheet } from 'typestyle' | ||||||||||
import { Choice } from './choice_group' | ||||||||||
import { fuzzysearch } from './parts/utils' | ||||||||||
import { fuzzysearch, exactsearch } from './parts/utils' | ||||||||||
import { clas, cssVar, pc, px } from './theme' | ||||||||||
import { wave } from './ui' | ||||||||||
|
||||||||||
|
@@ -61,6 +61,8 @@ export interface Dropdown { | |||||||||
tooltip?: S | ||||||||||
/** Whether to present the choices using a pop-up dialog. By default pops up a dialog only for more than 100 choices. Defaults to 'auto'. */ | ||||||||||
popup?: 'auto' | 'always' | 'never' | ||||||||||
/**Whether the search will be exact or fuzzy */ | ||||||||||
exactSearch?: B | ||||||||||
} | ||||||||||
|
||||||||||
type DropdownItem = { | ||||||||||
|
@@ -170,10 +172,19 @@ const | |||||||||
getPageSpecification = () => ({ itemCount: PAGE_SIZE, height: ROW_HEIGHT * PAGE_SIZE } as Fluent.IPageSpecification), | ||||||||||
choicesToItems = (choices: Choice[] = [], v?: S | S[]) => choices.map(({ name, label, disabled = false }, idx) => | ||||||||||
({ name, text: label || name, idx, checked: Array.isArray(v) ? v.includes(name) : v === name, show: true, disabled })), | ||||||||||
useItems = (choices?: Choice[], v?: S | S[]) => { | ||||||||||
useItems = (choices?: Choice[], v?: S | S[], exactSearch?: boolean) => { | ||||||||||
const [items, setItems] = React.useState<DropdownItem[]>(choicesToItems(choices, v)) | ||||||||||
const onSearchChange = (_e?: React.ChangeEvent<HTMLInputElement>, newVal = '') => setItems(items => items.map(i => ({ ...i, show: fuzzysearch(i.text, newVal) }))) | ||||||||||
|
||||||||||
const onSearchChange = (_e?: React.ChangeEvent<HTMLInputElement>, newVal = '') => { | ||||||||||
setItems((items) => | ||||||||||
items.map((i) => ({ | ||||||||||
...i, | ||||||||||
show: exactSearch | ||||||||||
? exactsearch(i.text, newVal) // Assuming exactsearch is a function for exact matching | ||||||||||
: fuzzysearch(i.text, newVal), // Assuming fuzzysearch is a function for fuzzy matching | ||||||||||
Comment on lines
+183
to
+184
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for extra comments.
Suggested change
|
||||||||||
})) | ||||||||||
); | ||||||||||
}; | ||||||||||
return [items, setItems, onSearchChange] as const | ||||||||||
}, | ||||||||||
onRenderCell = (onChecked: any) => (item?: DropdownItem) => item | ||||||||||
|
@@ -323,4 +334,4 @@ export const XDropdown = ({ model: m }: { model: Dropdown }) => | |||||||||
? <BaseDropdown model={m} /> | ||||||||||
: (m.choices?.length || 0) > 100 | ||||||||||
? <DialogDropdown model={m} /> | ||||||||||
: <BaseDropdown model={m} /> | ||||||||||
: <BaseDropdown model={m} /> |
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 |
---|---|---|
|
@@ -24,6 +24,14 @@ export function fuzzysearch(haystack: S, needle: S) { | |
} | ||
return true | ||
} | ||
// parts / utils.ts | ||
export const exactsearch = (searchTerm: string, itemText: string): boolean => { | ||
|
||
// Convert both strings to lowercase for case-insensitive comparison | ||
return itemText.toLowerCase() === searchTerm.toLowerCase(); // Exact match | ||
}; | ||
Comment on lines
+27
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for a separate function since it's so simple, can be inlined. |
||
|
||
|
||
|
||
// https://github.com/h2oai/wave/issues/1395. | ||
export const fixMenuOverflowStyles: Partial<IContextualMenuStyles> = { | ||
|
@@ -32,4 +40,4 @@ export const fixMenuOverflowStyles: Partial<IContextualMenuStyles> = { | |
'.ms-ContextualMenu-link': { lineHeight: 'unset' }, | ||
'.ms-ContextualMenu-submenuIcon': { lineHeight: 'unset', display: 'flex', alignItems: 'center' }, | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.