brackt/app/components/draft/MiniDraftGrid.stories.tsx
Claude a2cbedbb82
Address all code review issues for draft room context menus
Layout bug: flex-1 min-w-20 was nested inside headerInner instead of the
direct flex-child wrapper in MiniDraftGrid, breaking equal column sizing.
Fixed by moving the classes to the outermost element in both the menu and
non-menu paths (matching DraftGridSection's pattern).

MiniDraftGrid improvements:
- Hoist hasHeaderMenu constant above the draftSlots.map() loop
- Add optional connectedTeams prop; disconnected teams render italic +
  muted-foreground, consistent with DraftGridSection
- connectedTeams now wired through the route's miniDraftGrid useMemo

DraftGridSection interface:
- Make onForceAutopick and onForceManualPickOpen optional (?) to match
  every other commissioner callback; add null checks at all three call
  sites (context menu, mobile MoreVertical button, mobile Sheet)
- Gate those two callbacks behind isCommissioner at the route level

Tests (new files):
- app/components/__tests__/MiniDraftGrid.test.tsx — covers layout classes,
  connected/disconnected styling, and all four context menu interactions
- app/components/__tests__/DraftGridSection.test.tsx — covers all three
  context menu surfaces for both commissioner and non-commissioner roles

Storybook: add CommissionerView and DisconnectedTeams stories to
MiniDraftGrid.stories.tsx

https://claude.ai/code/session_017JCShLVs9xZ6FZmyrUFaE1
2026-04-25 07:11:13 +00:00

175 lines
4.4 KiB
TypeScript

import type { Meta, StoryObj } from "@storybook/react-vite";
import { MiniDraftGrid } from "./MiniDraftGrid";
const meta: Meta<typeof MiniDraftGrid> = {
title: "Draft/MiniDraftGrid",
component: MiniDraftGrid,
parameters: {
layout: "padded",
},
};
export default meta;
type Story = StoryObj<typeof MiniDraftGrid>;
const teamNames = ["Alpha", "Bravo", "Charlie", "Delta"];
const ownerMap: Record<string, string> = {};
const draftSlots = teamNames.map((name, i) => {
const id = `team-${i + 1}`;
ownerMap[id] = name;
return { id, draftOrder: i + 1, team: { id, name, logoUrl: null } };
});
function buildRound(round: number, teamCount: number, picks: Array<number | null>) {
const isEvenRound = round % 2 === 0;
return Array.from({ length: teamCount }, (_, i) => {
const teamIndex = isEvenRound ? teamCount - 1 - i : i;
const pickNumber = (round - 1) * teamCount + i + 1;
const pick = picks[i];
return {
pickNumber,
round,
pickInRound: i + 1,
teamId: draftSlots[teamIndex].id,
...(pick !== null
? {
pick: {
participant: { name: `Participant ${pick}` },
sport: { name: ["NFL", "NBA", "NHL", "MLB"][pick % 4] },
},
}
: {}),
};
});
}
const fullGrid = [
buildRound(1, 4, [1, 2, 3, 4]),
buildRound(2, 4, [5, 6, null, null]),
buildRound(3, 4, [null, null, null, null]),
buildRound(4, 4, [null, null, null, null]),
];
export const Round1ShowsFirstTwo: Story = {
name: "Round 1 — Shows Rounds 1 & 2",
args: {
draftSlots,
draftGrid: fullGrid,
currentPick: 1,
currentRound: 1,
ownerMap,
},
};
export const Round2: Story = {
name: "Round 2 — Shows Rounds 1 & 2",
args: {
draftSlots,
draftGrid: fullGrid,
currentPick: 5,
currentRound: 2,
ownerMap,
},
};
export const Round3: Story = {
name: "Round 3 — Shows Rounds 2 & 3",
args: {
draftSlots,
draftGrid: fullGrid,
currentPick: 9,
currentRound: 3,
ownerMap,
},
};
export const Round4: Story = {
name: "Round 4 — Shows Rounds 3 & 4",
args: {
draftSlots,
draftGrid: fullGrid,
currentPick: 13,
currentRound: 4,
ownerMap,
},
};
export const AllPicked: Story = {
name: "Both Rounds Fully Picked",
args: {
draftSlots,
draftGrid: [
buildRound(1, 4, [1, 2, 3, 4]),
buildRound(2, 4, [5, 6, 7, 8]),
buildRound(3, 4, [null, null, null, null]),
],
currentPick: 9,
currentRound: 3,
ownerMap,
},
};
export const SixTeams: Story = {
name: "6 Teams — Snake Draft",
args: (() => {
const names6 = ["Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot"];
const ownerMap6: Record<string, string> = {};
const slots6 = names6.map((name, i) => {
const id = `team-${i + 1}`;
ownerMap6[id] = name;
return { id, draftOrder: i + 1, team: { id, name, logoUrl: null } };
});
const grid6 = [
buildRound(1, 6, [1, 2, 3, 4, 5, 6]),
buildRound(2, 6, [7, 8, null, null, null, null]),
];
return {
draftSlots: slots6,
draftGrid: grid6,
currentPick: 9,
currentRound: 2,
ownerMap: ownerMap6,
};
})(),
};
export const EmptyGrid: Story = {
name: "Empty Grid",
args: {
draftSlots,
draftGrid: [],
currentPick: 1,
currentRound: 1,
ownerMap,
},
};
export const CommissionerView: Story = {
name: "Commissioner — All Actions Available (right-click headers and cells)",
args: {
draftSlots,
draftGrid: fullGrid,
currentPick: 6,
currentRound: 2,
ownerMap,
connectedTeams: new Set(["team-1", "team-2", "team-3"]), // team-4 disconnected
onAdjustTimeBankOpen: (teamId) => alert(`Adjust time bank for ${teamId}`),
onSetAutodraftOpen: (teamId) => alert(`Set autodraft for ${teamId}`),
onForceAutopick: (pickNumber, teamId) => alert(`Force autopick ${pickNumber} for ${teamId}`),
onForceManualPickOpen: (pickNumber, teamId) => alert(`Force manual pick ${pickNumber} for ${teamId}`),
onReplacePick: (pickNumber, teamId) => alert(`Replace pick ${pickNumber} for ${teamId}`),
onRollbackToPick: (pickNumber) => alert(`Roll back to pick ${pickNumber}`),
},
};
export const DisconnectedTeams: Story = {
name: "Disconnected Teams",
args: {
draftSlots,
draftGrid: fullGrid,
currentPick: 3,
currentRound: 1,
ownerMap,
connectedTeams: new Set(["team-1"]), // team-2 through team-4 disconnected
},
};