-
Notifications
You must be signed in to change notification settings - Fork 13
/
ConceptHomeMappingsTableRows.jsx
151 lines (139 loc) · 5.64 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import React from 'react';
import {
TableRow, TableCell, Chip, Tooltip
} from '@mui/material';
import { map, get, forEach, orderBy } from 'lodash';
import ExistsInOCLIcon from '../common/ExistsInOCLIcon';
import DoesnotExistsInOCLIcon from '../common/DoesnotExistsInOCLIcon';
import MappingOptions from './MappingOptions';
import { getSiteTitle, toParentURI } from '../../common/utils';
import MappingInlineForm from './MappingInlineForm';
const SITE_TITLE = getSiteTitle()
const ConceptHomeMappingsTableRows = ({ concept, mappings, mapType, isIndirect, isSelf, onCreateNewMapping, suggested, onRemoveMapping, onReactivateMapping }) => {
const [form, setForm] = React.useState(false)
const [addNewMapType, setAddNewMapType] = React.useState('')
const conceptCodeAttr = 'cascade_target_concept_code'
const conceptCodeName = 'cascade_target_concept_name'
const sourceAttr = 'cascade_target_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
const getOrderedMappings = () => {
const parentURL = toParentURI(concept.url || concept.version_url)
const sameParentMappings = []
const differentParentMappings = []
forEach(mappings, mapping => {
if(mapping.cascade_target_concept_url && toParentURI(mapping.cascade_target_concept_url) === parentURL)
sameParentMappings.push(mapping)
else
differentParentMappings.push(mapping)
})
return [...orderBy(sameParentMappings, 'cascade_target_concept_name'), ...orderBy(differentParentMappings, ['cascade_target_source_name', 'cascade_target_concept_name'])]
}
const onAddNewClick = mapType => {
setAddNewMapType(mapType)
setForm(true)
return false
}
const onRemoveClick = mapping => onRemoveMapping(mapping, !isIndirect)
const onReactivateClick = mapping => onReactivateMapping(mapping, !isIndirect)
const rowSpanCount = count + 1 + (form ? 1 : 0)
return (
<React.Fragment>
{
mapType &&
<TableRow hover>
<TableCell align='left' rowSpan={rowSpanCount} style={{paddingRight: '5px', verticalAlign: 'top', paddingTop: '7px'}}>
<Tooltip placement='left' title={isIndirect ? 'Inverse Mappings' : (isSelf ? 'Self Mapping' : 'Direct Mappings')}>
<Chip
size='small'
variant='outlined'
color='default'
label={
<span>
<span>{mapType}</span>
{isIndirect && <sup>-1</sup>}
{isSelf && <sup>∞</sup>}
</span>
}
style={{border: 'none'}}
/>
</Tooltip>
</TableCell>
</TableRow>
}
{
map(getOrderedMappings(), mapping => {
const targetURL = get(mapping, 'cascade_target_concept_url')
let title;
if(targetURL)
title = isIndirect ? `Source concept is defined in ${SITE_TITLE}` : `Target concept is defined in ${SITE_TITLE}`
else
title = isIndirect ? `Source concept is not defined in ${SITE_TITLE}` : `Target concept is not defined in ${SITE_TITLE}`
const cursor = targetURL ? 'pointer' : 'not-allowed'
return (
<TableRow
hover key={mapping.url} 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 className={mapping.retired ? 'retired' : ''}>
{ 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}
concept={concept}
onAddNewClick={onAddNewClick}
onRemove={onRemoveClick}
onReactivate={onReactivateClick}
showNewMappingOption={Boolean(onCreateNewMapping)}
isIndirect={isIndirect}
/>
</TableCell>
</TableRow>
)
})
}
{
form &&
<TableRow>
<TableCell colSpan={4}>
<MappingInlineForm
defaultMapType={addNewMapType}
concept={concept}
onClose={() => setForm(false)}
isDirect={!isIndirect}
onSubmit={onCreateNewMapping}
suggested={suggested}
/>
</TableCell>
</TableRow>
}
</React.Fragment>
)
}
export default ConceptHomeMappingsTableRows;