Skip to content

Commit ac8b217

Browse files
committed
Colour accordions according to stage groups
If a single audience stage exists that stages colour is used. If multiple stages exist then the stages are grouped into "core" and "advanced". If all of the stages are a single group then that group colouring is used, otherwise the standard colour mix (yellow) is used.
1 parent c41b2fd commit ac8b217

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

src/app/services/userViewingContext.ts

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -422,24 +422,36 @@ export function notRelevantMessage(userContext: UseUserContextReturnType): strin
422422
}
423423

424424
export function audienceStyle(audienceString: string): string {
425-
switch (audienceString) {
426-
case stageLabelMap.a_level:
427-
return "stage-label-alevel";
428-
case stageLabelMap.gcse:
429-
return "stage-label-gcse";
430-
case stageLabelMap.scotland_national_5:
431-
return "stage-label-national-5";
432-
case stageLabelMap.scotland_higher:
433-
return "stage-label-higher";
434-
case stageLabelMap.scotland_advanced_higher:
435-
return "stage-label-advanced-higher";
436-
case stageLabelMap.core:
437-
return "stage-label-core";
438-
case stageLabelMap.advanced:
439-
return "stage-label-advanced";
440-
default:
441-
return "stage-label-all";
442-
}
425+
const audienceStages = audienceString.split('\n').flatMap(line => line.split(', '));
426+
427+
// Convert to css labels
428+
const stageLabels = audienceStages.map(
429+
stage => {switch (stage) {
430+
case stageLabelMap.core:
431+
case stageLabelMap.gcse:
432+
case stageLabelMap.scotland_national_5:
433+
return "stage-label-core";
434+
435+
case stageLabelMap.advanced:
436+
case stageLabelMap.a_level:
437+
case stageLabelMap.scotland_advanced_higher:
438+
return "stage-label-advanced";
439+
440+
case stageLabelMap.scotland_higher:
441+
// Scotland higher has a unique styling
442+
return "stage-label-higher";
443+
444+
default:
445+
return "stage-label-all";
446+
}}
447+
);
448+
const uniqueLabels = audienceStages.length === 1
449+
? new Set(stageLabels)
450+
// If multiple stages are present group into "advanced" and "core"
451+
: new Set(stageLabels.map(v => v === "stage-label-higher" ? "stage-label-advanced" : v));
452+
453+
// If only one group exists use that colour, otherwise, use the mixed colour
454+
return uniqueLabels.size === 1 ? uniqueLabels.values().next().value : "stage-label-all";
443455
}
444456

445457
export function stringifyAudience(audience: ContentDTO["audience"], userContext: UseUserContextReturnType, intendedAudience: boolean): string {

0 commit comments

Comments
 (0)