Skip to content

Commit c1f0866

Browse files
committed
OpenConceptLab/ocl_issues#2290 | using standard chips
1 parent 1ba02ff commit c1f0866

2 files changed

Lines changed: 34 additions & 18 deletions

File tree

src/components/common/BaseEntityChip.jsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const Avatar = ({ entity, icon }) => {
108108
</MuiAvatar>
109109
}
110110

111-
const Label = ({ entity, hideType }) => {
111+
const Label = ({ entity, hideType, hideRepoVersion }) => {
112112
return (
113113
<span style={{display: 'flex', alignItems: 'center'}} className='entity-label'>
114114
<span className='entity-id'>
@@ -120,6 +120,16 @@ const Label = ({ entity, hideType }) => {
120120
{entity.display_name}
121121
</span>
122122
}
123+
{
124+
['Source Version', 'Collection Version'].includes(entity?.type) && entity.version && !hideRepoVersion &&
125+
<React.Fragment>
126+
<span className='divider-span' />
127+
<span className='entity-type'>
128+
{entity.version}
129+
</span>
130+
</React.Fragment>
131+
132+
}
123133
{
124134
!hideType &&
125135
<React.Fragment>
@@ -134,13 +144,13 @@ const Label = ({ entity, hideType }) => {
134144
}
135145

136146

137-
const BaseEntityChip = ({ entity, icon, hideType, primary, size, sx, noLink, ...rest }) => {
147+
const BaseEntityChip = ({ entity, icon, hideType, hideRepoVersion, primary, size, sx, noLink, ...rest }) => {
138148
const sizeStyle = ENTITY_CHIP_SIZE_MAP[size || 'medium'] || ENTITY_CHIP_SIZE_MAP.medium
139149
const baseStyle = primary ? PRIMARY_STYLE : SECONDARY_STYLE
140150
return (
141151
<Chip
142152
avatar={<Avatar entity={entity} icon={icon} />}
143-
label={<Label entity={entity} hideType={hideType} />}
153+
label={<Label entity={entity} hideType={hideType} hideRepoVersion={hideRepoVersion} />}
144154
variant='outlined'
145155
sx={{
146156
borderRadius: '4px',

src/components/concepts/History.jsx

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react'
2+
import { useHistory } from 'react-router-dom';
23
import moment from 'moment'
34
import Skeleton from '@mui/material/Skeleton';
45
import Timeline from '@mui/lab/Timeline';
@@ -19,16 +20,21 @@ import compact from 'lodash/compact'
1920
import map from 'lodash/map'
2021

2122
import { copyURL } from '../../common/utils';
23+
import UserChip from '../users/UserChip'
24+
import RepoChip from '../repos/RepoChip'
2225

2326
const History = ({ versions, loading, icon, resource }) => {
27+
const history = useHistory()
2428
const getRepoDetails = uri => {
2529
const parts = compact(uri.split('/'))
2630
return {
2731
ownerType: parts[0],
2832
owner: parts[1],
33+
type: parts[2] === 'sources' ? 'Source Version' : (parts[2] === 'collections' ? 'Collection Version' : parts[2]),
2934
id: parts[3],
3035
version: parts[4],
31-
uri: uri
36+
uri: uri,
37+
version_url: uri
3238
}
3339
}
3440
return (
@@ -95,21 +101,21 @@ const History = ({ versions, loading, icon, resource }) => {
95101
}
96102
</TimelineSeparator>
97103
<TimelineContent>
98-
<Card variant="outlined">
104+
<Card variant="outlined" sx={{cursor: 'pointer'}} onClick={event => {event.preventDefault(); event.stopPropagation(); history.push(url); return false;}}>
99105
<CardContent sx={{padding: '4px 12px !important'}}>
100106
<div className='col-xs-12 padding-0' style={{display: 'flex'}}>
101107
<div className='col-xs-8 padding-left-0'>
102-
<Button variant='text' color='primary' href={`#${version.version_url}`} sx={{margin: 0, padding: 0, fontSize: '12px', textTransform: 'none', minWidth: 'auto'}}>
103-
<Typography sx={{fontSize: '16px'}} component="div">
104-
{
105-
version.update_comment ?
106-
version.update_comment :
107-
<i>-</i>
108-
}
109-
</Typography>
110-
</Button>
111-
<Typography sx={{ fontSize: '12px' }} color="text.secondary">
112-
<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()}
108+
{
109+
version.update_comment &&
110+
<Button variant='text' color='primary' href={`#${version.version_url}`} sx={{margin: 0, padding: 0, fontSize: '12px', textTransform: 'none', minWidth: 'auto'}}>
111+
<Typography sx={{fontSize: '16px'}} component="div">
112+
{version.update_comment}
113+
</Typography>
114+
</Button>
115+
}
116+
<Typography sx={{ fontSize: '12px', display: 'inline-flex', alignItems: 'center' }} color="text.secondary" component='span'>
117+
<UserChip size='small' hideType user={{username: version.version_updated_by, type: 'User', url: `/users/${version.version_updated_by}`}} sx={{'.MuiChip-label': {padding: 0}, marginRight: '4px', border: 0, padding: 0, minWidth: 'auto', '.MuiAvatar-root': {margin: '0 4px 0 0', width: '16px', height: '16px', background: 'transparent'}}} />
118+
updated {moment(version.version_updated_on).fromNow()}
113119
</Typography>
114120
{
115121
version.source_versions?.length > 0 ?
@@ -121,7 +127,7 @@ const History = ({ versions, loading, icon, resource }) => {
121127
map(version.source_versions, repoVersion => {
122128
const repo = getRepoDetails(repoVersion)
123129
return (
124-
<Button key={repoVersion} variant='text' href={`#${repoVersion}`} sx={{margin: '0 4px', padding: 0, fontSize: '12px', textTransform: 'none', minWidth: 'auto'}}>{repo.id}/{repo.version}</Button>
130+
<RepoChip hideType key={repoVersion} repo={repo} size='small' sx={{padding: '4px', '.MuiChip-label': {padding: '0 2px 0 0'}, margin: '2px 0'}} />
125131
)
126132
})
127133
}
@@ -137,7 +143,7 @@ const History = ({ versions, loading, icon, resource }) => {
137143
map(version.collection_versions, repoVersion => {
138144
const repo = getRepoDetails(repoVersion)
139145
return (
140-
<Button key={repoVersion} variant='text' href={`#${repoVersion}`} sx={{margin: '0 4px', padding: 0, fontSize: '12px', textTransform: 'none', minWidth: 'auto'}}>{repo.id}/{repo.version}</Button>
146+
<RepoChip hideType key={repoVersion} repo={repo} size='small' sx={{padding: '4px', '.MuiChip-label': {padding: '0 2px 0 0'}, margin: '2px 0'}} />
141147
)
142148
})
143149
}

0 commit comments

Comments
 (0)