Hide "add more content" if all contexts selected#1950
Conversation
When an additional context is added, it is initialised to undefined. Isaac handles this by showing an empty box, but Ada shows a misleading stage/exam board selection when actually a useEffect is re-initialising the new context to All/Ada.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1950 +/- ##
==========================================
+ Coverage 42.46% 42.49% +0.02%
==========================================
Files 575 575
Lines 24521 24553 +32
Branches 8071 8135 +64
==========================================
+ Hits 10413 10433 +20
- Misses 13442 13454 +12
Partials 666 666 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
[VRT] Update baselines for hotfix/hide-add-stages
| const isAllContexts = userContexts.some(uc => uc.stage === STAGE.ALL && (isPhy || uc.examBoard === EXAM_BOARD.ALL)) || | ||
| !getFilteredStageOptions({byUserContexts: userContexts, hideFurtherA: true}).length; |
There was a problem hiding this comment.
This is fine on Sci, but the Ada picker is really quite broken (through no fault of this PR) and this component really needs some more time put into it :/
very skippable essay:
First, some context about ALL. IIRC the original intention on Sci was that you can only select STAGE.ALL if there was only one stage. This prevented you selecting overlapping combinations (e.g. ALL + GCSE).
As an aside, this is why the
userContexts.length === 1check was there before; the new.someapproach doesn't rely on this assumption so is perhaps more future-proof, but right now can only ever be true on the first stage.
The inclusion of exam board breaks this assumption. ALL / AQA and ALL / SQA is a non-overlapping stage / exam board pair, but we never allowed this because we'd kept the "only allow ALL on the first stage" rule. Your fix where you also check uc.examBoard === EXAM_BOARD.ALL would fix this, but we also only allow ALL to appear in the stage dropdown if there is only one combination, so if you try to add another combination the original ALL selection is forcibly removed and you can't select it again.
This is then where the problem compounds, because while we could just stop the dropdown hiding ALL, it then becomes very difficult to prevent overlapping combinations, or at least any solution that does has a terrible UX. If you have GCSE / AQA and A Level / AQA already and then decide you want all of AQA, you have to just know to delete one of them to set the other's stage to ALL. There are a few other conceivably annoying scenarios too.
I wonder if, rather than having a super complex solution that deals with all these cases, we actually even need it. Is it likely a teacher wants ALL / AQA and ALL / SQA? To me, if they want two exam boards, they're probably teaching two classes at different age groups, so managing this with specific combinations would be fine.
My suggestion, then, is simply this:
const noMoreValidStages = !getFilteredStageOptions({byUserContexts: userContexts, hideFurtherA: true}).length;
const isAllStages = userContexts.length === 1 && userContexts[0].stage === STAGE.ALL || noMoreValidStages;That is, we take the getFilteredStageOptions check you've added (as noMoreValidStages) and mix it in with just the ALL stage check that was there before (would be happy to use the .some approach you used too). I prefer the name isAllStages as we would just be using stages now, so the uses would need to keep the old name.
This seems to function entirely fine, i.e. you can keep adding stages and it runs until there are no more unique combinations. The only thing you can't do is multiple ALL / {exam board} pairs, but I think that's a fair tradeoff as this seems rare.
Also fixes a bug where additional contexts on Ada were initialised to All Stages/Ada despite displaying a different stage/exam board combination.