Skip to content
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
wants to merge 66 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
c55d12e
Add shadcn components
bodhish Oct 18, 2024
6b0daf2
Add seach by multiple fileds
bodhish Oct 19, 2024
0c6200c
Merge remote-tracking branch 'g/filter-component' into issues/8691-ad…
i0am0arunava Oct 20, 2024
cb5d577
Add seach by multiple fileds
i0am0arunava Oct 20, 2024
c4cfde4
required changes fixed
i0am0arunava Oct 22, 2024
9aa5285
conflict resolved
i0am0arunava Oct 22, 2024
b5b51b4
sd
i0am0arunava Oct 23, 2024
2c8e255
conflict resolved
i0am0arunava Oct 23, 2024
85a7ce6
Merge branch 'develop' into issues/8691-add-better-serchui
i0am0arunava Oct 23, 2024
ecda175
conflict resolved
i0am0arunava Oct 24, 2024
4a5d79d
checked
i0am0arunava Oct 24, 2024
67c8fcf
solved
i0am0arunava Oct 24, 2024
49ae4dd
Merge branch 'develop' into issues/8691-add-better-serchui
gigincg Oct 25, 2024
0cec042
tested locally
i0am0arunava Oct 29, 2024
185b44b
Merge remote-tracking branch 'fh/develop' into issues/8691-add-better…
i0am0arunava Oct 29, 2024
7262ada
Merge branch 'issues/8691-add-better-serchui' of https://github.com/i…
i0am0arunava Oct 29, 2024
6115516
tested locally
i0am0arunava Oct 29, 2024
65b58bc
tested done locally
i0am0arunava Oct 29, 2024
b6e1aca
tested done locally made required changes and removed unused packages…
i0am0arunava Oct 30, 2024
490d266
Merge branch 'develop' into issues/8691-add-better-serchui
i0am0arunava Oct 30, 2024
3028543
fised issue erroclassname=hidden
i0am0arunava Oct 30, 2024
38ad7d0
Merge branch 'issues/8691-add-better-serchui' of https://github.com/i…
i0am0arunava Oct 30, 2024
6b962dc
Merge branch 'develop' into issues/8691-add-better-serchui
i0am0arunava Oct 30, 2024
a6b754d
fised issue erroclassname=hidden
i0am0arunava Oct 30, 2024
973d068
added i18n content for serchfield compnent
i0am0arunava Oct 30, 2024
c7bb7b7
added i18n content for serchfield compnent
i0am0arunava Oct 30, 2024
4c9d929
type are defined in correct way
i0am0arunava Oct 30, 2024
c9404a8
Update src/components/Patient/ManagePatients.tsx
i0am0arunava Oct 30, 2024
593eda3
Update src/CAREUI/display/Count.tsx
i0am0arunava Oct 30, 2024
ba889eb
Update src/Locale/en.json
i0am0arunava Oct 30, 2024
0d3bf62
Update src/Locale/en.json
i0am0arunava Oct 30, 2024
a3d1fb9
type are defined in correct way
i0am0arunava Oct 30, 2024
2a33019
phonehelp section problem is fixed
i0am0arunava Oct 30, 2024
e535a94
type are defined in correct way
i0am0arunava Oct 30, 2024
9efea86
work removed usestae and useeffect and added phhelp feature in a simp…
i0am0arunava Oct 31, 2024
fe09b27
work removed usestae and useeffect and added phhelp feature in a simp…
i0am0arunava Oct 31, 2024
1919710
fixed at a one time only one filter will be applied for the serchbymu…
i0am0arunava Nov 2, 2024
7d4a20d
Merge branch 'develop' into issues/8691-add-better-serchui
i0am0arunava Nov 2, 2024
4f15037
error function name changed to Onerro in phnumberfiedl and serchbyfield
i0am0arunava Nov 2, 2024
f7c535f
error function name changed to Onerro in phnumberfiedl and serchbyfield
i0am0arunava Nov 2, 2024
6ff1219
made some changes,requseted by reviewer
i0am0arunava Nov 3, 2024
a8936a5
fixed the bug related to filter when applying advanced filter
i0am0arunava Nov 4, 2024
c8ce4cc
fixed the bug related to filter when applying advanced filter
i0am0arunava Nov 4, 2024
144511f
Merge branch 'develop' into issues/8691-add-better-serchui
i0am0arunava Nov 4, 2024
04bd5b1
hide help added
i0am0arunava Nov 4, 2024
25ff81d
Merge branch 'issues/8691-add-better-serchui' of https://github.com/i…
i0am0arunava Nov 4, 2024
9287679
hide help added
i0am0arunava Nov 4, 2024
795a7c3
Merge branch 'develop' into issues/8691-add-better-serchui
i0am0arunava Nov 5, 2024
9e5826b
merged develop
i0am0arunava Nov 16, 2024
0067cde
fixed: clear input value after clearing filter
i0am0arunava Nov 17, 2024
eb4b6bf
Merge remote-tracking branch 'gh/develop' into issues/8691-add-better…
i0am0arunava Nov 17, 2024
189896e
Discard changes to .env
sainak Nov 18, 2024
e039027
fixed
i0am0arunava Nov 18, 2024
bac1db6
Merge remote-tracking branch 'hgh/develop' into issues/8691-add-bette…
i0am0arunava Nov 18, 2024
3e75b22
merge conflict resolving
i0am0arunava Nov 19, 2024
7a4ecac
debouncing added for search field
i0am0arunava Nov 19, 2024
b7e3e00
debouncing added for search field
i0am0arunava Nov 19, 2024
acc6362
Merge branch 'develop' into issues/8691-add-better-serchui
i0am0arunava Nov 20, 2024
db5962c
Merge branch 'develop' into issues/8691-add-better-serchui
i0am0arunava Nov 21, 2024
12af40e
fixed debouncing and prevent unnecessary api calls
i0am0arunava Nov 24, 2024
fa58519
Merge remote-tracking branch 'xx/develop' into issues/8691-add-better…
i0am0arunava Nov 24, 2024
9102b20
cleanup
shivankacker Nov 26, 2024
a9746cc
minor fixes
shivankacker Nov 26, 2024
241a1f1
Merge branch 'develop' into issues/8691-add-better-serchui
shivankacker Nov 26, 2024
53a6c35
Fixed keyboard shortcutes
shivankacker Nov 26, 2024
84c1155
Merge branch 'issues/8691-add-better-serchui' of https://github.com/i…
shivankacker Nov 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
631 changes: 496 additions & 135 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@
"@hello-pangea/dnd": "^17.0.0",
"@pnotify/core": "^5.2.0",
"@pnotify/mobile": "^5.2.0",
"@radix-ui/react-dialog": "^1.1.2",
"@radix-ui/react-dropdown-menu": "^2.1.2",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-popover": "^1.1.2",
"@radix-ui/react-scroll-area": "^1.2.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-toast": "^1.2.2",
"@radix-ui/react-tooltip": "^1.1.3",
Expand All @@ -72,6 +76,7 @@
"browserslist-useragent-regexp": "^4.1.3",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"cmdk": "^1.0.0",
"cross-env": "^7.0.3",
"cypress": "^13.14.2",
"dayjs": "^1.11.11",
Expand Down Expand Up @@ -173,4 +178,4 @@
"node": ">=20.12.0"
},
"packageManager": "npm@10.5.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert this line

}
}
220 changes: 220 additions & 0 deletions src/Components/Common/SearchByMultipleFields.tsx
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 (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This component should have a default state where it says a simple help text. EG
image

<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;
4 changes: 3 additions & 1 deletion src/Components/Form/FormFields/FormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ const FormField = ({
)}
</div>
<div className={field?.className}>{props.children}</div>
<FieldErrorText error={field?.error} className={field?.errorClassName} />
{field?.error && (
<FieldErrorText error={field.error} className={field?.errorClassName} />
)}
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved
</div>
);
};
Expand Down
14 changes: 6 additions & 8 deletions src/Components/Form/FormFields/PhoneNumberFormField.tsx
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,17 @@
field={{
...field,
error: field.error || error,
labelSuffix: field.labelSuffix || (
<PhoneNumberTypesHelp types={props.types} />
),
labelSuffix: field.labelSuffix || "",
}}
>
<div className="relative rounded-md shadow-sm">
<div className="relative rounded-md">
<Popover>
{({ open }: { open: boolean }) => {
return (
<>
<PopoverButton className="absolute h-full">
<div className="absolute inset-y-0 left-0 m-0.5 flex w-[4.5rem] cursor-pointer items-center justify-around bg-slate-100">
<span className="rounded-md pl-4">
<div className="hover:border-1 absolute inset-y-0 left-0 flex cursor-pointer items-center justify-around border-gray-200 hover:border hover:bg-gray-50">
<span className="rounded-md pl-2">
{country?.flag ?? "🇮🇳"}
</span>
<CareIcon
Expand All @@ -128,7 +126,7 @@
name={field.name}
autoComplete={props.autoComplete ?? "tel"}
className={classNames(
"cui-input-base h-full pl-20 tracking-widest sm:leading-6",
"cui-input-base h-full pl-14 tracking-widest sm:leading-6",
field.error && "border-danger-500",
field.className,
)}
Expand Down Expand Up @@ -156,7 +154,7 @@
);
}

const PhoneNumberTypesHelp = (props: { types: PhoneNumberType[] }) => {

Check failure on line 157 in src/Components/Form/FormFields/PhoneNumberFormField.tsx

View workflow job for this annotation

GitHub Actions / lint

'PhoneNumberTypesHelp' is assigned a value but never used. Allowed unused vars must match /^_/u
const { t } = useTranslation();

return (
Expand Down Expand Up @@ -204,7 +202,7 @@
const [searchValue, setSearchValue] = useState<string>("");

return (
<div className="absolute z-10 w-full rounded-md border border-secondary-300 bg-white shadow-lg transition-all duration-300">
<div className="absolute z-10 w-full rounded-md border border-gray-300 bg-white shadow-lg transition-all duration-300">
<div className="relative m-2">
<CareIcon
icon="l-search"
Expand Down
Loading
Loading