-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
219 additions
and
132 deletions.
There are no files selected for viewing
125 changes: 0 additions & 125 deletions
125
src/components/PeopleManagement/GroupDetailPage/DownloadCsvButton.jsx
This file was deleted.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
src/components/PeopleManagement/GroupDetailPage/DownloadCsvIconButton.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { defineMessages, useIntl } from '@edx/frontend-platform/i18n'; | ||
|
||
import { | ||
Icon, IconButtonWithTooltip, Toast, useToggle, | ||
} from '@openedx/paragon'; | ||
import { Download } from '@openedx/paragon/icons'; | ||
import { logError } from '@edx/frontend-platform/logging'; | ||
import GeneralErrorModal from '../GeneralErrorModal'; | ||
import { downloadCsv, getTimeStampedFilename } from '../../../utils'; | ||
|
||
const csvHeaders = ['Name', 'Email', 'Recent action', 'Enrollments']; | ||
|
||
const DownloadCsvIconButton = ({ fetchAllData, dataCount, testId }) => { | ||
const [isToastOpen, openToast, closeToast] = useToggle(false); | ||
const [isErrorModalOpen, openErrorModal, closeErrorModal] = useToggle(false); | ||
const intl = useIntl(); | ||
const messages = defineMessages({ | ||
downloadToastText: { | ||
id: 'adminPortal.peopleManagement.groupDetail.downloadCsv.toast', | ||
defaultMessage: 'Downloaded group members', | ||
description: 'Toast message for the download button on the group detail page.', | ||
}, | ||
downloadHoverText: { | ||
id: 'adminPortal.peopleManagement.groupDetail.downloadCsv.toast', | ||
defaultMessage: `Download (${dataCount})`, | ||
description: 'Tooltip message for the download button on the group detail page.', | ||
}, | ||
}); | ||
|
||
const dataEntryToRow = (entry) => { | ||
const { memberDetails: { userEmail, userName }, recentAction, enrollments } = entry; | ||
return [userName, userEmail, recentAction, enrollments]; | ||
}; | ||
|
||
const handleClick = async () => { | ||
fetchAllData().then((response) => { | ||
const fileName = getTimeStampedFilename('group-report.csv'); | ||
downloadCsv(fileName, response.results, csvHeaders, dataEntryToRow); | ||
openToast(); | ||
}).catch((err) => { | ||
logError(err); | ||
openErrorModal(); | ||
}); | ||
}; | ||
|
||
return ( | ||
<> | ||
{ isToastOpen | ||
&& ( | ||
<Toast onClose={closeToast} show={isToastOpen}> | ||
{intl.formatMessage(messages.downloadToastText)} | ||
</Toast> | ||
)} | ||
<GeneralErrorModal | ||
isOpen={isErrorModalOpen} | ||
close={closeErrorModal} | ||
/> | ||
<IconButtonWithTooltip | ||
data-testid={testId} | ||
tooltipContent={intl.formatMessage(messages.downloadHoverText)} | ||
src={Download} | ||
iconAs={Icon} | ||
alt="Download group members" | ||
variant="primary" | ||
onClick={handleClick} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
DownloadCsvIconButton.defaultProps = { | ||
testId: 'download-csv-icon-button', | ||
}; | ||
|
||
DownloadCsvIconButton.propTypes = { | ||
fetchAllData: PropTypes.func.isRequired, | ||
dataCount: PropTypes.number.isRequired, | ||
testId: PropTypes.string, | ||
}; | ||
|
||
export default DownloadCsvIconButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.