Skip to content

Commit

Permalink
Merge pull request #873 from kevinhughes27/safe-checklist
Browse files Browse the repository at this point in the history
make checklist safe for blank tournaments
  • Loading branch information
kevinhughes27 authored Nov 25, 2018
2 parents 590fa1b + 697f2f1 commit 0e4aecd
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions clients/admin_next/src/views/Home/Checklist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Stepper from '@material-ui/core/Stepper';
import Step from "@material-ui/core/Step";
import StepButton from "@material-ui/core/StepButton";
import StepContent from "@material-ui/core/StepContent";
import { sumBy } from "lodash";
import { isEmpty, sumBy } from "lodash";
import Plan from "./Plan";
import Schedule from "./Schedule";
import Seed from "./Seed";
Expand All @@ -23,34 +23,39 @@ interface State {
completed: Set<number>;
}

const count = (array: ReadonlyArray<any> | null) => {
return (array || []).length;
}

class Checklist extends React.Component<Props, State> {
constructor(props: Props) {
super(props);

const { fields, teams, divisions, games } = this.props;

const divisionsAndFields = divisions.length > 0 && fields.length > 0;
const enoughTeams = sumBy(divisions, "numTeams") === teams.length;
const divisionsAndFields = !isEmpty(divisions) && !isEmpty(fields);
const enoughTeams = divisions && sumBy(divisions, "numTeams") === count(teams);

const completed = new Set();
const completed = new Set([-1]);

if (divisionsAndFields && enoughTeams) {
completed.add(0);
}

const scheduleBuilt = games.filter((g) => g.scheduled).length === games.length;
const scheduleBuilt = games && games.filter((g) => g.scheduled).length === games.length;

if (completed.has(0) && scheduleBuilt) {
completed.add(1);
}

const divisionsSeeded = divisions.filter((d) => d.isSeeded).length === divisions.length
const divisionsSeeded = divisions && divisions.filter((d) => d.isSeeded).length === divisions.length

if (completed.has(1) && divisionsSeeded) {
completed.add(2);
}

const activeStep = Math.max(...completed.values()) + 1;
const lastCompleted = Math.max(...completed.values());
const activeStep = lastCompleted + 1;

this.state = {
activeStep,
Expand All @@ -70,11 +75,13 @@ class Checklist extends React.Component<Props, State> {

const maxTeams = sumBy(divisions, "numTeams");

const scheduledGames = games.filter((g) => g.scheduled);
const scheduledGames = games && games.filter((g) => g.scheduled);

const seededDivisions = divisions && divisions.filter((d) => d.isSeeded);

const seededDivisions = divisions.filter((d) => d.isSeeded)
const scoredGames = games && games.filter((g) => g.scoreConfirmed);

const missingScores = games.filter((g) => {
const missingScores = games && games.filter((g) => {
const finished = g.endTime && new Date(g.endTime) < new Date();
return finished && !g.scoreConfirmed;
});
Expand All @@ -91,10 +98,10 @@ class Checklist extends React.Component<Props, State> {
</StepButton>
<StepContent>
<Plan
fields={fields.length}
teams={teams.length}
fields={count(fields)}
teams={count(teams)}
maxTeams={maxTeams}
divisions={divisions.length}
divisions={count(divisions)}
/>
</StepContent>
</Step>
Expand All @@ -108,8 +115,8 @@ class Checklist extends React.Component<Props, State> {
</StepButton>
<StepContent>
<Schedule
games={games.length}
scheduled={scheduledGames.length}
games={count(games)}
scheduled={count(scheduledGames)}
/>
</StepContent>
</Step>
Expand All @@ -123,8 +130,8 @@ class Checklist extends React.Component<Props, State> {
</StepButton>
<StepContent>
<Seed
divisions={divisions.length}
seeded={seededDivisions.length}
divisions={count(divisions)}
seeded={count(seededDivisions)}
/>
</StepContent>
</Step>
Expand All @@ -138,10 +145,10 @@ class Checklist extends React.Component<Props, State> {
</StepButton>
<StepContent>
<Play
games={games.length}
scored={games.filter((g) => g.scoreConfirmed).length}
missing={missingScores.length}
disputes={scoreDisputes.length}
games={count(games)}
scored={count(scoredGames)}
missing={count(missingScores)}
disputes={count(scoreDisputes)}
/>
</StepContent>
</Step>
Expand Down

0 comments on commit 0e4aecd

Please sign in to comment.