import PropTypes from 'prop-types'; import React, { Component } from 'react'; import Alert from 'Components/Alert'; import LoadingIndicator from 'Components/Loading/LoadingIndicator'; import FilterMenu from 'Components/Menu/FilterMenu'; import ConfirmModal from 'Components/Modal/ConfirmModal'; import PageContent from 'Components/Page/PageContent'; import PageContentBody from 'Components/Page/PageContentBody'; import PageToolbar from 'Components/Page/Toolbar/PageToolbar'; import PageToolbarButton from 'Components/Page/Toolbar/PageToolbarButton'; import PageToolbarSection from 'Components/Page/Toolbar/PageToolbarSection'; import PageToolbarSeparator from 'Components/Page/Toolbar/PageToolbarSeparator'; import Table from 'Components/Table/Table'; import TableBody from 'Components/Table/TableBody'; import TablePager from 'Components/Table/TablePager'; import { align, icons, kinds } from 'Helpers/Props'; import getFilterValue from 'Utilities/Filter/getFilterValue'; import hasDifferentItems from 'Utilities/Object/hasDifferentItems'; import translate from 'Utilities/String/translate'; import getSelectedIds from 'Utilities/Table/getSelectedIds'; import removeOldSelectedState from 'Utilities/Table/removeOldSelectedState'; import selectAll from 'Utilities/Table/selectAll'; import toggleSelected from 'Utilities/Table/toggleSelected'; import CutoffUnmetRowConnector from './CutoffUnmetRowConnector'; function getMonitoredValue(props) { const { filters, selectedFilterKey } = props; return getFilterValue(filters, selectedFilterKey, 'monitored', false); } class CutoffUnmet extends Component { // // Lifecycle constructor(props, context) { super(props, context); this.state = { allSelected: false, allUnselected: false, lastToggled: null, selectedState: {}, isConfirmSearchAllCutoffUnmetModalOpen: false, isInteractiveImportModalOpen: false }; } componentDidUpdate(prevProps) { if (hasDifferentItems(prevProps.items, this.props.items)) { this.setState((state) => { return removeOldSelectedState(state, prevProps.items); }); } } // // Control getSelectedIds = () => { return getSelectedIds(this.state.selectedState); }; // // Listeners onSelectAllChange = ({ value }) => { this.setState(selectAll(this.state.selectedState, value)); }; onSelectedChange = ({ id, value, shiftKey = false }) => { this.setState((state) => { return toggleSelected(state, this.props.items, id, value, shiftKey); }); }; onSearchSelectedPress = () => { const selected = this.getSelectedIds(); this.props.onSearchSelectedPress(selected); }; onToggleSelectedPress = () => { const albumIds = this.getSelectedIds(); this.props.batchToggleCutoffUnmetAlbums({ albumIds, monitored: !getMonitoredValue(this.props) }); }; onSearchAllCutoffUnmetPress = () => { this.setState({ isConfirmSearchAllCutoffUnmetModalOpen: true }); }; onSearchAllCutoffUnmetConfirmed = () => { this.props.onSearchAllCutoffUnmetPress(); this.setState({ isConfirmSearchAllCutoffUnmetModalOpen: false }); }; onConfirmSearchAllCutoffUnmetModalClose = () => { this.setState({ isConfirmSearchAllCutoffUnmetModalOpen: false }); }; // // Render render() { const { isFetching, isPopulated, error, items, isArtistFetching, isArtistPopulated, selectedFilterKey, filters, columns, totalRecords, isSearchingForCutoffUnmetAlbums, isSaving, onFilterSelect, ...otherProps } = this.props; const { allSelected, allUnselected, selectedState, isConfirmSearchAllCutoffUnmetModalOpen } = this.state; const isAllPopulated = isPopulated && isArtistPopulated; const isAnyFetching = isFetching || isArtistFetching; const itemsSelected = !!this.getSelectedIds().length; const isShowingMonitored = getMonitoredValue(this.props); return ( { isAnyFetching && !isAllPopulated && } { !isAnyFetching && error && Error fetching cutoff unmet } { isAllPopulated && !error && !items.length && {translate('NoCutoffUnmetItems')} } { isAllPopulated && !error && !!items.length &&
{ items.map((item) => { return ( ); }) }
{translate('SearchForAllCutoffUnmetAlbumsConfirmationCount', { totalRecords })}
{translate('MassSearchCancelWarning')}
} confirmLabel={translate('Search')} onConfirm={this.onSearchAllCutoffUnmetConfirmed} onCancel={this.onConfirmSearchAllCutoffUnmetModalClose} /> }
); } } CutoffUnmet.propTypes = { isFetching: PropTypes.bool.isRequired, isPopulated: PropTypes.bool.isRequired, error: PropTypes.object, items: PropTypes.arrayOf(PropTypes.object).isRequired, isArtistFetching: PropTypes.bool.isRequired, isArtistPopulated: PropTypes.bool.isRequired, selectedFilterKey: PropTypes.string.isRequired, filters: PropTypes.arrayOf(PropTypes.object).isRequired, columns: PropTypes.arrayOf(PropTypes.object).isRequired, totalRecords: PropTypes.number, isSearchingForCutoffUnmetAlbums: PropTypes.bool.isRequired, isSaving: PropTypes.bool.isRequired, onFilterSelect: PropTypes.func.isRequired, onSearchSelectedPress: PropTypes.func.isRequired, batchToggleCutoffUnmetAlbums: PropTypes.func.isRequired, onSearchAllCutoffUnmetPress: PropTypes.func.isRequired }; export default CutoffUnmet;