From 945f4aca244e8ce9ea31b2b1558d014c9b0f80c5 Mon Sep 17 00:00:00 2001 From: dogukanoksuz Date: Fri, 5 Jul 2024 10:21:14 +0000 Subject: [PATCH] fix: Role mapping search issue --- src/components/settings/async-transfer-list.tsx | 5 ++++- src/components/settings/ldap-role-mapping.tsx | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/settings/async-transfer-list.tsx b/src/components/settings/async-transfer-list.tsx index 8e4ecaa..d156a0f 100644 --- a/src/components/settings/async-transfer-list.tsx +++ b/src/components/settings/async-transfer-list.tsx @@ -31,6 +31,7 @@ interface ITransferListProps { onSave?: (items: T[]) => void onSearch?: (text: string) => void renderName?: keyof T + defaultSearch?: string } const AsyncTransferList = ( @@ -41,7 +42,9 @@ const AsyncTransferList = ( const [checked, setChecked] = useState([]) const [left, setLeft] = useState([]) const [right, setRight] = useState([]) - const [leftSearch, setLeftSearch] = useState("") + const [leftSearch, setLeftSearch] = useState( + props.defaultSearch || "" + ) const [rightSearch, setRightSearch] = useState("") const handleSelectedProp = () => { diff --git a/src/components/settings/ldap-role-mapping.tsx b/src/components/settings/ldap-role-mapping.tsx index 87b4843..e3d0217 100644 --- a/src/components/settings/ldap-role-mapping.tsx +++ b/src/components/settings/ldap-role-mapping.tsx @@ -2,6 +2,8 @@ import { useEffect, useState } from "react" import { apiService } from "@/services" import { useTranslation } from "react-i18next" +import { useDebounce } from "@/lib/debounce" + import { SelectRole } from "../selectbox/role-select" import { Card } from "../ui/card" import { useToast } from "../ui/use-toast" @@ -20,8 +22,9 @@ export default function LdapRoleMapping(props: { const [roleList, setRoleList] = useState([]) const [selectedRoleList, setSelectedRoleList] = useState([]) const [selectedRole, setSelectedRole] = useState("") + const [searchValue, setSearchValue] = useState("") - const fetchRoleMappingList = (param?: string) => { + const fetchRoleMappingList = useDebounce((param?: string) => { setRoleListLoading(true) apiService .getInstance() @@ -54,8 +57,9 @@ export default function LdapRoleMapping(props: { .finally(() => { setRoleListLoading(false) setKey((prev) => prev + 1) + setSearchValue(param || "") }) - } + }, 300) const [key, setKey] = useState(0) @@ -105,6 +109,7 @@ export default function LdapRoleMapping(props: { onSave={handleRoleMappingSave} onSearch={(v: string) => fetchRoleMappingList(v)} key={key} + defaultSearch={searchValue} /> )}