Skip to content

Commit 67ddd01

Browse files
Merge pull request #1715 from ral-facilities/bugfix/hide-progressbars
Handle isDeleted and no prepared id cases in progress bars
2 parents 65abb84 + f600c27 commit 67ddd01

File tree

8 files changed

+82
-16
lines changed

8 files changed

+82
-16
lines changed

packages/datagateway-common/src/app.types.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ export interface Download {
266266
isDeleted: boolean;
267267
isEmailSent: boolean;
268268
isTwoLevel: boolean;
269-
preparedId: string;
269+
preparedId?: string;
270270
sessionId: string;
271271
size: number;
272272
status: DownloadStatus;

packages/datagateway-download/public/res/default.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
"progress": "Progress",
3939
"calculating_progress": "Calculating...",
4040
"progress_unavailable": "Unknown",
41-
"progress_complete": ""
41+
"progress_complete": "",
42+
"progress_queued": "Queued"
4243
},
4344
"downloadConfirmDialog": {
4445
"close_arialabel": "Close download confirmation dialog",

packages/datagateway-download/src/downloadApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export const getPercentageComplete = async ({
324324
preparedId,
325325
settings: { idsUrl },
326326
}: {
327-
preparedId: string;
327+
preparedId: string | undefined;
328328
settings: { idsUrl: string };
329329
}): Promise<DownloadProgress> => {
330330
const { data } = await axios.get(`${idsUrl}/getPercentageComplete`, {

packages/datagateway-download/src/downloadApiHooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ export const useDownloadPercentageComplete = <T = DownloadProgress>({
735735
const idsUrl = accessMethods[download.transport]?.idsUrl;
736736

737737
return useQuery(
738-
[QueryKey.DOWNLOAD_PROGRESS, preparedId],
738+
[QueryKey.DOWNLOAD_PROGRESS, preparedId ?? ''], // undefined preparedId is handled in downloadProgressIndicator & disables the query anyway
739739
() =>
740740
getPercentageComplete({
741741
preparedId: preparedId,

packages/datagateway-download/src/downloadConfirmation/downloadConfirmDialog.component.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ const DownloadConfirmDialog: React.FC<DownloadConfirmDialogProps> = (
218218
if (
219219
isDownloadInfoAvailable &&
220220
downloadInfo &&
221+
downloadInfo.preparedId &&
221222
downloadInfo.status === 'COMPLETE'
222223
) {
223224
// Download the file as long as it is available for instant download.

packages/datagateway-download/src/downloadStatus/downloadProgressIndicator.component.test.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ function renderComponent({ download = mockDownload } = {}): RenderResult {
4141
}
4242

4343
describe('DownloadProgressIndicator', () => {
44+
afterEach(() => {
45+
jest.clearAllMocks();
46+
});
47+
4448
describe('should show calculating text', () => {
4549
it('when querying the download progress', async () => {
4650
(
@@ -106,6 +110,21 @@ describe('DownloadProgressIndicator', () => {
106110
// should not show progress bar
107111
expect(screen.queryByRole('progressbar')).toBeNull();
108112
});
113+
114+
it('when download is deleted', async () => {
115+
renderComponent({
116+
download: {
117+
...mockDownload,
118+
isDeleted: true,
119+
},
120+
});
121+
122+
expect(
123+
await screen.findByText('downloadStatus.progress_complete')
124+
).toBeInTheDocument();
125+
// should not show progress bar
126+
expect(screen.queryByRole('progressbar')).toBeNull();
127+
});
109128
});
110129

111130
describe('should show unavailable', () => {
@@ -124,6 +143,20 @@ describe('DownloadProgressIndicator', () => {
124143
await screen.findByText('downloadStatus.progress_unavailable')
125144
).toBeInTheDocument();
126145
});
146+
147+
it('when download has no preparedId', async () => {
148+
renderComponent({
149+
download: {
150+
...mockDownload,
151+
preparedId: undefined,
152+
},
153+
});
154+
155+
expect(
156+
await screen.findByText('downloadStatus.progress_unavailable')
157+
).toBeInTheDocument();
158+
expect(getPercentageComplete).not.toHaveBeenCalled();
159+
});
127160
});
128161

129162
it('should show progress at 0% when the download is being prepared', async () => {
@@ -140,6 +173,21 @@ describe('DownloadProgressIndicator', () => {
140173
expect(screen.getByText('0%')).toBeInTheDocument();
141174
});
142175

176+
it('should show queued when download is paused and has no preparedId', async () => {
177+
renderComponent({
178+
download: {
179+
...mockDownload,
180+
status: 'PAUSED',
181+
preparedId: undefined,
182+
},
183+
});
184+
185+
expect(
186+
await screen.findByText('downloadStatus.progress_queued')
187+
).toBeInTheDocument();
188+
expect(getPercentageComplete).not.toHaveBeenCalled();
189+
});
190+
143191
it('should show progress of the given download item', async () => {
144192
(
145193
getPercentageComplete as jest.MockedFunction<typeof getPercentageComplete>

packages/datagateway-download/src/downloadStatus/downloadProgressIndicator.component.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,36 @@ function DownloadProgressIndicator({
2121
const { data: progress, isLoading: isLoadingProgress } =
2222
useDownloadPercentageComplete({
2323
download,
24-
enabled: download.status === 'RESTORING' || download.status === 'PAUSED',
24+
enabled:
25+
!download.isDeleted &&
26+
typeof download.preparedId !== 'undefined' && // do not send download status request for downloads with no preparedId as it will just fail
27+
(download.status === 'RESTORING' || download.status === 'PAUSED'),
2528
});
2629

2730
if (isLoadingProgress) {
2831
return <>{t('downloadStatus.calculating_progress')}</>;
2932
}
3033

31-
// if the download is already completed/restored
32-
// should show text such as N/A, completed, or empty string.
34+
// if the download is completed, expired or deleted
35+
// should show text such as N/A or empty string.
3336
// depending on the translation configuration.
34-
if (download.status === 'COMPLETE' || download.status === 'EXPIRED')
37+
if (
38+
download.status === 'COMPLETE' ||
39+
download.status === 'EXPIRED' ||
40+
download.isDeleted
41+
)
3542
return <>{t('downloadStatus.progress_complete')}</>;
3643

3744
// if the download is being prepared, show 0%
3845
if (download.status === 'PREPARING') return <ProgressBar progress={0} />;
3946

47+
// if the download is paused with no preparedId, show that it is queued
48+
if (
49+
download.status === 'PAUSED' &&
50+
typeof download.preparedId === 'undefined'
51+
)
52+
return <>{t('downloadStatus.progress_queued')}</>;
53+
4054
// display a label indicating progress unavailable when
4155
// progress is not returned or the download status doesn't match.
4256
if (typeof progress === 'undefined')

packages/datagateway-download/src/downloadStatus/downloadStatusTable.component.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,12 @@ const DownloadStatusTable: React.FC<DownloadStatusTableProps> = (
357357
actionsWidth={100}
358358
actions={[
359359
function DownloadButton({ rowData }: TableActionProps) {
360-
const downloadItem = rowData as FormattedDownload;
361-
const isHTTP = !!downloadItem.transport.match(/https|http/);
360+
const { transport, status, preparedId, fileName, id } =
361+
rowData as FormattedDownload;
362+
const isHTTP = !!transport.match(/https|http/);
362363

363-
const isComplete = downloadItem.status === 'COMPLETE';
364+
const isComplete =
365+
status === 'COMPLETE' && typeof preparedId !== 'undefined';
364366

365367
const isDownloadable = isHTTP && isComplete;
366368

@@ -370,7 +372,7 @@ const DownloadStatusTable: React.FC<DownloadStatusTableProps> = (
370372
!isHTTP
371373
? t<string, string>(
372374
'downloadStatus.non_https_download_disabled_tooltip',
373-
{ transport: downloadItem.transport }
375+
{ transport }
374376
)
375377
: t<string, string>(
376378
'downloadStatus.https_download_disabled_tooltip'
@@ -386,17 +388,17 @@ const DownloadStatusTable: React.FC<DownloadStatusTableProps> = (
386388
? {
387389
component: 'a',
388390
href: getDataUrl(
389-
downloadItem.preparedId,
390-
downloadItem.fileName,
391+
preparedId,
392+
fileName,
391393
settings.idsUrl
392394
),
393395
target: '_blank',
394396
}
395397
: { component: 'button' })}
396398
aria-label={t('downloadStatus.download', {
397-
filename: downloadItem.fileName,
399+
filename: fileName,
398400
})}
399-
key={`download-${downloadItem.id}`}
401+
key={`download-${id}`}
400402
size="small"
401403
disabled={!isDownloadable}
402404
>

0 commit comments

Comments
 (0)