From 52a995a46e84ddc569d92b9d64b75fd7478fc649 Mon Sep 17 00:00:00 2001 From: Kobe Date: Wed, 24 Jan 2024 18:09:49 -0500 Subject: [PATCH] update prop for plan select - fuzzy search --- packages/frontend/components/Form/Select.tsx | 20 ++++--------------- .../frontend/components/Plan/AddPlanModal.tsx | 4 +--- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/packages/frontend/components/Form/Select.tsx b/packages/frontend/components/Form/Select.tsx index 6f48dfbd3..955c4ede1 100644 --- a/packages/frontend/components/Form/Select.tsx +++ b/packages/frontend/components/Form/Select.tsx @@ -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 = ({ label, options, @@ -47,9 +42,9 @@ export const PlanSelect: React.FC = ({ isNumeric, isSearchable, noValueOptionLabel, - fuzzySearchOptions, + useFuzzySearch, }) => { - var filterOptions = fuzzySearchOptions + var filterOptions = useFuzzySearch ? (option: FilterOptionOption, inputValue: string) => { if (inputValue.length !== 0) { const list = new Fuse(options, { @@ -58,14 +53,7 @@ export const PlanSelect: React.FC = ({ 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); diff --git a/packages/frontend/components/Plan/AddPlanModal.tsx b/packages/frontend/components/Plan/AddPlanModal.tsx index ee3a5337f..be612eed9 100644 --- a/packages/frontend/components/Plan/AddPlanModal.tsx +++ b/packages/frontend/components/Plan/AddPlanModal.tsx @@ -245,9 +245,7 @@ export const AddPlanModal: React.FC = ({ 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 />