-
Notifications
You must be signed in to change notification settings - Fork 12
/
Concept.jsx
71 lines (65 loc) · 2.52 KB
/
Concept.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
import React from 'react';
import { LocalOffer as LocalOfferIcon } from '@mui/icons-material'
import { merge, get, isArray, reject, keys, isEmpty, includes, map } from 'lodash'
import { DARKGRAY } from '../../common/constants';
import ResourceLabel from '../common/ResourceLabel';
import LastUpdatedOnLabel from '../common/LastUpdatedOnLabel';
const DEFAULT_FIELDS = [{concept_class: 'Class'}, {datatype: 'Datatype'}]
const LABEL_FIELDS = ['id', 'display_name', 'name', 'owner', 'source']
const Concept = props => {
const { viewFields, history, currentLayoutURL, url, hideAttributes, version_url, is_latest_version } = props;
const customFields = isArray(viewFields) ? reject(viewFields, fieldConfig => includes(LABEL_FIELDS, keys(fieldConfig)[0])) : [];
const fields = isEmpty(customFields) ? DEFAULT_FIELDS : customFields;
const getNavigationURL = () => {
if(window.location.hash.includes('/collections/') || !is_latest_version)
return version_url || url
return url
}
const navigateTo = () => {
if(currentLayoutURL)
history.replace(currentLayoutURL)
history.push(getNavigationURL())
}
const getValue = attr => {
const value = get(props, attr, '')
if(isArray(value))
return value.join(', ')
return value
}
return (
<div className='col-sm-12' style={merge({paddingTop: '10px', paddingLeft: 0, paddingRight: 0}, get(props, 'style', {}))}>
<span onClick={navigateTo} style={{cursor: 'pointer'}}>
<ResourceLabel
id={props.display_name} name={props.id} noSeparator
icon={<LocalOfferIcon fontSize='small' style={{width: '10pt', color: DARKGRAY}}/>}
/>
</span>
{
!hideAttributes &&
<React.Fragment>
<div className='col-sm-11 no-side-padding resource-attributes'>
{
map(fields, (field, i) => {
const attr = keys(field)[0]
const label = field[attr];
return (
<React.Fragment key={attr}>
<span className='resource-attr'>
{label}:
</span>
<span className='resource-value' style={{marginRight: '0px'}}>
{getValue(attr)}
</span>
{i < fields.length - 1 && <span style={{marginRight: '5px'}}>, </span>}
</React.Fragment>
)
})
}
</div>
<LastUpdatedOnLabel date={props.version_created_on} />
</React.Fragment>
}
</div>
)
}
export default Concept;