2018-11-23 07:04:42 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
|
|
|
import Icon from 'Components/Icon';
|
|
|
|
import TableRowCell from 'Components/Table/Cells/TableRowCell';
|
|
|
|
import Popover from 'Components/Tooltip/Popover';
|
2020-07-28 18:47:25 +00:00
|
|
|
import { icons, kinds, tooltipPositions } from 'Helpers/Props';
|
2020-09-01 03:41:20 +00:00
|
|
|
import translate from 'Utilities/String/translate';
|
2018-11-23 07:04:42 +00:00
|
|
|
import styles from './QueueStatusCell.css';
|
|
|
|
|
|
|
|
function getDetailedPopoverBody(statusMessages) {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{
|
|
|
|
statusMessages.map(({ title, messages }) => {
|
|
|
|
return (
|
|
|
|
<div key={title}>
|
|
|
|
{title}
|
|
|
|
<ul>
|
|
|
|
{
|
|
|
|
messages.map((message) => {
|
|
|
|
return (
|
|
|
|
<li key={message}>
|
|
|
|
{message}
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function QueueStatusCell(props) {
|
|
|
|
const {
|
|
|
|
sourceTitle,
|
|
|
|
status,
|
2020-03-29 17:48:34 +00:00
|
|
|
trackedDownloadStatus,
|
|
|
|
trackedDownloadState,
|
2018-11-23 07:04:42 +00:00
|
|
|
statusMessages,
|
|
|
|
errorMessage
|
|
|
|
} = props;
|
|
|
|
|
2020-03-29 17:48:34 +00:00
|
|
|
const hasWarning = trackedDownloadStatus === 'warning';
|
|
|
|
const hasError = trackedDownloadStatus === 'error';
|
2018-11-23 07:04:42 +00:00
|
|
|
|
|
|
|
// status === 'downloading'
|
|
|
|
let iconName = icons.DOWNLOADING;
|
|
|
|
let iconKind = kinds.DEFAULT;
|
2020-09-01 03:41:20 +00:00
|
|
|
let title = translate('Downloading');
|
2018-11-23 07:04:42 +00:00
|
|
|
|
2020-03-29 17:48:34 +00:00
|
|
|
if (status === 'paused') {
|
2018-11-23 07:04:42 +00:00
|
|
|
iconName = icons.PAUSED;
|
2020-09-01 03:41:20 +00:00
|
|
|
title = translate('Paused');
|
2018-11-23 07:04:42 +00:00
|
|
|
}
|
|
|
|
|
2020-03-29 17:48:34 +00:00
|
|
|
if (status === 'queued') {
|
2018-11-23 07:04:42 +00:00
|
|
|
iconName = icons.QUEUED;
|
2020-09-01 03:41:20 +00:00
|
|
|
title = translate('Queued');
|
2018-11-23 07:04:42 +00:00
|
|
|
}
|
|
|
|
|
2020-03-29 17:48:34 +00:00
|
|
|
if (status === 'completed') {
|
2018-11-23 07:04:42 +00:00
|
|
|
iconName = icons.DOWNLOADED;
|
2020-09-01 03:41:20 +00:00
|
|
|
title = translate('Downloaded');
|
2020-03-29 17:48:34 +00:00
|
|
|
|
|
|
|
if (trackedDownloadState === 'importPending') {
|
2020-09-01 03:41:20 +00:00
|
|
|
title += ` - ${translate('WaitingToImport')}`;
|
2020-05-24 20:30:33 +00:00
|
|
|
iconKind = kinds.PURPLE;
|
2020-03-29 17:48:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (trackedDownloadState === 'importing') {
|
2020-09-01 03:41:20 +00:00
|
|
|
title += ` - ${translate('Importing')}`;
|
2020-05-24 20:30:33 +00:00
|
|
|
iconKind = kinds.PURPLE;
|
2020-03-29 17:48:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (trackedDownloadState === 'failedPending') {
|
2020-09-01 03:41:20 +00:00
|
|
|
title += ` - ${translate('WaitingToProcess')}`;
|
2020-05-24 20:30:33 +00:00
|
|
|
iconKind = kinds.DANGER;
|
2020-03-29 17:48:34 +00:00
|
|
|
}
|
2018-11-23 07:04:42 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 20:30:33 +00:00
|
|
|
if (hasWarning) {
|
|
|
|
iconKind = kinds.WARNING;
|
|
|
|
}
|
|
|
|
|
2020-03-29 17:48:34 +00:00
|
|
|
if (status === 'delay') {
|
2018-11-23 07:04:42 +00:00
|
|
|
iconName = icons.PENDING;
|
2020-09-01 03:41:20 +00:00
|
|
|
title = translate('Pending');
|
2018-11-23 07:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (status === 'DownloadClientUnavailable') {
|
|
|
|
iconName = icons.PENDING;
|
|
|
|
iconKind = kinds.WARNING;
|
2020-09-01 03:41:20 +00:00
|
|
|
title = `${translate('Pending')} - ${translate('DownloadClientUnavailable')}`;
|
2018-11-23 07:04:42 +00:00
|
|
|
}
|
|
|
|
|
2020-03-29 17:48:34 +00:00
|
|
|
if (status === 'failed') {
|
2018-11-23 07:04:42 +00:00
|
|
|
iconName = icons.DOWNLOADING;
|
|
|
|
iconKind = kinds.DANGER;
|
2020-09-01 03:41:20 +00:00
|
|
|
title = translate('DownloadFailed');
|
2018-11-23 07:04:42 +00:00
|
|
|
}
|
|
|
|
|
2020-03-29 17:48:34 +00:00
|
|
|
if (status === 'warning') {
|
2018-11-23 07:04:42 +00:00
|
|
|
iconName = icons.DOWNLOADING;
|
|
|
|
iconKind = kinds.WARNING;
|
2020-09-01 03:41:20 +00:00
|
|
|
const warningMessage = errorMessage || translate('CheckDownloadClientForDetails');
|
2023-08-13 17:07:25 +00:00
|
|
|
title = translate('DownloadWarning', { warningMessage });
|
2018-11-23 07:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hasError) {
|
2020-03-29 17:48:34 +00:00
|
|
|
if (status === 'completed') {
|
2018-11-23 07:04:42 +00:00
|
|
|
iconName = icons.DOWNLOAD;
|
|
|
|
iconKind = kinds.DANGER;
|
2023-08-13 17:07:25 +00:00
|
|
|
title = translate('ImportFailed', { sourceTitle });
|
2018-11-23 07:04:42 +00:00
|
|
|
} else {
|
|
|
|
iconName = icons.DOWNLOADING;
|
|
|
|
iconKind = kinds.DANGER;
|
2020-09-01 03:41:20 +00:00
|
|
|
title = translate('DownloadFailed');
|
2018-11-23 07:04:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<TableRowCell className={styles.status}>
|
|
|
|
<Popover
|
|
|
|
anchor={
|
|
|
|
<Icon
|
|
|
|
name={iconName}
|
|
|
|
kind={iconKind}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
title={title}
|
|
|
|
body={hasWarning || hasError ? getDetailedPopoverBody(statusMessages) : sourceTitle}
|
|
|
|
position={tooltipPositions.RIGHT}
|
2019-06-14 03:54:25 +00:00
|
|
|
canFlip={false}
|
2018-11-23 07:04:42 +00:00
|
|
|
/>
|
|
|
|
</TableRowCell>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
QueueStatusCell.propTypes = {
|
|
|
|
sourceTitle: PropTypes.string.isRequired,
|
|
|
|
status: PropTypes.string.isRequired,
|
2020-03-29 17:48:34 +00:00
|
|
|
trackedDownloadStatus: PropTypes.string.isRequired,
|
|
|
|
trackedDownloadState: PropTypes.string.isRequired,
|
2018-11-23 07:04:42 +00:00
|
|
|
statusMessages: PropTypes.arrayOf(PropTypes.object),
|
|
|
|
errorMessage: PropTypes.string
|
|
|
|
};
|
|
|
|
|
2020-03-29 17:48:34 +00:00
|
|
|
QueueStatusCell.defaultProps = {
|
2020-09-01 03:41:20 +00:00
|
|
|
trackedDownloadStatus: translate('Ok'),
|
|
|
|
trackedDownloadState: translate('Downloading')
|
2020-03-29 17:48:34 +00:00
|
|
|
};
|
|
|
|
|
2018-11-23 07:04:42 +00:00
|
|
|
export default QueueStatusCell;
|