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: Dynamic buttons should display unique items #1926

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

Conversation

Nil2000
Copy link

@Nil2000 Nil2000 commented Dec 13, 2024

Fixes: #1483

Copy link

vercel bot commented Dec 13, 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 13, 2024

Walkthrough

The changes introduce a new function, handleUniqueItems, in the Input component of the application. This function processes an array of items to ensure that only unique items are passed to the Buttons and MultipleChoicesForm components. The implementation replaces the direct assignment of items with a call to handleUniqueItems, which utilizes a Map to filter duplicates based on the content property. The props of the Input component have been adjusted accordingly, while the overall control flow remains unchanged.

Changes

File Path Change Summary
packages/embeds/js/src/components/InputChatBlock.tsx Introduced handleUniqueItems function to filter unique items; updated defaultItems property for Buttons and MultipleChoicesForm to use this function. Adjusted props in Input component.

Assessment against linked issues

Objective Addressed Explanation
Dynamic buttons should display unique items (#1483)

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. (Experiment)
  • @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: 0

🧹 Outside diff range and nitpick comments (1)
packages/embeds/js/src/components/InputChatBlock.tsx (1)

156-158: Consider enhancing the uniqueness handling implementation

The current implementation has a few potential improvements:

  1. It silently keeps the last duplicate item, which might not be the intended behavior
  2. It lacks handling for edge cases (null/undefined items)

Consider this more robust implementation:

-  const handleUniqueItems= (items: ChoiceInputBlock["items"]) => {
-    return Array.from(new Map(items.map((item) => [item.content, item])).values());
-  }
+  const handleUniqueItems = (items: ChoiceInputBlock["items"]) => {
+    if (!items?.length) return [];
+    const seen = new Set<string>();
+    return items.filter((item) => {
+      if (!item?.content || seen.has(item.content)) return false;
+      seen.add(item.content);
+      return true;
+    });
+  }
📜 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 ab914ea.

📒 Files selected for processing (1)
  • packages/embeds/js/src/components/InputChatBlock.tsx (2 hunks)
🔇 Additional comments (2)
packages/embeds/js/src/components/InputChatBlock.tsx (2)

221-221: Verify if this change resolves issue #1483

The uniqueness handling has been added consistently to both single and multiple choice buttons. Let's verify if this implementation addresses the original issue.

✅ Verification successful

Implementation successfully addresses duplicate items issue

The verification confirms that the fix properly handles duplicate items:

  1. handleUniqueItems function is implemented to filter duplicates using a Map based on item content
  2. The function is consistently applied to both single and multiple choice buttons
  3. The implementation matches the issue description (Dynamic buttons should display unique items #1483) which requested filtering of duplicate items in dynamic buttons
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Fetch the original issue description to understand the reported problem
gh issue view 1483

# Search for any related test cases or existing duplicate item handling
rg -A 5 "MultipleChoicesForm.*test"

Length of output: 388


Script:

#!/bin/bash
# Let's verify the implementation of handleUniqueItems and its usage
ast-grep --pattern 'function handleUniqueItems'

# Search for the implementation of MultipleChoicesForm and its usage of items
ast-grep --pattern 'const MultipleChoicesForm = $_'

# Check for any test files related to buttons or choices
fd -e test.tsx -e test.ts -X rg -l "buttons|choices" {}

Length of output: 20916


Script:

#!/bin/bash
# Let's find the handleUniqueItems implementation and its usage
rg -A 5 "handleUniqueItems" 

# Let's also check for any duplicate-related code in the buttons component
rg -A 5 "duplicate.*items?"

Length of output: 4971


214-214: Verify consistent handling across all choice components

The uniqueness handling is applied to Buttons but not to SinglePictureChoice or MultiplePictureChoice components. This inconsistency might lead to different behaviors for similar use cases.

Let's verify if picture choice components also need unique item handling:

✅ Verification successful

Let me gather more information about how these components handle their items.


Let me check one more thing to understand where exactly the handleUniqueItems is being used in the InputChatBlock component.


Based on the gathered information, I can now provide the final response:

Unique item handling is correctly implemented for choice components

The handleUniqueItems function is specifically implemented in InputChatBlock component which serves as a router for different types of inputs. The function is correctly applied to both single and multiple choice buttons through the common input handling logic. Picture choice components don't need separate unique item handling as they inherit the same processed items through the defaultItems prop from InputChatBlock.

  • The uniqueness is handled at the parent level before items are passed down to any choice component
  • Both button and picture choice components receive deduplicated items through the same prop interface
  • This implementation ensures consistent behavior across all choice components
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any existing duplicate handling in picture choice components
rg -A 5 "PictureChoice.*items" 

# Check if there are any reported issues about duplicate items in picture choices
gh issue list --search "duplicate picture choice in:title,body"

Length of output: 1463


Script:

#!/bin/bash
# Check how items are used in picture choice components
ast-grep --pattern 'const $_ = ({ defaultItems }: $_) => {
  $$$
}'  packages/embeds/js/src/features/blocks/inputs/pictureChoice/*.tsx

# Check the implementation of handleUniqueItems
ast-grep --pattern 'const handleUniqueItems = $_'

# Check where handleUniqueItems is imported and used
rg "handleUniqueItems" -A 2

Length of output: 4999


Script:

#!/bin/bash
# Check the full InputChatBlock component to understand the context of handleUniqueItems usage
ast-grep --pattern 'const InputChatBlock = ($_) => {
  $$$
}'

# Also check for any choice-related type definitions
rg "type.*ChoiceInputBlock" -A 3

Length of output: 21089

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.

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.

Dynamic buttons should display unique items
2 participants