-
Notifications
You must be signed in to change notification settings - Fork 0
[feature] Auto completion field on room #9
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
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
7f501fb
[fix] Fixed "uncontrolled to controlled" warning by using an explicit…
Jch4ipas 03ae7b2
[feature] implement debounced autocomplete search for rooms
Jch4ipas 3bac2ca
[feature] search room with autocompletion on external api
Jch4ipas 58d3e72
[fix] prevent double data fetching on initial component mount on Filt…
Jch4ipas 861f6a5
[chore] rename filterCombobox to match component name filterDebounced…
Jch4ipas 9739c59
[fix] resolve type mismatches in FilterSelect component
Jch4ipas e529b10
[fix] add missing translation keys for filter components
Jch4ipas 6ffb44c
[feature] add conditional autocomplete based on cascading state
Jch4ipas 964c7a9
[refactor] extract SortableHeaderProps and resolve TS (types) warnings
Jch4ipas deb68ef
[chore] remove obsolete roomDisplay and storage suggestions code
Jch4ipas c54595d
[refactor] extract room suggestions fetch into a dedicated method
Jch4ipas da9fd5b
[chore] replace special whitespace character with standard space
Jch4ipas 94cbe98
[feature] make SearchFieldAutoComplete generic and update getRoomApiS…
Jch4ipas 4c2c771
[chore] `npx shadcn@latest add popover command`
Jch4ipas 60cf363
[feature] upgrade FilterDebouncedInput to use shadcn combobox
Jch4ipas 01290d7
[fix] handle GraphQL errors in room suggestions fetcher
Jch4ipas 76f84ad
[fix] resolve 'unknown' type inference in text search
Jch4ipas cb7e2da
[chore] `npx shadcn@latest add command`
Jch4ipas 6763d71
[refactor] extract SortableHeader into an independent component
Jch4ipas beef806
[refactor] extract fetchStorage variables type into an interface in t…
Jch4ipas 8d38212
[refactor] remove useless try catch
Jch4ipas 32659a8
[feature] store selectedRoomId in ActiveFilters from API suggestions
Jch4ipas e6f653d
[fix] load existing barcode details into filters and mock disabled se…
Jch4ipas f1b5246
[fix] align onFilterChange with strict generic types
Jch4ipas 070b206
[refactor] remove deadcode
Jch4ipas 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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,87 @@ | ||
| import { useState, useEffect, useRef } from "react"; | ||
| import { Input } from "@/components/ui/input.tsx"; | ||
| import { Popover, PopoverContent, PopoverAnchor } from "@/components/ui/popover.tsx"; | ||
| import { Command, CommandGroup, CommandItem, CommandList } from "@/components/ui/command.tsx"; | ||
|
|
||
| export const FilterDebouncedInput = ({ | ||
| placeholder, | ||
| value, | ||
| onSearch, | ||
| suggestions, | ||
| disable, | ||
| }: { | ||
| placeholder: string; | ||
| value: string | null; | ||
| onSearch: (searchTerm: string) => void; | ||
| suggestions: string[]; | ||
| disable?: boolean; | ||
| }) => { | ||
| const [localValue, setLocalValue] = useState(value || ""); | ||
| const [open, setOpen] = useState(false); | ||
| const isInitialMount = useRef(true); | ||
|
|
||
| useEffect(() => { | ||
| setLocalValue(value || ""); | ||
| }, [value]); | ||
|
|
||
| useEffect(() => { | ||
| if (isInitialMount.current) { | ||
| isInitialMount.current = false; | ||
| return; | ||
| } | ||
| const timeoutId = setTimeout(() => { | ||
| if (localValue !== (value || "")) { | ||
| onSearch(localValue); | ||
| } | ||
| }, 1000); | ||
|
|
||
| return () => clearTimeout(timeoutId); | ||
| }, [localValue]); | ||
|
|
||
| return ( | ||
| <Popover open={open && suggestions.length > 0} onOpenChange={setOpen}> | ||
| <div className="w-1/2 m-1"> | ||
| <PopoverAnchor asChild> | ||
| <Input | ||
| type="text" | ||
| value={localValue} | ||
| onChange={(e: React.ChangeEvent<HTMLInputElement>) => { | ||
| setLocalValue(e.target.value); | ||
| setOpen(true); | ||
| }} | ||
| disabled={disable} | ||
| className="w-full" | ||
| placeholder={placeholder} | ||
| /> | ||
| </PopoverAnchor> | ||
|
|
||
| <PopoverContent | ||
| className="p-0 w-[var(--radix-popover-trigger-width)]" | ||
| align="start" | ||
| onOpenAutoFocus={(e) => e.preventDefault()} | ||
| > | ||
| <Command shouldFilter={false}> | ||
| <CommandList> | ||
| <CommandGroup> | ||
| {suggestions.map((suggestion, index) => ( | ||
| <CommandItem | ||
| key={`${suggestion}-${index}`} | ||
| value={suggestion} | ||
| onSelect={(currentValue) => { | ||
| setLocalValue(currentValue); | ||
| onSearch(currentValue); | ||
| setOpen(false); | ||
| }} | ||
| className="cursor-pointer data-[selected=true]:bg-primary data-[selected=true]:text-primary-foreground" | ||
| > | ||
| {suggestion} | ||
| </CommandItem> | ||
| ))} | ||
| </CommandGroup> | ||
| </CommandList> | ||
| </Command> | ||
| </PopoverContent> | ||
| </div> | ||
| </Popover> | ||
| ); | ||
| }; |
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
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
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,58 @@ | ||
| import { useState } from "react"; | ||
| import { FilterDebouncedInput } from "@/components/parts/filterDebouncedInput"; | ||
|
|
||
| interface SmartAutocompleteProps<T> { | ||
| placeholder: string; | ||
| value: string | null; | ||
| onChange: (val: string) => void; | ||
| fetchData?: (searchTerm: string) => Promise<T[]>; | ||
| getDisplayValue: (item: T) => string; | ||
| onSelectItem?: (item: T) => void; | ||
| disable?: boolean; | ||
| isAutoComplete?: boolean; | ||
| } | ||
|
|
||
| export const SearchFieldAutoComplete = <T,>({ | ||
| placeholder, | ||
| value, | ||
| onChange, | ||
| fetchData, | ||
| getDisplayValue, | ||
| onSelectItem, | ||
| disable, | ||
| isAutoComplete | ||
| }: SmartAutocompleteProps<T>) => { | ||
|
|
||
| const [rawSuggestions, setRawSuggestions] = useState<T[]>([]); | ||
|
|
||
| const handleSearch = async (searchTerm: string) => { | ||
| onChange(searchTerm); | ||
|
|
||
| const matchedItem = rawSuggestions.find(item => getDisplayValue(item) === searchTerm); | ||
|
|
||
| if (matchedItem && onSelectItem) { | ||
| onSelectItem(matchedItem); | ||
| } | ||
| if (isAutoComplete && fetchData && searchTerm.length >= 2) { | ||
| try { | ||
| const results = await fetchData(searchTerm); | ||
| setRawSuggestions(results); | ||
| } catch (error) { | ||
| console.error("Erreur lors de la recherche :", error); | ||
| setRawSuggestions([]); | ||
| } | ||
| } else { | ||
| setRawSuggestions([]); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <FilterDebouncedInput | ||
| placeholder={placeholder} | ||
| value={value} | ||
| onSearch={handleSearch} | ||
| suggestions={rawSuggestions.map(getDisplayValue)} | ||
| disable={disable} | ||
| /> | ||
| ); | ||
| }; |
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.