-
Notifications
You must be signed in to change notification settings - Fork 33
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
[Netmanager-app]improved on the grids hooks #2544
base: staging
Are you sure you want to change the base?
Changes from all commits
a5ea7a3
75f3b1e
b9fb6b7
e0a8e4f
6c7fcaf
97a29e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type React from "react" | ||
import { Card, CardContent } from "@/components/ui/card" | ||
import { Skeleton } from "@/components/ui/skeleton" | ||
|
||
export const AnalyticsSkeleton: React.FC = () => { | ||
return ( | ||
<Card className="p-4"> | ||
<CardContent className="space-y-6"> | ||
{/* Header section skeleton */} | ||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-12 gap-4 mb-6"> | ||
<div className="col-span-1 sm:col-span-2 lg:col-span-6 mb-4 sm:mb-0"> | ||
<Skeleton className="h-10 w-full rounded-md" /> | ||
</div> | ||
<div className="col-span-1 sm:col-span-2 lg:col-span-6 flex flex-col sm:flex-row justify-start sm:justify-end items-stretch sm:items-center gap-4"> | ||
<Skeleton className="h-10 w-32 sm:w-36" /> | ||
<Skeleton className="h-10 w-36 sm:w-40" /> | ||
<Skeleton className="h-10 w-10" /> | ||
</div> | ||
</div> | ||
|
||
{/* Dashboard content skeleton */} | ||
<div className="space-y-4"> | ||
{/* Chart skeletons */} | ||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4"> | ||
<Skeleton className="h-64 w-full rounded-md" /> | ||
<Skeleton className="h-64 w-full rounded-md" /> | ||
</div> | ||
|
||
{/* Table skeleton */} | ||
<Skeleton className="h-80 w-full rounded-md" /> | ||
|
||
{/* Additional metrics skeletons */} | ||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4"> | ||
<Skeleton className="h-32 w-full rounded-md" /> | ||
<Skeleton className="h-32 w-full rounded-md" /> | ||
<Skeleton className="h-32 w-full rounded-md" /> | ||
</div> | ||
</div> | ||
</CardContent> | ||
</Card> | ||
) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import { | |
import { AxiosError } from "axios"; | ||
import { grids } from "../apis/grids"; | ||
import { CreateGrid, Grid } from "@/app/types/grids"; | ||
import { GridsState, setError, setGrids } from "../redux/slices/gridsSlice"; | ||
import { setError, setGrids } from "../redux/slices/gridsSlice"; | ||
import { useDispatch } from "react-redux"; | ||
import { useAppSelector } from "../redux/hooks"; | ||
|
||
|
@@ -16,24 +16,21 @@ interface ErrorResponse { | |
} | ||
|
||
// Hook to get the grid summary | ||
export const useGrids = (networkId: string) => { | ||
export const useGrids = () => { | ||
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. 💡 Verification agent 🧩 Analysis chainHook signature simplified - verify impact on consumers. The function signature has been changed to remove the 🏁 Script executed: #!/bin/bash
# Check for any instances where useGrids is called with parameters
rg "useGrids\(\S" --type tsx --type ts Length of output: 68 Below is a revised verification step to further check for any consumers that might still be passing parameters to the updated hook signature: Next Steps:
This additional verification is important because the earlier command failed due to the unrecognized file type "tsx". Once you’ve checked that no consumers pass parameters, the hook signature change should be safe. Thanks for double-checking! 🏁 Script executed: #!/bin/bash
# Check for any instances where useGrids is called with non-empty arguments
# (i.e. where there's something between the parentheses other than just whitespace).
rg "useGrids\\(\\s*[^)]" -g "*.ts" -g "*.tsx" Length of output: 285 Action Required: Update Consumer Usage of It appears that although the hook signature was simplified (removing the
Please remove the argument from this call to align with the updated hook signature. Verify that this change doesn't affect the component's logic or any dependent behavior. |
||
const dispatch = useDispatch(); | ||
const activeNetwork = useAppSelector((state) => state.user.activeNetwork); | ||
|
||
const { data, isLoading, error } = useQuery< | ||
GridsState, | ||
AxiosError<ErrorResponse> | ||
>({ | ||
const { data, isLoading, error } = useQuery({ | ||
queryKey: ["grids", activeNetwork?.net_name], | ||
queryFn: () => grids.getGridsApi(networkId), | ||
queryFn: () => grids.getGridsApi(activeNetwork?.net_name || ""), | ||
enabled: !!activeNetwork?.net_name, | ||
onSuccess: (data: GridsState) => { | ||
onSuccess: (data: any) => { | ||
dispatch(setGrids(data.grids)); | ||
}, | ||
onError: (error: AxiosError<ErrorResponse>) => { | ||
onError: (error: Error) => { | ||
dispatch(setError(error.message)); | ||
}, | ||
} as UseQueryOptions<GridsState, AxiosError<ErrorResponse>>); | ||
}); | ||
|
||
return { | ||
grids: data?.grids ?? [], | ||
|
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.
🛠️ Refactor suggestion
Consider using the AnalyticsSkeleton component.
You've created a nice AnalyticsSkeleton component but are using a simple spinner here. For better user experience, consider using the skeleton UI which would provide a closer representation of the content being loaded.
📝 Committable suggestion