diff --git a/client/src/lib/queryClient.ts b/client/src/lib/queryClient.ts index a8b3fc1..97ca3bd 100644 --- a/client/src/lib/queryClient.ts +++ b/client/src/lib/queryClient.ts @@ -29,7 +29,28 @@ export const getQueryFn: (options: { }) => QueryFunction = ({ on401: unauthorizedBehavior }) => async ({ queryKey }) => { - const res = await fetch(queryKey[0] as string, { + let url = queryKey[0] as string; + + // Handle query parameters if they exist in the second element of queryKey + if (queryKey.length > 1 && typeof queryKey[1] === 'object') { + const params = new URLSearchParams(); + const queryParams = queryKey[1] as Record; + + Object.entries(queryParams).forEach(([key, value]) => { + if (value !== undefined && value !== null) { + params.append(key, value.toString()); + } + }); + + const queryString = params.toString(); + if (queryString) { + url = `${url}${url.includes('?') ? '&' : '?'}${queryString}`; + } + } + + console.log('Fetching URL:', url); + + const res = await fetch(url, { credentials: "include", }); diff --git a/client/src/pages/sites-page.tsx b/client/src/pages/sites-page.tsx index 3c1b897..59075b7 100644 --- a/client/src/pages/sites-page.tsx +++ b/client/src/pages/sites-page.tsx @@ -4,7 +4,7 @@ import { useQuery, useMutation } from "@tanstack/react-query"; import { queryClient } from "@/lib/queryClient"; import { useLocation } from "wouter"; import { Button } from "@/components/ui/button"; -import { Plus, Edit, Trash2, RefreshCw, HardDrive, Network } from "lucide-react"; +import { Plus, Edit, Trash2, RefreshCw, HardDrive, Network, ChevronLeft } from "lucide-react"; import { Dialog, DialogContent, @@ -171,8 +171,9 @@ export default function SitesPage() { data: sitesData, isLoading: isLoadingSites, refetch: refetchSites, + error: sitesError } = useQuery>({ - queryKey: [`/api/connections/${selectedConnection}/ad-sites?top=${MAX_ITEMS_PER_PAGE}&skip=${(currentSitePage - 1) * MAX_ITEMS_PER_PAGE}`], + queryKey: selectedConnection ? [`/api/connections/${selectedConnection}/ad-sites`, { top: MAX_ITEMS_PER_PAGE, skip: (currentSitePage - 1) * MAX_ITEMS_PER_PAGE }] : [], enabled: !!selectedConnection, }); @@ -181,13 +182,20 @@ export default function SitesPage() { data: subnetsData, isLoading: isLoadingSubnets, refetch: refetchSubnets, + error: subnetsError } = useQuery>({ - queryKey: [`/api/connections/${selectedConnection}/ad-subnets?top=${MAX_ITEMS_PER_PAGE}&skip=${(currentSubnetPage - 1) * MAX_ITEMS_PER_PAGE}`], + queryKey: selectedConnection ? [`/api/connections/${selectedConnection}/ad-subnets`, { top: MAX_ITEMS_PER_PAGE, skip: (currentSubnetPage - 1) * MAX_ITEMS_PER_PAGE }] : [], enabled: !!selectedConnection, }); // Update pagination information when data changes useEffect(() => { + // Debug logging + console.log("Sites Data:", sitesData); + console.log("Sites Error:", sitesError); + console.log("Subnets Data:", subnetsData); + console.log("Subnets Error:", subnetsError); + if (sitesData?.metadata) { setTotalSitePages(sitesData.metadata.totalPages || 1); } @@ -195,7 +203,7 @@ export default function SitesPage() { if (subnetsData?.metadata) { setTotalSubnetPages(subnetsData.metadata.totalPages || 1); } - }, [sitesData, subnetsData]); + }, [sitesData, subnetsData, sitesError, subnetsError]); // Site form setup const siteForm = useForm({ @@ -481,7 +489,18 @@ export default function SitesPage() { return (
-

AD Sites and Subnets

+
+ +

AD Sites and Subnets

+