Skip to content

feat: add TanStack Query hooks for all domain modules#28

Open
helseaCat wants to merge 1 commit into
mainfrom
feat/frontend-query-hooks
Open

feat: add TanStack Query hooks for all domain modules#28
helseaCat wants to merge 1 commit into
mainfrom
feat/frontend-query-hooks

Conversation

@helseaCat
Copy link
Copy Markdown
Owner

@helseaCat helseaCat commented May 29, 2026

Description

Add TanStack Query hooks for all domain modules — contracts, expectations, tasks, and payloads/deviations. Each hook handles caching, stale times, and cache invalidation on mutations.

Changes

  • src/hooks/useContracts.ts — useContracts, useContract, useCreateContract, useUpdateContract, usePublishContract (staleTime: 30s)
  • src/hooks/useExpectations.ts — useExpectations, useExpectation, useCreateExpectation, useUpdateExpectation, useActivateExpectation, useDeactivateExpectation (staleTime: 30s)
  • src/hooks/useTasks.ts — useTasks (with status filter), useTask, useCreateTask, useTransitionTaskStatus (staleTime: 15s)
  • src/hooks/usePayloads.ts — usePayloads, usePayload, useSubmitPayload, usePayloadDeviations, useDeviationsByContract (staleTime: 15s payloads, 60s deviations)

Testing done

  • npx tsc --noEmit passes
  • All hooks properly typed with query keys and mutation invalidation

Checklist

  • No new warnings
  • Self-reviewed

Summary by CodeRabbit

  • New Features
    • Added contract management capabilities including creation, updates, and publishing
    • Added expectations management with create, update, and activation controls
    • Added payload submission and deviation tracking functionality
    • Added task creation and status transition capabilities

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

📝 Walkthrough

Walkthrough

This PR adds four new React Query hook files that wrap data-access patterns for contracts, expectations, payloads, and tasks. Each file exports typed query hooks for fetching data and mutation hooks for modifying data, with consistent cache-staleness configurations and automatic cache invalidation on mutations.

Changes

React Query Data Layer Hooks

Layer / File(s) Summary
Contract data hooks
nexus-frontend/src/hooks/useContracts.ts
Query hooks useContracts() and useContract() fetch contract lists and individual contracts with 30-second staleness. Mutation hooks useCreateContract(), useUpdateContract(), and usePublishContract() call the corresponding API methods and invalidate ['contracts'] cache on success.
Expectations data hooks
nexus-frontend/src/hooks/useExpectations.ts
Query hooks useExpectations() and useExpectation() fetch expectation lists and individual expectations with 30-second staleness. Mutation hooks useCreateExpectation(), useUpdateExpectation(), useActivateExpectation(), and useDeactivateExpectation() update the API and invalidate ['expectations'] cache on success.
Payloads data hooks
nexus-frontend/src/hooks/usePayloads.ts
Query hooks usePayloads(), usePayload(), usePayloadDeviations(), and useDeviationsByContract() fetch payloads and deviations with contract-scoped and pagination-aware cache keys. Mutation hook useSubmitPayload() submits payloads and invalidates ['payloads'] cache on success.
Tasks data hooks
nexus-frontend/src/hooks/useTasks.ts
Query hooks useTasks() and useTask() fetch task lists (with optional status filter) and individual tasks with 15-second staleness. Mutation hooks useCreateTask() and useTransitionTaskStatus() call the API and invalidate ['tasks'] cache on success.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 Four new hooks hop into the fold,
React Query patterns, tried and true, bold!
Lists and singles, mutations galore,
Contracts and tasks and expectations more—
Cache keys sync'd, invalidation flows tight,
Data layer done, frontend feels right! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add TanStack Query hooks for all domain modules' clearly and accurately summarizes the main change: introducing TanStack Query hooks across multiple domain modules (contracts, expectations, tasks, payloads).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/frontend-query-hooks

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
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@nexus-frontend/src/hooks/usePayloads.ts`:
- Around line 22-28: The mutation in useSubmitPayload (mutationFn ->
payloadsApi.submit) currently only invalidates ['payloads'] onSuccess; also call
qc.invalidateQueries for the deviations cache so dependent hooks
usePayloadDeviations and useDeviationsByContract refresh — e.g., add
qc.invalidateQueries({ queryKey: ['deviations'] }) (or a more specific queryKey
pattern you use for deviations) in the onSuccess handler after invalidating
['payloads'] so deviation data is refetched after a submit.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: db547619-e48c-4cdd-ab9f-7f78ef231793

📥 Commits

Reviewing files that changed from the base of the PR and between accc518 and 1d6871d.

📒 Files selected for processing (5)
  • nexus-frontend/src/hooks/.gitkeep
  • nexus-frontend/src/hooks/useContracts.ts
  • nexus-frontend/src/hooks/useExpectations.ts
  • nexus-frontend/src/hooks/usePayloads.ts
  • nexus-frontend/src/hooks/useTasks.ts

Comment on lines +22 to +28
export function useSubmitPayload() {
const qc = useQueryClient();
return useMutation({
mutationFn: (data: SubmitPayloadRequest) => payloadsApi.submit(data),
onSuccess: () => qc.invalidateQueries({ queryKey: ['payloads'] }),
});
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Consider invalidating deviation queries after payload submission.

If submitting a payload can create or modify deviations, the deviation queries (usePayloadDeviations, useDeviationsByContract) will not refresh because they use a separate ['deviations'] cache key. With a 60-second staleTime on deviations, users could see stale deviation data after submission.

🔄 Proposed fix to invalidate deviation queries
 export function useSubmitPayload() {
   const qc = useQueryClient();
   return useMutation({
     mutationFn: (data: SubmitPayloadRequest) => payloadsApi.submit(data),
-    onSuccess: () => qc.invalidateQueries({ queryKey: ['payloads'] }),
+    onSuccess: () => {
+      qc.invalidateQueries({ queryKey: ['payloads'] });
+      qc.invalidateQueries({ queryKey: ['deviations'] });
+    },
   });
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function useSubmitPayload() {
const qc = useQueryClient();
return useMutation({
mutationFn: (data: SubmitPayloadRequest) => payloadsApi.submit(data),
onSuccess: () => qc.invalidateQueries({ queryKey: ['payloads'] }),
});
}
export function useSubmitPayload() {
const qc = useQueryClient();
return useMutation({
mutationFn: (data: SubmitPayloadRequest) => payloadsApi.submit(data),
onSuccess: () => {
qc.invalidateQueries({ queryKey: ['payloads'] });
qc.invalidateQueries({ queryKey: ['deviations'] });
},
});
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@nexus-frontend/src/hooks/usePayloads.ts` around lines 22 - 28, The mutation
in useSubmitPayload (mutationFn -> payloadsApi.submit) currently only
invalidates ['payloads'] onSuccess; also call qc.invalidateQueries for the
deviations cache so dependent hooks usePayloadDeviations and
useDeviationsByContract refresh — e.g., add qc.invalidateQueries({ queryKey:
['deviations'] }) (or a more specific queryKey pattern you use for deviations)
in the onSuccess handler after invalidating ['payloads'] so deviation data is
refetched after a submit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant