-
Notifications
You must be signed in to change notification settings - Fork 461
Expand file tree
/
Copy pathlist.js
More file actions
58 lines (49 loc) · 1.55 KB
/
Copy pathlist.js
File metadata and controls
58 lines (49 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React, { forwardRef } from 'react';
import { Link } from 'react-router-dom';
import { isNil, reject } from 'ramda';
import { useTranslation } from 'react-i18next';
import { Avatar, List, ListItemAvatar, ListItemButton, ListItemText, Typography } from '@mui/material';
import BookmarkIcon from '@mui/icons-material/Bookmark';
const CardsList = ({ cardsList }) => {
const { t } = useTranslation();
const ListItemLink = (cardId) => {
const EditCardLink = forwardRef((props, ref) => {
const { data } = props;
const location = {
pathname: `/cards/${data.id}/edit`,
state: data,
};
return <Link ref={ref} to={location} {...props} />
});
const description = cardsList[cardId].from_alias
? reject(
isNil,
[cardsList[cardId].from_alias, cardsList[cardId].action.args]
).join(', ')
: cardsList[cardId].func
return (
<ListItemButton
component={EditCardLink}
data={{ id: cardId, ...cardsList[cardId] }}
key={cardId}>
<ListItemAvatar>
<Avatar>
<BookmarkIcon />
</Avatar>
</ListItemAvatar>
<ListItemText
primary={cardId}
secondary={description}
/>
</ListItemButton>
);
}
return (
cardsList && Object.keys(cardsList).length > 0
? <List sx={{ width: '100%' }}>
{Object.keys(cardsList).map(ListItemLink)}
</List>
: <Typography>{t('cards.list.no-cards-registered')}</Typography>
);
}
export default React.memo(CardsList);