Radarr/frontend/src/Activity/Queue/QueueStatusCell.js

158 lines
3.9 KiB
JavaScript
Raw Normal View History

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';
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,
trackedDownloadStatus,
trackedDownloadState,
2018-11-23 07:04:42 +00:00
statusMessages,
errorMessage
} = props;
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
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
}
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
}
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');
if (trackedDownloadState === 'importPending') {
2020-09-01 03:41:20 +00:00
title += ` - ${translate('WaitingToImport')}`;
iconKind = kinds.PURPLE;
}
if (trackedDownloadState === 'importing') {
2020-09-01 03:41:20 +00:00
title += ` - ${translate('Importing')}`;
iconKind = kinds.PURPLE;
}
if (trackedDownloadState === 'failedPending') {
2020-09-01 03:41:20 +00:00
title += ` - ${translate('WaitingToProcess')}`;
iconKind = kinds.DANGER;
}
2018-11-23 07:04:42 +00:00
}
if (hasWarning) {
iconKind = kinds.WARNING;
}
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
}
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
}
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');
title = translate('DownloadWarning', { warningMessage });
2018-11-23 07:04:42 +00:00
}
if (hasError) {
if (status === 'completed') {
2018-11-23 07:04:42 +00:00
iconName = icons.DOWNLOAD;
iconKind = kinds.DANGER;
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}
canFlip={false}
2018-11-23 07:04:42 +00:00
/>
</TableRowCell>
);
}
QueueStatusCell.propTypes = {
sourceTitle: PropTypes.string.isRequired,
status: PropTypes.string.isRequired,
trackedDownloadStatus: PropTypes.string.isRequired,
trackedDownloadState: PropTypes.string.isRequired,
2018-11-23 07:04:42 +00:00
statusMessages: PropTypes.arrayOf(PropTypes.object),
errorMessage: PropTypes.string
};
QueueStatusCell.defaultProps = {
2020-09-01 03:41:20 +00:00
trackedDownloadStatus: translate('Ok'),
trackedDownloadState: translate('Downloading')
};
2018-11-23 07:04:42 +00:00
export default QueueStatusCell;