Skip to content

Commit 6e75945

Browse files
authored
Merge pull request #14 from OpenConceptLab/issues#2486
Issues#2486
2 parents 13cfe98 + dd6abcb commit 6e75945

4 files changed

Lines changed: 92 additions & 15 deletions

File tree

src/components/map-projects/MapProjects.jsx

Lines changed: 89 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import { useTranslation } from 'react-i18next';
44

55
import moment from 'moment'
66
import reject from 'lodash/reject'
7+
import times from 'lodash/times'
8+
79
import 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'
814
import Paper from '@mui/material/Paper'
915
import Typography from '@mui/material/Typography'
1016
import Table from '@mui/material/Table';
@@ -15,10 +21,17 @@ import TableHead from '@mui/material/TableHead';
1521
import TableRow from '@mui/material/TableRow';
1622
import Skeleton from '@mui/material/Skeleton';
1723
import ListItemText from '@mui/material/ListItemText'
24+
import ListItemIcon from '@mui/material/ListItemIcon'
25+
import Tooltip from '@mui/material/Tooltip'
26+
1827
import 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+
2032
import APIService from '../../services/APIService'
2133
import { getCurrentUser } from '../../common/utils'
34+
2235
import OwnerIcon from '../common/OwnerIcon'
2336
import NoResults from '../search/NoResults';
2437
import 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
{

src/i18n/locales/en/translations.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"view_all_attributes": "View all attributes",
4343
"all": "All",
4444
"actions": "Actions",
45+
"more_actions": "More actions",
4546
"metadata": "Metadata",
4647
"copied_to_clipboard": "Copied to clipboard",
4748
"navigate": "Navigate",

src/i18n/locales/es/translations.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"about": "Acerca de",
2525
"view_all_attributes": "Ver todos los atributos",
2626
"actions": "Acciones",
27+
"more_actions": "Más acciones",
2728
"metadata": "Metadatos",
2829
"copied_to_clipboard": "Copiado al portapapeles",
2930
"navigate": "Navegar",

src/i18n/locales/zh/translations.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"view_all_attributes": "查看全部属性",
4242
"all": "全部",
4343
"actions": "操作",
44+
"more_actions": "更多操作",
4445
"metadata": "元数据",
4546
"copied_to_clipboard": "已复制到粘贴板",
4647
"navigate": "导航",

0 commit comments

Comments
 (0)