Allow overriding bracket destination to "eliminated"

This commit is contained in:
Kalle
2025-02-24 21:35:04 +02:00
parent 636fa90956
commit b1d9d0f212
3 changed files with 29 additions and 16 deletions

View File

@@ -164,9 +164,17 @@ export function PlacementsTable({
const overridenDestinationBracket = overridenDestination
? bracket.tournament.bracketByIdx(
overridenDestination.destinationBracketIdx,
)!
)
: undefined;
const key = () => {
if (overridenDestinationBracket === null) {
return "null";
}
return overridenDestinationBracket?.idx;
};
return (
<tr key={s.team.id}>
<td>
@@ -221,7 +229,7 @@ export function PlacementsTable({
) : null}
<td>{team?.seed}</td>
<EditableDestination
key={overridenDestinationBracket?.idx}
key={key()}
source={bracket}
destination={dest}
overridenDestination={overridenDestinationBracket}
@@ -249,7 +257,7 @@ function EditableDestination({
}: {
source: Bracket;
destination?: Bracket;
overridenDestination?: Bracket;
overridenDestination?: Bracket | null;
possibleDestinations: Bracket[];
allMatchesFinished: boolean;
canEditDestination: boolean;
@@ -273,9 +281,10 @@ function EditableDestination({
);
};
const possibleDestinations = !destination
? (["ELIMINATED", ..._possibleDestinations] as const)
: _possibleDestinations;
const possibleDestinations = [
"ELIMINATED",
..._possibleDestinations,
] as const;
if (editingDestination) {
return (
@@ -325,7 +334,7 @@ function EditableDestination({
<td className="text-theme font-bold">
<span>→ {overridenDestination.name}</span>
</td>
) : destination ? (
) : destination && overridenDestination !== null ? (
<td
className={clsx({
"italic text-lighter": !allMatchesFinished,

View File

@@ -237,7 +237,7 @@ describe("Bracket progression override", () => {
).toBeFalsy();
});
it("ignores -1 override (used to indicate no progression)", () => {
it("destinationBracketIdx = -1 eliminates the team", () => {
const tournament = new Tournament({
...SWIM_OR_SINK_167([
{
@@ -252,7 +252,7 @@ describe("Bracket progression override", () => {
11,
);
expect(tournament.brackets[2].participantTournamentTeamIds).toHaveLength(
11,
10,
);
expect(tournament.brackets[3].participantTournamentTeamIds).toHaveLength(
11,

View File

@@ -274,27 +274,31 @@ export class Tournament {
allRelevantMatchesFinished = false;
}
const excludedOverridenTeams = sourcedTeams.filter(
// exclude teams that would be going to this bracket according
// to the bracket progression rules, but have been overridden
// by the TO to go somewhere else or get eliminated (in the case of destinationBracketIdx = -1)
const withOverriddenTeamsExcluded = sourcedTeams.filter(
(teamId) =>
!this.ctx.bracketProgressionOverrides.some(
(override) =>
override.sourceBracketIdx === source.bracketIdx &&
override.tournamentTeamId === teamId &&
// "no progression" override
override.destinationBracketIdx !== -1 &&
// redundant override
override.destinationBracketIdx !== bracketIdx,
),
);
teams.push(...excludedOverridenTeams);
teams.push(...withOverriddenTeamsExcluded);
}
const teamsFromOverride: { id: number; sourceBracketIdx: number }[] = [];
for (const source of sources) {
for (const override of this.ctx.bracketProgressionOverrides) {
if (override.sourceBracketIdx !== source.bracketIdx) continue;
if (override.destinationBracketIdx !== bracketIdx) continue;
if (
override.sourceBracketIdx !== source.bracketIdx ||
override.destinationBracketIdx !== bracketIdx
) {
continue;
}
teamsFromOverride.push({
id: override.tournamentTeamId,