forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDeleteConfirmationModal.jsx
More file actions
132 lines (125 loc) · 3.64 KB
/
DeleteConfirmationModal.jsx
File metadata and controls
132 lines (125 loc) · 3.64 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
121
122
123
124
125
126
127
128
129
130
131
132
import React from 'react';
import PropTypes from 'prop-types';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
import { getConfig } from '@edx/frontend-platform';
import {
ActionRow,
AlertModal,
Button,
Collapsible,
Hyperlink,
Truncate,
} from '@openedx/paragon';
import messages from './messages';
const DeleteConfirmationModal = ({
isDeleteConfirmationOpen,
closeDeleteConfirmation,
handleBulkDelete,
selectedRows,
fileType,
// injected
intl,
}) => {
const firstSelectedRow = selectedRows[0]?.original;
let activeContentRows = [];
if (Array.isArray(selectedRows)) {
activeContentRows = selectedRows.filter(row => row.original?.activeStatus === 'active');
}
const isDeletingCourseContent = activeContentRows.length > 0;
const deletedCourseContent = activeContentRows.map(({ original }) => (
<li style={{ listStyle: 'None' }} key={original.id}>
<Collapsible
styling="basic"
title={(
<h3 className="h5 m-n2">
<Truncate.Deprecated lines={1}>
{original.displayName}
</Truncate.Deprecated>
</h3>
)}
data-testid={`collapsible-${original.id}`}
>
<ul className="px-2 py-0">
{original.usageLocations.map(location => (
<li key={`usage-location-${location.displayLocation}`} style={{ listStyle: 'square' }}>
<Hyperlink destination={`${getConfig().STUDIO_BASE_URL}${location.url}`} target="_blank">
{location.displayLocation}
</Hyperlink>
</li>
))}
</ul>
</Collapsible>
</li>
));
return (
<AlertModal
className="small"
title={intl.formatMessage(
messages.deleteConfirmationTitle,
{
fileName: firstSelectedRow?.displayName,
fileNumber: selectedRows.length,
fileType,
},
)}
isOpen={isDeleteConfirmationOpen}
onClose={closeDeleteConfirmation}
footerNode={(
<ActionRow>
<Button variant="tertiary" onClick={closeDeleteConfirmation}>
{intl.formatMessage(messages.cancelButtonLabel)}
</Button>
<Button onClick={handleBulkDelete}>
{intl.formatMessage(messages.deleteFileButtonLabel)}
</Button>
</ActionRow>
)}
>
{intl.formatMessage(
messages.deleteConfirmationMessage,
{
fileName: firstSelectedRow?.displayName,
fileNumber: selectedRows.length,
fileType,
},
)}
{isDeletingCourseContent && (
<div className="mt-3">
{intl.formatMessage(
messages.deleteConfirmationUsageMessage,
{
fileNumber: activeContentRows.length,
fileType,
},
)}
<ul className="p-0">
{deletedCourseContent}
</ul>
</div>
)}
</AlertModal>
);
};
DeleteConfirmationModal.defaultProps = {
selectedRows: [],
};
DeleteConfirmationModal.propTypes = {
selectedRows: PropTypes.arrayOf(PropTypes.shape({
original: PropTypes.shape({
id: PropTypes.string,
displayName: PropTypes.string,
activeStatus: PropTypes.string,
usageLocations: PropTypes.arrayOf(PropTypes.shape({
url: PropTypes.string,
displayLocation: PropTypes.string,
})),
}),
})),
isDeleteConfirmationOpen: PropTypes.bool.isRequired,
closeDeleteConfirmation: PropTypes.func.isRequired,
handleBulkDelete: PropTypes.func.isRequired,
fileType: PropTypes.string.isRequired,
// injected
intl: intlShape.isRequired,
};
export default injectIntl(DeleteConfirmationModal);