-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a34c27
commit f0412cb
Showing
16 changed files
with
465 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
app/webpacker/components/Panel/pages/RunValidatorsPage/CompetitionRangeSelector.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { Form } from 'semantic-ui-react'; | ||
import { QueryClient, useQuery } from '@tanstack/react-query'; | ||
import UtcDatePicker from '../../../wca/UtcDatePicker'; | ||
import getCompetitionList from './api/getCompetitionList'; | ||
import Loading from '../../../Requests/Loading'; | ||
import Errored from '../../../Requests/Errored'; | ||
|
||
const RUN_VALIDATORS_QUERY_CLIENT = new QueryClient(); | ||
const MAX_COMPETITIONS_PER_QUERY = 50; | ||
|
||
export default function CompetitionRangeSelector({ range, setRange }) { | ||
const [startDate, setStartDate] = useState(range?.startDate); | ||
const [endDate, setEndDate] = useState(range?.endDate); | ||
|
||
const enableCompetitionListFetch = Boolean(startDate && endDate); | ||
|
||
const { | ||
data: competitionList, isLoading, isError, refetch, | ||
} = useQuery({ | ||
queryKey: ['competitionCountInRange'], | ||
queryFn: () => getCompetitionList(startDate, endDate, MAX_COMPETITIONS_PER_QUERY), | ||
enabled: enableCompetitionListFetch, | ||
}, RUN_VALIDATORS_QUERY_CLIENT); | ||
|
||
useEffect(() => { | ||
setRange({ startDate, endDate }); | ||
if (enableCompetitionListFetch) { | ||
refetch(); | ||
} | ||
}, [startDate, endDate, setRange, enableCompetitionListFetch, refetch]); | ||
|
||
return ( | ||
<> | ||
<Form.Field | ||
label="Start Date" | ||
control={UtcDatePicker} | ||
showYearDropdown | ||
dateFormatOverride="yyyy-MM-dd" | ||
dropdownMode="select" | ||
isoDate={startDate} | ||
onChange={setStartDate} | ||
/> | ||
<Form.Field | ||
label="End Date" | ||
control={UtcDatePicker} | ||
showYearDropdown | ||
dateFormatOverride="yyyy-MM-dd" | ||
dropdownMode="select" | ||
isoDate={endDate} | ||
onChange={setEndDate} | ||
/> | ||
{enableCompetitionListFetch && ( | ||
<> | ||
{isLoading && (<Loading />)} | ||
{isError && <Errored />} | ||
{!isLoading && !isError && ( | ||
<div> | ||
{`The checks will run for ${competitionList.length}${ | ||
competitionList.length >= MAX_COMPETITIONS_PER_QUERY ? '+' : '' | ||
} competitions`} | ||
</div> | ||
)} | ||
</> | ||
)} | ||
</> | ||
); | ||
} |
Oops, something went wrong.