Fix get_resource/transition_answer: scope feature lookup to its own alternative
Deploy / deploy (push) Successful in 28s

Both resolved a feature by name flattened across every alternative on
the question, not scoped to the one the caller actually meant - fine
when every question had exactly one alternative with a resource
feature, silently wrong now that /review has three (Applicants,
Inquiries, Subscribers all use the same empty feature name). Every
lookup always resolved to the first alternative's feature - Subscribers
was reading the (empty) Applicants bucket instead of its own, and
Invite/Decline/Mark-handled buttons would have had the same problem
had two of those transitions ever been clicked side by side.

Threaded a new `alternative` parameter through get_resource,
transition_answer, and their client-side callers
(ResourceFeature/ResourceValue/AnswerRow) - the fix lives entirely in
the already-generic resource-fetching machinery, no per-alternative
special-casing.
This commit is contained in:
Bendik Aagaard Lynghaug
2026-08-05 15:04:02 +02:00
parent c73981da2d
commit 6df895b1d3
3 changed files with 41 additions and 7 deletions
+8 -1
View File
@@ -84,6 +84,7 @@ pub async fn store_answer(
#[server]
pub async fn transition_answer(
question_id: String,
alternative: String,
feature_name: String,
item_id: String,
to: String,
@@ -100,10 +101,16 @@ pub async fn transition_answer(
.get(&question_id)
.cloned()
.ok_or_else(|| ServerFnError::new("unknown question"))?;
// Same alternative-scoped lookup as get_resource, and for the same
// reason - a feature name isn't unique across a whole question,
// only within its own alternative.
let feature = question
.alternatives
.iter()
.flat_map(|a| &a.features)
.find(|a| a.name == alternative)
.ok_or_else(|| ServerFnError::new("unknown alternative"))?
.features
.iter()
.find(|f| f.name == feature_name)
.ok_or_else(|| ServerFnError::new("unknown feature"))?;
let resource = feature