-
Notifications
You must be signed in to change notification settings - Fork 952
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): handle historcal linking with basic navigation (#7397)
* feat(web): handle historcal linking with basic navigation * remove console log * call last hour * change nav in ranking panel test * use builtin date range formatting * PR feedback * PR feedback * make buttons a11y friends + remove last_hour * onClick handler on button * simplify navigation logic * PR feedback
- Loading branch information
Showing
11 changed files
with
232 additions
and
61 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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import useGetState from 'api/getState'; | ||
import Badge from 'components/Badge'; | ||
import { Button } from 'components/Button'; | ||
import { FormattedTime } from 'components/Time'; | ||
import { useAtomValue } from 'jotai'; | ||
import { ChevronLeft, ChevronRight } from 'lucide-react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useParams } from 'react-router-dom'; | ||
import { twMerge } from 'tailwind-merge'; | ||
import { RouteParameters } from 'types'; | ||
import { useNavigateWithParameters } from 'utils/helpers'; | ||
import { endDatetimeAtom, isHourlyAtom, startDatetimeAtom } from 'utils/state/atoms'; | ||
|
||
const TWENTY_FOUR_HOURS = 24 * 60 * 60 * 1000; | ||
|
||
export default function HistoricalTimeHeader() { | ||
const { i18n } = useTranslation(); | ||
const startDatetime = useAtomValue(startDatetimeAtom); | ||
const endDatetime = useAtomValue(endDatetimeAtom); | ||
const isHourly = useAtomValue(isHourlyAtom); | ||
const { isLoading } = useGetState(); | ||
const { urlDatetime } = useParams<RouteParameters>(); | ||
const navigate = useNavigateWithParameters(); | ||
|
||
function handleRightClick() { | ||
if (!endDatetime || !urlDatetime) { | ||
return; | ||
} | ||
const currentEndDatetime = new Date(endDatetime); | ||
const newDate = new Date(currentEndDatetime.getTime() + TWENTY_FOUR_HOURS); | ||
|
||
const twentyFourHoursAgo = new Date(Date.now() - TWENTY_FOUR_HOURS); | ||
if (newDate >= twentyFourHoursAgo) { | ||
navigate({ datetime: '' }); | ||
return; | ||
} | ||
navigate({ datetime: newDate.toISOString() }); | ||
} | ||
|
||
function handleLeftClick() { | ||
if (!endDatetime) { | ||
return; | ||
} | ||
const currentEndDatetime = new Date(endDatetime); | ||
const newDate = new Date(currentEndDatetime.getTime() - TWENTY_FOUR_HOURS); | ||
navigate({ datetime: newDate.toISOString() }); | ||
} | ||
|
||
return ( | ||
<div className="flex min-h-6 flex-row items-center justify-between"> | ||
{!isLoading && startDatetime && endDatetime && ( | ||
<Badge | ||
pillText={ | ||
<FormattedTime | ||
datetime={startDatetime} | ||
language={i18n.languages[0]} | ||
endDatetime={endDatetime} | ||
/> | ||
} | ||
type="success" | ||
/> | ||
)} | ||
<div className="flex flex-row items-center gap-2"> | ||
<Button | ||
backgroundClasses="bg-transparent" | ||
onClick={handleLeftClick} | ||
size="sm" | ||
type="tertiary" | ||
isDisabled={!isHourly} | ||
icon={ | ||
<ChevronLeft | ||
className={twMerge('text-brand-green', !isHourly && 'opacity-50')} | ||
/> | ||
} | ||
/> | ||
<Button | ||
backgroundClasses="bg-transparent" | ||
size="sm" | ||
onClick={handleRightClick} | ||
type="tertiary" | ||
isDisabled={!isHourly || !urlDatetime} | ||
icon={ | ||
<ChevronRight | ||
className={twMerge( | ||
'text-brand-green', | ||
(!urlDatetime || !isHourly) && 'opacity-50' | ||
)} | ||
/> | ||
} | ||
/> | ||
<Button | ||
size="sm" | ||
type="secondary" | ||
onClick={() => navigate({ datetime: '' })} | ||
isDisabled={!urlDatetime} | ||
> | ||
Latest | ||
</Button> | ||
</div> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.