Build a React team builder with role constraints
React Team Builder with Role Constraints
Implement a small React UI that allows a user to build a team from a list of available players, adhering to specific role-based constraints.
UI Components
- Left Panel: Displays a list of available players. Each player row must show at least their name and role, along with an "Add" button.
- Right Panel: Displays the list of players currently selected for the team.
Core Behaviors
1. Add Player
- Clicking the "Add" button for an available player moves them to the "current team" list.
- The same player cannot be added to the team more than once (prevent duplicates).
2. Role Constraints
- Each player role has defined minimum and maximum limits. These rules should be represented as data, potentially passed via props.
- Example Rules:
Goalkeeper: min 1, max 1Defender: min 3, max 5Midfielder: min 2, max 5Forward: min 1, max 3
- Example Rules:
- If adding a player would cause a role's maximum limit to be exceeded, the action must be blocked, and a user-visible message should be displayed.
- (Optional) Provide a visual indicator or mechanism to show whether the current team satisfies all role minimums.
3. Player Details Dialog
- Clicking a player's name in either the available players list or the current team list should open a modal or dialog displaying that player's detailed information.
4. Sorting and Determinism
- If the UI requires sorting players (e.g., by rating, number, or name), ensure the sorting is deterministic.
- If the primary sort key can result in ties, define a secondary sort key (e.g., player name) to maintain stable ordering.
Input Data
Assume the component receives the following data structures:
- An array of
Playerobjects:type Player = { id: string; name: string; role: string; rating?: number; bio?: string; }; - A map of role constraints:
type RoleRule = { min: number; max: number }; Record<string, RoleRule>
Your task is to implement the necessary React component(s) and state management to support all the described UI and behaviors.
AI interview prep
Core dilemma
Managing complex, interconnected UI state with derived data and enforcing business rules (role constraints) efficiently across multiple components, ensuring a responsive and consistent user experience.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Build a React team builder with role constraints
React Team Builder with Role Constraints
Implement a small React UI that allows a user to build a team from a list of available players, adhering to specific role-based constraints.
UI Components
- Left Panel: Displays a list of available players. Each player row must show at least their name and role, along with an "Add" button.
- Right Panel: Displays the list of players currently selected for the team.
Core Behaviors
1. Add Player
- Clicking the "Add" button for an available player moves them to the "current team" list.
- The same player cannot be added to the team more than once (prevent duplicates).
2. Role Constraints
- Each player role has defined minimum and maximum limits. These rules should be represented as data, potentially passed via props.
- Example Rules:
Goalkeeper: min 1, max 1Defender: min 3, max 5Midfielder: min 2, max 5Forward: min 1, max 3
- Example Rules:
- If adding a player would cause a role's maximum limit to be exceeded, the action must be blocked, and a user-visible message should be displayed.
- (Optional) Provide a visual indicator or mechanism to show whether the current team satisfies all role minimums.
3. Player Details Dialog
- Clicking a player's name in either the available players list or the current team list should open a modal or dialog displaying that player's detailed information.
4. Sorting and Determinism
- If the UI requires sorting players (e.g., by rating, number, or name), ensure the sorting is deterministic.
- If the primary sort key can result in ties, define a secondary sort key (e.g., player name) to maintain stable ordering.
Input Data
Assume the component receives the following data structures:
- An array of
Playerobjects:type Player = { id: string; name: string; role: string; rating?: number; bio?: string; }; - A map of role constraints:
type RoleRule = { min: number; max: number }; Record<string, RoleRule>
Your task is to implement the necessary React component(s) and state management to support all the described UI and behaviors.