Fix bracket progression submit crashing when changing bracket format
Some checks failed
Tests and checks on push / run-checks-and-tests (push) Has been cancelled
Updates translation progress / update-translation-progress-issue (push) Has been cancelled

This commit is contained in:
Kalle
2025-02-13 23:35:38 +02:00
parent c52c84f358
commit ffbaee9e10
4 changed files with 43 additions and 33 deletions

View File

@@ -569,6 +569,7 @@ export interface TournamentRound {
maps: ColumnType<TournamentRoundMaps | null, string | null, string | null>;
}
// when updating this also update `defaultBracketSettings` in tournament-utils.ts
export interface TournamentStageSettings {
// SE
thirdPlaceMatch?: boolean;

View File

@@ -92,8 +92,6 @@ export const action: ActionFunction = async ({ request }) => {
rankedModesShort.find((mode) => mode === data.toToolsMode) ?? null,
bracketProgression: data.bracketProgression ?? null,
minMembersPerTeam: data.minMembersPerTeam ?? undefined,
teamsPerGroup: data.teamsPerGroup ?? undefined,
thirdPlaceMatch: data.thirdPlaceMatch ?? undefined,
isRanked: data.isRanked ?? undefined,
isInvitational: data.isInvitational ?? false,
deadlines: data.strictDeadline ? ("STRICT" as const) : ("DEFAULT" as const),
@@ -101,8 +99,6 @@ export const action: ActionFunction = async ({ request }) => {
enableSubs: data.enableSubs ?? undefined,
requireInGameNames: data.requireInGameNames ?? undefined,
autonomousSubs: data.autonomousSubs ?? undefined,
swissGroupCount: data.swissGroupCount ?? undefined,
swissRoundCount: data.swissRoundCount ?? undefined,
tournamentToCopyId: data.tournamentToCopyId,
regClosesAt: data.regClosesAt
? dateToDatabaseTimestamp(
@@ -283,35 +279,8 @@ export const newCalendarEventActionSchema = z
checkboxValueToBoolean,
z.boolean().nullish(),
),
//
// tournament format related fields
//
bracketProgression: bracketProgressionSchema.nullish(),
minMembersPerTeam: z.coerce.number().int().min(1).max(4).nullish(),
withUndergroundBracket: z.preprocess(checkboxValueToBoolean, z.boolean()),
thirdPlaceMatch: z.preprocess(
checkboxValueToBoolean,
z.boolean().nullish(),
),
teamsPerGroup: z.coerce
.number()
.min(TOURNAMENT.MIN_GROUP_SIZE)
.max(TOURNAMENT.MAX_GROUP_SIZE)
.nullish(),
swissGroupCount: z.coerce.number().int().positive().nullish(),
swissRoundCount: z.coerce.number().int().positive().nullish(),
followUpBrackets: z.preprocess(
safeJSONParse,
z
.array(
z.object({
name: z.string(),
placements: z.array(z.number()),
}),
)
.min(1)
.nullish(),
),
bracketProgression: bracketProgressionSchema.nullish(),
})
.refine(
async (schema) => {

View File

@@ -10,6 +10,7 @@ import { SendouSwitch } from "~/components/elements/Switch";
import { PlusIcon } from "~/components/icons/Plus";
import { TOURNAMENT } from "~/features/tournament";
import * as Progression from "~/features/tournament-bracket/core/Progression";
import { defaultBracketSettings } from "../../tournament/tournament-utils";
const defaultBracket = (): Progression.InputBracket => ({
id: nanoid(),
@@ -154,7 +155,15 @@ function TournamentFormatBracketSelector({
const isFirstBracket = count === 1;
const updateBracket = (newProps: Partial<Progression.InputBracket>) => {
onChange({ ...bracket, ...newProps });
const defaultSettings = newProps.type
? defaultBracketSettings(newProps.type)
: undefined;
onChange({
...bracket,
...newProps,
settings: newProps.settings ?? defaultSettings ?? bracket.settings,
});
};
return (

View File

@@ -5,6 +5,8 @@ import { rankedModesShort } from "~/modules/in-game-lists/modes";
import { weekNumberToDate } from "~/utils/dates";
import invariant from "~/utils/invariant";
import { tournamentLogoUrl } from "~/utils/urls";
import type { Tables, TournamentStageSettings } from "../../db/tables";
import { assertUnreachable } from "../../utils/types";
import { MapPool } from "../map-list-generator/core/map-pool";
import { currentSeason } from "../mmr/season";
import { BANNED_MAPS } from "../sendouq-settings/banned-maps";
@@ -307,3 +309,32 @@ export function resolveLeagueRoundStartDate(
return date;
}
export function defaultBracketSettings(
type: Tables["TournamentStage"]["type"],
): TournamentStageSettings {
switch (type) {
case "single_elimination": {
return {
thirdPlaceMatch: true,
};
}
case "double_elimination": {
return {};
}
case "round_robin": {
return {
teamsPerGroup: 4,
};
}
case "swiss": {
return {
roundCount: 5,
groupCount: 1,
};
}
default: {
assertUnreachable(type);
}
}
}