Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allowing group data download button to apply to selected rows #1230

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -124,6 +124,7 @@ const LearnerCreditGroupMembersTable = ({
setRefresh={setRefresh}
groupUuid={groupUuid}
/>,
<GroupMembersCsvDownloadTableAction />,
]}
additionalColumns={[
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,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 @@ -732,6 +737,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 @@
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
Loading