All files / src/utils tournamentRounds.js

100% Statements 59/59
100% Branches 8/8
100% Functions 1/1
100% Lines 59/59

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 691x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x   1x   1x 1x 1x 1x 1x   1x   1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x   1x 1x 1x   1x 1x 21x 21x 21x 21x  
// Single source of truth for tournament round display labels.
//
// Matches carry a `tournament_round` key (e.g. "quarterfinal"). Different
// surfaces want different verbosity:
//   - compact bracket / match-center views use short labels ("QF")
//   - admin and detail views use full labels ("Quarterfinal")
 
export const TOURNAMENT_ROUNDS = {
  group_stage: { short: 'Group Stage', long: 'Group Stage' },
  // Fest U15 GA Cup Qualifier (SB-1879): placement games between groups.
  crossover: { short: 'Crossover', long: 'Crossover' },
  round_of_32: { short: 'R32', long: 'Round of 32' },
  round_of_16: { short: 'R16', long: 'Round of 16' },
  quarterfinal: { short: 'QF', long: 'Quarterfinal' },
  semifinal: { short: 'SF', long: 'Semifinal' },
  third_place: { short: '3rd Place', long: 'Third Place' },
  final: { short: 'Final', long: 'Final' },
  // MLS NEXT Fest (SB-1752). Real rounds, but not an elimination tree: none of
  // these is a knockout or bracket round, so a tournament whose only "finals"
  // are placement finals does not switch on the bracket view.
  showcase: { short: 'Showcase', long: 'Showcase' },
  consolation: { short: 'Consolation', long: 'Consolation' },
  placement_final: { short: 'Placement', long: 'Placement Final' },
};
 
// Elimination rounds in playing order (R32 → R16 → QF → SF → 3rd → Final).
export const KNOCKOUT_ROUND_ORDER = [
  'round_of_32',
  'round_of_16',
  'quarterfinal',
  'semifinal',
  'third_place',
  'final',
];
 
export const KNOCKOUT_ROUNDS = new Set(KNOCKOUT_ROUND_ORDER);
 
// The rounds the bracket view draws, one column each. The third-place match is
// a knockout round but sits outside the tree, so it has no column.
export const BRACKET_ROUND_ORDER = KNOCKOUT_ROUND_ORDER.filter(
  round => round !== 'third_place'
);
 
export const BRACKET_ROUNDS = new Set(BRACKET_ROUND_ORDER);
 
// Rounds where a level score has to be broken, so the score editor offers
// shootout inputs. Wider than KNOCKOUT_ROUNDS: consolation and placement
// matches need a winner too, without being part of the knockout tree.
export const SHOOTOUT_ROUNDS = new Set([
  ...KNOCKOUT_ROUND_ORDER,
  'consolation',
  'placement_final',
]);
 
export const ROUND_LABELS_SHORT = Object.fromEntries(
  Object.entries(TOURNAMENT_ROUNDS).map(([key, { short }]) => [key, short])
);
 
export const ROUND_LABELS_LONG = Object.fromEntries(
  Object.entries(TOURNAMENT_ROUNDS).map(([key, { long }]) => [key, long])
);
 
// Resolve a round key to a label. Returns null for unknown/empty rounds.
export function roundLabel(round, { short = false } = {}) {
  const entry = TOURNAMENT_ROUNDS[round];
  if (!entry) return null;
  return short ? entry.short : entry.long;
}