-
Notifications
You must be signed in to change notification settings - Fork 12
/
ConceptCollections.jsx
140 lines (131 loc) · 6.3 KB
/
ConceptCollections.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import React from 'react';
import { Link } from 'react-router-dom'
import {
Accordion, AccordionSummary, AccordionDetails, CircularProgress, IconButton, Tooltip,
} from '@mui/material';
import {
Loyalty as LoyaltyIcon, Info as InfoIcon,
NewReleases as ReleaseIcon, Block as RetireIcon
} from '@mui/icons-material'
import { map, get, isEmpty, find, groupBy, orderBy, without, includes } from 'lodash';
import ResourceLabel from '../common/ResourceLabel';
import { DARKGRAY } from '../../common/constants';
import TabCountLabel from '../common/TabCountLabel';
const ACCORDIAN_HEADING_STYLES = {
fontWeight: 'bold',
}
const ACCORDIAN_DETAILS_STYLES = {
maxHeight: '300px', overflow: 'auto', display: 'inline-block', width: '100%', padding: '0'
}
const None = () => (<div style={{padding: '20px', fontWeight: '300'}}>None</div>);
const ConceptCollections = ({ concept, isLoadingCollections }) => {
const conceptCollections = get(concept, 'collections') || []
const count = isLoadingCollections ? null : conceptCollections.length
const getProminentCollectionVersion = collectionVersions => {
const orderedVersions = orderBy(collectionVersions, 'created_at', ['desc'])
const releasedVersion = find(orderedVersions, {released: true, retired: false})
if(releasedVersion)
return releasedVersion
const headVersion = find(orderedVersions, {version: 'HEAD'})
if(headVersion)
return headVersion
return orderedVersions[0]
}
const [expand, setExpand] = React.useState([]);
const toggleExpand = collectionURL => {
if(includes(expand, collectionURL))
setExpand(without(expand, collectionURL))
else
setExpand([...expand, collectionURL])
}
const ReleasedIndicator = (<Tooltip title='Released'><ReleaseIcon fontSize='small' color='primary' /></Tooltip>);
const RetiredIndicator = (<Tooltip title='Retired'><RetireIcon fontSize='small' className='retired-red' /></Tooltip>);
return (
<React.Fragment>
<Accordion defaultExpanded>
<AccordionSummary
className='light-gray-bg less-paded-accordian-header'
expandIcon={<span />}
aria-controls="panel1a-content"
>
<span className='flex-vertical-center' style={{width: '100%', justifyContent: 'space-between'}}>
<TabCountLabel style={ACCORDIAN_HEADING_STYLES} label='Collection Membership' count={count} />
<span className='flex-vertical-center' style={{marginLeft: '10px'}}>
<Tooltip title='Showing only collections owned by the same organization or user'>
<InfoIcon fontSize='small' color='action' />
</Tooltip>
</span>
</span>
</AccordionSummary>
<AccordionDetails style={ACCORDIAN_DETAILS_STYLES}>
{
isLoadingCollections ?
<div style={{textAlign: 'center', padding: '10px'}}>
<CircularProgress />
</div> : (
isEmpty(conceptCollections) ?
None() :
map(groupBy(conceptCollections, 'short_code'), (collections, short_code) => {
const prominentVersion = getProminentCollectionVersion(collections)
const moreCount = collections.length - 1
const isExpanded = includes(expand, prominentVersion.version_url)
return (
<React.Fragment key={prominentVersion.version_url}>
<div className='col-md-12 no-side-padding' style={{borderBottom: '1px solid lightgray'}}>
<div className='col-md-12 flex-vertical-center' style={{padding: '0 10px'}}>
<Link to={prominentVersion.version_url}>
<div style={{padding: '10px', display: 'inline-flex'}}>
<ResourceLabel
noSeparator
id={short_code}
name={`${prominentVersion.name} / ${prominentVersion.version}`}
icon={<LoyaltyIcon fontSize='small' style={{width: '10pt', color: DARKGRAY}}/>}
colorClass="collection-bg"
/>
</div>
</Link>
{prominentVersion.released && ReleasedIndicator}
{prominentVersion.retired && RetiredIndicator}
{
moreCount > 0 &&
<IconButton style={{marginLeft: '5px'}} size='small' color='primary' onClick={() => toggleExpand(prominentVersion.version_url)}>
<span style={{fontSize: '12px'}}>{`+${moreCount}`}</span>
</IconButton>
}
</div>
{
isExpanded &&
<div className='col-md-11' style={{marginLeft: '30px', marginBottom: '10px'}}>
{
map(without(collections, prominentVersion), collection => (
<React.Fragment key={collection.version_url}>
<Link to={collection.version_url}>
<div style={{padding: '0px 15px', display: 'inline-flex'}}>
<ResourceLabel
noSeparator
id={collection.short_code}
name={`${collection.name} / ${collection.version}`}
icon={<LoyaltyIcon fontSize='small' style={{width: '10pt', color: DARKGRAY}}/>}
colorClass="collection-bg"
/>
</div>
</Link>
{collection.released && ReleasedIndicator}
{collection.retired && RetiredIndicator}
</React.Fragment>
))
}
</div>
}
</div>
</React.Fragment>
)
})
)
}
</AccordionDetails>
</Accordion>
</React.Fragment>
)
}
export default ConceptCollections;