Skip to content

Conversation

@bilalabbad
Copy link
Contributor

@bilalabbad bilalabbad commented Oct 20, 2025

Use RAC tag for diff counter.

Summary by CodeRabbit

  • New Features

    • Added diff summary view displaying counts of added, updated, removed, and conflicted items by branch.
  • Improvements

    • Enhanced error handling with explicit error screen display when issues occur.
    • Improved loading state management with skeleton display during data fetch.

@bilalabbad bilalabbad self-assigned this Oct 20, 2025
@bilalabbad bilalabbad requested a review from a team as a code owner October 20, 2025 12:10
@bilalabbad bilalabbad added type/bug Something isn't working as expected group/frontend Issue related to the frontend (React) type/housekeeping Maintenance task labels Oct 20, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 20, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (3)
  • main
  • stable
  • develop

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This 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)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "request to DiffTreeSummary uses tanstack query" refers to a real and significant aspect of the changeset. The changes introduce tanstack query integration for DiffTreeSummary data fetching across multiple modules: a new React Query hook (useGetDiffSummary), a query options factory, and updates to the UI component to use the new hook pattern. While the phrasing "request to" is somewhat awkward, the title clearly communicates that the changeset involves refactoring DiffTreeSummary data fetching to use tanstack query, which is the primary technical change. A teammate scanning the pull request history would understand the core change relates to this migration.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 GetDiffTreeSummaryFromApiParams interface extends Get_Diff_Tree_SummaryQueryVariables without adding any members, making it redundant. You could either:

  1. Use Get_Diff_Tree_SummaryQueryVariables directly, or
  2. 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

📥 Commits

Reviewing files that changed from the base of the PR and between 12e420b and 01dde0e.

📒 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-query package 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:

  1. Line 25: The type assertion as GetDiffSummaryResponse bypasses 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.

  2. Line 25: The null coalescing ?? null is redundant since if data.DiffTreeSummary is falsy, it will already return null or the falsy value. The ?? null doesn'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 zod or 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 (where getDiffSummary throws 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: () => {},
},

@bilalabbad bilalabbad changed the base branch from develop to release-1.5 October 20, 2025 14:11
@bilalabbad bilalabbad force-pushed the bab-diff-summary branch 2 times, most recently from f0f9d41 to b106c22 Compare October 21, 2025 15:01
@bilalabbad bilalabbad changed the title WIP: fix DiffTreeSummary using tanstack query request to DiffTreeSummary uses tanstack query Oct 21, 2025
@bilalabbad bilalabbad merged commit 03f5449 into release-1.5 Oct 22, 2025
36 checks passed
@bilalabbad bilalabbad deleted the bab-diff-summary branch October 22, 2025 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

group/frontend Issue related to the frontend (React) type/bug Something isn't working as expected type/housekeeping Maintenance task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants