-
Notifications
You must be signed in to change notification settings - Fork 444
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 Add a better search UI for patients index page #8691 #8834
Open
i0am0arunava
wants to merge
66
commits into
ohcnetwork:develop
Choose a base branch
from
i0am0arunava:issues/8691-add-better-serchui
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
66 commits
Select commit
Hold shift + click to select a range
c55d12e
Add shadcn components
bodhish 6b0daf2
Add seach by multiple fileds
bodhish 0c6200c
Merge remote-tracking branch 'g/filter-component' into issues/8691-ad…
i0am0arunava cb5d577
Add seach by multiple fileds
i0am0arunava c4cfde4
required changes fixed
i0am0arunava 9aa5285
conflict resolved
i0am0arunava b5b51b4
sd
i0am0arunava 2c8e255
conflict resolved
i0am0arunava 85a7ce6
Merge branch 'develop' into issues/8691-add-better-serchui
i0am0arunava ecda175
conflict resolved
i0am0arunava 4a5d79d
checked
i0am0arunava 67c8fcf
solved
i0am0arunava 49ae4dd
Merge branch 'develop' into issues/8691-add-better-serchui
gigincg 0cec042
tested locally
i0am0arunava 185b44b
Merge remote-tracking branch 'fh/develop' into issues/8691-add-better…
i0am0arunava 7262ada
Merge branch 'issues/8691-add-better-serchui' of https://github.com/i…
i0am0arunava 6115516
tested locally
i0am0arunava 65b58bc
tested done locally
i0am0arunava b6e1aca
tested done locally made required changes and removed unused packages…
i0am0arunava 490d266
Merge branch 'develop' into issues/8691-add-better-serchui
i0am0arunava 3028543
fised issue erroclassname=hidden
i0am0arunava 38ad7d0
Merge branch 'issues/8691-add-better-serchui' of https://github.com/i…
i0am0arunava 6b962dc
Merge branch 'develop' into issues/8691-add-better-serchui
i0am0arunava a6b754d
fised issue erroclassname=hidden
i0am0arunava 973d068
added i18n content for serchfield compnent
i0am0arunava c7bb7b7
added i18n content for serchfield compnent
i0am0arunava 4c9d929
type are defined in correct way
i0am0arunava c9404a8
Update src/components/Patient/ManagePatients.tsx
i0am0arunava 593eda3
Update src/CAREUI/display/Count.tsx
i0am0arunava ba889eb
Update src/Locale/en.json
i0am0arunava 0d3bf62
Update src/Locale/en.json
i0am0arunava a3d1fb9
type are defined in correct way
i0am0arunava 2a33019
phonehelp section problem is fixed
i0am0arunava e535a94
type are defined in correct way
i0am0arunava 9efea86
work removed usestae and useeffect and added phhelp feature in a simp…
i0am0arunava fe09b27
work removed usestae and useeffect and added phhelp feature in a simp…
i0am0arunava 1919710
fixed at a one time only one filter will be applied for the serchbymu…
i0am0arunava 7d4a20d
Merge branch 'develop' into issues/8691-add-better-serchui
i0am0arunava 4f15037
error function name changed to Onerro in phnumberfiedl and serchbyfield
i0am0arunava f7c535f
error function name changed to Onerro in phnumberfiedl and serchbyfield
i0am0arunava 6ff1219
made some changes,requseted by reviewer
i0am0arunava a8936a5
fixed the bug related to filter when applying advanced filter
i0am0arunava c8ce4cc
fixed the bug related to filter when applying advanced filter
i0am0arunava 144511f
Merge branch 'develop' into issues/8691-add-better-serchui
i0am0arunava 04bd5b1
hide help added
i0am0arunava 25ff81d
Merge branch 'issues/8691-add-better-serchui' of https://github.com/i…
i0am0arunava 9287679
hide help added
i0am0arunava 795a7c3
Merge branch 'develop' into issues/8691-add-better-serchui
i0am0arunava 9e5826b
merged develop
i0am0arunava 0067cde
fixed: clear input value after clearing filter
i0am0arunava eb4b6bf
Merge remote-tracking branch 'gh/develop' into issues/8691-add-better…
i0am0arunava 189896e
Discard changes to .env
sainak e039027
fixed
i0am0arunava bac1db6
Merge remote-tracking branch 'hgh/develop' into issues/8691-add-bette…
i0am0arunava 3e75b22
merge conflict resolving
i0am0arunava 7a4ecac
debouncing added for search field
i0am0arunava b7e3e00
debouncing added for search field
i0am0arunava acc6362
Merge branch 'develop' into issues/8691-add-better-serchui
i0am0arunava db5962c
Merge branch 'develop' into issues/8691-add-better-serchui
i0am0arunava 12af40e
fixed debouncing and prevent unnecessary api calls
i0am0arunava fa58519
Merge remote-tracking branch 'xx/develop' into issues/8691-add-better…
i0am0arunava 9102b20
cleanup
shivankacker a9746cc
minor fixes
shivankacker 241a1f1
Merge branch 'develop' into issues/8691-add-better-serchui
shivankacker 53a6c35
Fixed keyboard shortcutes
shivankacker 84c1155
Merge branch 'issues/8691-add-better-serchui' of https://github.com/i…
shivankacker 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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,220 @@ | ||
import React, { | ||
useState, | ||
useCallback, | ||
useRef, | ||
useEffect, | ||
useMemo, | ||
} from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { Input } from "@/Components/ui/input"; | ||
import { Button } from "@/Components/ui/button"; | ||
import { cn } from "@/lib/utils"; | ||
import CareIcon from "@/CAREUI/icons/CareIcon"; | ||
import PhoneNumberFormField from "@/Components/Form/FormFields/PhoneNumberFormField"; | ||
import { | ||
Command, | ||
CommandGroup, | ||
CommandItem, | ||
CommandList, | ||
} from "@/Components/ui/command"; | ||
import { | ||
Popover, | ||
PopoverContent, | ||
PopoverTrigger, | ||
} from "@/Components/ui/popover"; | ||
|
||
interface SearchOption { | ||
key: string; | ||
label: string; | ||
type: "text" | "phone"; | ||
placeholder: string; | ||
value: string; | ||
shortcut_key: string; | ||
component?: React.ComponentType<any>; | ||
} | ||
|
||
interface SearchByMultipleFieldsProps { | ||
options: SearchOption[]; | ||
onSearch: (key: string, value: string) => void; | ||
initialOption?: SearchOption; | ||
className?: string; | ||
inputClassName?: string; | ||
buttonClassName?: string; | ||
} | ||
|
||
const SearchByMultipleFields: React.FC<SearchByMultipleFieldsProps> = ({ | ||
options, | ||
onSearch, | ||
initialOption, | ||
className, | ||
inputClassName, | ||
buttonClassName, | ||
}) => { | ||
const { t } = useTranslation(); | ||
const [selectedOption, setSelectedOption] = useState<SearchOption>( | ||
initialOption || options[0], | ||
); | ||
const [searchValue, setSearchValue] = useState(selectedOption.value || ""); | ||
const [open, setOpen] = useState(false); | ||
const inputRef = useRef<HTMLInputElement>(null); | ||
|
||
useEffect(() => { | ||
const handleKeyDown = (e: KeyboardEvent) => { | ||
if (e.key === "/" && document.activeElement !== inputRef.current) { | ||
e.preventDefault(); | ||
setOpen(true); | ||
} | ||
|
||
if (open) { | ||
if (e.key === "Escape") { | ||
setOpen(false); | ||
} | ||
} | ||
|
||
options.forEach((option) => { | ||
if (e.key.toLowerCase() === option.shortcut_key.toLowerCase()) { | ||
e.preventDefault(); | ||
handleOptionChange(option); | ||
} | ||
}); | ||
}; | ||
|
||
document.addEventListener("keydown", handleKeyDown); | ||
return () => document.removeEventListener("keydown", handleKeyDown); | ||
}, []); | ||
|
||
const handleOptionChange = useCallback( | ||
(option: SearchOption) => { | ||
setSelectedOption(option); | ||
setSearchValue(option.value || ""); | ||
setOpen(false); | ||
inputRef.current?.focus(); | ||
onSearch(option.key, option.value); | ||
}, | ||
[onSearch], | ||
); | ||
|
||
const handleSearchChange = useCallback( | ||
(value: string) => { | ||
setSearchValue(value); | ||
onSearch(selectedOption.key, value); | ||
}, | ||
[selectedOption, onSearch], | ||
); | ||
|
||
const handleKeyDown = useCallback( | ||
(e: React.KeyboardEvent<HTMLInputElement>) => { | ||
console.log(e.key); | ||
if (e.key === "Escape") { | ||
setSearchValue(""); | ||
onSearch(selectedOption.key, ""); | ||
} | ||
if (e.key === "/") { | ||
e.preventDefault(); | ||
setOpen(true); | ||
} | ||
}, | ||
[selectedOption, onSearch], | ||
); | ||
|
||
const renderSearchInput = useMemo(() => { | ||
const commonProps = { | ||
ref: inputRef, | ||
value: searchValue, | ||
onChange: (e: any) => | ||
handleSearchChange(e.target ? e.target.value : e.value), | ||
rithviknishad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
onKeyDown: handleKeyDown, | ||
className: cn( | ||
"flex-grow border-none shadow-none focus-visible:ring-0 h-10", | ||
inputClassName, | ||
), | ||
}; | ||
|
||
switch (selectedOption.type) { | ||
case "phone": | ||
return ( | ||
<PhoneNumberFormField | ||
name={selectedOption.key} | ||
placeholder={t(selectedOption.placeholder)} | ||
types={["mobile", "landline"]} | ||
{...commonProps} | ||
/> | ||
); | ||
default: | ||
return ( | ||
<Input | ||
type="text" | ||
placeholder={t(selectedOption.placeholder)} | ||
{...commonProps} | ||
/> | ||
); | ||
} | ||
}, [ | ||
selectedOption, | ||
searchValue, | ||
handleSearchChange, | ||
handleKeyDown, | ||
t, | ||
inputClassName, | ||
]); | ||
|
||
return ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
<div className={className}> | ||
<div className="flex items-center rounded-t-lg border-x border-t border-gray-200 bg-white"> | ||
<Popover open={open} onOpenChange={setOpen}> | ||
<PopoverTrigger asChild> | ||
<Button | ||
variant="ghost" | ||
className="focus:ring-0" | ||
size="sm" | ||
onClick={() => setOpen(true)} | ||
> | ||
<CareIcon icon="l-search" className="mr-2 h-4 w-4" />/ | ||
</Button> | ||
</PopoverTrigger> | ||
<PopoverContent className="w-[200px] p-0"> | ||
<Command> | ||
<CommandList> | ||
<CommandGroup> | ||
{options.map((option) => ( | ||
<CommandItem | ||
key={option.key} | ||
onSelect={() => handleOptionChange(option)} | ||
> | ||
<CareIcon icon="l-search" className="mr-2 h-4 w-4" /> | ||
<span className="flex-1">{t(option.label)}</span> | ||
<kbd className="ml-auto text-xs text-gray-400"> | ||
{option.label.charAt(0).toUpperCase()} | ||
i0am0arunava marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</kbd> | ||
</CommandItem> | ||
))} | ||
</CommandGroup> | ||
</CommandList> | ||
</Command> | ||
</PopoverContent> | ||
</Popover> | ||
{renderSearchInput} | ||
</div> | ||
<div className="flex flex-wrap gap-2 rounded-b-lg border-x border-b border-gray-200 bg-gray-50 p-2 shadow"> | ||
{options.map((option) => ( | ||
<Button | ||
key={option.key} | ||
onClick={() => handleOptionChange(option)} | ||
variant="outline" | ||
size="xs" | ||
className={cn( | ||
selectedOption.key === option.key | ||
? "bg-primary-100 text-primary-700" | ||
: "bg-gray-100 text-gray-700 hover:bg-gray-200", | ||
buttonClassName, | ||
)} | ||
> | ||
{t(option.label)} | ||
</Button> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default SearchByMultipleFields; |
This file contains 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
rithviknishad marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains 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
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.
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.
revert this line