@@ -4,7 +4,13 @@ import { useTranslation } from 'react-i18next';
44
55import moment from 'moment'
66import reject from 'lodash/reject'
7+ import times from 'lodash/times'
8+
79import Button from '@mui/material/Button'
10+ import Divider from '@mui/material/Divider'
11+ import IconButton from '@mui/material/IconButton'
12+ import Menu from '@mui/material/Menu'
13+ import MenuItem from '@mui/material/MenuItem'
814import Paper from '@mui/material/Paper'
915import Typography from '@mui/material/Typography'
1016import Table from '@mui/material/Table' ;
@@ -15,10 +21,17 @@ import TableHead from '@mui/material/TableHead';
1521import TableRow from '@mui/material/TableRow' ;
1622import Skeleton from '@mui/material/Skeleton' ;
1723import ListItemText from '@mui/material/ListItemText'
24+ import ListItemIcon from '@mui/material/ListItemIcon'
25+ import Tooltip from '@mui/material/Tooltip'
26+
1827import AddIcon from '@mui/icons-material/Add'
19- import times from 'lodash/times'
28+ import MoreVertIcon from '@mui/icons-material/MoreVert'
29+ import ContentCopy from '@mui/icons-material/ContentCopy' ;
30+ import DeleteOutlined from '@mui/icons-material/DeleteOutlined' ;
31+
2032import APIService from '../../services/APIService'
2133import { getCurrentUser } from '../../common/utils'
34+
2235import OwnerIcon from '../common/OwnerIcon'
2336import NoResults from '../search/NoResults' ;
2437import MapProjectDeleteConfirmDialog from './MapProjectDeleteConfirmDialog' ;
@@ -31,6 +44,8 @@ const MapProjects = () => {
3144 const [ loading , setLoading ] = React . useState ( [ ] )
3245 const [ projects , setProjects ] = React . useState ( [ ] )
3346 const [ deleteProject , setDeleteProject ] = React . useState ( null )
47+ const [ actionMenuAnchorEl , setActionMenuAnchorEl ] = React . useState ( null )
48+ const [ actionMenuProject , setActionMenuProject ] = React . useState ( null )
3449
3550 const fetchProjects = ( ) => {
3651 fetchUserProjects ( )
@@ -52,8 +67,8 @@ const MapProjects = () => {
5267 fetchProjects ( )
5368 } , [ ] )
5469
55- const onProjectDelete = success => {
56- if ( success ) {
70+ const onProjectDelete = ( success ) => {
71+ if ( success === true ) {
5772 setProjects ( reject ( projects , { id : deleteProject . id } ) )
5873 }
5974 setDeleteProject ( null )
@@ -67,6 +82,34 @@ const MapProjects = () => {
6782 }
6883 }
6984
85+ const openActionMenu = ( event , project ) => {
86+ event . preventDefault ( )
87+ event . stopPropagation ( )
88+ setActionMenuAnchorEl ( event . currentTarget )
89+ setActionMenuProject ( project )
90+ }
91+
92+ const closeActionMenu = event => {
93+ event ?. preventDefault ?. ( )
94+ event ?. stopPropagation ?. ( )
95+ setActionMenuAnchorEl ( null )
96+ setActionMenuProject ( null )
97+ }
98+
99+ const onMenuCopyClick = event => {
100+ if ( actionMenuProject ) {
101+ onCopyClick ( event , actionMenuProject )
102+ }
103+ closeActionMenu ( event )
104+ }
105+
106+ const onMenuDeleteClick = event => {
107+ event . preventDefault ( )
108+ event . stopPropagation ( )
109+ setDeleteProject ( actionMenuProject )
110+ closeActionMenu ( event )
111+ }
112+
70113 const isSplitView = false
71114 const loaded = loading . length === 2
72115 return (
@@ -120,7 +163,17 @@ const MapProjects = () => {
120163 }
121164 {
122165 projects . map ( project => (
123- < TableRow key = { project . id } >
166+ < TableRow
167+ key = { project . id }
168+ onClick = { ( ) => history . push ( project . url ) }
169+ hover
170+ sx = { {
171+ cursor : 'pointer' ,
172+ '&.MuiTableRow-hover:hover' : {
173+ backgroundColor : 'primary.95'
174+ } ,
175+ } }
176+ >
124177 < TableCell > { project . id } </ TableCell >
125178 < TableCell >
126179 < span style = { { display : 'flex' , alignItems : 'center' } } >
@@ -154,24 +207,45 @@ const MapProjects = () => {
154207 />
155208 </ TableCell >
156209 < TableCell align = 'right' >
157- < span style = { { display : 'flex' , alignItems : 'center' } } >
158- < Button size = 'small' color = 'primary' variant = 'contained' sx = { { textTransform : 'none' , margin : '0 4px' } } href = { `#${ project . url } ` } >
159- { t ( 'common.open' ) }
160- </ Button >
161- < Button size = 'small' variant = 'contained' color = 'secondary' sx = { { margin : '0 4px' , textTransform : 'none' } } onClick = { event => onCopyClick ( event , project ) } >
162- { t ( 'map_project.create_similar' ) }
163- </ Button >
164- < Button size = 'small' color = 'error' variant = 'text' sx = { { margin : '0 4px' , textTransform : 'none' } } onClick = { ( ) => setDeleteProject ( project ) } >
165- { t ( 'common.delete' ) }
166- </ Button >
167- </ span >
210+ < Tooltip title = { t ( 'common.more_actions' ) } >
211+ < IconButton
212+ color = 'secondary'
213+ size = 'small'
214+ aria-label = { t ( 'common.more_actions' ) }
215+ aria-haspopup = 'menu'
216+ aria-controls = { actionMenuAnchorEl ? 'map-project-actions-menu' : undefined }
217+ aria-expanded = { actionMenuAnchorEl ? 'true' : undefined }
218+ onClick = { event => openActionMenu ( event , project ) }
219+ >
220+ < MoreVertIcon fontSize = 'small' />
221+ </ IconButton >
222+ </ Tooltip >
168223 </ TableCell >
169224 </ TableRow >
170225 ) )
171226 }
172227 </ TableBody >
173228 </ Table >
174229 </ TableContainer >
230+ < Menu
231+ id = 'map-project-actions-menu'
232+ anchorEl = { actionMenuAnchorEl }
233+ open = { Boolean ( actionMenuAnchorEl ) }
234+ onClose = { closeActionMenu }
235+ onClick = { event => event . stopPropagation ( ) }
236+ anchorOrigin = { { vertical : 'bottom' , horizontal : 'right' } }
237+ transformOrigin = { { vertical : 'top' , horizontal : 'right' } }
238+ >
239+ < MenuItem onClick = { onMenuCopyClick } >
240+ < ListItemIcon > < ContentCopy fontSize = "small" /> </ ListItemIcon >
241+ < ListItemText > { t ( 'map_project.create_similar' ) } </ ListItemText >
242+ </ MenuItem >
243+ < Divider />
244+ < MenuItem onClick = { onMenuDeleteClick } sx = { { color : 'error.main' } } >
245+ < ListItemIcon sx = { { color : 'error.main' } } > < DeleteOutlined fontSize = "small" /> </ ListItemIcon >
246+ < ListItemText > { t ( 'common.delete' ) } </ ListItemText >
247+ </ MenuItem >
248+ </ Menu >
175249 </ Paper >
176250 </ Paper >
177251 {
0 commit comments