-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
base: main
Are you sure you want to change the base?
Conversation
@Nil2000 is attempting to deploy a commit to the Typebot Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe changes introduce a new function, Changes
Assessment against linked issues
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 implementationThe current implementation has a few potential improvements:
- It silently keeps the last duplicate item, which might not be the intended behavior
- 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
📒 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:
handleUniqueItems
function is implemented to filter duplicates using a Map based on item content- The function is consistently applied to both single and multiple choice buttons
- 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be done on the server side instead if possible
Fixes: #1483