Fix dashboard counts to update on load#155
Fix dashboard counts to update on load#155ncurrie3 wants to merge 3 commits intoGoogleCloudPlatform:mainfrom
Conversation
272c465 to
9094c08
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces the ability to override the Hub API endpoint via a new HubEndpoint option in the backend synchronization logic, including support for environment variable fallbacks in hub-connected contexts. On the frontend, the home page is updated to dynamically fetch and display the count of active agents and groves by integrating with the stateManager. Feedback was provided regarding the stateManager's seeding methods, which are currently additive and do not dispatch update events, potentially leading to stale data or desynchronized UI components.
web/src/components/pages/home.ts
Outdated
| this.agents = Array.isArray(data) ? data : data.agents || []; | ||
| stateManager.seedAgents(this.agents); | ||
| } | ||
|
|
||
| if (grovesResp.ok) { | ||
| const data = await grovesResp.json(); | ||
| this.groves = Array.isArray(data) ? data : data.groves || []; | ||
| stateManager.seedGroves(this.groves); | ||
| } |
There was a problem hiding this comment.
The seedAgents and seedGroves methods in StateManager are additive (they use Map.set without clearing existing entries). Since loadData performs a full fetch of all agents and groves for the dashboard, calling these methods without clearing the existing state in the manager will result in stale data persisting if items were deleted on the server but no SSE 'deleted' event was received. Additionally, seedAgents and seedGroves do not dispatch update events; consequently, other components listening to the state manager will not be synchronized with the data fetched here. Consider updating StateManager to support a 'reset' or 'sync' operation that replaces the map and notifies listeners, or ensure the scope is fully reset before seeding.
|
/gemini review pls :) |
There was a problem hiding this comment.
Code Review
This pull request updates the StateManager to allow clearing data during seeding and introduces event notifications for state changes. The ScionPageHome component is refactored to fetch and display real-time counts for active agents and groves by subscribing to these state updates. Feedback suggests addressing a potential race condition in the asynchronous data loading process and updating the seedAgents documentation to reflect the newly added notification logic.
| if (agentsResp.ok) { | ||
| const data = await agentsResp.json(); | ||
| this.agents = Array.isArray(data) ? data : data.agents || []; | ||
| stateManager.seedAgents(this.agents); | ||
| } | ||
|
|
||
| if (grovesResp.ok) { | ||
| const data = await grovesResp.json(); | ||
| this.groves = Array.isArray(data) ? data : data.groves || []; | ||
| stateManager.seedGroves(this.groves); | ||
| } |
There was a problem hiding this comment.
This data loading logic has two issues:
- Race Condition:
loadDatais asynchronous and may complete after the user has navigated away from the dashboard. CallingstateManager.seedAgentsat that point would populate the global state with dashboard data while the app is in a different scope (e.g., a specific Grove), leading to inconsistent UI state. - Redundant Updates: Manually setting
this.agentsandthis.groveshere is unnecessary becauseseedAgentsandseedGrovesnow trigger events that this component already listens to viaonAgentsUpdatedandonGrovesUpdated.
It is recommended to check this.isConnected before seeding and let the state manager's events handle the local property updates.
if (!this.isConnected) return;
if (agentsResp.ok) {
const data = await agentsResp.json();
const agents = Array.isArray(data) ? data : data.agents || [];
stateManager.seedAgents(agents);
}
if (grovesResp.ok) {
const data = await grovesResp.json();
const groves = Array.isArray(data) ? data : data.groves || [];
stateManager.seedGroves(groves);
}| for (const agent of agents) { | ||
| this.state.agents.set(agent.id, agent); | ||
| } | ||
| this.notify('agents-updated'); |
There was a problem hiding this comment.
PR #155 Review: Fix dashboard counts to update on loadExecutive SummaryThis PR makes the dashboard's "Active Agents" and "Groves" stat cards dynamic by fetching data via the REST API and subscribing to SSE state updates. The change is low-to-medium risk — the dashboard component itself is well-structured, but the modifications to Critical Issues1.
|
Description
This PR updates the Dashboard page (
/) to make the "Active Agents" and "Groves" counts dynamic.Previously, these values were hardcoded as
--and did not update on load.Changes:
dashboardscope instateManager.connectedCallbackvia a newloadDatamethod.agents-updatedandgroves-updatedto keep counts fresh.Tests
Fixes #154