-
Notifications
You must be signed in to change notification settings - Fork 12
/
ConceptHomeMappingsTableRows.jsx
96 lines (89 loc) · 3.54 KB
/
ConceptHomeMappingsTableRows.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
import React from 'react';
import {
TableRow, TableCell, Chip, Tooltip
} from '@mui/material';
import { map, get } from 'lodash';
import ExistsInOCLIcon from '../common/ExistsInOCLIcon';
import DoesnotExistsInOCLIcon from '../common/DoesnotExistsInOCLIcon';
import MappingOptions from './MappingOptions';
const ConceptHomeMappingsTableRows = ({ mapType, mappings, isIndirect }) => {
const conceptCodeAttr = isIndirect ? 'from_concept_code' : 'to_concept_code';
const conceptCodeName = isIndirect ? 'from_concept_name' : 'to_concept_name';
const sourceAttr = isIndirect ? 'from_source_name' : 'to_source_name';
const onDefaultClick = (event, targetURL) => {
event.stopPropagation()
event.preventDefault()
if(targetURL)
window.location.hash = targetURL
}
const getConceptName = (mapping, attr) => {
let name = get(mapping, attr) || get(mapping, `${attr}_resolved`);
if(name) return name;
return get(mapping, `${attr.split('_name')[0]}.display_name`)
}
const count = get(mappings, 'length') || 0
return (
<React.Fragment>
{
mapType &&
<TableRow hover>
<TableCell align='left' rowSpan={count + 1} style={{paddingRight: '5px', verticalAlign: 'top', paddingTop: '7px'}}>
<Tooltip title={isIndirect ? 'Inverse Mappings' : 'Direct Mappings'}>
<Chip
size='small'
variant='outlined'
color='default'
label={
isIndirect ?
<span><span>{mapType}</span><sup>-1</sup></span>:
mapType
}
style={{border: 'none'}}
/>
</Tooltip>
</TableCell>
</TableRow>
}
{
map(mappings, mapping => {
const targetURL = isIndirect ? get(mapping, 'from_concept_url') : get(mapping, 'to_concept_url');
let title;
if(targetURL)
title = isIndirect ? 'Source concept is defined in OCL' : 'Target concept is defined in OCL'
else
title = isIndirect ? 'Source concept is not defined in OCL' : 'Target concept is not defined in OCL'
const cursor = targetURL ? 'pointer' : 'not-allowed'
return (
<TableRow
hover key={mapping.uuid} onClick={event => onDefaultClick(event, targetURL)} style={{cursor: cursor}} className={targetURL ? 'underline-text' : ''}>
<TableCell align='left' className='ellipsis-text' style={{maxWidth: '200px'}}>
<span className='flex-vertical-center' style={{paddingTop: '7px'}}>
<span className='flex-vertical-center' style={{marginRight: '4px'}}>
{
targetURL ?
<ExistsInOCLIcon title={title} /> :
<DoesnotExistsInOCLIcon title={title} />
}
</span>
<span>
{ mapping[conceptCodeAttr] }
</span>
</span>
</TableCell>
<TableCell align='left'>
{ getConceptName(mapping, conceptCodeName) }
</TableCell>
<TableCell align='left'>
{get(mapping, sourceAttr)}
</TableCell>
<TableCell align='right' style={{width: '24px', paddingRight: '5px'}}>
<MappingOptions mapping={mapping} />
</TableCell>
</TableRow>
)
})
}
</React.Fragment>
)
}
export default ConceptHomeMappingsTableRows;