SF-3722 Fix errors on format options when no source access#3715
SF-3722 Fix errors on format options when no source access#3715pmachapman wants to merge 1 commit intomasterfrom
Conversation
| // If the user does not have access to the source project, just show chapter 1 | ||
| this.chaptersWithDrafts = this.translateSource?.texts | ||
| .find(t => t.bookNum === bookNum) | ||
| ?.chapters.map(c => c.number) ?? [initialChapterNum ?? 1]; |
There was a problem hiding this comment.
🟡 Fallback chapter list uses initialChapterNum from route params instead of always chapter 1
When the user does not have access to the source project, the fallback for chaptersWithDrafts is [initialChapterNum ?? 1]. The code comment on line 295 says "just show chapter 1", but initialChapterNum is captured from route params and could be any chapter number (e.g. 2 from a URL like /format/EXO/2). This means:
Root Cause and Impact
When the user navigates to the format page via a URL with a chapter parameter (e.g. chapter 2), initialChapterNum is set to 2. In the no-source-access case:
this.chaptersWithDrafts = this.translateSource?.texts
.find(t => t.bookNum === bookNum)
?.chapters.map(c => c.number) ?? [initialChapterNum ?? 1];this.translateSource is null, so chaptersWithDrafts becomes [2] instead of [1]. Furthermore, when the user switches to a different book while still having no source access, initialChapterNum from the original route is reused as the fallback, showing an incorrect chapter for the new book.
The fix should be ?? [1] to match the stated intent of always showing chapter 1 when the user has no source access.
| ?.chapters.map(c => c.number) ?? [initialChapterNum ?? 1]; | |
| ?.chapters.map(c => c.number) ?? [1]; |
Was this helpful? React with 👍 or 👎 to provide feedback.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3715 +/- ##
==========================================
- Coverage 81.44% 81.44% -0.01%
==========================================
Files 620 620
Lines 38954 38961 +7
Branches 6336 6362 +26
==========================================
+ Hits 31728 31732 +4
+ Misses 6256 6244 -12
- Partials 970 985 +15 ☔ View full report in Codecov by Sentry. |
1621063 to
85bde82
Compare
|
Why do we need access to the source in order to show the draft? |
@Nateowami To get the list of valid chapters for the draft (we can't use the versification to calculate this in the frontend). |
|
Why can't we fetch the draft from the back end and see how many chapters are in it? |
@Nateowami We retrieve each chapter individually. If we were to fetch the whole draft, we would need a way to parse the USFM and calculate the number of chapters on the frontend. We also can't use the versification to figure out the chapters on the frontend (as is is not present there), so we would likely need some new endpoint just to get the number of chapters. The simplest way is just to see the numbers of chapters in the source USFM, as these should match the chapters drafted. |
This PR updates the draft USFM format options page to show a warning if the user cannot access the source project, and only allow access to the first chapter.
This change is