mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-10-01 23:58:36 -05:00
Allow overriding bracket destination to "eliminated"
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user