release/86 #2
No files matched your search
@@ -0,0 +1,170 @@
|
||||
import type {
|
||||
CompetitionGameView,
|
||||
CompetitionProjection,
|
||||
IsoDateTime,
|
||||
SeriesProjection,
|
||||
} from "@lolympus/contracts";
|
||||
|
||||
export type CompetitionSeriesHistorySeries = Extract<
|
||||
SeriesProjection,
|
||||
{ status: "in-progress" | "completed" }
|
||||
>;
|
||||
|
||||
export interface CompetitionSeriesHistoryRow {
|
||||
series: CompetitionSeriesHistorySeries;
|
||||
games: CompetitionGameView[];
|
||||
occurredAt: IsoDateTime;
|
||||
timestampSource: "game-start" | "decision";
|
||||
}
|
||||
|
||||
export interface CompetitionSeriesHistoryDay {
|
||||
dateKey: string;
|
||||
rows: CompetitionSeriesHistoryRow[];
|
||||
}
|
||||
|
||||
type HistoryProjection = Pick<CompetitionProjection, "series" | "games">;
|
||||
|
||||
export function createCompetitionSeriesHistory(
|
||||
projection: HistoryProjection,
|
||||
timeZone = "Asia/Seoul",
|
||||
): CompetitionSeriesHistoryDay[] {
|
||||
const gamesBySeriesId = new Map<string, CompetitionGameView[]>();
|
||||
for (const game of projection.games) {
|
||||
const seriesGames = gamesBySeriesId.get(game.seriesId) ?? [];
|
||||
seriesGames.push(game);
|
||||
gamesBySeriesId.set(game.seriesId, seriesGames);
|
||||
}
|
||||
|
||||
const rows: CompetitionSeriesHistoryRow[] = [];
|
||||
for (const series of projection.series) {
|
||||
const games = [...(gamesBySeriesId.get(series.seriesId) ?? [])].sort(
|
||||
compareGames,
|
||||
);
|
||||
if (series.status === "in-progress") {
|
||||
const occurredAt = earliestStartedAt(games);
|
||||
if (!occurredAt) continue;
|
||||
rows.push({
|
||||
series,
|
||||
games,
|
||||
occurredAt,
|
||||
timestampSource: "game-start",
|
||||
});
|
||||
continue;
|
||||
}
|
||||
if (series.status !== "completed") continue;
|
||||
|
||||
const gameStartedAt = earliestStartedAt(games);
|
||||
rows.push({
|
||||
series,
|
||||
games,
|
||||
occurredAt: gameStartedAt ?? series.outcome.completedAt,
|
||||
timestampSource: gameStartedAt ? "game-start" : "decision",
|
||||
});
|
||||
}
|
||||
|
||||
rows.sort(compareRows);
|
||||
|
||||
const days: CompetitionSeriesHistoryDay[] = [];
|
||||
for (const row of rows) {
|
||||
const dateKey = dateKeyInTimeZone(row.occurredAt, timeZone);
|
||||
const currentDay = days.at(-1);
|
||||
if (currentDay?.dateKey === dateKey) {
|
||||
currentDay.rows.push(row);
|
||||
} else {
|
||||
days.push({ dateKey, rows: [row] });
|
||||
}
|
||||
}
|
||||
return days;
|
||||
}
|
||||
|
||||
export function getSeriesHistoryStatusLabel(
|
||||
series: CompetitionSeriesHistorySeries,
|
||||
): string {
|
||||
if (series.status === "in-progress") return "진행 중";
|
||||
switch (series.outcome.type) {
|
||||
case "played":
|
||||
return "종료";
|
||||
case "draw":
|
||||
return "무승부";
|
||||
case "walkover":
|
||||
return "부전승";
|
||||
case "forfeit":
|
||||
return "기권승";
|
||||
case "administrative":
|
||||
return "판정";
|
||||
}
|
||||
}
|
||||
|
||||
export function formatSeriesGameDuration(
|
||||
durationSeconds: number,
|
||||
): string | null {
|
||||
if (!Number.isFinite(durationSeconds) || durationSeconds <= 0) return null;
|
||||
const totalSeconds = Math.floor(durationSeconds);
|
||||
const hours = Math.floor(totalSeconds / 3_600);
|
||||
const minutes = Math.floor((totalSeconds % 3_600) / 60);
|
||||
const seconds = totalSeconds % 60;
|
||||
if (hours > 0) {
|
||||
return `${hours}:${padNumber(minutes)}:${padNumber(seconds)}`;
|
||||
}
|
||||
return `${minutes}:${padNumber(seconds)}`;
|
||||
}
|
||||
|
||||
function compareGames(
|
||||
left: CompetitionGameView,
|
||||
right: CompetitionGameView,
|
||||
): number {
|
||||
return (
|
||||
left.ordinal - right.ordinal ||
|
||||
timestampValue(left.startedAt) - timestampValue(right.startedAt) ||
|
||||
left.id.localeCompare(right.id)
|
||||
);
|
||||
}
|
||||
|
||||
function compareRows(
|
||||
left: CompetitionSeriesHistoryRow,
|
||||
right: CompetitionSeriesHistoryRow,
|
||||
): number {
|
||||
return (
|
||||
timestampValue(left.occurredAt) - timestampValue(right.occurredAt) ||
|
||||
left.series.stage.displayOrder - right.series.stage.displayOrder ||
|
||||
left.series.seriesId.localeCompare(right.series.seriesId)
|
||||
);
|
||||
}
|
||||
|
||||
function earliestStartedAt(games: CompetitionGameView[]): IsoDateTime | null {
|
||||
let earliest: { value: number; startedAt: IsoDateTime } | null = null;
|
||||
for (const game of games) {
|
||||
const value = timestampValue(game.startedAt);
|
||||
if (!Number.isFinite(value)) continue;
|
||||
if (!earliest || value < earliest.value) {
|
||||
earliest = { value, startedAt: game.startedAt };
|
||||
}
|
||||
}
|
||||
return earliest?.startedAt ?? null;
|
||||
}
|
||||
|
||||
function dateKeyInTimeZone(value: IsoDateTime, timeZone: string): string {
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) return "unknown";
|
||||
const parts = new Intl.DateTimeFormat("en-US", {
|
||||
timeZone,
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
}).formatToParts(date);
|
||||
const part = (type: Intl.DateTimeFormatPartTypes) =>
|
||||
parts.find((entry) => entry.type === type)?.value;
|
||||
const year = part("year");
|
||||
const month = part("month");
|
||||
const day = part("day");
|
||||
return year && month && day ? `${year}-${month}-${day}` : "unknown";
|
||||
}
|
||||
|
||||
function timestampValue(value: IsoDateTime): number {
|
||||
const timestamp = Date.parse(value);
|
||||
return Number.isNaN(timestamp) ? Number.POSITIVE_INFINITY : timestamp;
|
||||
}
|
||||
|
||||
function padNumber(value: number): string {
|
||||
return value.toString().padStart(2, "0");
|
||||
}
|
||||
@@ -0,0 +1,477 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import type {
|
||||
CompetitionGameView,
|
||||
GameId,
|
||||
GameSlotId,
|
||||
SeriesId,
|
||||
SeriesProjection,
|
||||
TeamId,
|
||||
} from "@lolympus/contracts";
|
||||
import {
|
||||
createCompetitionSeriesHistory,
|
||||
formatSeriesGameDuration,
|
||||
getSeriesHistoryStatusLabel,
|
||||
} from "../src/components/competition/competition-series-history.ts";
|
||||
|
||||
test("aggregates Games under their Series and preserves Series slot scores", () => {
|
||||
const teamA = teamId("team-a");
|
||||
const teamB = teamId("team-b");
|
||||
const series = completedSeries({
|
||||
id: "series-score",
|
||||
teamA,
|
||||
teamB,
|
||||
scoreA: 2,
|
||||
scoreB: 1,
|
||||
completedAt: "2026-07-12T13:00:00.000Z",
|
||||
});
|
||||
const laterGame = game({
|
||||
id: "game-later",
|
||||
seriesId: series.seriesId,
|
||||
ordinal: 2,
|
||||
displayNumber: 4,
|
||||
blueTeamId: teamB,
|
||||
redTeamId: teamA,
|
||||
winnerTeamId: teamB,
|
||||
startedAt: "2026-07-12T12:30:00.000Z",
|
||||
});
|
||||
const earlierGame = game({
|
||||
id: "game-earlier",
|
||||
seriesId: series.seriesId,
|
||||
ordinal: 1,
|
||||
displayNumber: 19,
|
||||
blueTeamId: teamA,
|
||||
redTeamId: teamB,
|
||||
winnerTeamId: teamA,
|
||||
startedAt: "2026-07-12T12:00:00.000Z",
|
||||
});
|
||||
|
||||
const history = createCompetitionSeriesHistory({
|
||||
series: [series],
|
||||
games: [laterGame, earlierGame],
|
||||
});
|
||||
|
||||
assert.equal(history.length, 1);
|
||||
assert.equal(history[0].dateKey, "2026-07-12");
|
||||
assert.equal(history[0].rows.length, 1);
|
||||
assert.deepEqual(
|
||||
history[0].rows[0].series.entries.map((entry) => entry.gameWins),
|
||||
[2, 1],
|
||||
);
|
||||
assert.deepEqual(
|
||||
history[0].rows[0].games.map(({ ordinal }) => ordinal),
|
||||
[1, 2],
|
||||
);
|
||||
assert.equal(history[0].rows[0].occurredAt, earlierGame.startedAt);
|
||||
assert.equal(history[0].rows[0].timestampSource, "game-start");
|
||||
});
|
||||
|
||||
test("groups and orders Series by the Asia/Seoul calendar day", () => {
|
||||
const firstDay = playedSeriesWithGame({
|
||||
id: "first-day",
|
||||
displayOrder: 3,
|
||||
startedAt: "2026-07-12T14:55:00.000Z",
|
||||
});
|
||||
const secondDayLater = playedSeriesWithGame({
|
||||
id: "second-day-later",
|
||||
displayOrder: 2,
|
||||
startedAt: "2026-07-12T16:05:00.000Z",
|
||||
});
|
||||
const secondDayEarlier = playedSeriesWithGame({
|
||||
id: "second-day-earlier",
|
||||
displayOrder: 1,
|
||||
startedAt: "2026-07-12T15:05:00.000Z",
|
||||
});
|
||||
|
||||
const history = createCompetitionSeriesHistory({
|
||||
series: [secondDayLater.series, firstDay.series, secondDayEarlier.series],
|
||||
games: [secondDayLater.game, secondDayEarlier.game, firstDay.game],
|
||||
});
|
||||
|
||||
assert.deepEqual(
|
||||
history.map(({ dateKey }) => dateKey),
|
||||
["2026-07-12", "2026-07-13"],
|
||||
);
|
||||
assert.deepEqual(
|
||||
history[1].rows.map(({ series }) => series.seriesId),
|
||||
[secondDayEarlier.series.seriesId, secondDayLater.series.seriesId],
|
||||
);
|
||||
});
|
||||
|
||||
test("includes recorded in-progress Series and game-less completed decisions only", () => {
|
||||
const teamA = teamId("team-a");
|
||||
const teamB = teamId("team-b");
|
||||
const running = inProgressSeries("running-recorded", teamA, teamB, 1, 0);
|
||||
const runningGame = game({
|
||||
id: "running-game",
|
||||
seriesId: running.seriesId,
|
||||
ordinal: 1,
|
||||
displayNumber: 1,
|
||||
blueTeamId: teamA,
|
||||
redTeamId: teamB,
|
||||
winnerTeamId: teamA,
|
||||
startedAt: "2026-07-13T09:00:00.000Z",
|
||||
});
|
||||
const administrative = completedSeries({
|
||||
id: "administrative",
|
||||
teamA,
|
||||
teamB,
|
||||
scoreA: 0,
|
||||
scoreB: 0,
|
||||
completedAt: "2026-07-13T10:00:00.000Z",
|
||||
outcome: "administrative",
|
||||
});
|
||||
const unrecordedRunning = inProgressSeries(
|
||||
"running-unrecorded",
|
||||
teamA,
|
||||
teamB,
|
||||
0,
|
||||
0,
|
||||
);
|
||||
|
||||
const history = createCompetitionSeriesHistory({
|
||||
series: [
|
||||
readySeries("ready", teamA, teamB),
|
||||
waitingSeries("waiting"),
|
||||
inactiveSeries("inactive"),
|
||||
unrecordedRunning,
|
||||
administrative,
|
||||
running,
|
||||
],
|
||||
games: [runningGame],
|
||||
});
|
||||
const rows = history.flatMap(({ rows }) => rows);
|
||||
|
||||
assert.deepEqual(
|
||||
rows.map(({ series }) => series.seriesId),
|
||||
[running.seriesId, administrative.seriesId],
|
||||
);
|
||||
assert.equal(rows[0].timestampSource, "game-start");
|
||||
assert.equal(rows[1].timestampSource, "decision");
|
||||
assert.equal(rows[1].occurredAt, administrative.outcome.completedAt);
|
||||
});
|
||||
|
||||
test("sorts tied timestamps deterministically and ignores orphan Games", () => {
|
||||
const teamA = teamId("team-a");
|
||||
const teamB = teamId("team-b");
|
||||
const earlierDisplayOrder = completedSeries({
|
||||
id: "series-z",
|
||||
teamA,
|
||||
teamB,
|
||||
scoreA: 2,
|
||||
scoreB: 0,
|
||||
displayOrder: 1,
|
||||
completedAt: "2026-07-13T12:00:00.000Z",
|
||||
});
|
||||
const laterDisplayOrder = completedSeries({
|
||||
id: "series-a",
|
||||
teamA,
|
||||
teamB,
|
||||
scoreA: 2,
|
||||
scoreB: 1,
|
||||
displayOrder: 2,
|
||||
completedAt: "2026-07-13T12:00:00.000Z",
|
||||
});
|
||||
const orphanGame = game({
|
||||
id: "orphan-game",
|
||||
seriesId: seriesId("missing-series"),
|
||||
ordinal: 1,
|
||||
displayNumber: 99,
|
||||
blueTeamId: teamA,
|
||||
redTeamId: teamB,
|
||||
winnerTeamId: teamA,
|
||||
startedAt: "2026-07-13T08:00:00.000Z",
|
||||
});
|
||||
|
||||
const rows = createCompetitionSeriesHistory({
|
||||
series: [laterDisplayOrder, earlierDisplayOrder],
|
||||
games: [orphanGame],
|
||||
}).flatMap(({ rows }) => rows);
|
||||
|
||||
assert.deepEqual(
|
||||
rows.map(({ series }) => series.seriesId),
|
||||
[earlierDisplayOrder.seriesId, laterDisplayOrder.seriesId],
|
||||
);
|
||||
assert.equal(rows.every(({ games }) => games.length === 0), true);
|
||||
});
|
||||
|
||||
test("returns explicit status labels for played and adjudicated outcomes", () => {
|
||||
const teamA = teamId("team-a");
|
||||
const teamB = teamId("team-b");
|
||||
|
||||
assert.equal(
|
||||
getSeriesHistoryStatusLabel(
|
||||
inProgressSeries("running", teamA, teamB, 1, 0),
|
||||
),
|
||||
"진행 중",
|
||||
);
|
||||
assert.equal(
|
||||
getSeriesHistoryStatusLabel(
|
||||
completedSeries({ id: "played", teamA, teamB, scoreA: 2, scoreB: 1 }),
|
||||
),
|
||||
"종료",
|
||||
);
|
||||
assert.equal(
|
||||
getSeriesHistoryStatusLabel(
|
||||
completedSeries({
|
||||
id: "draw",
|
||||
teamA,
|
||||
teamB,
|
||||
scoreA: 1,
|
||||
scoreB: 1,
|
||||
outcome: "draw",
|
||||
}),
|
||||
),
|
||||
"무승부",
|
||||
);
|
||||
assert.equal(
|
||||
getSeriesHistoryStatusLabel(
|
||||
completedSeries({
|
||||
id: "walkover",
|
||||
teamA,
|
||||
teamB,
|
||||
scoreA: 0,
|
||||
scoreB: 0,
|
||||
outcome: "walkover",
|
||||
}),
|
||||
),
|
||||
"부전승",
|
||||
);
|
||||
assert.equal(
|
||||
getSeriesHistoryStatusLabel(
|
||||
completedSeries({
|
||||
id: "forfeit",
|
||||
teamA,
|
||||
teamB,
|
||||
scoreA: 1,
|
||||
scoreB: 1,
|
||||
outcome: "forfeit",
|
||||
}),
|
||||
),
|
||||
"기권승",
|
||||
);
|
||||
assert.equal(
|
||||
getSeriesHistoryStatusLabel(
|
||||
completedSeries({
|
||||
id: "administrative",
|
||||
teamA,
|
||||
teamB,
|
||||
scoreA: 0,
|
||||
scoreB: 0,
|
||||
outcome: "administrative",
|
||||
}),
|
||||
),
|
||||
"판정",
|
||||
);
|
||||
});
|
||||
|
||||
test("formats recorded Game duration and omits unknown legacy zero values", () => {
|
||||
assert.equal(formatSeriesGameDuration(1_875), "31:15");
|
||||
assert.equal(formatSeriesGameDuration(3_661), "1:01:01");
|
||||
assert.equal(formatSeriesGameDuration(0), null);
|
||||
assert.equal(formatSeriesGameDuration(-1), null);
|
||||
});
|
||||
|
||||
function playedSeriesWithGame({
|
||||
id,
|
||||
displayOrder,
|
||||
startedAt,
|
||||
}: {
|
||||
id: string;
|
||||
displayOrder: number;
|
||||
startedAt: string;
|
||||
}) {
|
||||
const teamA = teamId(`${id}-a`);
|
||||
const teamB = teamId(`${id}-b`);
|
||||
const series = completedSeries({
|
||||
id,
|
||||
teamA,
|
||||
teamB,
|
||||
scoreA: 2,
|
||||
scoreB: 0,
|
||||
displayOrder,
|
||||
completedAt: startedAt,
|
||||
});
|
||||
return {
|
||||
series,
|
||||
game: game({
|
||||
id: `${id}-game`,
|
||||
seriesId: series.seriesId,
|
||||
ordinal: 1,
|
||||
displayNumber: displayOrder,
|
||||
blueTeamId: teamA,
|
||||
redTeamId: teamB,
|
||||
winnerTeamId: teamA,
|
||||
startedAt,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
function completedSeries({
|
||||
id,
|
||||
teamA,
|
||||
teamB,
|
||||
scoreA,
|
||||
scoreB,
|
||||
displayOrder = 1,
|
||||
completedAt = "2026-07-13T00:00:00.000Z",
|
||||
outcome = "played",
|
||||
}: {
|
||||
id: string;
|
||||
teamA: TeamId;
|
||||
teamB: TeamId;
|
||||
scoreA: number;
|
||||
scoreB: number;
|
||||
displayOrder?: number;
|
||||
completedAt?: string;
|
||||
outcome?: "played" | "draw" | "walkover" | "forfeit" | "administrative";
|
||||
}): Extract<SeriesProjection, { status: "completed" }> {
|
||||
const base = {
|
||||
seriesId: seriesId(id),
|
||||
stage: { type: "upper" as const, roundNumber: 1, displayOrder },
|
||||
rule: { type: "first-to" as const, winsRequired: 2, maxGames: 3 },
|
||||
status: "completed" as const,
|
||||
entries: [
|
||||
{ slot: "A" as const, teamId: teamA, gameWins: scoreA },
|
||||
{ slot: "B" as const, teamId: teamB, gameWins: scoreB },
|
||||
] as const,
|
||||
};
|
||||
|
||||
if (outcome === "draw") {
|
||||
return {
|
||||
...base,
|
||||
outcome: {
|
||||
type: "draw",
|
||||
basis: { type: "played", decidedByGameIds: [] },
|
||||
completedAt,
|
||||
},
|
||||
};
|
||||
}
|
||||
if (outcome !== "played") {
|
||||
return {
|
||||
...base,
|
||||
outcome: {
|
||||
type: outcome,
|
||||
winnerTeamId: teamA,
|
||||
loserTeamId: teamB,
|
||||
decisionFactId: `fact-${id}` as never,
|
||||
completedAt,
|
||||
},
|
||||
};
|
||||
}
|
||||
return {
|
||||
...base,
|
||||
outcome: {
|
||||
type: "played",
|
||||
winnerTeamId: teamA,
|
||||
loserTeamId: teamB,
|
||||
decidedByGameIds: [],
|
||||
completedAt,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function inProgressSeries(
|
||||
id: string,
|
||||
teamA: TeamId,
|
||||
teamB: TeamId,
|
||||
scoreA: number,
|
||||
scoreB: number,
|
||||
): Extract<SeriesProjection, { status: "in-progress" }> {
|
||||
return {
|
||||
seriesId: seriesId(id),
|
||||
stage: { type: "upper", roundNumber: 1, displayOrder: 1 },
|
||||
rule: { type: "first-to", winsRequired: 2, maxGames: 3 },
|
||||
status: "in-progress",
|
||||
entries: [
|
||||
{ slot: "A", teamId: teamA, gameWins: scoreA },
|
||||
{ slot: "B", teamId: teamB, gameWins: scoreB },
|
||||
],
|
||||
...(scoreA === scoreB
|
||||
? {}
|
||||
: { leaderTeamId: scoreA > scoreB ? teamA : teamB }),
|
||||
};
|
||||
}
|
||||
|
||||
function readySeries(
|
||||
id: string,
|
||||
teamA: TeamId,
|
||||
teamB: TeamId,
|
||||
): Extract<SeriesProjection, { status: "ready" }> {
|
||||
return {
|
||||
seriesId: seriesId(id),
|
||||
stage: { type: "upper", roundNumber: 1, displayOrder: 1 },
|
||||
rule: { type: "first-to", winsRequired: 2, maxGames: 3 },
|
||||
status: "ready",
|
||||
entries: [
|
||||
{ slot: "A", teamId: teamA, gameWins: 0 },
|
||||
{ slot: "B", teamId: teamB, gameWins: 0 },
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
function waitingSeries(
|
||||
id: string,
|
||||
): Extract<SeriesProjection, { status: "waiting" }> {
|
||||
return {
|
||||
seriesId: seriesId(id),
|
||||
stage: { type: "upper", roundNumber: 1, displayOrder: 1 },
|
||||
rule: { type: "first-to", winsRequired: 2, maxGames: 3 },
|
||||
status: "waiting",
|
||||
entries: [
|
||||
{ slot: "A", teamId: null, gameWins: 0 },
|
||||
{ slot: "B", teamId: null, gameWins: 0 },
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
function inactiveSeries(
|
||||
id: string,
|
||||
): Extract<SeriesProjection, { status: "inactive" }> {
|
||||
return { ...waitingSeries(id), status: "inactive" };
|
||||
}
|
||||
|
||||
function game({
|
||||
id,
|
||||
seriesId: parentSeriesId,
|
||||
ordinal,
|
||||
displayNumber,
|
||||
blueTeamId,
|
||||
redTeamId,
|
||||
winnerTeamId,
|
||||
startedAt,
|
||||
}: {
|
||||
id: string;
|
||||
seriesId: SeriesId;
|
||||
ordinal: number;
|
||||
displayNumber: number;
|
||||
blueTeamId: TeamId;
|
||||
redTeamId: TeamId;
|
||||
winnerTeamId: TeamId;
|
||||
startedAt: string;
|
||||
}): CompetitionGameView {
|
||||
return {
|
||||
id: id as GameId,
|
||||
seriesId: parentSeriesId,
|
||||
gameSlotId: `${id}-slot` as GameSlotId,
|
||||
ordinal,
|
||||
displayNumber,
|
||||
evidence: { type: "legacy", legacyReference: id },
|
||||
teams: {
|
||||
blue: { side: "blue", teamId: blueTeamId },
|
||||
red: { side: "red", teamId: redTeamId },
|
||||
},
|
||||
winnerTeamId,
|
||||
startedAt,
|
||||
durationSeconds: 1_875,
|
||||
participants: [],
|
||||
};
|
||||
}
|
||||
|
||||
function seriesId(value: string): SeriesId {
|
||||
return value as SeriesId;
|
||||
}
|
||||
|
||||
function teamId(value: string): TeamId {
|
||||
return value as TeamId;
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
# Implementation Plan: Series Result History UI
|
||||
|
||||
## Overview
|
||||
|
||||
Replace the existing completed-Game mini-card grid with a tested chronological
|
||||
Series result history. Keep data derivation pure, render responsive semantic rows,
|
||||
and preserve all current Competition/API contracts.
|
||||
|
||||
## Architecture Decisions
|
||||
|
||||
- Derive a local view model from `projection.series` and `projection.games`; no API
|
||||
or persistence change is required.
|
||||
- Anchor a played Series to its earliest accepted Game start. Anchor a game-less
|
||||
completed decision to its decision time only for grouping and sorting.
|
||||
- Keep the original narrowed Series and Game objects in each row so the UI does not
|
||||
duplicate domain state or collapse outcome semantics.
|
||||
- Use a native `details/summary` disclosure for Game history and omit it when a
|
||||
Series has no Games.
|
||||
- Extract the new UI from `CompetitionResults.tsx` so the format selector remains
|
||||
focused.
|
||||
|
||||
## Task List
|
||||
|
||||
### Phase 1: Result-History Contract
|
||||
|
||||
#### Task 1: Specify aggregation and chronology test-first
|
||||
|
||||
**Acceptance criteria:**
|
||||
|
||||
- [ ] Tests cover Series aggregation, ordinal Game order, KST date boundaries,
|
||||
chronological order, outcome variants, and deterministic fallbacks.
|
||||
- [ ] The focused test fails because the model module does not yet exist.
|
||||
|
||||
**Verification:**
|
||||
|
||||
- [ ] Run the focused Node test and record the expected RED failure.
|
||||
|
||||
**Files likely touched:**
|
||||
|
||||
- `apps/web/test/competition-series-history.test.ts`
|
||||
|
||||
#### Task 2: Implement the pure history model
|
||||
|
||||
**Acceptance criteria:**
|
||||
|
||||
- [ ] Only recorded in-progress and completed Series are returned.
|
||||
- [ ] Date grouping and format helpers are explicitly KST-aware.
|
||||
- [ ] Decision outcomes and missing legacy durations remain distinguishable.
|
||||
|
||||
**Verification:**
|
||||
|
||||
- [ ] Focused history tests pass.
|
||||
- [ ] Existing web tests still pass.
|
||||
|
||||
**Files likely touched:**
|
||||
|
||||
- `apps/web/src/components/competition/competition-series-history.ts`
|
||||
- `apps/web/test/competition-series-history.test.ts`
|
||||
|
||||
### Checkpoint: Model
|
||||
|
||||
- [ ] Pure tests pass without a React or browser dependency.
|
||||
|
||||
### Phase 2: Responsive Result UI
|
||||
|
||||
#### Task 3: Render date sections and Series rows
|
||||
|
||||
**Acceptance criteria:**
|
||||
|
||||
- [ ] Desktop uses a flat schedule-like row; mobile stacks metadata and matchup
|
||||
without horizontal scrolling.
|
||||
- [ ] Status and official winner are communicated with visible text and typography,
|
||||
not color alone.
|
||||
- [ ] Game-less decisions do not show fake start times or `0 : 0`.
|
||||
|
||||
**Verification:**
|
||||
|
||||
- [ ] Changed component files pass ESLint.
|
||||
- [ ] Web build succeeds.
|
||||
|
||||
**Files likely touched:**
|
||||
|
||||
- `apps/web/src/components/competition/CompetitionSeriesHistory.tsx`
|
||||
|
||||
#### Task 4: Integrate accessible Game disclosures
|
||||
|
||||
**Acceptance criteria:**
|
||||
|
||||
- [ ] Each Series with Games exposes a native keyboard-operable disclosure.
|
||||
- [ ] Games use Series-local ordinal, team-ID winner lookup, and omit unknown
|
||||
zero-duration values.
|
||||
- [ ] The old completed-Game mini-card block is removed.
|
||||
|
||||
**Verification:**
|
||||
|
||||
- [ ] Full web tests, lint, and build pass.
|
||||
- [ ] Source review checks heading order, disclosure semantics, and 320px layout.
|
||||
|
||||
**Files likely touched:**
|
||||
|
||||
- `apps/web/src/components/competition/CompetitionSeriesHistory.tsx`
|
||||
- `apps/web/src/components/competition/CompetitionResults.tsx`
|
||||
|
||||
### Checkpoint: Complete
|
||||
|
||||
- [ ] All specification success criteria are met.
|
||||
- [ ] Git diff contains only the feature spec, plan, tests, model, and UI integration.
|
||||
- [ ] Unrelated working-tree files are unchanged.
|
||||
|
||||
## Risks and Mitigations
|
||||
|
||||
| Risk | Impact | Mitigation |
|
||||
|---|---|---|
|
||||
| Game sides are mistaken for Series slots | High | Use Series A/B entries and outcome team IDs; test side swaps. |
|
||||
| Completion time is shown as start time | Medium | Track timestamp source and render a blank time for decisions. |
|
||||
| KST day changes by deploy environment | Medium | Use explicit `Intl.DateTimeFormat` timezone and boundary tests. |
|
||||
| Long team names break mobile rows | Medium | Use balanced minmax columns and allow wrapping. |
|
||||
| Existing dirty work is overwritten | High | Restrict patches and verification to named feature files. |
|
||||
|
||||
## Open Questions
|
||||
|
||||
None.
|
||||
@@ -0,0 +1,131 @@
|
||||
# Spec: Series Result History UI
|
||||
|
||||
## Objective
|
||||
|
||||
Replace the compact `Game N - winner` cards below Competition brackets with a
|
||||
chronological, Series-centric result history. Users should be able to scan when a
|
||||
Series was played, its round, participants, official result, and current score,
|
||||
then expand the row to inspect the accepted Games that produced that record.
|
||||
|
||||
This first version is a truthful activity/result history, not a future schedule.
|
||||
It uses only recorded Competition projection data and does not invent scheduled
|
||||
times, venues, replay links, or team logos.
|
||||
|
||||
## Approved Product Decisions
|
||||
|
||||
- Keep the bracket first as the topology view and place the chronological history
|
||||
below it.
|
||||
- Render one primary row per Series, never one primary row per Game.
|
||||
- Include a started `in-progress` Series when it has at least one accepted Game, so
|
||||
completed Games do not disappear while a best-of Series is still running.
|
||||
- Include every completed Series, including draw, walkover, forfeit, and
|
||||
administrative outcomes with no accepted Game.
|
||||
- Exclude inactive, waiting, ready, and game-less in-progress Series because they do
|
||||
not have a truthful result timestamp.
|
||||
- Use the earliest accepted Game `startedAt` as the Series activity time. For a
|
||||
game-less decision, group by `outcome.completedAt` but display no fake start time.
|
||||
- Group and format dates explicitly in `Asia/Seoul`.
|
||||
- Keep individual Games in a native, keyboard-accessible disclosure below the Series
|
||||
row.
|
||||
|
||||
## Tech Stack
|
||||
|
||||
- React 19 and TypeScript 6 under `apps/web`
|
||||
- Tailwind CSS 4 and daisyUI semantic tokens
|
||||
- Shared Competition contracts from `@lolympus/contracts`
|
||||
- Node's built-in test runner with TypeScript type stripping for pure model tests
|
||||
|
||||
## Commands
|
||||
|
||||
- Focused RED/GREEN test:
|
||||
`pnpm --filter web exec node --test --experimental-strip-types test/competition-series-history.test.ts`
|
||||
- Full web tests: `pnpm --filter web test`
|
||||
- Web lint: `pnpm --filter web lint`
|
||||
- Web build: `pnpm --filter web build`
|
||||
|
||||
## Project Structure
|
||||
|
||||
- `apps/web/src/components/competition/competition-series-history.ts` derives the
|
||||
stable, timezone-aware history view model without React.
|
||||
- `apps/web/src/components/competition/CompetitionSeriesHistory.tsx` renders the
|
||||
semantic date sections, responsive Series rows, and Game disclosures.
|
||||
- `apps/web/src/components/competition/CompetitionResults.tsx` replaces the existing
|
||||
completed-Game card grid with the new component.
|
||||
- `apps/web/test/competition-series-history.test.ts` specifies aggregation, ordering,
|
||||
outcome, and formatting behavior.
|
||||
|
||||
## Code Style
|
||||
|
||||
Use contract discriminators and team IDs as the source of truth:
|
||||
|
||||
```ts
|
||||
const shouldInclude =
|
||||
(series.status === "in-progress" && games.length > 0) ||
|
||||
series.status === "completed";
|
||||
|
||||
const winnerTeamId =
|
||||
series.status === "completed" && series.outcome.type !== "draw"
|
||||
? series.outcome.winnerTeamId
|
||||
: undefined;
|
||||
```
|
||||
|
||||
The UI uses flat, full-width rows and existing semantic tokens. It does not reuse
|
||||
the bordered bracket card layout or introduce new dependencies.
|
||||
|
||||
## Testing Strategy
|
||||
|
||||
Develop the pure model test-first. Cover:
|
||||
|
||||
- Games aggregated by `seriesId` and ordered by Series-local `ordinal`;
|
||||
- Series score preserved from A/B entries even when blue/red sides change;
|
||||
- chronological ordering independent of projection graph order;
|
||||
- `Asia/Seoul` grouping across the UTC day boundary;
|
||||
- started in-progress Series and game-less completed decisions;
|
||||
- exclusion of unstarted and orphan data;
|
||||
- played, draw, walkover, forfeit, and administrative status semantics;
|
||||
- deterministic tie-breaking and legacy zero-duration formatting.
|
||||
|
||||
After unit tests, run full web tests, changed-file lint, and the TypeScript/Vite build.
|
||||
Review the markup for native keyboard interaction, heading order, visible status text,
|
||||
and mobile layouts down to 320px.
|
||||
|
||||
## Boundaries
|
||||
|
||||
### Always
|
||||
|
||||
- Use `series.entries` for A/B score and `outcome.winnerTeamId` for the official
|
||||
winner; never infer identity from score, array position, or blue/red side.
|
||||
- Keep game-less adjudications visible without presenting `0 : 0` as a played score.
|
||||
- Omit `durationSeconds === 0` because it represents missing legacy data.
|
||||
- Preserve all unrelated working-tree changes.
|
||||
|
||||
### Ask First
|
||||
|
||||
- Change the public Competition contract, database schema, or projector.
|
||||
- Add Series scheduling or external replay/venue data.
|
||||
- Add a frontend dependency or test framework.
|
||||
|
||||
### Never
|
||||
|
||||
- Present `completedAt` as a scheduled or actual start time.
|
||||
- Reuse free-text `match.schedule` as official Series scheduling data.
|
||||
- Parse `series.code` for identity, winner, or ordering.
|
||||
- Make status or winner understandable only through color.
|
||||
|
||||
## Success Criteria
|
||||
|
||||
- A completed `2 : 1` Series appears as one chronological row with both teams, the
|
||||
official score, round label, status, and an expandable three-Game history.
|
||||
- In-progress Series retain already accepted Games and display `진행 중`.
|
||||
- No-game decisions appear with the correct decision label and no misleading score
|
||||
or start time.
|
||||
- Date grouping and time display are stable in `Asia/Seoul` regardless of runtime
|
||||
timezone.
|
||||
- The layout is readable without horizontal scrolling at 320px and uses the wider
|
||||
double-elimination page naturally on desktop.
|
||||
- Focused/full tests, lint, and web build pass without modifying unrelated work.
|
||||
|
||||
## Open Questions
|
||||
|
||||
None. The user approved the Series-centric, result-history-first direction and
|
||||
requested implementation.
|
||||
Reference in new issue
Block a user