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 707adfc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 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
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 707adfc

Please sign in to comment.