refactor(frontend): re-file use-refresh-model-inputs into services and utils#14045
refactor(frontend): re-file use-refresh-model-inputs into services and utils#14045tarciorodrigues wants to merge 2 commits into
Conversation
…-inputs Move the five pure helpers (isModelNode, findModelFieldKey, buildRefreshPayload, createUpdatedNode, validateModelValue) verbatim to utils/model-node-helpers.ts. The hook file keeps one-way deprecated re-exports for the four previously public helpers so every consumer and path-based jest.mock compiles unchanged; validateModelValue was private and is now exported only from the new module. No behavior change.
Move refreshAllModelInputs, the private refreshSingleNode and the module-level concurrency queue (isRefreshInProgress + pendingRefresh) verbatim to services/refresh-model-inputs.ts, together with the RefreshOptions type. The hook file keeps only the ~20-line useRefreshModelInputs hook plus one-way deprecated re-exports, so all seven consumers and the path-based jest.mocks compile unchanged. The queue lives in exactly one module; the double concurrency guard is intentionally untouched. No behavior change.
WalkthroughChangesThe model-input refresh implementation is extracted from the hook into shared service and utility modules. The hook preserves its public entry point and deprecated exports through re-exports. Model input refresh
Sequence Diagram(s)sequenceDiagram
participant Caller
participant refreshAllModelInputs
participant QueryClient
participant BackendAPI
participant FlowStore
Caller->>refreshAllModelInputs: request model input refresh
refreshAllModelInputs->>QueryClient: invalidate model queries
refreshAllModelInputs->>BackendAPI: refresh model node
BackendAPI-->>refreshAllModelInputs: return updated template
refreshAllModelInputs->>FlowStore: update node and translations
Suggested reviewers: Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error)
✅ Passed checks (8 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.
🧹 Nitpick comments (1)
src/frontend/src/services/refresh-model-inputs.ts (1)
74-77: 🚀 Performance & Scalability | 🔵 Trivial | ⚖️ Poor tradeoffUnbounded parallel refresh fan-out.
Promise.allfires anapi.postfor every model node simultaneously. On flows with many model nodes this can burst the backend. Consider bounding concurrency (e.g. a small worker pool /p-limit) if large flows are expected. Preserved from prior behavior, so non-blocking.🤖 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/frontend/src/services/refresh-model-inputs.ts` around lines 74 - 77, Bound concurrency in the refresh flow around refreshTasks and refreshSingleNode instead of starting every refresh request simultaneously with Promise.all. Use a small worker pool or existing concurrency limiter while preserving refreshSingleNode’s behavior and awaiting completion of all node refreshes.
🤖 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/frontend/src/services/refresh-model-inputs.ts`:
- Around line 74-77: Bound concurrency in the refresh flow around refreshTasks
and refreshSingleNode instead of starting every refresh request simultaneously
with Promise.all. Use a small worker pool or existing concurrency limiter while
preserving refreshSingleNode’s behavior and awaiting completion of all node
refreshes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7efff2f1-6c3a-4c95-84cc-1c5e515f5993
📒 Files selected for processing (3)
src/frontend/src/hooks/use-refresh-model-inputs.tssrc/frontend/src/services/refresh-model-inputs.tssrc/frontend/src/utils/model-node-helpers.ts
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## release-1.11.0 #14045 +/- ##
==================================================
+ Coverage 60.22% 60.23% +0.01%
==================================================
Files 2390 2337 -53
Lines 230284 228826 -1458
Branches 34535 32111 -2424
==================================================
- Hits 138688 137842 -846
+ Misses 89980 89368 -612
Partials 1616 1616
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Why
LE-1735 Tier A componentization — work package 4.
hooks/use-refresh-model-inputs.tsmixed three concerns in one 326-line file: five pure template/node helpers, the refresh orchestration with a module-level concurrency queue, and the React hook itself. This PR re-files each concern where it belongs, behavior-preserving, so the hook path stays a thin React-facing surface.What
utils/model-node-helpers.tswith the five pure helpers (isModelNode,findModelFieldKey,buildRefreshPayload,createUpdatedNode,validateModelValue) moved verbatim.validateModelValuewas private and is now exported only from the new module.services/refresh-model-inputs.tswithrefreshAllModelInputs, the privaterefreshSingleNode, the module-level concurrency queue (isRefreshInProgress+pendingRefresh) and theRefreshOptionstype, all moved verbatim. The queue lives in exactly one module. Note:src/services/is a new top-level directory.hooks/use-refresh-model-inputs.tskeeps only theuseRefreshModelInputshook plus one-way@deprecatedre-exports, so all seven prod consumers and the six path-based jest mocks compile unchanged. No consumer was repointed; the deprecated re-exports are transitional and get removed in a follow-up once consumers migrate.Tests
use-refresh-model-inputs.test.ts(873 lines, 34 tests) green before and after each commit — it exercises the moved queue and orchestration directly through the old path.— 66 tests.
make format_frontendno drift; fullmake test_frontend: 443 of 445 suites green; the two red suites (AuthModal, KnowledgeBaseUploadModal) are userEvent 5s timeouts under a loaded parallel run, pass 51/51 in isolation and do not touch this diff.git grepshowszero imports of the private symbols from anywhere else.custom_component/updateper click withthe selection preserved and the dropdown closing opens and closes without spurious refreshes; zero console errors.
Note
Rapid double-refresh through the UI is not reproducible from the dropdown because it closes on the first click; the
anti-storm queue behavior is asserted by the 34-
Refs LE-1735
Screenshots
Model dropdown
Light
Before
After
Dark
Before
After
Summary by CodeRabbit