Skip to content

Commit dd99d6d

Browse files
committed
Make ternaries consistent everywhere
1 parent 660152e commit dd99d6d

15 files changed

+382
-348
lines changed

src/app/components/content/IsaacAccordion.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ export const IsaacAccordion = ({doc}: {doc: ContentDTO}) => {
5454
// Handle conditional display settings
5555
.map(section => {
5656
const sectionDisplay = mergeDisplayOptions(accordionDisplay, section.display);
57-
const sectionDisplaySettings = isIntendedAudience(section.audience, userContext, user) ?
58-
sectionDisplay?.["audience"] : sectionDisplay?.["nonAudience"];
57+
const sectionDisplaySettings = isIntendedAudience(section.audience, userContext, user)
58+
? sectionDisplay?.["audience"]
59+
: sectionDisplay?.["nonAudience"];
5960
if (sectionDisplaySettings?.includes("open")) {section.startOpen = true;}
6061
if (sectionDisplaySettings?.includes("closed")) {section.startOpen = false;}
6162
if (sectionDisplaySettings?.includes("de-emphasised")) {section.deEmphasised = true;}

src/app/components/content/IsaacInlineRegion.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,18 @@ export const useInlineRegionPart = (pageQuestions: AppQuestionDTO[] | undefined)
5353
...currentAttempts?.[currentFeedbackPart ?? 0]?.explanation,
5454
value: undefined,
5555
// if the response explanation exists (i.e. it has a value or children), use it; otherwise use the default feedback
56-
children: currentFeedbackPart !== undefined ? [
57-
(currentAttempts?.[currentFeedbackPart]?.explanation?.value || currentAttempts?.[currentFeedbackPart]?.explanation?.children?.length) &&
58-
currentAttempts?.[currentFeedbackPart]?.explanation !== undefined ? currentAttempts?.[currentFeedbackPart]?.explanation as ContentDTO : defaultFeedback(
59-
currentAttempts?.[currentFeedbackPart]?.correct ? "CORRECT" :
60-
currentAttempts?.[currentFeedbackPart]?.answer?.value !== undefined ? "INCORRECT" : "NOT_ANSWERED"
61-
)
62-
] : undefined,
56+
children: currentFeedbackPart !== undefined
57+
? [
58+
(currentAttempts?.[currentFeedbackPart]?.explanation?.value || currentAttempts?.[currentFeedbackPart]?.explanation?.children?.length) &&
59+
currentAttempts?.[currentFeedbackPart]?.explanation !== undefined
60+
? currentAttempts?.[currentFeedbackPart]?.explanation as ContentDTO
61+
: defaultFeedback(
62+
currentAttempts?.[currentFeedbackPart]?.correct
63+
? "CORRECT"
64+
: currentAttempts?.[currentFeedbackPart]?.answer?.value !== undefined ? "INCORRECT" : "NOT_ANSWERED"
65+
)
66+
]
67+
: undefined,
6368
};
6469
const lockedDates = inlineQuestions?.map(q => q.locked).filter(d => d) as Date[] | undefined;
6570
return {

src/app/components/content/IsaacQuestion.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,13 @@ export const IsaacQuestion = withRouter(({doc, location}: {doc: ApiTypes.Questio
153153
// Determine Action Buttons
154154
const isLongRunningQuestionType = isLLMFreeTextQuestion;
155155
const submitButtonLabel = isLongRunningQuestionType && questionPart?.loading ? "Marking your answer…" : "Check my answer";
156-
const primaryAction =
157-
isFastTrack ? determineFastTrackPrimaryAction(fastTrackInfo) :
158-
isInlineQuestion ? {disabled: !canSubmit, value: submitButtonLabel, type: "submit", onClick: () => {
159-
submitInlineRegion(inlineContext, currentGameboard, currentUser, pageQuestions, dispatch, hidingAttempts);
160-
}} :
161-
/* else ? */ {disabled: !canSubmit || awaitingFeedback, value: submitButtonLabel, type: "submit"};
156+
const primaryAction = isFastTrack
157+
? determineFastTrackPrimaryAction(fastTrackInfo)
158+
: isInlineQuestion
159+
? {disabled: !canSubmit, value: submitButtonLabel, type: "submit", onClick: () => {
160+
submitInlineRegion(inlineContext, currentGameboard, currentUser, pageQuestions, dispatch, hidingAttempts);
161+
}}
162+
: {disabled: !canSubmit || awaitingFeedback, value: submitButtonLabel, type: "submit"};
162163

163164
const secondaryAction = isFastTrack ?
164165
determineFastTrackSecondaryAction(fastTrackInfo) :
@@ -257,10 +258,10 @@ export const IsaacQuestion = withRouter(({doc, location}: {doc: ApiTypes.Questio
257258
{/* Action Buttons */}
258259
{recordConfidence ?
259260
<ConfidenceQuestions state={confidenceState} setState={setConfidenceState}
260-
validationPending={validationPending} setValidationPending={setValidationPending}
261-
disableInitialState={confidenceDisabled}
262-
identifier={doc.id} type={"question"}
263-
validationResponse={validationResponse} />
261+
validationPending={validationPending} setValidationPending={setValidationPending}
262+
disableInitialState={confidenceDisabled}
263+
identifier={doc.id} type={"question"}
264+
validationResponse={validationResponse} />
264265
:
265266
(!correct || canSubmit || (fastTrackInfo.isFastTrackPage && (primaryAction || secondaryAction))) && !locked &&
266267
<div

src/app/components/elements/Accordion.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ export const Accordion = withRouter(({id, trustedTitle, index, children, startOp
176176
}>
177177
{siteSpecific(
178178
audienceString,
179-
above["sm"](deviceSize) ? audienceString : audienceString.replaceAll(",", "\n")).split("\n").map((line, i, arr) => <>
179+
above["sm"](deviceSize) ? audienceString : audienceString.replaceAll(",", "\n")
180+
).split("\n").map(
181+
(line, i, arr) => <>
180182
{line}{i < arr.length && <br/>}
181183
</>
182184
)}

src/app/components/elements/EditorRenderer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ function EditorListener() {
5757
const type = getType(doc);
5858
const colClasses = type === "question" ? "question-panel" : "";
5959

60-
return doc ? <Row className={`${type}-content-container`}>
60+
return doc
61+
? <Row className={`${type}-content-container`}>
6162
<Col className={classNames("py-4", colClasses, {"mw-760": isAda})}>
6263
<FigureNumberingContext.Provider value={{}}>
6364
<WithFigureNumbering doc={doc}>

src/app/components/elements/LLMFreeTextQuestionFeedbackView.tsx

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -60,41 +60,43 @@ export default function LLMFreeTextQuestionFeedbackView({validationResponse, has
6060
</Table>
6161
</div>
6262
{hasSubmitted && <>
63-
{!sentFeedback ? <div className="feedback-collection">
64-
<p className="mb-4">Before submitting another response, please say whether you agree with the predicted mark.</p>
65-
<ul className="no-bullet px-2 mb-4">
66-
<li>
67-
<StyledCheckbox
68-
id="disagree" label={<p>Disagree</p>} className='"mb-4'
69-
checked={feedback.disagree} onChange={() => setFeedback({...noFeedback, disagree: !feedback.disagree})}
70-
/>
71-
</li>
72-
<li>
73-
<StyledCheckbox
74-
id="partlyAgree" label={<p>Partly agree</p>} className='"mb-4'
75-
checked={feedback.partlyAgree} onChange={() => setFeedback({...noFeedback, partlyAgree: !feedback.partlyAgree})}
76-
/>
77-
</li>
78-
<li>
79-
<StyledCheckbox
80-
id="agree" label={<p>Agree</p>}
81-
checked={feedback.agree} onChange={() => setFeedback({...noFeedback, agree: !feedback.agree})}
82-
/>
83-
</li>
84-
</ul>
85-
<Button
86-
color="primary" outline disabled={Object.values(feedback).every(a => !a)}
87-
onClick={() => {
88-
dispatch(logAction({type: "LLM_FREE_TEXT_QUESTION_FEEDBACK", events: {...validationResponse, pageId, userFeedback: feedback}}));
89-
setSentFeedback(true);
90-
}}
91-
>
92-
Send feedback
93-
</Button>
94-
</div> :
95-
<div className="feedback-collection submitted">
96-
<span className="icon-feedback-sent-tick" /> Feedback submitted
97-
</div>}
63+
{!sentFeedback
64+
? <div className="feedback-collection">
65+
<p className="mb-4">Before submitting another response, please say whether you agree with the predicted mark.</p>
66+
<ul className="no-bullet px-2 mb-4">
67+
<li>
68+
<StyledCheckbox
69+
id="disagree" label={<p>Disagree</p>} className='"mb-4'
70+
checked={feedback.disagree} onChange={() => setFeedback({...noFeedback, disagree: !feedback.disagree})}
71+
/>
72+
</li>
73+
<li>
74+
<StyledCheckbox
75+
id="partlyAgree" label={<p>Partly agree</p>} className='"mb-4'
76+
checked={feedback.partlyAgree} onChange={() => setFeedback({...noFeedback, partlyAgree: !feedback.partlyAgree})}
77+
/>
78+
</li>
79+
<li>
80+
<StyledCheckbox
81+
id="agree" label={<p>Agree</p>}
82+
checked={feedback.agree} onChange={() => setFeedback({...noFeedback, agree: !feedback.agree})}
83+
/>
84+
</li>
85+
</ul>
86+
<Button
87+
color="primary" outline disabled={Object.values(feedback).every(a => !a)}
88+
onClick={() => {
89+
dispatch(logAction({type: "LLM_FREE_TEXT_QUESTION_FEEDBACK", events: {...validationResponse, pageId, userFeedback: feedback}}));
90+
setSentFeedback(true);
91+
}}
92+
>
93+
Send feedback
94+
</Button>
95+
</div>
96+
: <div className="feedback-collection submitted">
97+
<span className="icon-feedback-sent-tick" /> Feedback submitted
98+
</div>
99+
}
98100
</>}
99101
</div>;
100-
}
102+
}

src/app/components/elements/ReportButton.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ export const ReportButton = ({pageId} : {pageId?: string}) => {
1818
title="Report a problem (opens in new tab)"
1919
onClick={(event) => {
2020
logPageReport();
21-
window.open(pageId ? `/contact?preset=contentProblem&page=${pageId}` : "/contact?preset=contentProblem",
22-
"_blank");
23-
}
24-
}
21+
window.open(pageId ? `/contact?preset=contentProblem&page=${pageId}` : "/contact?preset=contentProblem", "_blank");
22+
}}
2523
/>;
26-
};
24+
};

src/app/components/elements/inputs/InlineNumericEntryZone.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,21 @@ export const InlineNumericEntryZone = ({questionDTO, setModified, correctness, f
2323

2424
const attempt = ((questionDTO?.validationResponse ?? questionDTO.bestAttempt) as QuantityValidationResponseDTO | undefined);
2525

26-
const valueCorrectness = correctness === "NOT_SUBMITTED" ? "NOT_SUBMITTED" :
27-
attempt?.correctValue ? "CORRECT" :
28-
attempt?.correctValue === undefined ? "NOT_SUBMITTED" : // this fixes an edge case caused by the value not being marked (i.e. correctValue === undefined) if the units are not answered; we should not colour the value in this case
29-
(attempt?.answer as QuantityDTO | undefined)?.value ? "INCORRECT" : "NOT_ANSWERED";
30-
const unitCorrectness = correctness === "NOT_SUBMITTED" ? "NOT_SUBMITTED" :
31-
attempt?.correctUnits ? "CORRECT" :
32-
(attempt?.answer as QuantityDTO | undefined)?.units !== undefined ? "INCORRECT" : "NOT_ANSWERED";
26+
const valueCorrectness = correctness === "NOT_SUBMITTED"
27+
? "NOT_SUBMITTED"
28+
: attempt?.correctValue
29+
? "CORRECT"
30+
: attempt?.correctValue === undefined
31+
? "NOT_SUBMITTED" // this fixes an edge case caused by the value not being marked (i.e. correctValue === undefined) if the units are not answered; we should not colour the value in this case
32+
: (attempt?.answer as QuantityDTO | undefined)?.value
33+
? "INCORRECT"
34+
: "NOT_ANSWERED";
35+
36+
const unitCorrectness = correctness === "NOT_SUBMITTED"
37+
? "NOT_SUBMITTED"
38+
: attempt?.correctUnits
39+
? "CORRECT"
40+
: (attempt?.answer as QuantityDTO | undefined)?.units !== undefined ? "INCORRECT" : "NOT_ANSWERED";
3341

3442
const showFeedback = (correctness : QuestionCorrectness) => {
3543
// whether the provided correctness requires a feedback icon to be shown

src/app/components/elements/list-groups/TopicSummaryLinks.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ export function TopicSummaryLinks({items, search}: {items: ContentSummaryDTO[];
5454
>
5555
<div className={"stage-label d-flex align-items-center justify-content-center " + classNames({[audienceStyle(audienceString)]: isAda})}>
5656
{siteSpecific(
57-
audienceString,
58-
above["sm"](deviceSize) ? audienceString : audienceString.replaceAll(",", "\n")).split("\n").map((line, i, arr) => <>
59-
{line}{i < arr.length && <br/>}
60-
</>
61-
)}
57+
audienceString,
58+
above["sm"](deviceSize) ? audienceString : audienceString.replaceAll(",", "\n")
59+
).split("\n").map((line, i, arr) => <>
60+
{line}{i < arr.length && <br/>}
61+
</>)}
6262
</div>
6363
<div className="title ps-3 d-flex">
6464
<div className="p-3">

src/app/components/elements/markup/portals/InlineEntryZone.tsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,26 @@ const InlineEntryZoneBase = ({inlineSpanId, className: contentClasses, widthPx,
9797
useEffect(() => {
9898
setCorrectness(
9999
// if the user has modified any question attempt without submitting, hide any validation.
100-
modified ? "NOT_SUBMITTED" :
101-
// if a question has been answered since loading the page, and the question has been validated, show the correctness of this attempt.
102-
// if the attempt is empty, prefer "NOT_ANSWERED" over "INCORRECT".
103-
questionDTO?.validationResponse?.correct ? "CORRECT" :
104-
questionDTO?.validationResponse?.correct === false ? (!questionDTO.validationResponse.answer?.value ? "NOT_ANSWERED" : "INCORRECT") :
105-
// if no question attempt has been submitted, it will either be displaying the previous best attempt if correct or incorrect,
106-
// or a *blank* attempt if the best attempt was empty (!) or does not exist.
107-
questionDTO?.bestAttempt?.correct ? "CORRECT" :
108-
questionDTO?.bestAttempt?.correct === false ? (!questionDTO.bestAttempt?.answer?.value ? "NOT_SUBMITTED" : "INCORRECT") :
109-
"NOT_SUBMITTED"
100+
modified
101+
? "NOT_SUBMITTED"
102+
// if a question has been answered since loading the page, and the question has been validated, show the correctness of this attempt.
103+
: questionDTO?.validationResponse?.correct
104+
? "CORRECT"
105+
: questionDTO?.validationResponse?.correct === false
106+
? (!questionDTO.validationResponse.answer?.value
107+
// if the attempt is empty, prefer "NOT_ANSWERED" over "INCORRECT".
108+
? "NOT_ANSWERED"
109+
: "INCORRECT"
110+
)
111+
: questionDTO?.bestAttempt?.correct
112+
// if no question attempt has been submitted, it will either be displaying the previous best attempt if correct or incorrect,
113+
// or a *blank* attempt if the best attempt was empty (!) or does not exist.
114+
? "CORRECT"
115+
: questionDTO?.bestAttempt?.correct === false
116+
? (!questionDTO.bestAttempt?.answer?.value
117+
? "NOT_SUBMITTED"
118+
: "INCORRECT")
119+
: "NOT_SUBMITTED"
110120
);
111121
}, [modified, questionDTO?.bestAttempt, questionDTO?.validationResponse]);
112122

src/app/components/elements/svg/HexagonConnection.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,11 @@ export function HexagonConnection({
110110
}: HexagonConnectionProps) {
111111
const filteredTargetIndices = targetIndices.filter(i => ![sourceIndex, i].includes(-1)); // Filter "not found" selections
112112
const {optionStrokeColour, ...pathProperties} = connectionProperties;
113-
const connectionFunction =
114-
fastTrack ? fastTrackConnectionLine :
115-
mobile ? mobileConnectionLine.bind(null, rowIndex) :
116-
rightAngledConnectionLine;
113+
const connectionFunction = fastTrack
114+
? fastTrackConnectionLine
115+
: mobile
116+
? mobileConnectionLine.bind(null, rowIndex)
117+
: rightAngledConnectionLine;
117118

118119
return <g>
119120
{optionIndices.filter(o => !targetIndices.includes(o)).map(optionIndex => <path

src/app/components/navigation/RevisionWarningBanner.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ export function RevisionWarningBanner() {
1212
const mostRecentAttemptDate = useAppSelector(selectors.questions.getMostRecentCorrectAttemptDate);
1313

1414
if (hideAttempts && hiddenAttempts) {
15-
const timespan = !mostRecentAttemptDate ? undefined : (
16-
mostRecentAttemptDate < new Date(new Date().setFullYear(new Date().getFullYear() - 1)) ? "more than 1 year ago" :
17-
mostRecentAttemptDate < new Date(new Date().setMonth(new Date().getMonth() - 1)) ? "in the last 12 months" :
18-
mostRecentAttemptDate < new Date(new Date().setDate(new Date().getDate() - 7)) ? "in the last month" :
19-
"in the last week"
20-
);
15+
const timespan = !mostRecentAttemptDate
16+
? undefined
17+
: mostRecentAttemptDate < new Date(new Date().setFullYear(new Date().getFullYear() - 1))
18+
? "more than 1 year ago"
19+
: mostRecentAttemptDate < new Date(new Date().setMonth(new Date().getMonth() - 1))
20+
? "in the last 12 months"
21+
: mostRecentAttemptDate < new Date(new Date().setDate(new Date().getDate() - 7))
22+
? "in the last month"
23+
: "in the last week";
2124

2225
return <RS.Alert color="warning" className={"no-print"}>
2326
<span>You are currently in <a href="\account#betafeatures">revision mode</a> which hides your previous attempts.</span>

0 commit comments

Comments
 (0)