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 a11d51d
Show file tree
Hide file tree
Showing 4 changed files with 18 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
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ describe('<BudgetDetailPage />', () => {
show_removed: true,
is_reversed: true,
},
[],
);
});
});
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 a11d51d

Please sign in to comment.