From 1da866a8029ac530abdd073dcac2f53ea9fc863e Mon Sep 17 00:00:00 2001 From: Alexander J Sheehan Date: Mon, 20 May 2024 15:51:43 +0000 Subject: [PATCH] feat: allowing group data download button to apply to selected rows --- .../members-tab/GroupMembersCsvDownloadTableAction.jsx | 6 +++++- .../members-tab/LearnerCreditGroupMembersTable.jsx | 1 + .../members-tab/tests/MembersTab.test.jsx | 8 +++++++- src/data/services/EnterpriseAccessApiService.js | 5 ++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/components/learner-credit-management/members-tab/GroupMembersCsvDownloadTableAction.jsx b/src/components/learner-credit-management/members-tab/GroupMembersCsvDownloadTableAction.jsx index 6fd83bed02..453d5c0941 100644 --- a/src/components/learner-credit-management/members-tab/GroupMembersCsvDownloadTableAction.jsx +++ b/src/components/learner-credit-management/members-tab/GroupMembersCsvDownloadTableAction.jsx @@ -11,6 +11,8 @@ import { useBudgetId, useSubsidyAccessPolicy } from '../data'; const GroupMembersCsvDownloadTableAction = ({ tableInstance, }) => { + const selectedEmails = Object.keys(tableInstance.state.selectedRowIds); + const selectedEmailCount = selectedEmails.length; const [alertModalOpen, setAlertModalOpen] = useState(false); const [alertModalExc, setAlertModalException] = useState(''); const { subsidyAccessPolicyId } = useBudgetId(); @@ -53,6 +55,7 @@ const GroupMembersCsvDownloadTableAction = ({ EnterpriseAccessApiService.fetchSubsidyHydratedGroupMembersData( subsidyAccessPolicyId, options, + selectedEmails, ).then(response => { // download CSV const blob = new Blob([response.data], { @@ -96,7 +99,7 @@ const GroupMembersCsvDownloadTableAction = ({ className="border rounded-0 border-dark-500" disabled={tableInstance.itemCount === 0} > - Download all ({tableInstance.itemCount}) + Download {selectedEmailCount > 0 ? `(${selectedEmailCount})` : `all (${tableInstance.itemCount})`} ); @@ -118,6 +121,7 @@ GroupMembersCsvDownloadTableAction.propTypes = { id: PropTypes.string, desc: PropTypes.bool, })), + selectedRowIds: PropTypes.shape(), }), }), }; diff --git a/src/components/learner-credit-management/members-tab/LearnerCreditGroupMembersTable.jsx b/src/components/learner-credit-management/members-tab/LearnerCreditGroupMembersTable.jsx index 1316ed2355..b0fd70cfe6 100644 --- a/src/components/learner-credit-management/members-tab/LearnerCreditGroupMembersTable.jsx +++ b/src/components/learner-credit-management/members-tab/LearnerCreditGroupMembersTable.jsx @@ -124,6 +124,7 @@ const LearnerCreditGroupMembersTable = ({ setRefresh={setRefresh} groupUuid={groupUuid} />, + , ]} additionalColumns={[ { diff --git a/src/components/learner-credit-management/members-tab/tests/MembersTab.test.jsx b/src/components/learner-credit-management/members-tab/tests/MembersTab.test.jsx index 2aa04ab1d9..ec7f0da2b0 100644 --- a/src/components/learner-credit-management/members-tab/tests/MembersTab.test.jsx +++ b/src/components/learner-credit-management/members-tab/tests/MembersTab.test.jsx @@ -715,11 +715,16 @@ describe('', () => { renderWithRouter(); userEvent.type(screen.getByText('Search by member details'), 'foobar'); userEvent.click(screen.getByTestId('members-table-enrollments-column-header')); + const removeToggle = screen.getByTestId('show-removed-toggle'); userEvent.click(removeToggle); - const downloadButton = screen.getByText('Download all (1)'); + const toggleAllRowsSelected = screen.getByTitle('Toggle All Current Page Rows Selected'); + userEvent.click(toggleAllRowsSelected); + + const downloadButton = screen.getByText('Download (1)'); expect(downloadButton).toBeInTheDocument(); + userEvent.click(downloadButton); expect(EnterpriseAccessApiService.fetchSubsidyHydratedGroupMembersData).toHaveBeenCalledWith( mockAssignableSubsidyAccessPolicy.uuid, @@ -732,6 +737,7 @@ describe('', () => { show_removed: true, is_reversed: true, }, + ['foobar@test.com'], ); }); }); diff --git a/src/data/services/EnterpriseAccessApiService.js b/src/data/services/EnterpriseAccessApiService.js index fe58d1078e..ff3c9d5ea5 100644 --- a/src/data/services/EnterpriseAccessApiService.js +++ b/src/data/services/EnterpriseAccessApiService.js @@ -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); }