2018-11-23 07:04:42 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2023-10-21 07:39:41 +00:00
|
|
|
import Icon from 'Components/Icon';
|
2020-07-28 18:47:25 +00:00
|
|
|
import TableRowCell from 'Components/Table/Cells/TableRowCell';
|
2023-10-21 07:39:41 +00:00
|
|
|
import Tooltip from 'Components/Tooltip/Tooltip';
|
|
|
|
import { icons, kinds, tooltipPositions } from 'Helpers/Props';
|
2018-11-23 07:04:42 +00:00
|
|
|
import formatTime from 'Utilities/Date/formatTime';
|
|
|
|
import formatTimeSpan from 'Utilities/Date/formatTimeSpan';
|
|
|
|
import getRelativeDate from 'Utilities/Date/getRelativeDate';
|
|
|
|
import formatBytes from 'Utilities/Number/formatBytes';
|
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 './TimeleftCell.css';
|
|
|
|
|
|
|
|
function TimeleftCell(props) {
|
|
|
|
const {
|
|
|
|
estimatedCompletionTime,
|
|
|
|
timeleft,
|
|
|
|
status,
|
|
|
|
size,
|
|
|
|
sizeleft,
|
|
|
|
showRelativeDates,
|
|
|
|
shortDateFormat,
|
|
|
|
timeFormat
|
|
|
|
} = props;
|
|
|
|
|
2020-05-24 20:30:33 +00:00
|
|
|
if (status === 'delay') {
|
2018-11-23 07:04:42 +00:00
|
|
|
const date = getRelativeDate(estimatedCompletionTime, shortDateFormat, showRelativeDates);
|
|
|
|
const time = formatTime(estimatedCompletionTime, timeFormat, { includeMinuteZero: true });
|
|
|
|
|
|
|
|
return (
|
2023-10-21 07:39:41 +00:00
|
|
|
<TableRowCell className={styles.timeleft}>
|
|
|
|
<Tooltip
|
|
|
|
anchor={<Icon name={icons.INFO} />}
|
|
|
|
tooltip={translate('DelayingDownloadUntil', { date, time })}
|
|
|
|
kind={kinds.INVERSE}
|
|
|
|
position={tooltipPositions.TOP}
|
|
|
|
/>
|
2018-11-23 07:04:42 +00:00
|
|
|
</TableRowCell>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-05-24 20:30:33 +00:00
|
|
|
if (status === 'downloadClientUnavailable') {
|
2018-11-23 07:04:42 +00:00
|
|
|
const date = getRelativeDate(estimatedCompletionTime, shortDateFormat, showRelativeDates);
|
|
|
|
const time = formatTime(estimatedCompletionTime, timeFormat, { includeMinuteZero: true });
|
|
|
|
|
|
|
|
return (
|
2023-10-21 07:39:41 +00:00
|
|
|
<TableRowCell className={styles.timeleft}>
|
|
|
|
<Tooltip
|
|
|
|
anchor={<Icon name={icons.INFO} />}
|
|
|
|
tooltip={translate('RetryingDownloadOn', { date, time })}
|
|
|
|
kind={kinds.INVERSE}
|
|
|
|
position={tooltipPositions.TOP}
|
|
|
|
/>
|
2018-11-23 07:04:42 +00:00
|
|
|
</TableRowCell>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-05-24 20:30:33 +00:00
|
|
|
if (!timeleft || status === 'completed' || status === 'failed') {
|
2018-11-23 07:04:42 +00:00
|
|
|
return (
|
|
|
|
<TableRowCell className={styles.timeleft}>
|
|
|
|
-
|
|
|
|
</TableRowCell>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const totalSize = formatBytes(size);
|
|
|
|
const remainingSize = formatBytes(sizeleft);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<TableRowCell
|
|
|
|
className={styles.timeleft}
|
|
|
|
title={`${remainingSize} / ${totalSize}`}
|
|
|
|
>
|
|
|
|
{formatTimeSpan(timeleft)}
|
|
|
|
</TableRowCell>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeleftCell.propTypes = {
|
|
|
|
estimatedCompletionTime: PropTypes.string,
|
|
|
|
timeleft: PropTypes.string,
|
|
|
|
status: PropTypes.string.isRequired,
|
|
|
|
size: PropTypes.number.isRequired,
|
|
|
|
sizeleft: PropTypes.number.isRequired,
|
|
|
|
showRelativeDates: PropTypes.bool.isRequired,
|
|
|
|
shortDateFormat: PropTypes.string.isRequired,
|
|
|
|
timeFormat: PropTypes.string.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
export default TimeleftCell;
|