Skip to content
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

fix: added clear search on removing badge and added keyboard shortcuts #9438

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/components/Common/SearchByMultipleFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ const SearchByMultipleFields: React.FC<SearchByMultipleFieldsProps> = ({
.some((element) => clearSearch.params?.includes(element));
clearinput ? setSearchValue("") : null;
inputRef.current?.focus();
if (clearSearch?.params && clearSearch?.params.includes("search")) {
setSearchValue("");
}
Comment on lines +87 to +89
Copy link
Contributor

@coderabbitai coderabbitai bot Dec 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Refactor clearSearch logic for better efficiency.

The current implementation has redundant logic for clearing the search value. Let's simplify it.

  useEffect(() => {
    if (clearSearch?.value) {
-      const clearinput = options
-        .map((op) => op.key)
-        .some((element) => clearSearch.params?.includes(element));
-      clearinput ? setSearchValue("") : null;
      inputRef.current?.focus();
-      if (clearSearch?.params && clearSearch?.params.includes("search")) {
+      if (clearSearch?.params?.some(param => 
+        param === "search" || options.some(op => op.key === param)
+      )) {
        setSearchValue("");
      }
    }
  }, [clearSearch]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (clearSearch?.params && clearSearch?.params.includes("search")) {
setSearchValue("");
}
useEffect(() => {
if (clearSearch?.value) {
inputRef.current?.focus();
if (clearSearch?.params?.some(param =>
param === "search" || options.some(op => op.key === param)
)) {
setSearchValue("");
}
}
}, [clearSearch]);
🧰 Tools
🪛 Biome (1.9.4)

[error] 87-87: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try this implement @noufalrahim

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

}
}, [clearSearch]);

Expand All @@ -110,6 +113,14 @@ const SearchByMultipleFields: React.FC<SearchByMultipleFieldsProps> = ({
e.preventDefault();
setOpen(true);
}
if ((e.ctrlKey || e.metaKey) && e.key === "k") {
e.preventDefault();
inputRef.current?.focus();
setOpen(false);
}
if (e.key === "Escape") {
setSearchValue("");
}
if (open) {
if (e.key === "ArrowDown") {
setFocusedIndex((prevIndex) =>
Expand Down
Loading