Skip to content

Change the default audience for Scotland qualifications #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/components/semantic/presenters/AudiencePresenter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ const csStagedExamBoards: Partial<Record<Stage, ExamBoard[]>> = {
"scotland_advanced_higher": ["sqa"],
};

function isExamboardArray(arr: string[]): arr is ExamBoard[] {
return arr.every(v => csExamBoards.includes(v));
}

function examBoardsForStage(audienceContext: AudienceContext): ExamBoard[] {
const stageSpecificExamBoards = audienceContext.stage?.length === 1 && csStagedExamBoards[audienceContext.stage[0]];
return stageSpecificExamBoards || csExamBoards;
Expand Down Expand Up @@ -77,18 +81,29 @@ function AudienceContextPresenter({doc, update, possible}: PresenterProps<Audien
unusedKeysAndFirstOption = unusedKeysAndFirstOption.filter(([k]) => k !== key);

const filteredUnusedOptions = new Set(possible[key]);
// Remove used options
values.forEach((value) => filteredUnusedOptions.delete(value));

// Restrict Exam Board options by Stage selection if set
if (isAda && key === "examBoard" && doc.stage && doc.stage.length === 1) {
if (isAda && isExamboardArray(values) && doc.stage && doc.stage.length === 1) {
filteredUnusedOptions.forEach((value) => {
if (!examBoardsForStage(doc).includes(value as ExamBoard)) {
filteredUnusedOptions.delete(value);
}
});

// Remove from values as well to prevent illegal combinations
values.forEach((value, i) => {
if (!examBoardsForStage(doc).includes(value as ExamBoard)) {
values.splice(i, 1);
}
})

// Select a default value
if (values.length < 1) values.push(examBoardsForStage(doc)[0]);
}

// Remove used options
values.forEach((value) => filteredUnusedOptions.delete(value));

return {
key,
values,
Expand Down