|
| 1 | +import React, {useState} from 'react'; |
| 2 | +import { fetchWithCreds } from '../actions'; |
| 3 | +import { auditAPIPath } from '../localconf'; |
| 4 | + |
| 5 | +export const getAuditData = async (url) => { |
| 6 | + const urlPath = `${auditAPIPath}log/${url}`; |
| 7 | + const { data } = await fetchWithCreds({ path: urlPath, method: 'GET' }); |
| 8 | + return data; |
| 9 | +}; |
| 10 | + |
| 11 | +const UserMetricDashboard = () => { |
| 12 | + const [totalLogins, setTotalLogins] = useState(-1); |
| 13 | + const [uchicagoLogins, setUchicagoLogins] = useState(-1); |
| 14 | + const [vaLogins, setVaLogins] = useState(-1); |
| 15 | + const [totalDownloads, setTotalDownloads] = useState(-1); |
| 16 | + |
| 17 | + const epochTimeThirtyDaysAgo = Math.round((Date.now() - (180 * 24 * 60 * 60 * 1000))/1000) |
| 18 | + |
| 19 | + getAuditData('login?start=' + epochTimeThirtyDaysAgo + '&count').then((count) => {console.log('setting total login', count); setTotalLogins(count.data);}); |
| 20 | + getAuditData('login?start=' + epochTimeThirtyDaysAgo + '&count&fence_idp=shibboleth').then((count) => {console.log('setting total login', count); setUchicagoLogins(count.data);});; |
| 21 | + getAuditData('login?start=' + epochTimeThirtyDaysAgo + '&count&idp=cognito').then((count) => {console.log('setting total login', count); setVaLogins(count.data);});; |
| 22 | + getAuditData('presigned_url?start=' + epochTimeThirtyDaysAgo + '&count').then((count) => {console.log('setting total login', count); setTotalDownloads(count.data);});; |
| 23 | + |
| 24 | + return ( |
| 25 | + <div className='dashboard'> |
| 26 | + <h1>Metrics</h1> |
| 27 | + <h3>Total Login: {totalLogins}</h3> |
| 28 | + <h3>Uchicago Login: {uchicagoLogins}</h3> |
| 29 | + <h3>VA Login: {vaLogins}</h3> |
| 30 | + <h3>Downloads: {totalDownloads}</h3> |
| 31 | + </div> |
| 32 | + ); |
| 33 | + |
| 34 | +} |
| 35 | + |
| 36 | +UserMetricDashboard.propTypes = { |
| 37 | +}; |
| 38 | + |
| 39 | +UserMetricDashboard.defaultProps = { |
| 40 | +}; |
| 41 | + |
| 42 | +export default UserMetricDashboard; |
0 commit comments