import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import Icon from 'Components/Icon'; import Label from 'Components/Label'; import IconButton from 'Components/Link/IconButton'; import Link from 'Components/Link/Link'; import MonitorToggleButton from 'Components/MonitorToggleButton'; import Table from 'Components/Table/Table'; import TableBody from 'Components/Table/TableBody'; import Popover from 'Components/Tooltip/Popover'; import { icons, kinds, sizes, sortDirections, tooltipPositions } from 'Helpers/Props'; import OrganizePreviewModalConnector from 'Organize/OrganizePreviewModalConnector'; import TrackFileEditorModal from 'TrackFile/Editor/TrackFileEditorModal'; import isBefore from 'Utilities/Date/isBefore'; import formatBytes from 'Utilities/Number/formatBytes'; import translate from 'Utilities/String/translate'; import getToggledRange from 'Utilities/Table/getToggledRange'; import AlbumGroupInfo from './AlbumGroupInfo'; import AlbumRowConnector from './AlbumRowConnector'; import styles from './ArtistDetailsSeason.css'; function getAlbumStatistics(albums) { let albumCount = 0; let trackFileCount = 0; let totalAlbumCount = 0; let monitoredAlbumCount = 0; let hasMonitoredAlbums = false; let sizeOnDisk = 0; albums.forEach((album) => { if (album.statistics) { sizeOnDisk = sizeOnDisk + album.statistics.sizeOnDisk; trackFileCount = trackFileCount + album.statistics.trackFileCount; if (album.statistics.trackFileCount === album.statistics.totalTrackCount || (album.monitored && isBefore(album.airDateUtc))) { albumCount++; } } if (album.monitored) { monitoredAlbumCount++; hasMonitoredAlbums = true; } totalAlbumCount++; }); return { albumCount, totalAlbumCount, trackFileCount, monitoredAlbumCount, sizeOnDisk, hasMonitoredAlbums }; } function getAlbumCountKind(monitored, albumCount, monitoredAlbumCount) { if (albumCount === monitoredAlbumCount && monitoredAlbumCount > 0) { return kinds.SUCCESS; } if (!monitored) { return kinds.WARNING; } return kinds.DANGER; } class ArtistDetailsSeason extends Component { // // Lifecycle constructor(props, context) { super(props, context); this.state = { isOrganizeModalOpen: false, isManageTracksOpen: false, lastToggledAlbum: null }; } componentDidMount() { this._expandByDefault(); } componentDidUpdate(prevProps) { const { artistId } = this.props; if (prevProps.artistId !== artistId) { this._expandByDefault(); return; } } // // Control _expandByDefault() { const { name, onExpandPress, items, uiSettings } = this.props; const expand = _.some(items, (item) => ((item.albumType === 'Album') && uiSettings.expandAlbumByDefault) || ((item.albumType === 'Single') && uiSettings.expandSingleByDefault) || ((item.albumType === 'EP') && uiSettings.expandEPByDefault) || ((item.albumType === 'Broadcast') && uiSettings.expandBroadcastByDefault) || ((item.albumType === 'Other') && uiSettings.expandOtherByDefault)); onExpandPress(name, expand); } // // Listeners onOrganizePress = () => { this.setState({ isOrganizeModalOpen: true }); }; onOrganizeModalClose = () => { this.setState({ isOrganizeModalOpen: false }); }; onManageTracksPress = () => { this.setState({ isManageTracksOpen: true }); }; onManageTracksModalClose = () => { this.setState({ isManageTracksOpen: false }); }; onExpandPress = () => { const { name, isExpanded } = this.props; this.props.onExpandPress(name, !isExpanded); }; onMonitorAlbumPress = (albumId, monitored, { shiftKey }) => { const lastToggled = this.state.lastToggledAlbum; const albumIds = [albumId]; if (shiftKey && lastToggled) { const { lower, upper } = getToggledRange(this.props.items, albumId, lastToggled); const items = this.props.items; for (let i = lower; i < upper; i++) { albumIds.push(items[i].id); } } this.setState({ lastToggledAlbum: albumId }); this.props.onMonitorAlbumsPress(_.uniq(albumIds), monitored); }; onMonitorAlbumsPress = (monitored, { shiftKey }) => { const albumIds = this.props.items.map((a) => a.id); this.props.onMonitorAlbumsPress(_.uniq(albumIds), monitored); }; // // Render render() { const { artistId, label, items, columns, isSaving, isExpanded, artistMonitored, sortKey, sortDirection, onSortPress, isSmallScreen, onTableOptionChange } = this.props; const { albumCount, totalAlbumCount, trackFileCount, monitoredAlbumCount, hasMonitoredAlbums, sizeOnDisk } = getAlbumStatistics(items); const { isOrganizeModalOpen, isManageTracksOpen } = this.state; return (