-
Notifications
You must be signed in to change notification settings - Fork 37
request to DiffTreeSummary uses tanstack query #7440
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
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (3)
Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThis pull request introduces a layered architecture for fetching diff summaries in the frontend. It adds a GraphQL API module that executes a query to retrieve diff statistics (added, updated, removed, conflicts). A domain layer module wraps this API call with type definitions and error handling. A React Query integration module provides query options and a custom hook for data fetching. Finally, the diff-summary UI component is refactored to use the new custom hook, replacing direct GraphQL queries with explicit error handling, improved loading states, and updated data access patterns. Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
frontend/app/src/entities/diff/api/get-diff-tree-summary-from-api.ts (1)
20-20: Consider removing redundant type alias.The
GetDiffTreeSummaryFromApiParamsinterface extendsGet_Diff_Tree_SummaryQueryVariableswithout adding any members, making it redundant. You could either:
- Use
Get_Diff_Tree_SummaryQueryVariablesdirectly, or- Keep it as an abstraction boundary if you anticipate needing to diverge from the generated types.
If kept, consider adding a comment explaining the purpose of the abstraction.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
frontend/app/src/entities/diff/api/get-diff-tree-summary-from-api.ts(1 hunks)frontend/app/src/entities/diff/domain/get-diff-summary.query.ts(1 hunks)frontend/app/src/entities/diff/domain/get-diff-summary.ts(1 hunks)frontend/app/src/entities/proposed-changes/ui/diff-summary.tsx(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
frontend/app/src/entities/diff/domain/get-diff-summary.ts (2)
frontend/app/src/entities/diff/api/get-diff-tree-summary-from-api.ts (1)
getDiffTreeSummaryFromApi(22-30)backend/infrahub/exceptions.py (1)
Error(5-18)
frontend/app/src/entities/proposed-changes/ui/diff-summary.tsx (2)
frontend/app/src/entities/diff/domain/get-diff-summary.query.ts (1)
useGetDiffSummary(16-18)frontend/app/src/shared/components/container.tsx (1)
Row(7-9)
frontend/app/src/entities/diff/domain/get-diff-summary.query.ts (1)
frontend/app/src/entities/diff/domain/get-diff-summary.ts (2)
GetDiffSummaryParams(3-3)getDiffSummary(16-26)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: E2E-testing-version-upgrade / From 1.3.0
- GitHub Check: E2E-testing-playwright
- GitHub Check: Cloudflare Pages
🔇 Additional comments (11)
frontend/app/src/entities/diff/domain/get-diff-summary.query.ts (2)
1-5: LGTM! Clean imports aligned with TanStack Query v5.The imports correctly use the
@tanstack/react-querypackage and properly structure the dependencies across API, domain, and shared layers.
16-18: LGTM! Proper TanStack Query v5 hook pattern.The hook correctly merges query options with optional config overrides using the spread operator, following TanStack Query best practices.
frontend/app/src/entities/proposed-changes/ui/diff-summary.tsx (4)
7-7: LGTM! Clean migration to new data-fetching architecture.The imports correctly reference the new useGetDiffSummary hook and supporting types, replacing the previous direct GraphQL query approach.
Also applies to: 10-11
43-61: LGTM! Excellent state handling with TanStack Query.The component correctly uses
isPending(TanStack Query v5 property), provides explicit error handling with user-friendly messages, and includes a defensive null check before accessing data properties.
64-86: LGTM! Clean render logic with proper data access.The component correctly accesses diff summary properties directly from the data object, protected by the null check above. The Row wrapper provides consistent layout.
91-95: LGTM! Consistent skeleton layout.The skeleton correctly uses the same Row wrapper and renders 4 placeholder badges to match the actual rendered state, ensuring a smooth loading experience.
frontend/app/src/entities/diff/domain/get-diff-summary.ts (2)
1-14: LGTM! Clear and well-structured type definitions.The types provide a clean contract for the domain layer, with proper nullable return type and clear parameter/response shapes.
16-26: Review type assertion for potential runtime safety issues.The implementation has two minor concerns:
Line 25: The type assertion
as GetDiffSummaryResponsebypasses type safety. If the GraphQL response shape diverges from the type definition (e.g., missing fields or different types), this could cause runtime errors. Consider adding runtime validation or using a type guard.Line 25: The null coalescing
?? nullis redundant since ifdata.DiffTreeSummaryis falsy, it will already returnnullor the falsy value. The?? nulldoesn't change behavior.Consider validating the response shape at runtime or documenting the assumption that the GraphQL generated types guarantee the shape. You could use a library like
zodor add a simple type guard:function isValidDiffSummary(data: any): data is GetDiffSummaryResponse { return ( typeof data?.num_added === 'number' && typeof data?.num_updated === 'number' && typeof data?.num_removed === 'number' && typeof data?.num_conflicts === 'number' ); } export const getDiffSummary: GetDiffSummary = async ({ branchName }) => { const { data, errors } = await getDiffTreeSummaryFromApi({ branch: branchName, }); if (errors) { throw new Error(errors.map((e) => e.message).join("; ")); } const summary = data.DiffTreeSummary; if (!summary) return null; if (!isValidDiffSummary(summary)) { throw new Error("Invalid diff summary response shape"); } return summary; };frontend/app/src/entities/diff/api/get-diff-tree-summary-from-api.ts (3)
1-7: LGTM! Proper GraphQL setup with generated types.The imports correctly reference Apollo Client utilities and generated TypeScript types from GraphQL codegen.
9-18: LGTM! Well-structured GraphQL query.The query correctly defines the operation with appropriate parameters and selects all necessary fields for the diff summary.
22-30: Verify intentional error suppression.The
processErrorMessage: () => {}in the context suppresses default GraphQL error processing, shifting error handling responsibility to the domain layer (wheregetDiffSummarythrows on errors). This is a valid pattern, but please confirm this is intentional.If this is intentional, consider adding a comment explaining why error processing is suppressed:
context: { // Suppress default error processing; errors are handled in the domain layer processErrorMessage: () => {}, },
frontend/app/src/entities/diff/domain/get-diff-summary.query.ts
Outdated
Show resolved
Hide resolved
01dde0e to
0db407a
Compare
f0f9d41 to
b106c22
Compare
a8f9ef9 to
0685ff3
Compare
Use RAC tag for diff counter.
Summary by CodeRabbit
New Features
Improvements