-
Notifications
You must be signed in to change notification settings - Fork 12
/
ConceptTable.jsx
130 lines (123 loc) · 4.47 KB
/
ConceptTable.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
import React from 'react';
import { Table, TableHead, TableBody, TableRow, TableCell, IconButton, Tooltip, Badge, CircularProgress, Chip, Button } from '@mui/material';
import {
QueryStats as HierarchyIcon,
} from '@mui/icons-material'
import { map, get, find, isEmpty, includes } from 'lodash';
import ConceptDisplayName from './ConceptDisplayName';
import ConceptCascadeVisualizeDialog from './ConceptCascadeVisualizeDialog';
const ConceptStatus = ({ status, added, onVisualize }) => {
let color = 'success'
const isSuccess = status === 200
if(isSuccess && !added)
color = 'warning'
if(!isSuccess)
color = 'error'
return (
<Badge badgeContent={added} color={color} showZero style={{margin: '5px 0'}}>
{
(isSuccess && added) ?
<Tooltip title='Visualize (Beta)' placement='right'>
<IconButton size='small' color='primary' onClick={onVisualize}>
<HierarchyIcon fontSize='inherit'/>
</IconButton>
</Tooltip> :
<Chip size='small' label={status === 200 ? 'Success' : 'Failed'} variant='outlined' color={color}/>
}
</Badge>
)
}
const ConceptTable = ({ concepts, showProgress, showStatus, visualFilters, onPreviewClick }) => {
const [visualize, setVisualize] = React.useState(false);
const [isClonedConcept, setIsClonedConcept] = React.useState(false)
let headers = ["Owner", "ID", "Display Name", "Class", "DataType", ""]
if(showStatus)
headers = ["Status", ...headers]
const getClonedConcept = concept => {
const equivalencyMapTypes = (visualFilters?.equivalencyMapType || '').split(',')
if(isEmpty(equivalencyMapTypes))
return get(concept, 'bundle.entry.0')
const mapping = find(concept?.bundle?.entry, entry => includes(equivalencyMapTypes, entry?.map_type) && entry.to_concept_code === concept.id)
if(mapping)
return find(concept?.bundle?.entry, {type: 'Concept', id: mapping.from_concept_code})
}
const onVisualize = (concept, isClonedConcept) => {
setVisualize(concept)
setIsClonedConcept(Boolean(isClonedConcept))
}
return (
<React.Fragment>
<Table stickyHeader size='small'>
<TableHead>
<TableRow>
{
headers.map(header => (
<TableCell style={{backgroundColor: 'rgba(0, 0, 0, 0.09)'}} key={header}>
<b>{header}</b>
</TableCell>
))
}
</TableRow>
</TableHead>
<TableBody>
{
map(concepts, concept => (
<TableRow key={concept.id}>
{
showStatus &&
<TableCell>
{
showProgress &&
<CircularProgress />
}
{
!showProgress && concept.status &&
<ConceptStatus status={concept.status} added={concept.total} onVisualize={() => onVisualize(getClonedConcept(concept), true)}/>
}
</TableCell>
}
<TableCell>
{concept.owner}/{concept.source}
</TableCell>
<TableCell>
{concept.id}
</TableCell>
<TableCell>
<ConceptDisplayName concept={concept} />
</TableCell>
<TableCell>
{concept.concept_class}
</TableCell>
<TableCell>
{concept.datatype}
</TableCell>
<TableCell align='right'>
<Tooltip title='Visualize (Beta)' placement='right'>
<IconButton size='small' color='secondary' onClick={() => setVisualize(concept)}>
<HierarchyIcon fontSize='inherit'/>
</IconButton>
</Tooltip>
{
onPreviewClick &&
<Button style={{marginLeft: '5px', textTransform: 'none'}} component="a" size='small' variant='text' onClick={() => onPreviewClick(concept)}>Preview</Button>
}
</TableCell>
</TableRow>
))
}
</TableBody>
</Table>
{
visualize &&
<ConceptCascadeVisualizeDialog
open
onClose={() => setVisualize(false)}
concept={visualize}
filters={isClonedConcept ? false : visualFilters}
noBreadcrumbs={isClonedConcept}
/>
}
</React.Fragment>
)
}
export default ConceptTable