-
Notifications
You must be signed in to change notification settings - Fork 12
/
AddReferencesResult.jsx
70 lines (67 loc) · 2.06 KB
/
AddReferencesResult.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
import React from 'react';
import MuiAlert from '@mui/material/Alert';
import {
Button, Dialog, DialogActions, DialogContent, DialogTitle,
Divider
} from '@mui/material'
import { filter, map, get, isEmpty } from 'lodash';
const ReferencesResult = ({references, severity, title, messageKey}) => (
<div className='col-md-12 no-side-padding'>
<MuiAlert variant="filled" severity={severity} style={{marginTop: '5px'}}>
{title}
</MuiAlert>
{
map(references, (reference, index) => {
const message = get(reference, messageKey);
return (
<React.Fragment key={index}>
<div style={{padding: '5px', background: 'rgba(0, 0, 0, 0.05)'}}>
<span style={{marginRight: '5px'}}><b>{reference.expression}:</b></span>
{message && <span>{message}</span>}
</div>
<Divider />
</React.Fragment>
)
})
}
</div>
);
const AddReferencesResult = ({ result, open, onClose, title }) => {
const added = filter(result, {added: true});
const notAdded = filter(result, {added: false});
return (
<Dialog open={open} onClose={onClose}>
<DialogTitle>
{title}
</DialogTitle>
<DialogContent>
<div className='col-md-12 no-side-padding'>
{
!isEmpty(added) &&
<ReferencesResult
references={added}
severity='success'
title={`${added.length} Reference(s) successfully added.`}
messageKey='message'
/>
}
{
!isEmpty(notAdded) &&
<ReferencesResult
references={notAdded}
severity='warning'
title={`${notAdded.length} Reference(s) listed below could not be added.`}
messageKey='message.0'
/>
}
</div>
</DialogContent>
<DialogActions>
<Button onClick={onClose} color="primary" variant='outlined'>
Close
</Button>
</DialogActions>
</Dialog>
)
}
export default AddReferencesResult;