forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTableActions.jsx
More file actions
120 lines (113 loc) · 3.66 KB
/
TableActions.jsx
File metadata and controls
120 lines (113 loc) · 3.66 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import React, { useContext, useEffect } from 'react';
import { isEmpty } from 'lodash';
import { PropTypes } from 'prop-types';
import { injectIntl, intlShape, FormattedMessage } from '@edx/frontend-platform/i18n';
import { getConfig } from '@edx/frontend-platform';
import {
Button,
DataTableContext,
Dropdown,
useToggle,
} from '@openedx/paragon';
import { Add, Tune } from '@openedx/paragon/icons';
import messages from '../messages';
import SortAndFilterModal from './sort-and-filter-modal';
const TableActions = ({
selectedFlatRows,
fileInputControl,
handleSort,
handleBulkDownload,
handleOpenDeleteConfirmation,
encodingsDownloadUrl,
fileType,
setInitialState,
// injected
intl,
}) => {
const [isSortOpen, openSort, closeSort] = useToggle(false);
const { state, clearSelection } = useContext(DataTableContext);
// This useEffect saves DataTable state so it can persist after table re-renders due to data reload.
useEffect(() => {
setInitialState(state);
}, [state]);
const handleOpenFileSelector = () => {
fileInputControl.click();
clearSelection();
};
return (
<>
<Button variant="outline-primary" onClick={openSort} iconBefore={Tune}>
<FormattedMessage {...messages.sortButtonLabel} />
</Button>
<Dropdown className="mx-2">
<Dropdown.Toggle
id="actions-menu-toggle"
alt="actions-menu-toggle"
variant="outline-primary"
>
<FormattedMessage {...messages.actionsButtonLabel} />
</Dropdown.Toggle>
<Dropdown.Menu>
{encodingsDownloadUrl ? (
<Dropdown.Item
download
href={`${getConfig().STUDIO_BASE_URL}${encodingsDownloadUrl}`}
>
<FormattedMessage {...messages.downloadEncodingsTitle} />
</Dropdown.Item>
) : null}
<Dropdown.Item
onClick={() => handleBulkDownload(selectedFlatRows)}
disabled={isEmpty(selectedFlatRows)}
>
<FormattedMessage {...messages.downloadTitle} />
</Dropdown.Item>
<Dropdown.Divider />
<Dropdown.Item
data-testid="open-delete-confirmation-button"
onClick={() => handleOpenDeleteConfirmation(selectedFlatRows)}
disabled={isEmpty(selectedFlatRows)}
>
<FormattedMessage {...messages.deleteTitle} />
</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
<Button iconBefore={Add} onClick={handleOpenFileSelector}>
{intl.formatMessage(messages.addFilesButtonLabel, { fileType })}
</Button>
<SortAndFilterModal {...{ isSortOpen, closeSort, handleSort }} />
</>
);
};
TableActions.defaultProps = {
selectedFlatRows: null,
};
TableActions.propTypes = {
selectedFlatRows: PropTypes.arrayOf(
PropTypes.shape({
original: PropTypes.shape({
displayName: PropTypes.string.isRequired,
wrapperType: PropTypes.string.isRequired,
locked: PropTypes.bool,
externalUrl: PropTypes.string,
thumbnail: PropTypes.string,
id: PropTypes.string.isRequired,
portableUrl: PropTypes.string,
}).isRequired,
}),
),
fileInputControl: PropTypes.shape({
click: PropTypes.func.isRequired,
}).isRequired,
handleOpenDeleteConfirmation: PropTypes.func.isRequired,
handleBulkDownload: PropTypes.func.isRequired,
encodingsDownloadUrl: PropTypes.string,
handleSort: PropTypes.func.isRequired,
fileType: PropTypes.string.isRequired,
setInitialState: PropTypes.func.isRequired,
intl: intlShape.isRequired,
};
TableActions.defaultProps = {
encodingsDownloadUrl: null,
};
export default injectIntl(TableActions);