fix(companies): refresh Statistics counts after adding a site #227
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/PMS-363-company-sites-counter-reactive"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Fixes the reactivity gap on the Company detail page (PMS-363, external review #2 finding #6): after adding a site, the Sites table updated but the Sites Statistics counter stayed at the mount-time value until a manual reload.
Root cause
All three Statistics counters derive from one source -
company_resource, the denormalized company fetch done once on mount:The add-site modal only restarted
sites_resource(the Sites table's own data).company_resourcewas never restarted anywhere, so the denormalizedsite_countstayed stale until a full page remount.Change
Restart
company_resourcealongsidesites_resourcein the site-formonsaved.ResourceisCopy, so it is passed intoCompanySitesCardby value. The counters keep their authoritative server-side source and refresh in the same render cycle.Rejected the derive-from-child-
len()alternative:PaginatedSitesdrops total/meta (struct PaginatedSites { data: Vec<SiteSummary> }), sodata.len()would break if the endpoint paginates.Counter audit (AC #3)
company_resourcecompany_resource<a href>full nav -> remount refetchescompany_resourceCorrection to the issue text: it stated the Contacts counter "uses a different data binding that refetches after a mutation." That is inaccurate - Contacts reads the same
company_resource(line 1049). It only appeared reactive because its add flow is a full navigation that remounts the page. All three counters shared one latent staleness; only Sites had an on-page mutation to expose it, and restartingcompany_resourcenow covers all three.No projects/assets/contracts counters exist on this page; the Statistics card has exactly these three.
Verification
cargo fmt --allcargo clippy --target wasm32-unknown-unknown -- -D warningsclean🤖 Generated with Claude Code