import classNames from 'classnames';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import CheckInput from 'Components/Form/CheckInput';
import HeartRating from 'Components/HeartRating';
import IconButton from 'Components/Link/IconButton';
import Link from 'Components/Link/Link';
import SpinnerIconButton from 'Components/Link/SpinnerIconButton';
import ProgressBar from 'Components/ProgressBar';
import RelativeDateCellConnector from 'Components/Table/Cells/RelativeDateCellConnector';
import VirtualTableRowCell from 'Components/Table/Cells/VirtualTableRowCell';
import TagListConnector from 'Components/TagListConnector';
import { icons } from 'Helpers/Props';
import DeleteSeriesModal from 'Series/Delete/DeleteSeriesModal';
import EditSeriesModalConnector from 'Series/Edit/EditSeriesModalConnector';
import SeriesBanner from 'Series/SeriesBanner';
import SeriesTitleLink from 'Series/SeriesTitleLink';
import formatBytes from 'Utilities/Number/formatBytes';
import getProgressBarKind from 'Utilities/Series/getProgressBarKind';
import titleCase from 'Utilities/String/titleCase';
import hasGrowableColumns from './hasGrowableColumns';
import SeriesStatusCell from './SeriesStatusCell';
import styles from './SeriesIndexRow.css';
class SeriesIndexRow extends Component {
//
// Lifecycle
constructor(props, context) {
super(props, context);
this.state = {
hasBannerError: false,
isEditSeriesModalOpen: false,
isDeleteSeriesModalOpen: false
};
}
onEditSeriesPress = () => {
this.setState({ isEditSeriesModalOpen: true });
};
onEditSeriesModalClose = () => {
this.setState({ isEditSeriesModalOpen: false });
};
onDeleteSeriesPress = () => {
this.setState({
isEditSeriesModalOpen: false,
isDeleteSeriesModalOpen: true
});
};
onDeleteSeriesModalClose = () => {
this.setState({ isDeleteSeriesModalOpen: false });
};
onUseSceneNumberingChange = () => {
// Mock handler to satisfy `onChange` being required for `CheckInput`.
//
};
onBannerLoad = () => {
if (this.state.hasBannerError) {
this.setState({ hasBannerError: false });
}
};
onBannerLoadError = () => {
if (!this.state.hasBannerError) {
this.setState({ hasBannerError: true });
}
};
//
// Render
render() {
const {
id,
monitored,
status,
title,
titleSlug,
seriesType,
network,
originalLanguage,
qualityProfile,
nextAiring,
previousAiring,
added,
statistics,
latestSeason,
year,
path,
genres,
ratings,
certification,
tags,
images,
useSceneNumbering,
showBanners,
showSearchAction,
columns,
isRefreshingSeries,
isSearchingSeries,
onRefreshSeriesPress,
onSearchPress
} = this.props;
const {
seasonCount,
episodeCount,
episodeFileCount,
totalEpisodeCount,
releaseGroups,
sizeOnDisk
} = statistics;
const {
hasBannerError,
isEditSeriesModalOpen,
isDeleteSeriesModalOpen
} = this.state;
return (
<>
{
columns.map((column) => {
const {
name,
isVisible
} = column;
if (!isVisible) {
return null;
}
if (name === 'status') {
return (
);
}
if (name === 'sortTitle') {
return (
{
showBanners ?
{
hasBannerError &&
{title}
}
:
}
);
}
if (name === 'seriesType') {
return (
{titleCase(seriesType)}
);
}
if (name === 'network') {
return (
{network}
);
}
if (name === 'originalLanguage') {
return (
{originalLanguage.name}
);
}
if (name === 'qualityProfileId') {
return (
{qualityProfile.name}
);
}
if (name === 'nextAiring') {
return (
);
}
if (name === 'previousAiring') {
return (
);
}
if (name === 'added') {
return (
);
}
if (name === 'seasonCount') {
return (
{seasonCount}
);
}
if (name === 'episodeProgress') {
const progress = episodeCount ? episodeFileCount / episodeCount * 100 : 100;
return (
);
}
if (name === 'latestSeason') {
if (!latestSeason) {
return (
);
}
const seasonStatistics = latestSeason.statistics || {};
const progress = seasonStatistics.episodeCount ?
seasonStatistics.episodeFileCount / seasonStatistics.episodeCount * 100 :
100;
return (
);
}
if (name === 'episodeCount') {
return (
{totalEpisodeCount}
);
}
if (name === 'year') {
return (
{year}
);
}
if (name === 'path') {
return (
{path}
);
}
if (name === 'sizeOnDisk') {
return (
{formatBytes(sizeOnDisk)}
);
}
if (name === 'genres') {
const joinedGenres = genres.join(', ');
return (
{joinedGenres}
);
}
if (name === 'ratings') {
return (
);
}
if (name === 'certification') {
return (
{certification}
);
}
if (name === 'releaseGroups') {
const joinedReleaseGroups = releaseGroups.join(', ');
const truncatedReleaseGroups = releaseGroups.length > 3 ?
`${releaseGroups.slice(0, 3).join(', ')}...` :
joinedReleaseGroups;
return (
{truncatedReleaseGroups}
);
}
if (name === 'tags') {
return (
);
}
if (name === 'useSceneNumbering') {
return (
);
}
if (name === 'actions') {
return (
{
showSearchAction &&
}
);
}
return null;
})
}
>
);
}
}
SeriesIndexRow.propTypes = {
id: PropTypes.number.isRequired,
monitored: PropTypes.bool.isRequired,
status: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
titleSlug: PropTypes.string.isRequired,
seriesType: PropTypes.string.isRequired,
originalLanguage: PropTypes.object.isRequired,
network: PropTypes.string,
qualityProfile: PropTypes.object.isRequired,
nextAiring: PropTypes.string,
previousAiring: PropTypes.string,
added: PropTypes.string,
statistics: PropTypes.object.isRequired,
latestSeason: PropTypes.object,
year: PropTypes.number,
path: PropTypes.string.isRequired,
genres: PropTypes.arrayOf(PropTypes.string).isRequired,
ratings: PropTypes.object.isRequired,
certification: PropTypes.string,
tags: PropTypes.arrayOf(PropTypes.number).isRequired,
images: PropTypes.arrayOf(PropTypes.object).isRequired,
useSceneNumbering: PropTypes.bool.isRequired,
showBanners: PropTypes.bool.isRequired,
showSearchAction: PropTypes.bool.isRequired,
columns: PropTypes.arrayOf(PropTypes.object).isRequired,
isRefreshingSeries: PropTypes.bool.isRequired,
isSearchingSeries: PropTypes.bool.isRequired,
onRefreshSeriesPress: PropTypes.func.isRequired,
onSearchPress: PropTypes.func.isRequired
};
SeriesIndexRow.defaultProps = {
statistics: {
seasonCount: 0,
episodeCount: 0,
episodeFileCount: 0,
totalEpisodeCount: 0,
releaseGroups: []
},
genres: [],
tags: []
};
export default SeriesIndexRow;