-
Notifications
You must be signed in to change notification settings - Fork 69
feat: add reusable tag selector for Add/Edit Task dialogs #390
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
Merged
its-me-abhishek
merged 4 commits into
CCExtractor:main
from
Hell1213:fix/issue-210-reusable-tags
Jan 17, 2026
+1,029
−242
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9a6e0b7
feat: create TagMultiSelect component for reusable tag selection
Hell1213 f6c346c
feat: integrate TagMultiSelect with AddTaskDialog
Hell1213 e35f306
feat: integrate TagMultiSelect with TaskDialog for editing
Hell1213 854cab3
test: add comprehensive tests for TagMultiSelect component
Hell1213 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
199 changes: 199 additions & 0 deletions
199
frontend/src/components/HomeComponents/Tasks/MultiSelect.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| import { useState, useRef, useEffect } from 'react'; | ||
| import { Badge } from '@/components/ui/badge'; | ||
| import { Button } from '@/components/ui/button'; | ||
| import { Input } from '@/components/ui/input'; | ||
| import { MultiSelectProps } from '@/components/utils/types'; | ||
| import { ChevronDown, Plus, Check, X } from 'lucide-react'; | ||
| import { getFilteredItems, shouldShowCreateOption } from './multi-select-utils'; | ||
|
|
||
| export const MultiSelect = ({ | ||
| availableItems, | ||
| selectedItems, | ||
| onItemsChange, | ||
| placeholder = 'Select or create items', | ||
| disabled = false, | ||
| className = '', | ||
| showActions = false, | ||
| onSave, | ||
| onCancel, | ||
| }: MultiSelectProps) => { | ||
| const [isOpen, setIsOpen] = useState(false); | ||
| const [searchTerm, setSearchTerm] = useState(''); | ||
| const dropdownRef = useRef<HTMLDivElement>(null); | ||
| const inputRef = useRef<HTMLInputElement>(null); | ||
|
|
||
| useEffect(() => { | ||
| const handleClickOutside = (event: MouseEvent) => { | ||
| if ( | ||
| dropdownRef.current && | ||
| !dropdownRef.current.contains(event.target as Node) | ||
| ) { | ||
| setIsOpen(false); | ||
| setSearchTerm(''); | ||
| } | ||
| }; | ||
|
|
||
| document.addEventListener('mousedown', handleClickOutside); | ||
| return () => document.removeEventListener('mousedown', handleClickOutside); | ||
| }, []); | ||
|
|
||
| const filteredItems = getFilteredItems( | ||
| availableItems, | ||
| selectedItems, | ||
| searchTerm | ||
| ); | ||
|
|
||
| const handleItemSelect = (item: string) => { | ||
| if (!selectedItems.includes(item)) { | ||
| onItemsChange([...selectedItems, item]); | ||
| } | ||
| setSearchTerm(''); | ||
| }; | ||
|
|
||
| const handleItemRemove = (itemToRemove: string) => { | ||
| onItemsChange(selectedItems.filter((item) => item !== itemToRemove)); | ||
| }; | ||
|
|
||
| const handleNewItemCreate = () => { | ||
| const trimmedTerm = searchTerm.trim(); | ||
| if ( | ||
| trimmedTerm && | ||
| !selectedItems.includes(trimmedTerm) && | ||
| !availableItems.includes(trimmedTerm) | ||
| ) { | ||
| onItemsChange([...selectedItems, trimmedTerm]); | ||
| setSearchTerm(''); | ||
| } | ||
| }; | ||
|
|
||
| const handleKeyDown = (e: React.KeyboardEvent) => { | ||
its-me-abhishek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (e.key === 'Enter') { | ||
| e.preventDefault(); | ||
| if (searchTerm.trim()) { | ||
| if (filteredItems.length > 0) { | ||
| handleItemSelect(filteredItems[0]); | ||
| } else { | ||
| handleNewItemCreate(); | ||
| } | ||
| } | ||
| } else if (e.key === 'Escape') { | ||
| setIsOpen(false); | ||
| setSearchTerm(''); | ||
| } | ||
| }; | ||
|
|
||
| const showCreate = shouldShowCreateOption( | ||
| searchTerm, | ||
| availableItems, | ||
| selectedItems | ||
| ); | ||
|
|
||
| return ( | ||
| <div className={`relative ${className}`} ref={dropdownRef}> | ||
| <Button | ||
| type="button" | ||
| variant="outline" | ||
| onClick={() => setIsOpen(!isOpen)} | ||
| disabled={disabled} | ||
| className="w-full justify-between text-left font-normal" | ||
| aria-label="Select items" | ||
| > | ||
| <span className="truncate"> | ||
| {selectedItems.length > 0 | ||
| ? `${selectedItems.length} item${selectedItems.length > 1 ? 's' : ''} selected` | ||
| : placeholder} | ||
| </span> | ||
| <ChevronDown className="h-4 w-4 opacity-50" /> | ||
| </Button> | ||
|
|
||
| {selectedItems.length > 0 && ( | ||
| <div className="flex flex-wrap items-center gap-2 mt-2"> | ||
| {selectedItems.map((item) => ( | ||
| <Badge key={item} className="flex items-center gap-1"> | ||
| <span>{item}</span> | ||
| <button | ||
| type="button" | ||
| onClick={() => handleItemRemove(item)} | ||
| className="ml-1 text-red-500 hover:text-red-700 text-xs" | ||
| disabled={disabled} | ||
| aria-label={`Remove ${item}`} | ||
| > | ||
| ✖ | ||
| </button> | ||
| </Badge> | ||
| ))} | ||
| {showActions && onSave && onCancel && ( | ||
| <div className="flex items-center gap-1 whitespace-nowrap"> | ||
| <Button | ||
| type="button" | ||
| variant="ghost" | ||
| size="icon" | ||
| onClick={onSave} | ||
| className="h-8 w-8" | ||
| aria-label="Save items" | ||
| > | ||
| <Check className="h-4 w-4 text-green-500" /> | ||
| </Button> | ||
| <Button | ||
| type="button" | ||
| variant="ghost" | ||
| size="icon" | ||
| onClick={onCancel} | ||
| className="h-8 w-8" | ||
| aria-label="Cancel" | ||
| > | ||
| <X className="h-4 w-4 text-red-500" /> | ||
| </Button> | ||
| </div> | ||
| )} | ||
| </div> | ||
| )} | ||
|
|
||
| {isOpen && ( | ||
| <div className="absolute z-50 w-full mt-1 bg-background border border-border rounded-md shadow-lg max-h-60 overflow-hidden"> | ||
| <div className="p-2 border-b"> | ||
| <Input | ||
| ref={inputRef} | ||
| value={searchTerm} | ||
| onChange={(e) => setSearchTerm(e.target.value)} | ||
| onKeyDown={handleKeyDown} | ||
| placeholder="Search or create..." | ||
| className="h-8" | ||
| autoFocus | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="max-h-40 overflow-y-auto"> | ||
| {filteredItems.map((item) => ( | ||
| <div | ||
| key={item} | ||
| className="px-3 py-2 cursor-pointer hover:bg-accent transition-colors" | ||
| onClick={() => handleItemSelect(item)} | ||
| > | ||
| <span className="text-sm">{item}</span> | ||
| </div> | ||
| ))} | ||
|
|
||
| {showCreate && ( | ||
| <div | ||
| className="flex items-center gap-2 px-3 py-2 cursor-pointer hover:bg-accent transition-colors border-t" | ||
| onClick={handleNewItemCreate} | ||
| > | ||
| <Plus className="h-4 w-4 text-muted-foreground" /> | ||
| <span className="flex-1 text-sm"> | ||
| Create "{searchTerm.trim()}" | ||
| </span> | ||
| </div> | ||
| )} | ||
|
|
||
| {filteredItems.length === 0 && !showCreate && ( | ||
| <div className="px-3 py-2 text-sm text-muted-foreground text-center"> | ||
| No items found | ||
| </div> | ||
| )} | ||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.