Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
fix(scans-count): completed scans count
Browse files Browse the repository at this point in the history
  • Loading branch information
adamtagscherer committed Nov 3, 2023
1 parent 977379e commit 37354d8
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions ui/src/layout/Dashboard/CounterDisplay/index.js
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;

0 comments on commit 37354d8

Please sign in to comment.