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

Fixed: Not display buttons when search bar is empty #1927

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Nil2000
Copy link
Contributor

@Nil2000 Nil2000 commented Dec 14, 2024

Fixes: #699

Copy link

vercel bot commented Dec 14, 2024

@Nil2000 is attempting to deploy a commit to the Typebot Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

coderabbitai bot commented Dec 14, 2024

Walkthrough

The pull request modifies the Buttons and MultipleChoicesForm components in the input blocks feature. The changes focus on enhancing the search functionality by introducing conditional initialization of filteredItems based on the isSearchable property. When search is enabled, the component now starts with an empty list of items and implements stricter filtering logic that clears items when the input is empty or contains only spaces.

Changes

File Change Summary
packages/embeds/js/src/features/blocks/inputs/buttons/components/Buttons.tsx - Conditionally initialize filteredItems based on isSearchable
- Updated filterItems to clear items on empty/space input
- Modified onClear handler to set filteredItems to an empty array
packages/embeds/js/src/features/blocks/inputs/buttons/components/MultipleChoicesForm.tsx - Similar changes to Buttons.tsx for search and filtering logic
- Conditional filteredItems initialization
- Updated filterItems and onClear handler behavior

Assessment against linked issues

Objective Addressed Explanation
Add option to not display buttons when search bar is empty [#699] Partial implementation detected, but full requirement unclear without seeing the complete implementation of isSearchable

Note: A complete assessment would require reviewing the full implementation of the isSearchable option, which is not fully visible in the provided diff.

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. This feature will be included in our Pro Plan when released.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
packages/embeds/js/src/features/blocks/inputs/buttons/components/Buttons.tsx (1)

33-36: Consider allowing multi-word search

While clearing results for empty input is correct, treating any space as an empty input might be too restrictive. Users might want to search for phrases containing spaces.

Consider this alternative implementation:

-if (inputValue === "" || inputValue.includes(" ")) {
+if (inputValue.trim() === "") {
   setFilteredItems([]);
   return;
 }

Also applies to: 40-40

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 11503dc and d67e657.

📒 Files selected for processing (2)
  • packages/embeds/js/src/features/blocks/inputs/buttons/components/Buttons.tsx (3 hunks)
  • packages/embeds/js/src/features/blocks/inputs/buttons/components/MultipleChoicesForm.tsx (3 hunks)
🔇 Additional comments (2)
packages/embeds/js/src/features/blocks/inputs/buttons/components/Buttons.tsx (2)

56-56: LGTM: Consistent clear behavior

Setting filteredItems to an empty array on clear is consistent with the PR objective and the new initialization behavior.


18-20: LGTM: Improved initial state handling

The conditional initialization of filteredItems based on isSearchable aligns with the PR objective. When search is enabled, starting with an empty array prevents displaying buttons before user input.

Let's verify this doesn't break any existing functionality:

✅ Verification successful

Change is safe and works as intended

The conditional initialization of filteredItems is correctly implemented and aligns with the component's behavior:

  • When isSearchable is true, it starts with an empty array and populates items only when the user types (via filterItems function)
  • When isSearchable is false, it shows all defaultItems immediately
  • The SearchInput component is only rendered when isSearchable is true
  • The filtering logic in filterItems function works with this initial state
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for tests or stories that might be affected by this change
rg -l "isSearchable.*true" --type ts --type tsx

Length of output: 77


Script:

#!/bin/bash
# Search for tests or stories that might be affected by this change, using ripgrep without file type filters
rg -l "isSearchable.*true"

# Also search for any usage of the Buttons component to understand the impact
rg -l "Buttons.*isSearchable"

Length of output: 60


Script:

#!/bin/bash
# Let's look for any tests related to the Buttons component
fd "Buttons.*test" --type f

# Search for any stories or usage of the Buttons component
fd "Buttons.*stories" --type f

# Look for the actual implementation to understand the component better
fd "Buttons.tsx" --type f

Length of output: 416


Script:

#!/bin/bash
# Let's examine the content of the Buttons component to understand its usage
cat packages/embeds/js/src/features/blocks/inputs/buttons/components/Buttons.tsx

# Also check for any imports of this component
rg -l "from.*buttons.*components.*Buttons"

Length of output: 3409

Comment on lines +18 to +20
const [filteredItems, setFilteredItems] = createSignal(
props.options?.isSearchable ? [] : props.defaultItems,
);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider extracting shared search logic

The search-related logic is duplicated between Buttons.tsx and MultipleChoicesForm.tsx. Consider extracting this into a shared hook or utility function.

Example implementation:

// useSearchableItems.ts
export const useSearchableItems = <T extends { content?: string }>(
  defaultItems: T[],
  isSearchable?: boolean
) => {
  const [filteredItems, setFilteredItems] = createSignal(
    isSearchable ? [] : defaultItems
  );

  const filterItems = (inputValue: string) => {
    if (inputValue.trim() === "") {
      setFilteredItems([]);
      return;
    }
    setFilteredItems(
      defaultItems.filter((item) =>
        item.content?.toLowerCase().includes(inputValue.toLowerCase())
      )
    );
  };

  const clearItems = () => setFilteredItems([]);

  return { filteredItems, filterItems, clearItems };
};

This would:

  1. Reduce code duplication
  2. Ensure consistent behavior across components
  3. Make future modifications easier

Would you like me to create an issue to track this refactoring task?

Also applies to: 55-59, 78-78

Copy link
Owner

@baptisteArno baptisteArno left a comment

Choose a reason for hiding this comment

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

Sorry, but it was not clear, I was thinking of having this as an option because I think showing the buttons on input mount is a good default.

So the logic is good but it needs to be under a new input setting IMO

@Nil2000
Copy link
Contributor Author

Nil2000 commented Dec 30, 2024

@baptisteArno Do you mean to have a radio button setting to enable/disable this?

@baptisteArno
Copy link
Owner

@baptisteArno Do you mean to have a radio button setting to enable/disable this?

Exactly, yes! Does that make sense?

@Nil2000
Copy link
Contributor Author

Nil2000 commented Jan 3, 2025

@baptisteArno Got it Will work on the issue this away then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an option to not display the buttons when the search bar is empty
2 participants