-
Notifications
You must be signed in to change notification settings - Fork 529
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: Ratelimit identifier component changes #2712
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
📝 Walkthrough📝 WalkthroughWalkthroughThe changes in the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ArrayInput
participant State
User->>ArrayInput: Enter item
ArrayInput->>State: Update input value
User->>ArrayInput: Press Enter
ArrayInput->>State: Call handleAdd
State->>ArrayInput: Add item to items
ArrayInput->>User: Display updated items
User->>ArrayInput: Unselect item
ArrayInput->>State: Call handleUnselect
State->>ArrayInput: Remove item from items
ArrayInput->>User: Display updated items
Possibly related PRs
Suggested labels
Suggested reviewers
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 (
|
Thank you for following the naming conventions for pull request titles! 🙏 |
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: 3
🧹 Outside diff range and nitpick comments (4)
apps/dashboard/components/array-input.tsx (4)
15-15
: Remove console.log statementDebug statements should not be committed to production code.
- console.log(selected);
25-32
: Add input validation and memoize handlerThe
handleAdd
function should validate input more strictly and be memoized for performance.- const handleAdd = () => { + const handleAdd = useCallback(() => { + const trimmedValue = inputValue.trim(); - if (inputValue.trim()) { + if (trimmedValue && trimmedValue.length >= 2) { - const newItems = Array.from(new Set([...items, inputValue.trim()])); + const newItems = Array.from(new Set([...items, trimmedValue])); setItems(newItems); setSelected(newItems); setInputValue(""); } - }; + }, [inputValue, items, setSelected]);
65-71
: Add ARIA labels and input validation attributesThe input field needs proper accessibility attributes and input validation.
<Input value={inputValue} onChange={(e) => setInputValue(e.target.value)} onKeyDown={handleKeyDown} placeholder={placeholder} + aria-label={title || "Add item"} + minLength={2} + role="combobox" + aria-expanded="false" className="flex-1 w-full bg-transparent outline-none placeholder:text-content-subtle" />
73-75
: Add aria-label to add buttonThe add button needs an accessible label.
- <Button size="icon" variant="secondary" onClick={handleAdd}> + <Button + size="icon" + variant="secondary" + onClick={handleAdd} + aria-label="Add item" + > <CornerDownLeft className="w-4 h-4" /> </Button>
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: 1
🧹 Outside diff range and nitpick comments (3)
apps/dashboard/app/(app)/ratelimits/[namespaceId]/filters.tsx (1)
49-49
: Improve layout structure with semantic HTMLThe layout changes improve the visual structure, but consider adding semantic HTML elements and ARIA labels for better accessibility.
- <div className="flex flex-row items-end justify-between gap-2"> + <section className="flex flex-row items-end justify-between gap-2" aria-label="Filter controls"> {props.identifier ? ( - <div className="flex-col align-end"> + <div className="flex-col align-end" role="group" aria-label="Identifier filters"> ... {props.interval ? ( - <div className="flex flex-col"> + <div className="flex flex-col" role="group" aria-label="Time interval filter">Also applies to: 51-51, 63-63
apps/dashboard/components/array-input.tsx (2)
28-35
: Add input validation and error handlingThe handleAdd function should validate the input format and handle potential duplicates more explicitly.
const handleAdd = () => { - if (inputValue.trim()) { + const trimmedValue = inputValue.trim(); + if (!trimmedValue) { + return; + } + if (items.includes(trimmedValue)) { + // Consider showing a user-friendly message + return; + } - const newItems = Array.from(new Set([...items, inputValue.trim()])); + const newItems = [...items, trimmedValue]; setItems(newItems); setSelected(newItems); setInputValue(""); - } };
79-81
: Add tooltip for the add buttonThe button's purpose might not be immediately clear from just the icon.
- <Button size="icon" variant="secondary" onClick={handleAdd}> + <Button + size="icon" + variant="secondary" + onClick={handleAdd} + title="Add item" + aria-label="Add item to list" + > <CornerDownLeft className="w-4 h-4" /> </Button>
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
apps/dashboard/app/(app)/ratelimits/[namespaceId]/filters.tsx
(2 hunks)apps/dashboard/components/array-input.tsx
(2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
apps/dashboard/components/array-input.tsx
[error] 53-53: The elements with the following roles can be changed to the following elements:
-
For examples and more information, see WAI-ARIA Roles
(lint/a11y/useSemanticElements)
For examples and more information, see WAI-ARIA Roles
(lint/a11y/useSemanticElements)
[error] 55-55: The elements with the following roles can be changed to the following elements:
🔇 Additional comments (2)
apps/dashboard/components/array-input.tsx (2)
15-19
: LGTM: State synchronization implemented correctly
The useEffect hook correctly synchronizes the local state with the selected prop, addressing the previous review comment.
37-44
: LGTM: Keyboard handling dependency fixed
The useCallback dependency array has been fixed to only include handleAdd, addressing the previous review comment.
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 (2)
apps/dashboard/components/array-input.tsx (2)
28-35
: Optimize handleAdd with useCallbackConsider memoizing the
handleAdd
function to prevent unnecessary recreations and optimize performance.- const handleAdd = () => { + const handleAdd = useCallback(() => { if (inputValue.trim()) { const newItems = Array.from(new Set([...items, inputValue.trim()])); setItems(newItems); setSelected(newItems); setInputValue(""); } - }; + }, [inputValue, items, setItems, setSelected]);
73-79
: Enhance input validation and user feedbackConsider adding the following improvements to the input field:
- Maximum length validation to prevent extremely long entries
- Visual feedback when attempting to add duplicate items
<Input value={inputValue} onChange={(e) => setInputValue(e.target.value)} onKeyDown={handleKeyDown} placeholder={placeholder} + maxLength={100} + aria-invalid={items.includes(inputValue.trim())} className="flex-1 w-full bg-transparent outline-none placeholder:text-content-subtle" />Also consider adding a helper text to show validation messages:
<div className="flex flex-wrap items-center w-full gap-1"> <Input /* ... existing props ... */ /> + {inputValue.trim() && items.includes(inputValue.trim()) && ( + <span className="text-xs text-red-500">This item already exists</span> + )} </div>
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
apps/dashboard/components/array-input.tsx
(2 hunks)
🔇 Additional comments (1)
apps/dashboard/components/array-input.tsx (1)
15-19
: LGTM! State synchronization implemented correctly.
The implementation properly synchronizes the local items
state with the selected
prop through useEffect, addressing the previous review comment.
fair point |
What does this PR do?
Fixes # (issue)
ENG-1587
If there is not an issue for this, please create one first. This is used to tracking purposes and also helps use understand why this PR exists
Type of change
How should this be tested?
Component works and causes no other issues
Checklist
Required
pnpm build
pnpm fmt
console.logs
git pull origin main
Appreciated
Summary by CodeRabbit
New Features
ArrayInput
component for improved item management, allowing users to add and remove items more intuitively.Bug Fixes
Refactor
Filters
component for enhanced presentation.