|
| 1 | +import React from 'react' |
| 2 | +import moment from 'moment' |
| 3 | +import Skeleton from '@mui/material/Skeleton'; |
| 4 | +import Timeline from '@mui/lab/Timeline'; |
| 5 | +import TimelineItem, { timelineItemClasses } from '@mui/lab/TimelineItem'; |
| 6 | +import TimelineSeparator from '@mui/lab/TimelineSeparator'; |
| 7 | +import TimelineConnector from '@mui/lab/TimelineConnector'; |
| 8 | +import TimelineContent from '@mui/lab/TimelineContent'; |
| 9 | +import TimelineDot from '@mui/lab/TimelineDot'; |
| 10 | +import Card from '@mui/material/Card'; |
| 11 | +import CardContent from '@mui/material/CardContent'; |
| 12 | +import Typography from '@mui/material/Typography'; |
| 13 | +import IconButton from '@mui/material/IconButton'; |
| 14 | +import Button from '@mui/material/Button'; |
| 15 | +import Tooltip from '@mui/material/Tooltip'; |
| 16 | +import CopyIcon from '@mui/icons-material/ContentCopy'; |
| 17 | + |
| 18 | +import compact from 'lodash/compact' |
| 19 | +import map from 'lodash/map' |
| 20 | + |
| 21 | +const History = ({ versions, loading, icon, resource }) => { |
| 22 | + const getRepoDetails = uri => { |
| 23 | + const parts = compact(uri.split('/')) |
| 24 | + return { |
| 25 | + ownerType: parts[0], |
| 26 | + owner: parts[1], |
| 27 | + id: parts[3], |
| 28 | + version: parts[4], |
| 29 | + uri: uri |
| 30 | + } |
| 31 | + } |
| 32 | + return ( |
| 33 | + <Timeline |
| 34 | + sx={{ |
| 35 | + [`& .${timelineItemClasses.root}:before`]: { |
| 36 | + flex: 0, |
| 37 | + padding: 0, |
| 38 | + }, |
| 39 | + }} |
| 40 | + > |
| 41 | + { |
| 42 | + loading ? |
| 43 | + <> |
| 44 | + <TimelineItem> |
| 45 | + <TimelineSeparator> |
| 46 | + <TimelineDot sx={{border: 0, padding: 0, background: 'none', boxShadow: 'none'}}> |
| 47 | + <Skeleton variant="circular" width={20} height={20} /> |
| 48 | + </TimelineDot> |
| 49 | + <TimelineConnector /> |
| 50 | + </TimelineSeparator> |
| 51 | + <TimelineContent> |
| 52 | + <Skeleton variant='text' sx={{marginTop: '-20px', height: '100px'}} /> |
| 53 | + </TimelineContent> |
| 54 | + </TimelineItem> |
| 55 | + <TimelineItem> |
| 56 | + <TimelineSeparator> |
| 57 | + <TimelineDot sx={{border: 0, padding: 0, background: 'none', boxShadow: 'none'}}> |
| 58 | + <Skeleton variant="circular" width={20} height={20} /> |
| 59 | + </TimelineDot> |
| 60 | + <TimelineConnector /> |
| 61 | + </TimelineSeparator> |
| 62 | + <TimelineContent> |
| 63 | + <Skeleton variant='text' sx={{marginTop: '-20px', height: '100px'}} /> |
| 64 | + </TimelineContent> |
| 65 | + </TimelineItem> |
| 66 | + <TimelineItem> |
| 67 | + <TimelineSeparator> |
| 68 | + <TimelineDot sx={{border: 0, padding: 0, background: 'none', boxShadow: 'none'}}> |
| 69 | + <Skeleton variant="circular" width={20} height={20} /> |
| 70 | + </TimelineDot> |
| 71 | + </TimelineSeparator> |
| 72 | + <TimelineContent> |
| 73 | + <Skeleton variant='text' sx={{marginTop: '-20px', height: '100px'}} /> |
| 74 | + </TimelineContent> |
| 75 | + </TimelineItem> |
| 76 | + </> : |
| 77 | + <> |
| 78 | + { |
| 79 | + map(versions, (version, index) => { |
| 80 | + const primaryRepo = getRepoDetails(version.url) |
| 81 | + const url = version.source_versions?.length > 0 ? version.source_versions[0] + resource + '/' + version.id + '/' : `${version.owner_url}sources/${primaryRepo.id}/HEAD/concepts/${version.id}/` |
| 82 | + return ( |
| 83 | + <TimelineItem key={version.version_url}> |
| 84 | + <TimelineSeparator> |
| 85 | + <TimelineDot variant='outlined' color='primary' sx={{cursor: 'pointer', padding: 0, border: 0}}> |
| 86 | + <Button variant='text' color='primary' href={`#${url}`} sx={{margin: 0, padding: 0, fontSize: '12px', textTransform: 'none', minWidth: 'auto'}}> |
| 87 | + {icon} |
| 88 | + </Button> |
| 89 | + </TimelineDot> |
| 90 | + { |
| 91 | + index !== (versions.length - 1) && |
| 92 | + <TimelineConnector /> |
| 93 | + } |
| 94 | + </TimelineSeparator> |
| 95 | + <TimelineContent> |
| 96 | + <Card variant="outlined"> |
| 97 | + <CardContent sx={{padding: '4px 12px !important'}}> |
| 98 | + <div className='col-xs-12 padding-0' style={{display: 'flex'}}> |
| 99 | + <div className='col-xs-8 padding-left-0'> |
| 100 | + <Button variant='text' color='primary' href={`#${version.version_url}`} sx={{margin: 0, padding: 0, fontSize: '12px', textTransform: 'none', minWidth: 'auto'}}> |
| 101 | + <Typography sx={{fontSize: '16px'}} component="div"> |
| 102 | + { |
| 103 | + version.update_comment ? |
| 104 | + version.update_comment : |
| 105 | + <i>-</i> |
| 106 | + } |
| 107 | + </Typography> |
| 108 | + </Button> |
| 109 | + <Typography sx={{ fontSize: '12px' }} color="text.secondary"> |
| 110 | + <Button variant='text' href={`#/users/${version.version_updated_by}`} sx={{margin: 0, padding: 0, fontSize: '12px', textTransform: 'none', minWidth: 'auto'}}>{version.version_updated_by}</Button> updated {moment(version.version_updated_on).fromNow()} |
| 111 | + </Typography> |
| 112 | + { |
| 113 | + version.source_versions?.length > 0 ? |
| 114 | + <div className='col-xs-12 padding-0'> |
| 115 | + <Typography sx={{ fontSize: '12px' }} color="text.secondary" component='span'> |
| 116 | + Source Versions: |
| 117 | + </Typography> |
| 118 | + { |
| 119 | + map(version.source_versions, repoVersion => { |
| 120 | + const repo = getRepoDetails(repoVersion) |
| 121 | + return ( |
| 122 | + <Button key={repoVersion} variant='text' href={`#${repoVersion}`} sx={{margin: '0 4px', padding: 0, fontSize: '12px', textTransform: 'none', minWidth: 'auto'}}>{repo.id}/{repo.version}</Button> |
| 123 | + ) |
| 124 | + }) |
| 125 | + } |
| 126 | + </div> : null |
| 127 | + } |
| 128 | + { |
| 129 | + version.collection_versions?.length > 0 ? |
| 130 | + <div className='col-xs-12 padding-0'> |
| 131 | + <Typography sx={{ fontSize: '12px' }} color="text.secondary" component='span'> |
| 132 | + Collection Versions: |
| 133 | + </Typography> |
| 134 | + { |
| 135 | + map(version.collection_versions, repoVersion => { |
| 136 | + const repo = getRepoDetails(repoVersion) |
| 137 | + return ( |
| 138 | + <Button key={repoVersion} variant='text' href={`#${repoVersion}`} sx={{margin: '0 4px', padding: 0, fontSize: '12px', textTransform: 'none', minWidth: 'auto'}}>{repo.id}/{repo.version}</Button> |
| 139 | + ) |
| 140 | + }) |
| 141 | + } |
| 142 | + </div> : null |
| 143 | + } |
| 144 | + </div> |
| 145 | + <div className='col-xs-4 padding-0' style={{textAlign: 'right', display: 'flex', alignItems: 'center', justifyContent: 'center', flexDirection: 'column'}}> |
| 146 | + <div className='col-xs-12 padding-0' style={{display: 'flex', alignItems: 'center', justifyContent: 'flex-end'}}> |
| 147 | + <Tooltip title='Standard Checksum' placement='left'> |
| 148 | + <Typography sx={{ fontSize: '12px' }} color="text.secondary"> |
| 149 | + {version.checksums?.standard?.slice(0, 8)} |
| 150 | + </Typography> |
| 151 | + </Tooltip> |
| 152 | + <IconButton size='small'><CopyIcon sx={{fontSize: '16px'}} /></IconButton> |
| 153 | + </div> |
| 154 | + <div className='col-xs-12 padding-0' style={{display: 'flex', alignItems: 'center', justifyContent: 'flex-end'}}> |
| 155 | + <Tooltip title='Smart Checksum' placement='left'> |
| 156 | + <Typography sx={{ fontSize: '12px' }} color="text.secondary"> |
| 157 | + {version.checksums?.smart?.slice(0, 8)} |
| 158 | + </Typography> |
| 159 | + </Tooltip> |
| 160 | + <IconButton size='small'><CopyIcon sx={{fontSize: '16px'}} /></IconButton> |
| 161 | + </div> |
| 162 | + </div> |
| 163 | + </div> |
| 164 | + </CardContent> |
| 165 | + </Card> |
| 166 | + </TimelineContent> |
| 167 | + </TimelineItem> |
| 168 | + ) |
| 169 | + }) |
| 170 | + } |
| 171 | + </> |
| 172 | + } |
| 173 | + </Timeline> |
| 174 | + ) |
| 175 | +} |
| 176 | + |
| 177 | +export default History |
0 commit comments