-
Notifications
You must be signed in to change notification settings - Fork 12
/
AllMappingsTables.jsx
50 lines (47 loc) · 1.64 KB
/
AllMappingsTables.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
import React from 'react';
import { CircularProgress } from '@mui/material';
import { isEmpty } from 'lodash';
import NestedMappingsTable from './NestedMappingsTable';
import { getIndirectMappings, getDirectMappings } from '../../common/utils';
const AllMappingsTables = ({concept_url, mappings, isLoading}) => {
const getMappingsHeader = (mappings, isDirect) => {
const count = mappings.length;
return `${isDirect ? 'Direct' : 'Inverse'} Mappings (${count})`
}
const directMappings = getDirectMappings(mappings, concept_url);
const indirectMappings = getIndirectMappings(mappings, concept_url);
const directMappingsHeader = getMappingsHeader(directMappings, true);
const indirectMappingsHeader = getMappingsHeader(indirectMappings);
const zeroMappings = isEmpty(mappings);
const getMappingsDom = (mappings, header) => {
const isPresent = !isEmpty(mappings);
return (
<div className='col-sm-6' style={
(isPresent || zeroMappings) ? {marginBottom: '10px'} : {}
}>
<h4 style={{background: 'lightgray', padding: "10px", marginTop: '10px', marginBottom: '0px'}}>
{ header }
</h4>
{
isPresent &&
<NestedMappingsTable mappings={mappings} />
}
</div>
);
}
return (
<React.Fragment>
{
isLoading ?
<div style={{margin: '10px 0', textAlign: 'center'}}>
<CircularProgress />
</div>:
<div>
{ getMappingsDom(directMappings, directMappingsHeader) }
{ getMappingsDom(indirectMappings, indirectMappingsHeader) }
</div>
}
</React.Fragment>
)
}
export default AllMappingsTables;