Skip to content

Commit

Permalink
Merge pull request #4912 from dfe-analytical-services/EES-5174
Browse files Browse the repository at this point in the history
EES-5174 fix data catalogue download all button
  • Loading branch information
amyb-hiveit authored Jun 3, 2024
2 parents 684ac2d + 0a4db51 commit 6d8be51
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import WarningMessage from '@common/components/WarningMessage';
import VisuallyHidden from '@common/components/VisuallyHidden';
import ButtonText from '@common/components/ButtonText';
import Tag from '@common/components/Tag';
import Button from '@common/components/Button';
import ButtonLink from '@frontend/components/ButtonLink';
import NotificationBanner from '@common/components/NotificationBanner';
import { releaseTypes } from '@common/services/types/releaseType';
import downloadService from '@common/services/downloadService';
import { Theme } from '@common/services/publicationService';
import { useMobileMedia } from '@common/hooks/useMedia';
import { SortDirection } from '@common/services/types/sort';
Expand Down Expand Up @@ -229,20 +228,6 @@ export default function DataCataloguePageNew({ showTypeFilter }: Props) {
});
};

const handleDownload = async () => {
if (!selectedPublication || !selectedRelease) {
return;
}
const fileIds = dataSets.map(dataSet => dataSet.fileId);
await downloadService.downloadFiles(selectedRelease.id, fileIds);

logEvent({
category: 'Data catalogue',
action: 'Data set file download - all',
label: `Publication: ${selectedPublication.title}, Release: ${selectedRelease.title}`,
});
};

const handleSortByChange = async (nextSortBy: DataSetFileSortOption) => {
await updateQueryParams({
...omit(router.query, 'page'),
Expand Down Expand Up @@ -516,14 +501,28 @@ export default function DataCataloguePageNew({ showTypeFilter }: Props) {
</div>

<p>
<Button
className="govuk-!-margin-bottom-0"
onClick={handleDownload}
>{`Download ${
dataSets.length === 1
? '1 data set'
: `all ${dataSets.length} data sets`
} (ZIP)`}</Button>
<ButtonLink
className="govuk-!-margin-bottom-2"
to={`${process.env.CONTENT_API_BASE_URL}/releases/${selectedRelease.id}/files`}
onClick={() => {
logEvent({
category: 'Data catalogue',
action: 'Data set file download - all',
label: `Publication: ${selectedPublication.title}, Release: ${selectedRelease.title}`,
});
}}
>
{`Download ${
totalResults === 1
? '1 data set'
: `all ${totalResults} data sets`
} (ZIP)`}
</ButtonLink>
<br />
<span>
Download includes data guidance and supporting
files.
</span>
</p>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ describe('DataCataloguePage', () => {
releaseInfo.getByText('This is the latest data'),
).toBeInTheDocument();
expect(
releaseInfo.getByRole('button', {
releaseInfo.getByRole('link', {
name: 'Download 1 data set (ZIP)',
}),
).toBeInTheDocument();
Expand Down Expand Up @@ -937,7 +937,7 @@ describe('DataCataloguePage', () => {
releaseInfo.getByText('This is not the latest data'),
).toBeInTheDocument();
expect(
releaseInfo.getByRole('button', {
releaseInfo.getByRole('link', {
name: 'Download all 2 data sets (ZIP)',
}),
).toBeInTheDocument();
Expand Down

0 comments on commit 6d8be51

Please sign in to comment.