-
Notifications
You must be signed in to change notification settings - Fork 12
/
ResourcesHorizontal.jsx
65 lines (61 loc) · 2.96 KB
/
ResourcesHorizontal.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import React from 'react';
import { CircularProgress, Card, CardHeader, Avatar } from '@mui/material';
import {
LocalOffer as LocalOfferIcon, Link as LinkIcon, List as ListIcon,
Loyalty as LoyaltyIcon, Home as HomeIcon, Person as PersonIcon,
} from '@mui/icons-material'
import { map, get } from 'lodash';
import { BLUE, WHITE, GREEN, ORANGE } from '../../common/constants';
const RESOURCES = [
{id: 'concepts', label: 'Concepts', icon: <LocalOfferIcon fontSize='small' style={{color: BLUE}} />, bgColor: BLUE},
{id: 'mappings', label: 'Mappings', icon: <LinkIcon fontSize='small' style={{color: BLUE}} />, bgColor: BLUE},
{id: 'sources', label: 'Sources', icon: <ListIcon fontSize='small' style={{color: GREEN}} />, bgColor: GREEN},
{id: 'collections', label: 'Collections', icon: <LoyaltyIcon fontSize='small' style={{color: GREEN}} />, bgColor: GREEN},
{id: 'organizations', label: 'Organizations', icon: <HomeIcon fontSize='small' style={{color: ORANGE}} />, bgColor: ORANGE},
{id: 'users', label: 'Users', icon: <PersonIcon fontSize='small' style={{color: ORANGE}}/>, bgColor: ORANGE},
]
const ResourcesHorizontal = props => {
const { active, results } = props;
const onClick = resource => {
if(active !== resource)
props.onClick(resource)
}
return (
<span className='col-sm-12 no-side-padding flex-vertical-center'>
{
map(RESOURCES, (resource, i) => {
const isActive = active === resource.id;
const count = <span style={isActive ? {color: WHITE} : {}}>
{get(results, `${resource.id}.total`, 0).toLocaleString()}
</span>;
const isLoading = results[resource.id].isLoadingCount
const resourceColor = resource.bgColor;
const inProgress = <CircularProgress
style={{width: '14px', height: '14px', color: isActive ? WHITE : resourceColor}}
/>;
let containerClasses = 'col-sm-2 ';
if(i === 0)
containerClasses += 'no-left-padding';
if(i === RESOURCES.length - 1)
containerClasses += 'no-right-padding';
return (
<div className={containerClasses} style={{padding: '0 5px'}} key={i}>
<Card className='col-sm-12 no-side-padding clickable' key={i} style={isActive ? {backgroundColor: resource.bgColor, color: WHITE} : {}} onClick={() => onClick(resource.id)}>
<CardHeader
avatar={
<Avatar aria-label="resource" style={isActive ? {backgroundColor: WHITE} : {border: `1px solid ${resourceColor}`, background: WHITE}}>
{resource.icon}
</Avatar>
}
title={<span style={isActive ? {fontSize: '16px', fontWeight: 'bold'} : {}}>{resource.label}</span>}
subheader={isLoading ? inProgress : count}
/>
</Card>
</div>
)
})
}
</span>
)
}
export default ResourcesHorizontal;