@@ -32,7 +32,7 @@ import {ReactComponent as UcteLogo} from '../images/ucte_logo.svg';
3232import { ReactComponent as IeeeLogo } from '../images/ieee_logo.svg' ;
3333
3434import { loadStudiesSuccess } from '../redux/actions' ;
35- import { deleteStudy , fetchStudies } from '../utils/rest-api' ;
35+ import { fetchStudies , deleteStudy , renameStudy } from '../utils/rest-api' ;
3636import CreateStudyForm from "./create-study-form" ;
3737
3838import { CardHeader } from "@material-ui/core" ;
@@ -46,6 +46,9 @@ import withStyles from "@material-ui/core/styles/withStyles";
4646import ListItemIcon from "@material-ui/core/ListItemIcon" ;
4747import ListItemText from "@material-ui/core/ListItemText" ;
4848import 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" ;
4952import Box from "@material-ui/core/Box" ;
5053
5154const useStyles = makeStyles ( ( theme ) => ( {
@@ -89,7 +92,8 @@ const useStyles = makeStyles((theme) => ({
8992} ) ) ;
9093
9194const 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+
260332const StudyManager = ( { onStudyClick} ) => {
261333 const dispatch = useDispatch ( ) ;
262334
0 commit comments