-
Notifications
You must be signed in to change notification settings - Fork 12
/
VersionList.jsx
200 lines (191 loc) · 9.6 KB
/
VersionList.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import React from 'react';
import {
Accordion, AccordionSummary, AccordionDetails, Divider, Tooltip,
IconButton, Button, Checkbox, Collapse
} from '@mui/material';
import { map, isEmpty, startCase, uniq, without, orderBy } from 'lodash';
import {
Search as SearchIcon, CompareArrows as CompareArrowsIcon,
InfoOutlined as InfoIcon, ExpandLess as UpIcon,
ExpandMore as DownIcon
} from '@mui/icons-material';
import { copyToClipboard } from '../../common/utils'
import LastUpdatedOnLabel from './LastUpdatedOnLabel';
import SourceChildVersionAssociationWithContainer from './SourceChildVersionAssociationWithContainer';
import RetiredChip from '../common/RetiredChip';
import TabCountLabel from '../common/TabCountLabel';
import BetaLabel from '../common/BetaLabel';
const ACCORDIAN_HEADING_STYLES = {
fontWeight: 'bold',
}
const ACCORDIAN_DETAILS_STYLES = {
overflowX: 'auto', display: 'inline-block', width: '100%', padding: '0'
}
const None = () => {
return <div style={{margin: '5px', fontWeight: '300'}}>None</div>
}
const _Checksum = ({ checksum }) => (
<span
style={{color: 'rgb(51, 115, 170)', marginLeft: '5px'}}
onClick={() => copyToClipboard(checksum, 'Copied to Clipboard!')}>
{checksum}
</span>
)
const Checksum = ({ title, label, checksum }) => checksum ? (
<Tooltip title={title} placement='left'>
<div>
<span>{label}:</span>
<_Checksum checksum={checksum} />
</div>
</Tooltip>
) : null;
const VersionList = ({ versions, resource }) => {
const sortedVersions = orderBy(versions, 'version_created_on', 'desc');
const [selectedList, setSelectedList] = React.useState([]);
const [expandChecksums, setExpandChecksums] = React.useState(false)
const onSelectChange = (event, id) => setSelectedList(
event.target.checked ? uniq([...selectedList, id]) : without(selectedList, id)
)
const isConcept = resource === 'concept';
const isMapping = resource === 'mapping';
const canSelect = (isConcept || isMapping) && sortedVersions.length > 1;
const gridClass = canSelect ? 'col-md-11' : 'col-md-12'
const showCompareOption = (isConcept || isMapping) && selectedList.length === 2;
const onCompareClick = event => {
event.stopPropagation()
event.preventDefault()
const url = `#/${resource}s/compare?lhs=${selectedList[0]}&rhs=${selectedList[1]}`
window.open(url, '_blank')
}
return (
<React.Fragment>
<Accordion expanded style={{borderRadius: 'unset'}}>
<AccordionSummary
className='light-gray-bg less-paded-accordion-header'
expandIcon={<span />}
aria-controls="panel1a-content"
style={{cursor: 'inherit'}}
>
<span className='flex-vertical-center' style={{width: '100%', justifyContent: 'space-between'}}>
<TabCountLabel style={ACCORDIAN_HEADING_STYLES} label={`${startCase(resource)} Version History`} count={!isEmpty(versions) && versions.length} />
<span className='flex-vertical-center' style={{marginLeft: '10px'}}>
{
showCompareOption &&
<Button
startIcon={<CompareArrowsIcon fontSize='inherit' />}
variant='text'
size='small'
color='primary'
style={{marginRight: '15px', textTransform: 'none'}}
onClick={onCompareClick}
>
Compare
</Button>
}
<Tooltip arrow title={`All changes to a ${resource} are automatically saved to its ${startCase(resource)} Version History`}>
<InfoIcon fontSize='small' color='action' />
</Tooltip>
</span>
</span>
</AccordionSummary>
<AccordionDetails style={ACCORDIAN_DETAILS_STYLES}>
{
isEmpty(sortedVersions) ?
None() :
map(sortedVersions, (version, index) => {
const isRetired = version.retired
return (
<React.Fragment key={index}>
<div className='col-md-12 flex-vertical-center' style={{padding: '0 3px'}}>
{
canSelect &&
<div className='col-md-1 no-side-padding'>
<Checkbox size='small' onChange={event => onSelectChange(event, version.version_url)} />
</div>
}
<div className={`${gridClass} no-side-padding flex-vertical-center`} style={{margin: '10px 0'}}>
<div className='col-md-11 no-side-padding flex-vertical-center'>
<div className={isRetired ? 'col-md-10 no-side-padding' : 'col-md-12 no-side-padding'}>
<div className='col-md-12 no-side-padding'>
{
Boolean(version.update_comment) &&
<span>{version.update_comment}</span>
}
</div>
<div className='col-md-12 no-side-padding' style={{marginTop: '5px'}}>
<LastUpdatedOnLabel
by={version.version_created_by}
date={version.version_created_on}
/>
</div>
{
version?.checksums &&
<div className='col-md-12 no-side-padding gray-italics-small' style={{marginTop: '-5px', marginBottom: '10px'}}>
<Tooltip title="Checksum of versions's metadata, locales, direct associations and source versions." placement='left'>
<div>
<BetaLabel label='Checksum' />:
<_Checksum checksum={version.checksums.all || version.checksums.meta} />
<span>
<IconButton size='small' color='primary' onClick={() => setExpandChecksums(!expandChecksums)}>
{expandChecksums ? <UpIcon fontSize='inherit' /> : <DownIcon fontSize='inherit' />}
</IconButton>
</span>
</div>
</Tooltip>
{
expandChecksums &&
<Collapse in={expandChecksums} style={{marginTop: '-5px', background: 'rgba(0, 0, 0, 0.1)', padding: '5px 5px 3px', borderRadius: '2px'}}>
<Checksum title="Checksum of versions's metadata." label='Metadata' checksum={version.checksums.meta} />
<Checksum title="Checksum of versions's names." label='Names' checksum={version.checksums.names} />
<Checksum title="Checksum of versions's descriptions." label='Descriptions' checksum={version.checksums.descriptions} />
<Checksum title="Checksum of versions's associations." label='Associations' checksum={version.checksums.mappings} />
<Checksum title="Checksum of versions's source versions." label='Source Versions' checksum={version.checksums.repo_versions} />
<Checksum title="Checksum of everything." label='All' checksum={version.checksums.all} />
</Collapse>
}
</div>
}
</div>
{
isRetired &&
<div className='col-md-2 no-right-padding'>
<RetiredChip size='small' />
</div>
}
</div>
<div className='col-md-1 no-right-padding' style={{paddingLeft: '5px'}}>
<Tooltip arrow title='Version Link'>
<IconButton href={`#${version.version_url}`} color='primary' size='small'>
<SearchIcon fontSize='inherit' />
</IconButton>
</Tooltip>
</div>
</div>
</div>
{
version && (!isEmpty(version.source_versions) || !isEmpty(version.collection_versions)) &&
<div className='col-md-11 no-side-padding' style={{textAlign: 'center', marginTop: '-15px'}}>
<SourceChildVersionAssociationWithContainer
associatedWith={{
source: version.source_versions,
collection: version.collection_versions
}}
resource={resource}
style={canSelect ? {marginLeft: '40px'} : {}}
/>
</div>
}
{
(index + 1) < versions.length &&
<Divider style={{width: '100%', display: 'inline-block'}} />
}
</React.Fragment>
)
})
}
</AccordionDetails>
</Accordion>
</React.Fragment>
);
}
export default VersionList;