Skip to content

Commit

Permalink
Fix circumvention page form
Browse files Browse the repository at this point in the history
  • Loading branch information
majakomel committed Aug 9, 2023
1 parent e81670a commit e38c58a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
15 changes: 3 additions & 12 deletions components/dashboard/Form.js
Expand Up @@ -10,15 +10,6 @@ import { getLocalisedRegionName } from '../../utils/i18nCountries'
import { StyledLabel } from '../aggregation/mat/Form'
import DateRangePicker from '../DateRangePicker'

const tomorrow = dayjs.utc().add(1, 'day').format('YYYY-MM-DD')
const lastMonthToday = dayjs.utc().subtract(30, 'day').format('YYYY-MM-DD')

const defaultDefaultValues = {
since: lastMonthToday,
until: tomorrow,
probe_cc: ['CN', 'IR', 'RU']
}

export const Form = ({ onChange, query, availableCountries }) => {
const intl = useIntl()

Expand All @@ -31,10 +22,10 @@ export const Form = ({ onChange, query, availableCountries }) => {
, [availableCountries, intl])

const query2formValues = useMemo(() => {
const countriesInQuery = query.probe_cc?.split(',') ?? defaultDefaultValues.probe_cc
const countriesInQuery = query.probe_cc?.split(',') ?? ''
return {
since: query?.since ?? defaultDefaultValues.since,
until: query?.until ?? defaultDefaultValues.until,
since: query?.since,
until: query?.until,
probe_cc: countryOptions.filter(country => countriesInQuery.includes(country.value)),
}
}, [countryOptions, query])
Expand Down
33 changes: 17 additions & 16 deletions pages/chart/circumvention.js
Expand Up @@ -17,19 +17,18 @@ const DashboardCircumvention = ({ availableCountries }) => {

useEffect(() => {
const { query } = router
if (Object.keys(query).length === 0) {
const tomorrow = dayjs.utc().add(1, 'day').format('YYYY-MM-DD')
const monthAgo = dayjs.utc().subtract(30, 'day').format('YYYY-MM-DD')
const probe_cc = ['CN', 'IR', 'RU'].join(',')
const href = {
query: {
since: monthAgo,
until: tomorrow,
probe_cc
},
}
router.replace(href, undefined, { shallow: true })
const tomorrow = dayjs.utc().add(1, 'day').format('YYYY-MM-DD')
const monthAgo = dayjs.utc().subtract(30, 'day').format('YYYY-MM-DD')
const probe_cc = ['CN', 'IR', 'RU'].join(',')
const href = {
query: {
since: monthAgo,
until: tomorrow,
probe_cc,
...query
},
}
router.replace(href, undefined, { shallow: true })
}, [])

// Sync page URL params with changes from form values
Expand Down Expand Up @@ -58,13 +57,15 @@ const DashboardCircumvention = ({ availableCountries }) => {
<NavBar />
<Container>
<Heading h={1}><FormattedMessage id='ReachabilityDash.Heading.CircumventionTools' /></Heading>
{router.isReady && <>
<Box my={2} bg='gray0' p={3}>
<FormattedMarkdown id='ReachabilityDash.CircumventionTools.Description' />
</Box>
<Form onChange={onChange} query={query} availableCountries={availableCountries} />
<Charts />
</>}
{Object.keys(query).length > 0 &&
<>
<Form onChange={onChange} query={query} availableCountries={availableCountries} />
<Charts />
</>
}
</Container>
</>
)
Expand Down

1 comment on commit e38c58a

@vercel
Copy link

@vercel vercel bot commented on e38c58a Aug 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

explorer – ./

explorer-one.vercel.app
explorer-ooni1.vercel.app
explorer-git-master-ooni1.vercel.app

Please sign in to comment.