Skip to content

Commit 7f4b4c9

Browse files
rename study (#103)
Allow to rename study Signed-off-by: AbdelHedhili <[email protected]> Co-authored-by: ChamseddineBhd <[email protected]>
1 parent 65d46af commit 7f4b4c9

File tree

4 files changed

+102
-8
lines changed

4 files changed

+102
-8
lines changed

src/components/study-manager.js

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {ReactComponent as UcteLogo} from '../images/ucte_logo.svg';
3232
import {ReactComponent as IeeeLogo} from '../images/ieee_logo.svg';
3333

3434
import {loadStudiesSuccess} from '../redux/actions';
35-
import {deleteStudy, fetchStudies} from '../utils/rest-api';
35+
import {fetchStudies, deleteStudy, renameStudy} from '../utils/rest-api';
3636
import CreateStudyForm from "./create-study-form";
3737

3838
import {CardHeader} from "@material-ui/core";
@@ -46,6 +46,9 @@ import withStyles from "@material-ui/core/styles/withStyles";
4646
import ListItemIcon from "@material-ui/core/ListItemIcon";
4747
import ListItemText from "@material-ui/core/ListItemText";
4848
import DeleteIcon from '@material-ui/icons/Delete';
49+
import SwapIcon from '@material-ui/icons/SwapHoriz';
50+
import TextField from "@material-ui/core/TextField";
51+
import InputLabel from "@material-ui/core/InputLabel";
4952
import Box from "@material-ui/core/Box";
5053

5154
const useStyles = makeStyles((theme) => ({
@@ -89,7 +92,8 @@ const useStyles = makeStyles((theme) => ({
8992
}));
9093

9194
const StudyCard = ({study, onClick}) => {
92-
const [open, setOpen] = React.useState(false);
95+
const [openDeleteDialog, setOpenDelete] = React.useState(false);
96+
const [openRenameDialog, setOpenRename] = React.useState(false);
9397
const dispatch = useDispatch();
9498
const classes = useStyles();
9599

@@ -141,7 +145,7 @@ const StudyCard = ({study, onClick}) => {
141145

142146
const handleDeleteStudy = () => {
143147
setAnchorEl(null);
144-
setOpen(true);
148+
setOpenDelete(true);
145149
};
146150

147151
const handleDeleteStudyConfirmed = () => {
@@ -152,12 +156,35 @@ const StudyCard = ({study, onClick}) => {
152156
});
153157
};
154158

155-
const handleCloseDialog = () => {
156-
setOpen(false);
159+
const handleCloseDeleteDialog = () => {
160+
setOpenDelete(false);
157161
};
158162

159163
const handleCancelDelete = () => {
160-
setOpen(false);
164+
setOpenDelete(false);
165+
};
166+
167+
const handleRenameStudy = () => {
168+
setAnchorEl(null);
169+
setOpenRename(true);
170+
};
171+
172+
const handleRenameStudyConfirmed = (newStudyNameValue) => {
173+
renameStudy(study.studyName, newStudyNameValue)
174+
.then(() => {
175+
fetchStudies().then(studies => {
176+
dispatch(loadStudiesSuccess(studies));
177+
});
178+
setOpenRename(false);
179+
});
180+
};
181+
182+
const handleCancelRename = () => {
183+
setOpenRename(false);
184+
};
185+
186+
const handleCloseRenameDialog = () => {
187+
setOpenDelete(false);
161188
};
162189

163190
const [expanded, setExpanded] = React.useState(false);
@@ -218,6 +245,14 @@ const StudyCard = ({study, onClick}) => {
218245
</ListItemIcon>
219246
<ListItemText primary={<FormattedMessage id="delete"/>} />
220247
</MenuItem>
248+
249+
<MenuItem onClick={handleRenameStudy}>
250+
<ListItemIcon>
251+
<SwapIcon fontSize="small"/>
252+
</ListItemIcon>
253+
<ListItemText primary={<FormattedMessage id="rename"/>} />
254+
</MenuItem>
255+
221256
</StyledMenu>
222257
</CardActions>
223258
<Collapse in={expanded} timeout="auto" unmountOnExit>
@@ -237,8 +272,8 @@ const StudyCard = ({study, onClick}) => {
237272
</CardContent>
238273
</Collapse>
239274
</Card>
240-
<Dialog open={open} onClose={handleCloseDialog} aria-labelledby="form-dialog-title">
241-
<DialogTitle id="form-dialog-title"><FormattedMessage id="deleteStudy"/></DialogTitle>
275+
<Dialog open={openDeleteDialog} onClose={handleCloseDeleteDialog} aria-labelledby="dialog-title-delete">
276+
<DialogTitle id="dialog-title-delete"><FormattedMessage id="deleteStudy"/></DialogTitle>
242277
<DialogContent>
243278
<DialogContentText>
244279
<FormattedMessage id="deleteStudyMsg"/>
@@ -253,10 +288,47 @@ const StudyCard = ({study, onClick}) => {
253288
</Button>
254289
</DialogActions>
255290
</Dialog>
291+
<RenameDialog studyName={study.studyName}
292+
openRenameDialog={openRenameDialog}
293+
handleCloseDialog={handleCloseRenameDialog}
294+
handleCancel={handleCancelRename}
295+
handleConfirm={handleRenameStudyConfirmed}/>
256296
</div>
257297
);
258298
};
259299

300+
const RenameDialog = (props) => {
301+
302+
const [newStudyNameValue, setNewStudyNameValue] = React.useState(props.studyName);
303+
304+
const updateStudyNameValue= (event) => {
305+
setNewStudyNameValue(event.target.value);
306+
};
307+
308+
const handleClick = () => {
309+
console.debug("newStudyName : " + newStudyNameValue);
310+
props.handleConfirm(newStudyNameValue);
311+
};
312+
313+
return (
314+
<Dialog open={props.openRenameDialog} onClose={props.handleCloseDialog} aria-labelledby="dialog-title-rename">
315+
<DialogTitle id="dialog-title-rename"><FormattedMessage id="renameStudy"/></DialogTitle>
316+
<DialogContent>
317+
<InputLabel htmlFor="newStudyName"><FormattedMessage id="renameStudyMsg"/></InputLabel>
318+
<TextField id="newStudyName" value={newStudyNameValue} required={true} onChange={updateStudyNameValue}></TextField>
319+
</DialogContent>
320+
<DialogActions>
321+
<Button onClick={props.handleCancel} color="primary">
322+
<FormattedMessage id="cancel"/>
323+
</Button>
324+
<Button onClick={handleClick} color="primary">
325+
<FormattedMessage id="rename"/>
326+
</Button>
327+
</DialogActions>
328+
</Dialog>
329+
);
330+
};
331+
260332
const StudyManager = ({onStudyClick}) => {
261333
const dispatch = useDispatch();
262334

src/translations/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"uploadMessage" : " No file selected",
1111
"cancel" : "CANCEL",
1212
"create" : "CREATE",
13+
"rename" : "Rename",
1314
"delete" : "Delete",
1415
"filter" : "Filter",
1516

@@ -24,6 +25,9 @@
2425
"studyNameDidNotMatchMsg" : "The given study name did not match with ",
2526
"studyDeletedSuccessMsg" : "Study deleted",
2627

28+
"renameStudyMsg" : "New study name:",
29+
"renameStudy" : "Rename study",
30+
2731
"studyNameErrorMsg" : "Study name should not be empty",
2832
"caseNameErrorMsg" : "Please select the case name",
2933
"caseDataErrorMsg" : "An error occured when importing the case",

src/translations/fr.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"uploadMessage" : " Aucun fichier sélectionné",
1111
"cancel" : "ANNULER",
1212
"create" : "CRÉER",
13+
"rename" : "Renommer",
1314
"delete" : "Supprimer",
1415
"filter" : "Filtre",
1516

@@ -23,6 +24,9 @@
2324
"studyNameDidNotMatchMsg" : "Le nom d'étude donné ne correspond pas à ",
2425
"studyDeletedSuccessMsg" : "Étude supprimée",
2526

27+
"renameStudyMsg" : "Nouveau nom de l'étude :",
28+
"renameStudy" : "Renommer l'étude",
29+
2630
"studyNameErrorMsg" : "Le nom de l'étude ne doit pas être vide",
2731
"caseNameErrorMsg" : "Veuillez sélectionner le nom de la situation",
2832
"caseDataErrorMsg" : "Une erreur s'est produite lors de l'importation du fichier",

src/utils/rest-api.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,17 @@ export function deleteStudy(studyName) {
9393
return fetch(deleteStudyUrl, {method:'delete'});
9494
}
9595

96+
export function renameStudy(studyName, newStudyName) {
97+
console.info("Renaming study " + studyName);
98+
const renameStudiesUrl = process.env.REACT_APP_API_STUDY_SERVER + "/v1/studies/" + studyName + "/rename";
99+
console.debug(renameStudiesUrl);
100+
return fetch(renameStudiesUrl, {
101+
method : 'POST',
102+
headers : {
103+
'Accept' : 'application/json',
104+
'Content-Type' : 'application/json'
105+
},
106+
body : JSON.stringify({newStudyName: newStudyName})
107+
}).then(response => response.json());
108+
}
109+

0 commit comments

Comments
 (0)