-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
3 changed files
with
75 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { useCallback, useEffect } from 'react'; | ||
import { JOB_COLORS } from 'src/constants'; | ||
import { abbreviateNumber } from 'src/utils/formatter'; | ||
import cx from 'classnames'; | ||
import { StatusType } from 'src/types'; | ||
import { useJobsListContext } from 'src/hooks/useJobsListContext'; | ||
import { useJobsOverview } from 'src/hooks/useJobsOverview'; | ||
|
||
const STATUS_BUTTONS: StatusType[] = [ | ||
'scheduled', | ||
'queued', | ||
'running', | ||
'completed', | ||
'failed', | ||
]; | ||
|
||
const Overview = () => { | ||
const { name, property, value, status, setStatus, jobListUpdatedAt } = | ||
useJobsListContext(); | ||
|
||
const { data, mutate: refreshOverview } = useJobsOverview({ | ||
name, | ||
property, | ||
value, | ||
}); | ||
|
||
useEffect(() => { | ||
refreshOverview(); | ||
}, [refreshOverview, jobListUpdatedAt]); | ||
|
||
const handleStatusSelect = useCallback( | ||
(btnStatus: StatusType) => () => | ||
setStatus(status !== btnStatus ? btnStatus : ''), | ||
[status, setStatus] | ||
); | ||
|
||
return ( | ||
<div className="flex w-full overflow-hidden rounded-box tabs"> | ||
{STATUS_BUTTONS.map((name) => ( | ||
<a | ||
key={name} | ||
className={cx( | ||
'tab h-16 transition-colors duration-200 flex-1', | ||
JOB_COLORS[name], | ||
{ | ||
'bg-opacity-25': status && status !== name, | ||
'tab-active bg-opacity-100': status === name, | ||
} | ||
)} | ||
onClick={handleStatusSelect(name)} | ||
> | ||
<div className="flex flex-col text-primary-content"> | ||
<span className="text-3xl font-bold"> | ||
{abbreviateNumber( | ||
data && data.data.length ? data.data[0][name] : 0 | ||
)} | ||
</span> | ||
<span className="text-sm">{name}</span> | ||
</div> | ||
</a> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Overview; |