Skip to content

reuse useProjectsQuery instead of fetchProjectsAction in useEffect#2793

Merged
dimaMachina merged 5 commits intomainfrom
prd-6346-2
Mar 20, 2026
Merged

reuse useProjectsQuery instead of fetchProjectsAction in useEffect#2793
dimaMachina merged 5 commits intomainfrom
prd-6346-2

Conversation

@dimaMachina
Copy link
Collaborator

No description provided.

@vercel
Copy link

vercel bot commented Mar 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agents-api Ready Ready Preview, Comment Mar 20, 2026 10:35pm
agents-docs Ready Ready Preview, Comment Mar 20, 2026 10:35pm
agents-manage-ui Ready Ready Preview, Comment Mar 20, 2026 10:35pm

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Mar 20, 2026

🦋 Changeset detected

Latest commit: 9a0ce4b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@inkeep/agents-manage-ui Patch
@inkeep/agents-api Patch
@inkeep/agents-cli Patch
@inkeep/agents-core Patch
@inkeep/agents-email Patch
@inkeep/agents-mcp Patch
@inkeep/agents-sdk Patch
@inkeep/agents-work-apps Patch
@inkeep/ai-sdk-provider Patch
@inkeep/create-agents Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel vercel bot temporarily deployed to Preview – agents-docs March 20, 2026 22:05 Inactive
@pullfrog
Copy link
Contributor

pullfrog bot commented Mar 20, 2026

TL;DR — Replaces manual useEffect + fetchProjectsAction data-fetching with the existing useProjectsQuery React Query hook across stats pages, and adopts the shared PageProps / RouteContext types to remove inline param type declarations from 10 page components and 2 API routes.

Key changes

  • Replace fetchProjectsAction with useProjectsQuery — Three stats pages (ai-calls, tool-calls, main stats) drop their hand-rolled useEffect fetch-and-setState loops in favor of a single useProjectsQuery({ tenantId }) call, eliminating ~60 lines of boilerplate.
  • Adopt PageProps type across trigger pages — Seven trigger page components replace inline { params: Promise<…> } type annotations with the shared PageProps<Route> generic, keeping param shapes consistent with the route definition.
  • Remove local RouteContext redeclarations — Two API route files delete their locally-defined RouteContext<_T> type, relying on the shared one already available.
  • Delete unused fetchProjectsAction — The server action and its fetchProjects import are removed from projects.ts now that no consumer remains.
  • Add changeset — Patch changeset for @inkeep/agents-manage-ui describing the cleanup.

Summary | 14 files | 5 commits | base: mainprd-6346-2


useProjectsQuery replaces imperative fetch loops in stats pages

Before: Each stats page managed its own projects / projectsLoading state and fetched via fetchProjectsAction inside a useEffect.
After: A single useProjectsQuery({ tenantId }) call provides data and isFetching, with caching and deduplication handled by React Query.

This removes three nearly-identical ~20-line useEffect blocks along with their useState declarations and error-swallowing catch clauses.

ai-calls/page.tsx · stats/page.tsx · tool-calls/page.tsx · projects.ts


Shared PageProps and RouteContext types replace inline declarations

Before: Each page component declared its own { params: Promise<{ tenantId: string; … }> } object type inline, and two API routes defined a local RouteContext<_T> type.
After: Pages use PageProps<Route> and API routes use the shared RouteContext<Route>, keeping param shapes derived from a single source of truth.

One webhook invocations page also narrows the searchParams type inline after destructuring, since PageProps provides a broader Record<string, string | string[] | undefined> shape.

triggers/invocations/page.tsx · conversations/route.ts · spans/route.ts

Pullfrog  | View workflow run | Triggered by Pullfrogpullfrog.com𝕏

@vercel vercel bot temporarily deployed to Preview – agents-docs March 20, 2026 22:11 Inactive
@github-actions github-actions bot deleted a comment from claude bot Mar 20, 2026
Copy link
Contributor

@pullfrog pullfrog bot left a comment

Choose a reason for hiding this comment

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

Clean refactor — no issues found.

What it does:

  1. Replaces manual useEffect + useState project-fetching in 3 stats pages with the existing useProjectsQuery hook, eliminating ~60 lines of duplicated data-fetching logic.
  2. Replaces inline { params: Promise<...> } type annotations in 7 trigger pages with the globally-available PageProps<Route> type (generated by the Next.js TypeScript plugin).
  3. Removes redundant local type RouteContext<_T> definitions in 2 API route files in favor of the global Next.js-generated RouteContext<Route> type.
  4. Removes the now-unused fetchProjectsAction server action.

Verified:

  • useProjectsQuery returns Project[] with initialData: [], so data is always defined — no risk of undefined breaking downstream .map() calls.
  • fetchProjects is still imported and used elsewhere (query hook, server utils, components) — only the server action wrapper was dead code.
  • No remaining references to fetchProjectsAction (only a vestigial variable name fetchProjectsActionMock in a test file that actually mocks fetchProjects).
  • useEffect imports remain in the stats pages since they're still used for other effects.
  • PageProps and RouteContext are ambient types from .next/types/ — no imports needed.

Pullfrog  | View workflow runpullfrog.com𝕏

Copy link
Contributor

@pullfrog pullfrog bot left a comment

Choose a reason for hiding this comment

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

New commits look good — both are type-safety fixes that follow from adopting PageProps. The explicit destructuring annotation on searchParams preserves the narrow status union type, and the typeof guard correctly narrows string | string[] | undefined to string.

Pullfrog  | View workflow runpullfrog.com𝕏

@dimaMachina
Copy link
Collaborator Author

@claude --review and add a changeset

Copy link
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

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

PR Review Summary

(0) Total Issues | Risk: Low

This is a clean refactoring PR that eliminates duplicated data-fetching boilerplate and consolidates type declarations to use Next.js-generated types.

Changes Verified

1. useProjectsQuery replaces manual useEffect + fetchProjectsAction

  • Three stats pages (ai-calls/page.tsx, stats/page.tsx, tool-calls/page.tsx) now use the existing useProjectsQuery hook
  • The hook provides initialData: [], so data is always defined — no undefined risk on downstream .map() calls
  • useEffect imports are correctly retained where still needed for other effects

2. PageProps<Route> replaces inline type declarations

  • Seven trigger pages adopt the globally-available PageProps<Route> type
  • Type narrowing is correctly preserved:
    • invocations/page.tsx: Adds explicit destructuring annotation for status union type
    • new/page.tsx: Adds typeof guard to narrow string | string[] | undefined to string

3. Global RouteContext<Route> replaces local definitions

  • Two API route files remove redundant local type RouteContext<_T> definitions
  • Both routes now use the Next.js-generated ambient type

4. Dead code removal

  • fetchProjectsAction server action is removed (no remaining references)
  • The underlying fetchProjects function is still imported where needed

✅ APPROVE

Summary: Clean refactoring that reduces ~130 lines of duplicated code by leveraging existing patterns. The type narrowing changes are correct and necessary for type safety with the more generic PageProps type.

@github-actions github-actions bot deleted a comment from claude bot Mar 20, 2026
Copy link
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

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

PR Review Summary

(0) Total Issues | Risk: Low

Re-review Delta

The only change since the prior automated review is adding a changeset file:

.changeset/little-hounds-battle.md

  • Package: @inkeep/agents-manage-ui — correct (only UI package changed)
  • Bump: patch — appropriate for refactoring with no breaking changes
  • Message follows repo guidelines (sentence case, action verb, describes the change)

✅ APPROVE

Summary: Changeset is well-formed. Prior review already approved the refactoring changes — this commit completes the PR by adding the required changeset.

Reviewers (1)
Reviewer Returned Main Findings Consider While You're Here Inline Comments Pending Recs Discarded
orchestrator 1 0 0 0 0 0 0
Total 1 0 0 0 0 0 0

Note: Sub-reviewers not dispatched — delta was trivial (changeset file only).

@github-actions github-actions bot deleted a comment from claude bot Mar 20, 2026
@dimaMachina dimaMachina added this pull request to the merge queue Mar 20, 2026
Merged via the queue into main with commit 6cc27ba Mar 20, 2026
18 checks passed
@dimaMachina dimaMachina deleted the prd-6346-2 branch March 20, 2026 22:48
dimaMachina added a commit that referenced this pull request Mar 20, 2026
…ct` (#2793)

* reuse `useProjectsQuery` instead of `fetchProjectsAction` in `useEffect`

* format

* upd

* fix lint

* Create little-hounds-battle.md
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