-
Notifications
You must be signed in to change notification settings - Fork 12
/
ServerConfigList.jsx
79 lines (71 loc) · 2.79 KB
/
ServerConfigList.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
import React from 'react';
import alertifyjs from 'alertifyjs';
import {
List, ListItem, ListItemIcon, ListItemText
} from '@mui/material';
import {
Check as CheckIcon
} from '@mui/icons-material';
import { get, map } from 'lodash';
import {
getAppliedServerConfig, getDefaultServerConfig, isServerSwitched, getServerConfigsForCurrentUser
} from '../../common/utils';
import BetaLabel from './BetaLabel'
const ServerConfigList = ({ onClose }) => {
const selectedConfig = getAppliedServerConfig();
const defaultConfig = getDefaultServerConfig();
const eligibleServerConfigs = getServerConfigsForCurrentUser()
const onChange = (event, config) => {
event.preventDefault();
event.stopPropagation();
if(selectedConfig?.id ? selectedConfig.id === config.id : selectedConfig?.url === config.url){
onClose();
return;
}
localStorage.setItem('server', JSON.stringify(config));
if(!isServerSwitched())
localStorage.removeItem('server')
onClose();
alertifyjs.success('Switching Server! This might take few seconds...', 2, () => {
const isOCLServer = config.type === 'ocl';
localStorage.setItem('server_configs', JSON.stringify(eligibleServerConfigs))
localStorage.removeItem('token');
localStorage.removeItem('user');
window.location.hash = isOCLServer ? '#/' : '#/fhir'
window.location.reload()
})
}
return (
<List component="div" disablePadding>
{
map(eligibleServerConfigs, config => {
const selected = selectedConfig.id ? selectedConfig.id === config.id : get(selectedConfig, 'url') === config.url;
const isDefault = defaultConfig.id ? defaultConfig.id === config.id : config.url === defaultConfig.url;
return (
<ListItem disabled={config.disabled} selected={selected} className='btn' button key={config.id} onClick={event => onChange(event, config)} style={{cursor: config.disabled ? 'not-allowed' : 'pointer'}}>
<ListItemIcon style={{minWidth: 'auto', marginRight: '15px', width: '22px', height: '22px'}}>
<img src={config.type === 'ocl' ? '/favicon.ico' : '/fhir.svg'} />
</ListItemIcon>
<ListItemText
primary={
<span>
<span>{ config.beta ? <BetaLabel label={config.name} /> : config.name }</span>
{
isDefault &&
<span style={{fontStyle: 'italic', marginLeft: '5px'}}>
(default)
</span>
}
</span>
}
secondary={config.url}
/>
{ selected && <CheckIcon /> }
</ListItem>
)
})
}
</List>
)
}
export default ServerConfigList;