Skip to content

Commit

Permalink
fix: HOTFIX Run/autorun is disabled when Confirmed cases: None
Browse files Browse the repository at this point in the history
Resolves #506
  • Loading branch information
ivan-aksamentov committed Apr 11, 2020
1 parent 3147b74 commit 99b70f3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/components/Main/Scenario/ScenarioCardPopulation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useTranslation } from 'react-i18next'
import { caseCountsNames } from '../state/caseCountsData'
import { ageDistributionNames } from '../state/countryAgeDistributionData'

import { CUSTOM_COUNTRY_NAME } from '../state/state'
import { CUSTOM_COUNTRY_NAME, NONE_COUNTRY_NAME } from '../state/state'

import { CardWithoutDropdown } from '../../Form/CardWithoutDropdown'
import { FormDatePicker } from '../../Form/FormDatePicker'
Expand All @@ -19,7 +19,7 @@ const countryOptions = ageDistributionNames.map((country) => ({ value: country,
countryOptions.push({ value: CUSTOM_COUNTRY_NAME, label: i18next.t(CUSTOM_COUNTRY_NAME) })

const caseCountOptions = caseCountsNames.map((country) => ({ value: country, label: country }))
caseCountOptions.push({ value: 'none', label: 'None' })
caseCountOptions.push({ value: NONE_COUNTRY_NAME, label: i18next.t(NONE_COUNTRY_NAME) })

export interface ScenarioCardPopulationProps {
errors?: FormikErrors<any>
Expand Down
5 changes: 5 additions & 0 deletions src/components/Main/state/caseCountsData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CaseCounts, Convert } from '../../../.generated/types'
import CaseCountsValidate, { errors } from '../../../.generated/CaseCountsValidate'
import allCaseCountsRaw from '../../../assets/data/case_counts.json'
import { NONE_COUNTRY_NAME } from './state'

function validate(): CaseCounts[] {
const valid = CaseCountsValidate(allCaseCountsRaw)
Expand All @@ -17,6 +18,10 @@ const caseCounts = validate()
export const caseCountsNames = caseCounts.map((cc) => cc.country)

export function getCaseCountsData(key: string) {
if (key === NONE_COUNTRY_NAME) {
return []
}

const caseCountFound = caseCounts.find((cc) => cc.country === key)
if (!caseCountFound) {
throw new Error(`Error: case counts "${key}" not found in JSON`)
Expand Down
1 change: 1 addition & 0 deletions src/components/Main/state/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface State {
export const DEFAULT_OVERALL_SCENARIO_NAME = 'United States of America'
export const CUSTOM_SCENARIO_NAME = i18next.t('Custom')
export const CUSTOM_COUNTRY_NAME = 'Custom'
export const NONE_COUNTRY_NAME = 'None'

export const defaultScenarioName = DEFAULT_OVERALL_SCENARIO_NAME

Expand Down
4 changes: 2 additions & 2 deletions src/components/Main/validation/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import i18next from 'i18next'

import { caseCountsNames } from '../state/caseCountsData'
import { ageDistributionNames } from '../state/countryAgeDistributionData'
import { CUSTOM_COUNTRY_NAME } from '../state/state'
import { CUSTOM_COUNTRY_NAME, NONE_COUNTRY_NAME } from '../state/state'

const ageRegions = [...ageDistributionNames, CUSTOM_COUNTRY_NAME]

const caseRegions = [...caseCountsNames, CUSTOM_COUNTRY_NAME]
const caseRegions = [...caseCountsNames, CUSTOM_COUNTRY_NAME, NONE_COUNTRY_NAME]

const MSG_REQUIRED = 'Required'
const MSG_NON_NEGATIVE = 'Should be non-negative'
Expand Down

0 comments on commit 99b70f3

Please sign in to comment.