feat(DICOM Upload): Added new DICOM upload dialogue launched from the worklist page (#3326)

* feat(DICOM Upload)
OHIF #3297
- DicomWebDataSource.store.dicom now accepts an ArrayBuffer of data sets to store
- DicomWebDataSource.store.dicom now also accepts optional callbacks to track upload and an AbortSignal object to cancel upload
- Added DicomFileUploader class that performs and tracks the upload of a DICOM file
- Added various UI pieces for the upload: DicomUpload, DicomUploadProgress, DicomUploadProgressItem
- ProgressLoadingBar was extracted from LoadingIndicatorProgress so it can be reused
- Modal dialogues can now optionally prevent an outside click from closing the Modal

* Passing an XMLHttpRequest to the dataSource.store.dicom method instead of callbacks and AbortSignal.
Cleanup of various UI pieces to minimize code and increase readability.

* Made the DicomUpload component a customization module exported by the cornerstone extension.

* Exposed a copy of the data source configuration via the IWebApiDataSource interface.
Added dicomUploadEnabled to a data source's configuration.

* Code clean up.

* Upgraded the dicomweb-client version to one that provides the ability to
pass a custom HTTP request. DICOM upload uses that custom HTTP request
to track progress and cancel requests.

* Distinguished between failed and cancelled uploads.

* Allow no selection in the upload dialogue.
Fixed the styling of various progress information so that everything aligns.

* Switched from cornerstone wado image loader to cornerstone dicom image loader for DICOM upload.

* Added special cancelled icon to differentiate from failed.

* Added a bit of spacing between the upload progress bar and percentage.

* Fixed minor issue with upload rejection.

* Performance improvement for cancel all uploads:
- use React memo for each upload item progress (row)
- do not await each request of a cancel all

* Fixed various padding/spacing for the DICOM upload drop zone component.
Changed the border dashing for the DICOM upload drop zone to be a background image gradient.
Added hover and active effects to the 'Cancel All Uploads' text.
This commit is contained in:
Joe Boccanfuso authored and GitHub committed 2023-04-28 16:13:47 -04:00
1 parent f377153b60
commit 66f6e3eade
32 files changed
+1126 -350

No files matched your search

@@ -0,0 +1,117 @@
import React, {
ReactElement,
memo,
useCallback,
useEffect,
useState,
} from 'react';
import PropTypes from 'prop-types';
import DicomFileUploader, {
DicomFileUploaderProgressEvent,
EVENTS,
UploadRejection,
UploadStatus,
} from '../../utils/DicomFileUploader';
import { Icon } from '@ohif/ui';
type DicomUploadProgressItemProps = {
dicomFileUploader: DicomFileUploader;
};
// eslint-disable-next-line react/display-name
const DicomUploadProgressItem = memo(
({ dicomFileUploader }: DicomUploadProgressItemProps): ReactElement => {
const [percentComplete, setPercentComplete] = useState(
dicomFileUploader.getPercentComplete()
);
const [failedReason, setFailedReason] = useState('');
const [status, setStatus] = useState(dicomFileUploader.getStatus());
console.info(`${dicomFileUploader.getFileId()}`);
const isComplete = useCallback(() => {
return (
status === UploadStatus.Failed ||
status === UploadStatus.Cancelled ||
status === UploadStatus.Success
);
}, [status]);
useEffect(() => {
const progressSubscription = dicomFileUploader.subscribe(
EVENTS.PROGRESS,
(dicomFileUploaderProgressEvent: DicomFileUploaderProgressEvent) => {
setPercentComplete(dicomFileUploaderProgressEvent.percentComplete);
}
);
dicomFileUploader
.load()
.catch((reason: UploadRejection) => {
setStatus(reason.status);
setFailedReason(reason.message ?? '');
})
.finally(() => setStatus(dicomFileUploader.getStatus()));
return () => progressSubscription.unsubscribe();
}, []);
const cancelUpload = useCallback(() => {
dicomFileUploader.cancel();
}, []);
const getStatusIcon = (): ReactElement => {
switch (dicomFileUploader.getStatus()) {
case UploadStatus.Success:
return (
<Icon name="status-tracked" className="text-primary-light"></Icon>
);
case UploadStatus.InProgress:
return <Icon name="icon-transferring"></Icon>;
case UploadStatus.Failed:
return <Icon name="icon-alert-small"></Icon>;
case UploadStatus.Cancelled:
return <Icon name="icon-alert-outline"></Icon>;
default:
return <></>;
}
};
return (
<div className="flex w-full p-2.5 text-lg min-h-14 items-center border-b border-secondary-light overflow-hidden">
<div className="flex flex-col gap-1 self-top w-0 grow shrink">
<div className="flex gap-4">
<div className="flex w-6 justify-center items-center shrink-0">
{getStatusIcon()}
</div>
<div className="text-ellipsis whitespace-nowrap overflow-hidden">
{dicomFileUploader.getFileName()}
</div>
</div>
{failedReason && <div className="pl-10">{failedReason}</div>}
</div>
<div className="w-24 flex items-center">
{!isComplete() && (
<>
{dicomFileUploader.getStatus() === UploadStatus.InProgress && (
<div className="w-10 text-right">{percentComplete}%</div>
)}
<div className="flex cursor-pointer ml-auto">
<Icon
className="w-6 h-6 self-center text-primary-active"
name="close"
onClick={cancelUpload}
/>
</div>
</>
)}
</div>
</div>
);
}
);
DicomUploadProgressItem.propTypes = {
dicomFileUploader: PropTypes.instanceOf(DicomFileUploader).isRequired,
};
export default DicomUploadProgressItem;