Skip to content

Commit

Permalink
update prop for plan select - fuzzy search
Browse files Browse the repository at this point in the history
  • Loading branch information
KobeZ123 committed Jan 24, 2024
1 parent 047cf3e commit 52a995a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
20 changes: 4 additions & 16 deletions packages/frontend/components/Form/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,9 @@ type PlanSelectProps = {
/** An option in the select dropdown that indicates "no selection". */
noValueOptionLabel?: string;
/** Fuzzy options to use */
fuzzySearchOptions?: IFuzzySearchOptions;
useFuzzySearch?: boolean;
};

interface IFuzzySearchOptions {
/** How strongly the fuzzy search tries to match: weak - matches anything */
matchStrength: "weak" | "normal" | "strong";
}

export const PlanSelect: React.FC<PlanSelectProps> = ({
label,
options,
Expand All @@ -47,9 +42,9 @@ export const PlanSelect: React.FC<PlanSelectProps> = ({
isNumeric,
isSearchable,
noValueOptionLabel,
fuzzySearchOptions,
useFuzzySearch,
}) => {
var filterOptions = fuzzySearchOptions
var filterOptions = useFuzzySearch

Check failure on line 47 in packages/frontend/components/Form/Select.tsx

View workflow job for this annotation

GitHub Actions / Run linting for all packages

Unexpected var, use let or const instead
? (option: FilterOptionOption<any>, inputValue: string) => {
if (inputValue.length !== 0) {
const list = new Fuse(options, {
Expand All @@ -58,14 +53,7 @@ export const PlanSelect: React.FC<PlanSelectProps> = ({
ignoreLocation: true,
findAllMatches: true,
includeScore: true,
threshold:
fuzzySearchOptions.matchStrength === "weak"
? 0.9
: fuzzySearchOptions.matchStrength === "normal"
? 0.6
: fuzzySearchOptions.matchStrength === "strong"
? 0.3
: 0.0,
threshold: 0.4,
}).search(inputValue);

return list.map((element) => element.item).includes(option.label);
Expand Down
4 changes: 1 addition & 3 deletions packages/frontend/components/Plan/AddPlanModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,7 @@ export const AddPlanModal: React.FC<AddPlanModalProps> = ({
rules={{ required: "Major is required." }}
helperText='First select your catalog year. If you still cannot find your major, select "No Major" above.'
isSearchable
fuzzySearchOptions={{
matchStrength: "normal",
}}
useFuzzySearch
/>
<PlanConcentrationsSelect
catalogYear={catalogYear}
Expand Down

0 comments on commit 52a995a

Please sign in to comment.