-
Notifications
You must be signed in to change notification settings - Fork 12
/
HomeMappings.jsx
124 lines (118 loc) · 4.74 KB
/
HomeMappings.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
import React from 'react';
import {
Accordion, AccordionSummary, AccordionDetails, CircularProgress,
Table, TableHead, TableRow, TableCell, TableBody, Tooltip
} from '@material-ui/core';
import {
Info as InfoIcon,
} from '@material-ui/icons'
import { get, isEmpty, forEach, map } from 'lodash';
import { BLUE, WHITE } from '../../common/constants'
import { generateRandomString } from '../../common/utils'
import ConceptHomeMappingsTableRows from '../mappings/ConceptHomeMappingsTableRows';
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 = () => {
return <div style={{padding: '20px', fontWeight: '300'}}>None</div>
}
const groupMappings = (concept, mappings) => {
const orderedMappings = {}
forEach(mappings, mapping => {
orderedMappings[mapping.map_type] = orderedMappings[mapping.map_type] || {order: null, direct: [], indirect: [], unknown: []}
const isDirect = mapping.from_concept_url === concept.url;
if(isDirect)
orderedMappings[mapping.map_type].direct.push(mapping)
else
orderedMappings[mapping.map_type].indirect.push(mapping)
})
return orderedMappings;
}
const HomeMappings = ({ concept, isLoadingMappings }) => {
const conceptMappings = get(concept, 'mappings') || [];
const count = isLoadingMappings ? null : conceptMappings.length;
const tbHeadCellStyles = {padding: '8px', color: WHITE}
const orderedMappings = groupMappings(concept, conceptMappings)
return (
<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 label='Associations' count={count} style={ACCORDIAN_HEADING_STYLES} />
<span className='flex-vertical-center' style={{marginLeft: '10px'}}>
<Tooltip title='Showing only associations in the same source'>
<InfoIcon fontSize='small' color='action' />
</Tooltip>
</span>
</span>
</AccordionSummary>
<AccordionDetails style={ACCORDIAN_DETAILS_STYLES}>
{
isLoadingMappings ?
<div style={{textAlign: 'center', padding: '10px'}}>
<CircularProgress />
</div> : (
isEmpty(conceptMappings) ?
None() :
<Table size="small" aria-label="concept-home-mappings" className='nested-mappings'>
<TableHead>
<TableRow style={{backgroundColor: BLUE, color: WHITE}}>
<TableCell align='left' style={tbHeadCellStyles}><b>Relationship</b></TableCell>
<TableCell align='left' style={tbHeadCellStyles}><b>Code</b></TableCell>
<TableCell align='left' style={tbHeadCellStyles}><b>Name</b></TableCell>
<TableCell align='left' style={tbHeadCellStyles}><b>Source</b></TableCell>
<TableCell align='right' />
</TableRow>
</TableHead>
<TableBody>
{
map(orderedMappings, (oMappings, mapType) => {
const key = generateRandomString()
const hasDirectMappings = !isEmpty(oMappings.direct)
return (
<React.Fragment key={key}>
{
hasDirectMappings &&
<ConceptHomeMappingsTableRows
mappings={oMappings.direct}
mapType={mapType}
/>
}
</React.Fragment>
)
})
}
{
map(orderedMappings, (oMappings, mapType) => {
const key = generateRandomString()
const hasInDirectMappings = !isEmpty(oMappings.indirect)
return (
<React.Fragment key={key}>
{
hasInDirectMappings &&
<ConceptHomeMappingsTableRows
mappings={oMappings.indirect}
mapType={mapType}
isIndirect
/>
}
</React.Fragment>
)
})
}
</TableBody>
</Table>
)
}
</AccordionDetails>
</Accordion>
)
}
export default HomeMappings;