mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
fix(view_users.tsx): add time tracking logic to debounce search - prevent new queries from being overwritten by previous ones
This commit is contained in:
parent
66680c421d
commit
d073a0e2e6
1 changed files with 14 additions and 3 deletions
|
@ -133,6 +133,7 @@ const ViewUserDashboard: React.FC<ViewUserDashboardProps> = ({
|
||||||
const [showColumnDropdown, setShowColumnDropdown] = useState(false);
|
const [showColumnDropdown, setShowColumnDropdown] = useState(false);
|
||||||
const [selectedFilter, setSelectedFilter] = useState("Email");
|
const [selectedFilter, setSelectedFilter] = useState("Email");
|
||||||
const filtersRef = useRef(null);
|
const filtersRef = useRef(null);
|
||||||
|
const lastSearchTimestamp = useRef(0);
|
||||||
|
|
||||||
// check if window is not undefined
|
// check if window is not undefined
|
||||||
if (typeof window !== "undefined") {
|
if (typeof window !== "undefined") {
|
||||||
|
@ -150,6 +151,7 @@ const ViewUserDashboard: React.FC<ViewUserDashboardProps> = ({
|
||||||
const handleFilterChange = (key: keyof FilterState, value: string | number | null) => {
|
const handleFilterChange = (key: keyof FilterState, value: string | number | null) => {
|
||||||
const newFilters = { ...filters, [key]: value };
|
const newFilters = { ...filters, [key]: value };
|
||||||
setFilters(newFilters);
|
setFilters(newFilters);
|
||||||
|
console.log("called from handleFilterChange - newFilters:", JSON.stringify(newFilters));
|
||||||
debouncedSearch(newFilters);
|
debouncedSearch(newFilters);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -159,6 +161,10 @@ const ViewUserDashboard: React.FC<ViewUserDashboardProps> = ({
|
||||||
if (!accessToken || !token || !userRole || !userID) {
|
if (!accessToken || !token || !userRole || !userID) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const currentTimestamp = Date.now();
|
||||||
|
lastSearchTimestamp.current = currentTimestamp;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Make the API call using userListCall with all filter parameters
|
// Make the API call using userListCall with all filter parameters
|
||||||
const data = await userListCall(
|
const data = await userListCall(
|
||||||
|
@ -171,9 +177,13 @@ const ViewUserDashboard: React.FC<ViewUserDashboardProps> = ({
|
||||||
filters.team || null
|
filters.team || null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Only update state if this is the most recent search
|
||||||
|
if (currentTimestamp === lastSearchTimestamp.current) {
|
||||||
if (data) {
|
if (data) {
|
||||||
setUserListResponse(data);
|
setUserListResponse(data);
|
||||||
console.log("called from debouncedSearch");
|
console.log("called from debouncedSearch filters:", JSON.stringify(filters));
|
||||||
|
console.log("called from debouncedSearch data:", JSON.stringify(data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error searching users:", error);
|
console.error("Error searching users:", error);
|
||||||
|
@ -252,6 +262,7 @@ const ViewUserDashboard: React.FC<ViewUserDashboardProps> = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
const refreshUserData = async () => {
|
const refreshUserData = async () => {
|
||||||
|
console.log("called from refreshUserData");
|
||||||
if (!accessToken || !token || !userRole || !userID) {
|
if (!accessToken || !token || !userRole || !userID) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue