Skip to content

Commit ab51ab4

Browse files
make settings a modal and add save button
1 parent 527cafb commit ab51ab4

File tree

4 files changed

+124
-41
lines changed

4 files changed

+124
-41
lines changed

src/components/SettingsBox/SettingsBox.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818
}
1919

2020
.setting-header{
21-
font-size:12px;
21+
font-weight:bold;
2222
margin:0;
23+
margin-bottom: 10px;
24+
padding:15px;
25+
color:white;
26+
background-color:#005B94;
2327
}
2428

2529
.setting-btn {
@@ -39,3 +43,4 @@
3943
background-color: #333232;
4044
color: #858282;
4145
}
46+

src/components/SettingsBox/SettingsBox.js

Lines changed: 91 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import React, { Component } from 'react';
22
import './SettingsBox.css';
33
import InputBox from '../Inputs/InputBox';
4-
import CheckBox from '../Inputs/CheckBox';
4+
import Checkbox from '@mui/material/Checkbox';
5+
56
import { headerDefinitions, types } from '../../util/data';
67
import FHIR from 'fhirclient';
8+
import { Box, Button, FormControlLabel, Grid, TextField } from '@mui/material';
9+
import CloseIcon from '@mui/icons-material/Close';
710

811
const clearQuestionnaireResponses =
912
({ ehrUrl, defaultUser, access_token }, consoleLog) =>
@@ -89,7 +92,7 @@ const resetRemsAdmin =
8992

9093
const resetHeaderDefinitions = [
9194
{
92-
display: 'Clear EHR QuestionnaireResponses',
95+
display: 'Clear In-Progress Forms',
9396
key: 'clearQuestionnaireResponses',
9497
reset: clearQuestionnaireResponses
9598
},
@@ -108,12 +111,44 @@ const resetHeaderDefinitions = [
108111
export default class SettingsBox extends Component {
109112
constructor(props) {
110113
super(props);
114+
this.state = {
115+
originalValues: []
116+
};
117+
this.cancelSettings = this.cancelSettings.bind(this);
118+
this.closeSettings = this.closeSettings.bind(this);
119+
this.saveSettings = this.saveSettings.bind(this);
120+
}
121+
122+
componentDidMount() {
123+
const headers = Object.keys(headerDefinitions).map(key => ([key, this.props.state[key]]));
124+
this.setState({originalValues: headers});
125+
}
126+
127+
closeSettings() {
128+
this.props.updateCB('showSettings', false);
129+
}
130+
saveSettings() {
131+
const headers = Object.keys(headerDefinitions).map(key => ([key, this.props.state[key]]));
132+
console.log(headers);
133+
localStorage.setItem('reqgenSettings', JSON.stringify(headers));
134+
this.closeSettings();
111135
}
112136

113-
componentDidMount() {}
137+
cancelSettings() {
138+
this.state.originalValues.forEach((e) => {
139+
try{
140+
this.props.updateCB(e[0], e[1]);
141+
} catch {
142+
console.log('Failed to reset setting value');
143+
}
144+
});
145+
this.closeSettings();
146+
}
114147

115148
render() {
116149
const { state, consoleLog, updateCB } = this.props;
150+
let firstCheckbox = true;
151+
let showBreak = true;
117152

118153
const headers = Object.keys(headerDefinitions)
119154
.map(key => ({ ...headerDefinitions[key], key }))
@@ -125,35 +160,46 @@ export default class SettingsBox extends Component {
125160

126161
return (
127162
<div>
163+
<Box flexGrow={1}>
164+
<h4 className='setting-header'>Settings</h4>
165+
<Grid container spacing={2} sx={{padding: '20px'}}>
128166
{headers.map(({ key, type, display }) => {
167+
129168
switch (type) {
130169
case 'input':
131170
return (
132-
<div key={key}>
133-
<p className="setting-header">{display}</p>
134-
<InputBox
135-
extraClass="setting-input"
136-
value={state[key]}
137-
updateCB={updateCB}
138-
elementName={key}
171+
<Grid key = {key} item xs={6}>
172+
<div>
173+
<TextField
174+
label={display}
175+
variant="outlined"
176+
value={state[key]}
177+
onChange = {(event)=>{updateCB(key, event.target.value);}}
178+
sx = {{width:'100%'}}
139179
/>
140180
</div>
181+
</Grid>
141182
);
142183
case 'check':
184+
if(firstCheckbox) {
185+
firstCheckbox = false;
186+
showBreak = true;
187+
} else {
188+
showBreak = false;
189+
}
143190
return (
144-
<div key={key}>
145-
<p className="setting-header">
146-
{display}
147-
<CheckBox
148-
extraClass="setting-checkbox"
149-
extraInnerClass="setting-inner-checkbox"
150-
toggle={state[key]}
151-
updateCB={updateCB}
152-
elementName={key}
191+
<React.Fragment key={key}>
192+
{showBreak ? <Grid item xs={12}></Grid> :''}
193+
<Grid item xs={3}>
194+
<FormControlLabel control = {
195+
<Checkbox
196+
value = {state[key]}
197+
onChange = {(event) => {updateCB(key, event.target.value);}}/>
198+
}
199+
label = {display}
153200
/>
154-
</p>
155-
<p>&nbsp;</p>
156-
</div>
201+
</Grid>
202+
</React.Fragment>
157203
);
158204
default:
159205
return (
@@ -163,15 +209,29 @@ export default class SettingsBox extends Component {
163209
);
164210
}
165211
})}
166-
{resetHeaderDefinitions.map(({ key, display, reset }) => {
167-
return (
168-
<div key={key}>
169-
<button className={'setting-btn btn btn-class'} onClick={reset(state, consoleLog)}>
170-
{display}
171-
</button>
172-
</div>
173-
);
174-
})}
212+
{resetHeaderDefinitions.map(({ key, display, reset }) => {
213+
return (
214+
<Grid item key={key} xs={4}>
215+
<Button variant='outlined' onClick={reset(state, consoleLog)}>
216+
{display}
217+
</Button>
218+
</Grid>
219+
);
220+
})}
221+
{/* spacer */}
222+
<hr style={{
223+
'width':'100%'
224+
}}/>
225+
<Grid item xs={8} />
226+
227+
<Grid item xs={2}>
228+
<Button variant = 'outlined' onClick = {this.cancelSettings}>Cancel</Button>
229+
</Grid>
230+
<Grid item xs={2}>
231+
<Button variant = 'contained' onClick = {this.saveSettings}>Save</Button>
232+
</Grid>
233+
</Grid>
234+
</Box>
175235
</div>
176236
);
177237
}

src/containers/RequestBuilder.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component } from 'react';
2-
import { Button, Box, IconButton } from '@mui/material';
2+
import { Button, Box, IconButton, Modal, DialogTitle } from '@mui/material';
33
import PersonIcon from '@mui/icons-material/Person';
44
import RefreshIcon from '@mui/icons-material/Refresh';
55
import DisplayBox from '../components/DisplayBox/DisplayBox';
@@ -69,6 +69,17 @@ export default class RequestBuilder extends Component {
6969
}
7070

7171
componentDidMount() {
72+
// load settings
73+
JSON.parse(localStorage.getItem('reqgenSettings') || '[]').forEach((element) => {
74+
try {
75+
this.setState({[element[0]]: element[1]});
76+
} catch {
77+
if(element[0]){
78+
console.log('Could not load setting:' + element[0]);
79+
}
80+
}
81+
});
82+
7283
if (!this.state.client) {
7384
this.reconnectEhr();
7485
} else {
@@ -265,16 +276,15 @@ export default class RequestBuilder extends Component {
265276
</button>
266277
</div>
267278
<div>
268-
{/* <div id="settings-header"></div> */}
269-
{this.state.showSettings && (
270-
<div className='settings-box'>
279+
<Modal open = {this.state.showSettings} onClose = {()=>{this.setState({showSettings:false});}} >
280+
<div className = 'settings-box'>
271281
<SettingsBox
272282
state={this.state}
273283
consoleLog={this.consoleLog}
274284
updateCB={this.updateStateElement}
275-
/>
285+
/>
276286
</div>
277-
)}
287+
</Modal>
278288
</div>
279289
<div style={{display: 'flex'}}>
280290
<Accordion style={{width: '95%'}} expanded={this.state.expanded} onChange={this.handleChange()}>

src/index.css

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,16 @@ input:not(:focus):not([value=""]):valid ~ .floating-label{
325325
.title {
326326
margin-bottom: 65px;
327327
}
328-
329328
.settings-box {
330-
width: 50%;
331-
margin-left: 20px;
329+
border: 1px solid black;
330+
width: 75%;
331+
height: 75%;
332+
background-color:white;
333+
position: fixed;
334+
top: 50%;
335+
left: 50%;
336+
transform: translate(-50%, -50%);
337+
overflow-y: auto;
338+
box-shadow: 10px 10px 20px black
339+
332340
}

0 commit comments

Comments
 (0)