This repository has been archived by the owner on Oct 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(scans-count): completed scans count
- Loading branch information
1 parent
977379e
commit 37354d8
Showing
1 changed file
with
18 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,31 @@ | ||
import React from 'react'; | ||
import React, {useMemo} from 'react'; | ||
import { useFetch } from 'hooks'; | ||
import { formatNumber } from 'utils/utils'; | ||
|
||
import './counter-display.scss'; | ||
|
||
const CounterDisplay = ({url, title, background}) => { | ||
const [{data, error, loading}] = useFetch(url, {queryParams: {"$count": true, "$top": 1, "$select": "id"}}); | ||
|
||
const [{data, error, loading}] = useFetch(url, {queryParams: {"$select": "state"}}); | ||
|
||
const completedScans = useMemo(() => { | ||
let ret = 0; | ||
|
||
data?.items.forEach((element) => { | ||
if (element.state === "Aborted" || element.state === "Failed" || element.state === "Done") { | ||
ret++ | ||
} | ||
}) | ||
|
||
return ret | ||
}, [data]) | ||
|
||
return ( | ||
<div className="dashboard-counter" style={{background}}> | ||
{loading || error ? "" : | ||
<div className="dashboard-counter-content"><div className="dashboard-counter-count">{formatNumber(data.count)}</div>{` ${title}`}</div> | ||
{loading || error ? "" : | ||
<div className="dashboard-counter-content"><div className="dashboard-counter-count">{formatNumber(completedScans)}</div>{` ${title}`}</div> | ||
} | ||
</div> | ||
) | ||
} | ||
|
||
export default CounterDisplay; | ||
export default CounterDisplay; |