Skip to content

refactor(client): dissolve api keys and utilities stores into typed query hooks - #1295

Merged
jamcalli merged 5 commits into
developfrom
refactor/openapi-react-query-store-conversions
Aug 4, 2026
Merged

refactor(client): dissolve api keys and utilities stores into typed query hooks#1295
jamcalli merged 5 commits into
developfrom
refactor/openapi-react-query-store-conversions

Conversation

@jamcalli

@jamcalli jamcalli commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Description

Related Issues

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Performance improvement
  • Code refactoring
  • Documentation update
  • Dependency update

Testing Performed

Screenshots

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • My changes work with existing functionality

Summary by CodeRabbit

  • New Features

    • Improved API key management with clearer loading, refresh, creation, and revocation states.
    • Added consistent scheduling actions and status updates across monitoring, approvals, and utility settings.
    • Improved delete-sync dry-run progress and results display.
    • Enhanced user tag and media label operation feedback.
  • Bug Fixes

    • Fixed approval and monitoring actions involving numeric identifiers.
    • Corrected watchlist exclusion requests.
    • Improved handling of unavailable storage information.
    • Standardized error messages and schedule refresh behavior.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: a5fea86d-21df-4f06-92e3-4499691a3735

📥 Commits

Reviewing files that changed from the base of the PR and between f6efaeb and 861e30f.

📒 Files selected for processing (1)
  • src/client/features/utilities/hooks/useSchedules.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/client/features/utilities/hooks/useSchedules.ts

Walkthrough

The PR replaces utility-store data flows with shared React Query hooks and mutations. It updates schedule, API-key, delete-sync, Plex-label, and user-tag operations. It also standardizes numeric route IDs, removes trailing endpoint slashes, and updates service type definitions.

Changes

Query and mutation migration

Layer / File(s) Summary
Shared schedules and schedule consumers
src/client/features/utilities/hooks/useSchedules.ts, src/client/features/plex/hooks/*, src/client/features/utilities/hooks/useDeleteSync*, src/client/features/utilities/hooks/usePlexLabels.ts, src/client/features/utilities/hooks/useSessionMonitoring.ts
Shared schedule queries, actions, invalidation, and mutation state replace utility-store schedule access.
Delete-sync and tag mutations
src/client/features/utilities/hooks/useDeleteSyncDryRun.ts, src/client/features/utilities/hooks/useDeleteSyncActions.ts, src/client/features/utilities/components/delete-sync/*, src/client/features/utilities/hooks/useUserTags.ts
Delete-sync dry runs and user-tag operations use React Query mutations, local state, minimum loading durations, and normalized API errors.
API-key query and mutation migration
src/client/features/utilities/hooks/useApiKeys.ts, src/client/features/utilities/pages/api-keys.tsx, src/client/features/utilities/store/apiKeysStore.ts
API-key loading, creation, revocation, refresh, visibility, and errors use query and mutation state. The API-key store is removed.
Numeric IDs and normalized routes
src/schemas/approval/*, src/schemas/session-monitoring/*, src/routes/v1/*, src/client/types/api.d.ts, src/client/features/approvals/hooks/useApprovalMutations.ts, src/client/features/utilities/hooks/useSessionMonitoringQueries.ts, src/client/features/utilities/hooks/useWatchlistExclusions.ts, src/types/*
Approval and session-monitoring IDs use numeric schemas and parameters. Watchlist-exclusion paths omit trailing slashes. Radarr and Sonarr folder types accept nullable free-space values.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% 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 clearly summarizes the main refactoring from API keys and utilities stores to typed query hooks.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/openapi-react-query-store-conversions

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/client/features/utilities/hooks/useSchedules.ts (1)

98-155: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Wrap the returned action functions in useCallback.

useScheduleActions returns new function identities on every render. Consumers place these functions in useCallback dependency arrays, for example useApprovalScheduler.ts Line 199 ([updateScheduleAction]), useSessionMonitoring.ts Line 109, and usePlexLabels.ts Line 341. Those memoized callbacks are therefore rebuilt on every render, which defeats the memoization and causes referential churn in dependent components.

The mutation objects returned by useMutation are stable in identity, so memoizing the wrappers is straightforward.

♻️ Proposed refactor
-  const runScheduleNow = async (name: string) => {
-    try {
-      const data = await runMutation.mutateAsync(name)
-      return data.success
-    } catch (_err) {
-      return false
-    }
-  }
+  const runMutateAsync = runMutation.mutateAsync
+  const runScheduleNow = useCallback(
+    async (name: string) => {
+      try {
+        const data = await runMutateAsync(name)
+        return data.success
+      } catch (_err) {
+        return false
+      }
+    },
+    [runMutateAsync],
+  )

Apply the same pattern to toggleScheduleStatus, updateSchedule, updateSessionMonitorSchedule, and updateAutoResetSchedule, and import useCallback from react.

🤖 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 `@src/client/features/utilities/hooks/useSchedules.ts` around lines 98 - 155,
Import useCallback from React and wrap the returned action functions
runScheduleNow, toggleScheduleStatus, updateSchedule,
updateSessionMonitorSchedule, and updateAutoResetSchedule in useCallback with
dependency arrays containing the mutation objects or callbacks they use.
Preserve each function’s existing behavior and arguments while ensuring their
identities remain stable across renders.
🤖 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.

Nitpick comments:
In `@src/client/features/utilities/hooks/useSchedules.ts`:
- Around line 98-155: Import useCallback from React and wrap the returned action
functions runScheduleNow, toggleScheduleStatus, updateSchedule,
updateSessionMonitorSchedule, and updateAutoResetSchedule in useCallback with
dependency arrays containing the mutation objects or callbacks they use.
Preserve each function’s existing behavior and arguments while ensuring their
identities remain stable across renders.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: c966409e-2467-4ad9-913d-2f29d9ee29ea

📥 Commits

Reviewing files that changed from the base of the PR and between 3fa11e7 and 0f0b26c.

⛔ Files ignored due to path filters (1)
  • docs/static/openapi.json is excluded by !docs/**
📒 Files selected for processing (28)
  • src/client/features/approvals/hooks/useApprovalMutations.ts
  • src/client/features/plex/hooks/useApprovalScheduler.ts
  • src/client/features/plex/hooks/useApprovalSystem.ts
  • src/client/features/plex/hooks/useQuotaSystem.ts
  • src/client/features/utilities/components/delete-sync/delete-sync-dry-run-modal.tsx
  • src/client/features/utilities/hooks/useApiKeys.ts
  • src/client/features/utilities/hooks/useDeleteSyncActions.ts
  • src/client/features/utilities/hooks/useDeleteSyncDryRun.ts
  • src/client/features/utilities/hooks/useDeleteSyncForm.ts
  • src/client/features/utilities/hooks/useDeleteSyncSchedule.ts
  • src/client/features/utilities/hooks/usePlexLabels.ts
  • src/client/features/utilities/hooks/useSchedules.ts
  • src/client/features/utilities/hooks/useSessionMonitoring.ts
  • src/client/features/utilities/hooks/useSessionMonitoringQueries.ts
  • src/client/features/utilities/hooks/useUserTags.ts
  • src/client/features/utilities/hooks/useWatchlistExclusionMutations.ts
  • src/client/features/utilities/hooks/useWatchlistExclusions.ts
  • src/client/features/utilities/pages/api-keys.tsx
  • src/client/features/utilities/store/apiKeysStore.ts
  • src/client/features/utilities/store/utilitiesStore.ts
  • src/client/types/api.d.ts
  • src/routes/v1/approval/approval.ts
  • src/routes/v1/session-monitoring/session-monitoring.ts
  • src/routes/v1/watchlist-exclusions/watchlist-exclusions.ts
  • src/schemas/approval/approval.schema.ts
  • src/schemas/session-monitoring/session-monitoring.schema.ts
  • src/types/radarr.types.ts
  • src/types/sonarr.types.ts
💤 Files with no reviewable changes (2)
  • src/client/features/utilities/store/apiKeysStore.ts
  • src/client/features/utilities/store/utilitiesStore.ts

@jamcalli
jamcalli merged commit 5b9dafe into develop Aug 4, 2026
9 checks passed
@jamcalli
jamcalli deleted the refactor/openapi-react-query-store-conversions branch August 4, 2026 07:05
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