@ethlete/cdk 4.71.0 → 4.71.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ethlete/cdk
2
2
 
3
+ ## 4.71.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`80c3e17`](https://github.com/ethlete-io/ethdk/commit/80c3e17a93adbf62a4261a9540b2c53060f1ac25) Thanks [@TomTomB](https://github.com/TomTomB)! - Fix match highlighting in unsorted bracket sources
8
+
3
9
  ## 4.71.0
4
10
 
5
11
  ### Minor Changes
@@ -1365,13 +1365,27 @@ const createParticipantsMapBase = (source) => {
1365
1365
  return map;
1366
1366
  };
1367
1367
 
1368
+ const TERMINAL_ROUND_SORT_PRIORITY = {
1369
+ [COMMON_BRACKET_ROUND_TYPE.FINAL]: 1,
1370
+ [DOUBLE_ELIMINATION_BRACKET_ROUND_TYPE.REVERSE_FINAL]: 2,
1371
+ [COMMON_BRACKET_ROUND_TYPE.THIRD_PLACE]: 3,
1372
+ };
1373
+ const sortSourceMatchesByRoundOrder = (source) => {
1374
+ const orderedRoundIds = [...source.rounds]
1375
+ .sort((a, b) => (TERMINAL_ROUND_SORT_PRIORITY[a.type] ?? 0) - (TERMINAL_ROUND_SORT_PRIORITY[b.type] ?? 0))
1376
+ .map((r) => r.id);
1377
+ const roundIndexMap = new Map(orderedRoundIds.map((id, i) => [id, i]));
1378
+ const sortedMatches = [...source.matches].sort((a, b) => (roundIndexMap.get(a.roundId) ?? 0) - (roundIndexMap.get(b.roundId) ?? 0));
1379
+ return { ...source, matches: sortedMatches };
1380
+ };
1368
1381
  const createNewBracketBase = (source, options) => {
1369
1382
  if (!canRenderLayoutInTournamentMode(options.layout, source.mode)) {
1370
1383
  throw new Error(`Cannot render layout ${options.layout} in mode ${source.mode}`);
1371
1384
  }
1372
- const participants = createParticipantsMapBase(source);
1373
- const rounds = createRoundsMapBase(source, options);
1374
- const matches = createMatchesMapBase(source, rounds, participants);
1385
+ const normalizedSource = sortSourceMatchesByRoundOrder(source);
1386
+ const participants = createParticipantsMapBase(normalizedSource);
1387
+ const rounds = createRoundsMapBase(normalizedSource, options);
1388
+ const matches = createMatchesMapBase(normalizedSource, rounds, participants);
1375
1389
  const bracketData = {
1376
1390
  matches,
1377
1391
  rounds,