-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathAssetListRow.jsx
73 lines (66 loc) · 2.05 KB
/
AssetListRow.jsx
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import PropTypes from 'prop-types';
import React from 'react';
import { Link } from 'react-router-dom';
import { useDispatch } from 'react-redux';
import { useTranslation } from 'react-i18next';
import prettyBytes from 'pretty-bytes';
import MenuItem from '../../../components/Dropdown/MenuItem';
import TableDropdown from '../../../components/Dropdown/TableDropdown';
import { deleteAssetRequest } from '../actions/assets';
const AssetMenu = ({ item: asset }) => {
const { t } = useTranslation();
const dispatch = useDispatch();
const handleAssetDelete = () => {
const { key, name } = asset;
if (window.confirm(t('Common.DeleteConfirmation', { name }))) {
dispatch(deleteAssetRequest(key));
}
};
return (
<TableDropdown aria-label={t('AssetList.ToggleOpenCloseARIA')}>
<MenuItem onClick={handleAssetDelete}>{t('AssetList.Delete')}</MenuItem>
<MenuItem href={asset.url} target="_blank">
{t('AssetList.OpenNewTab')}
</MenuItem>
</TableDropdown>
);
};
AssetMenu.propTypes = {
item: PropTypes.shape({
key: PropTypes.string.isRequired,
url: PropTypes.string.isRequired,
name: PropTypes.string.isRequired
}).isRequired
};
const AssetListRow = ({ asset, username }) => (
<tr className="asset-table__row" key={asset.key}>
<th scope="row">
<a href={asset.url} target="_blank" rel="noopener noreferrer">
{asset.name}
</a>
</th>
<td>{prettyBytes(asset.size)}</td>
<td>
{asset.sketchId && (
<Link to={`/${username}/sketches/${asset.sketchId}`}>
{asset.sketchName}
</Link>
)}
</td>
<td className="asset-table__dropdown-column">
<AssetMenu item={asset} />
</td>
</tr>
);
AssetListRow.propTypes = {
asset: PropTypes.shape({
key: PropTypes.string.isRequired,
url: PropTypes.string.isRequired,
sketchId: PropTypes.string,
sketchName: PropTypes.string,
name: PropTypes.string.isRequired,
size: PropTypes.number.isRequired
}).isRequired,
username: PropTypes.string.isRequired
};
export default AssetListRow;