Skip to content

Commit ee5398b

Browse files
committed
Address CutoffTimeLimitPanel review feedback
1 parent 57e5213 commit ee5398b

3 files changed

Lines changed: 49 additions & 32 deletions

File tree

src/components/CutoffTimeLimitPanel/CutoffTimeLimitPanel.test.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ jest.mock('react-i18next', () => ({
3131
return `Top ${values?.level}% to next round`;
3232
}
3333

34+
if (i18nKey === 'common.wca.advancement.linkedRanking') {
35+
return `Top ${values?.level} combined across ${values?.rounds} advance to next round`;
36+
}
37+
38+
if (i18nKey === 'common.wca.advancement.linkedPercent') {
39+
return `Top ${values?.level}% combined across ${values?.rounds} advance to next round`;
40+
}
41+
3442
if (i18nKey === 'common.wca.cumulativeTimelimit') {
3543
return `Time Limit: ${values?.time} Cumulative`;
3644
}

src/components/CutoffTimeLimitPanel/CutoffTimeLimitPanel.tsx

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Cutoff, Round, parseActivityCode } from '@wca/helpers';
1+
import { Competition, Cutoff, Round, parseActivityCode } from '@wca/helpers';
22
import classNames from 'classnames';
33
import { useMemo, useState } from 'react';
44
import { Trans, useTranslation } from 'react-i18next';
@@ -21,14 +21,11 @@ export function CutoffTimeLimitPanel({
2121
const cutoff = round.cutoff;
2222
const timeLimit = round.timeLimit;
2323
const timelimitTime = timeLimit && renderCentiseconds(timeLimit?.centiseconds);
24-
const eventRounds = useMemo(() => {
25-
const { eventId } = parseActivityCode(round.id);
26-
return (
27-
wcif?.events
28-
?.find((event) => event.id === eventId)
29-
?.rounds?.map((candidate) => candidate as CompatibleRound) || []
30-
);
31-
}, [round.id, wcif?.events]);
24+
const cumulativeRoundIds = getCumulativeRoundIds(timeLimit, round.id);
25+
const eventRounds = useMemo(
26+
() => getEventRoundsForRound(wcif?.events, round.id),
27+
[round.id, wcif?.events],
28+
);
3229
const advancement = useMemo(
3330
() => getAdvancementConditionForRound(eventRounds, round as CompatibleRound),
3431
[eventRounds, round],
@@ -55,8 +52,7 @@ export function CutoffTimeLimitPanel({
5552

5653
{timeLimit &&
5754
timeLimit?.cumulativeRoundIds.length > 0 &&
58-
timeLimit.cumulativeRoundIds.filter((activityCode) => activityCode !== round.id)
59-
.length === 0 && (
55+
cumulativeRoundIds.length === 0 && (
6056
<span className="px-2">
6157
<Trans
6258
i18nKey={'common.wca.cumulativeTimelimit'}
@@ -68,31 +64,28 @@ export function CutoffTimeLimitPanel({
6864

6965
{timeLimit &&
7066
timeLimit?.cumulativeRoundIds.length > 0 &&
71-
timeLimit.cumulativeRoundIds.filter((activityCode) => activityCode !== round.id)
72-
.length > 0 && (
67+
cumulativeRoundIds.length > 0 && (
7368
<div className="px-2">
7469
<span>
7570
<Trans
7671
i18nKey={'common.wca.cumulativeTimelimitWithrounds'}
7772
values={{ time: timelimitTime }}
7873
components={{ b: <span className="font-semibold" /> }}
7974
/>
80-
{timeLimit.cumulativeRoundIds
81-
.filter((activityCode) => activityCode !== round.id)
82-
.map((activityCode, i, arry) => {
83-
const { eventId, roundNumber } = parseActivityCode(activityCode);
84-
return (
85-
<Link
86-
key={activityCode}
87-
to={`/competitions/${wcif?.id}/events/${activityCode}`}>
88-
<span
89-
className={`cubing-icon event-${eventId} mx-1 before:-ml-1 before:mr-2`}>
90-
{t('common.activityCodeToName.round', { roundNumber })}
91-
{i < arry.length - 1 ? ', ' : ''}
92-
</span>
93-
</Link>
94-
);
95-
})}
75+
{cumulativeRoundIds.map((activityCode, i, arry) => {
76+
const { eventId, roundNumber } = parseActivityCode(activityCode);
77+
return (
78+
<Link
79+
key={activityCode}
80+
to={`/competitions/${wcif?.id}/events/${activityCode}`}>
81+
<span
82+
className={`cubing-icon event-${eventId} mx-1 before:-ml-1 before:mr-2`}>
83+
{t('common.activityCodeToName.round', { roundNumber })}
84+
{i < arry.length - 1 ? ', ' : ''}
85+
</span>
86+
</Link>
87+
);
88+
})}
9689
</span>
9790
</div>
9891
)}
@@ -110,6 +103,20 @@ export function CutoffTimeLimitPanel({
110103
);
111104
}
112105

106+
function getEventRoundsForRound(events: Competition['events'] | undefined, roundId: string) {
107+
const { eventId } = parseActivityCode(roundId);
108+
109+
return (
110+
events
111+
?.find((event) => event.id === eventId)
112+
?.rounds?.map((candidate) => candidate as CompatibleRound) || []
113+
);
114+
}
115+
116+
function getCumulativeRoundIds(timeLimit: Round['timeLimit'], roundId: string) {
117+
return timeLimit?.cumulativeRoundIds.filter((activityCode) => activityCode !== roundId) || [];
118+
}
119+
113120
function renderAdvancementText(
114121
t: ReturnType<typeof useTranslation>['t'],
115122
sourceType: 'registrations' | 'round' | 'linkedRounds',
@@ -177,9 +184,6 @@ function renderAdvancementText(
177184
? 'common.wca.advancement.linkedResultAchieved'
178185
: 'common.wca.advancement.resultAchieved',
179186
{
180-
defaultValue: isLinkedRounds
181-
? 'Competitors with a {{scope}} better than {{result}} combined across {{rounds}} advance to next round. Minimum of 25% of competitors must be eliminated.'
182-
: 'Competitors with a {{scope}} better than {{result}} advance to next round. Minimum of 25% of competitors must be eliminated.',
183187
scope: scopeLabel,
184188
result: resultValue,
185189
rounds: sourceRoundsLabel,

src/i18n/en/translation.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ common:
3333
advancement:
3434
ranking: 'Top <b>{{level}}</b> to next round'
3535
percent: 'Top <b>{{level}}%</b> to next round'
36+
linkedRanking: 'Top {{level}} combined across {{rounds}} advance to next round'
37+
linkedPercent: 'Top {{level}}% combined across {{rounds}} advance to next round'
3638
attemptResult: Result better than <b>{level}</b> advances to next round. Minimum of 25% of competitors must be eliminated.
39+
resultAchieved: Competitors with a {{scope}} better than {{result}} advance to next round. Minimum of 25% of competitors must be eliminated.
40+
linkedResultAchieved: Competitors with a {{scope}} better than {{result}} combined across {{rounds}} advance to next round. Minimum of 25% of competitors must be eliminated.
41+
resultThresholdUnknown: an unknown result
3742
resultType:
3843
single: single
3944
average: Average

0 commit comments

Comments
 (0)