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 21, 2024
1 parent ea27f5f commit a5cd207
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -53,6 +55,7 @@ const GroupMembersCsvDownloadTableAction = ({
EnterpriseAccessApiService.fetchSubsidyHydratedGroupMembersData(
subsidyAccessPolicyId,
options,
selectedEmails,
).then(response => {
// download CSV
const blob = new Blob([response.data], {
Expand Down Expand Up @@ -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})`}
</Button>
</>
);
Expand All @@ -118,6 +121,7 @@ GroupMembersCsvDownloadTableAction.propTypes = {
id: PropTypes.string,
desc: PropTypes.bool,
})),
selectedRowIds: 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
Original file line number Diff line number Diff line change
Expand Up @@ -713,11 +713,16 @@ describe('<BudgetDetailPage />', () => {
renderWithRouter(<BudgetDetailPageWrapper initialState={initialState} />);
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,
Expand All @@ -730,6 +735,7 @@ describe('<BudgetDetailPage />', () => {
show_removed: true,
is_reversed: true,
},
['[email protected]'],
);
});
});
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) {

Check warning on line 257 in src/data/services/EnterpriseAccessApiService.js

View check run for this annotation

Codecov / codecov/patch

src/data/services/EnterpriseAccessApiService.js#L257

Added line #L257 was not covered by tests
const queryParams = new URLSearchParams(options);
if (selectedEmails) {
selectedEmails.forEach((email) => queryParams.append('learners', email));

Check warning on line 260 in src/data/services/EnterpriseAccessApiService.js

View check run for this annotation

Codecov / codecov/patch

src/data/services/EnterpriseAccessApiService.js#L260

Added line #L260 was not covered by tests
}
const subsidyHydratedGroupLearnersEndpoint = `${EnterpriseAccessApiService.baseUrl}/subsidy-access-policies/${subsidyAccessPolicyUUID}/group-members?${queryParams.toString()}`;
return EnterpriseAccessApiService.apiClient().get(subsidyHydratedGroupLearnersEndpoint);
}
Expand Down

0 comments on commit a5cd207

Please sign in to comment.