Skip to content

Commit

Permalink
feat: allowing group data download button to apply to selected rows
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-sheehan-edx committed May 20, 2024
1 parent 54b25e3 commit dc27c74
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import { useBudgetId, useSubsidyAccessPolicy } from '../data';
const GroupMembersCsvDownloadTableAction = ({
tableInstance,
}) => {
let buttonNumRelevantRows = tableInstance.itemCount;
if (tableInstance?.selectedFlatRows.length > 0) {
buttonNumRelevantRows = tableInstance?.selectedFlatRows.length;
}
const [alertModalOpen, setAlertModalOpen] = useState(false);
const [alertModalExc, setAlertModalException] = useState('');
const { subsidyAccessPolicyId } = useBudgetId();
Expand Down Expand Up @@ -50,9 +54,13 @@ const GroupMembersCsvDownloadTableAction = ({
}
});

const selectedEmails = [];
tableInstance.selectedFlatRows.forEach((row) => selectedEmails.push(row.id));

EnterpriseAccessApiService.fetchSubsidyHydratedGroupMembersData(
subsidyAccessPolicyId,
options,
selectedEmails,
).then(response => {
// download CSV
const blob = new Blob([response.data], {
Expand Down Expand Up @@ -96,14 +104,17 @@ const GroupMembersCsvDownloadTableAction = ({
className="border rounded-0 border-dark-500"
disabled={tableInstance.itemCount === 0}
>
Download all ({tableInstance.itemCount})
Download {tableInstance?.selectedFlatRows.length > 0 ? '' : 'all '}({buttonNumRelevantRows})
</Button>
</>
);
};

GroupMembersCsvDownloadTableAction.propTypes = {
tableInstance: PropTypes.shape({
selectedFlatRows: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.string,
})),
itemCount: PropTypes.number,
state: PropTypes.shape({
filters: PropTypes.arrayOf(PropTypes.shape({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const LearnerCreditGroupMembersTable = ({
setRefresh={setRefresh}
groupUuid={groupUuid}
/>,
<GroupMembersCsvDownloadTableAction />,
]}
additionalColumns={[
{
Expand Down
5 changes: 4 additions & 1 deletion src/data/services/EnterpriseAccessApiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,11 @@ class EnterpriseAccessApiService {
return EnterpriseAccessApiService.apiClient().post(url, payload);
}

static fetchSubsidyHydratedGroupMembersData(subsidyAccessPolicyUUID, options) {
static fetchSubsidyHydratedGroupMembersData(subsidyAccessPolicyUUID, options, selectedEmails) {
const queryParams = new URLSearchParams(options);
if (selectedEmails) {
selectedEmails.forEach((email) => queryParams.append('learners', email));
}
const subsidyHydratedGroupLearnersEndpoint = `${EnterpriseAccessApiService.baseUrl}/subsidy-access-policies/${subsidyAccessPolicyUUID}/group-members?${queryParams.toString()}`;
return EnterpriseAccessApiService.apiClient().get(subsidyHydratedGroupLearnersEndpoint);
}
Expand Down

0 comments on commit dc27c74

Please sign in to comment.