Added: Sort Album Table on Artist Details Page

Fixes #171
pull/273/head
Qstick 7 years ago
parent b0fb369290
commit 289647b6b1

@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import React, { Component } from 'react'; import React, { Component } from 'react';
import isAfter from 'Utilities/Date/isAfter'; import isAfter from 'Utilities/Date/isAfter';
import getToggledRange from 'Utilities/Table/getToggledRange'; import getToggledRange from 'Utilities/Table/getToggledRange';
import { icons } from 'Helpers/Props'; import { icons, sortDirections } from 'Helpers/Props';
import Icon from 'Components/Icon'; import Icon from 'Components/Icon';
import IconButton from 'Components/Link/IconButton'; import IconButton from 'Components/Link/IconButton';
import Link from 'Components/Link/Link'; import Link from 'Components/Link/Link';
@ -114,6 +114,9 @@ class ArtistDetailsSeason extends Component {
columns, columns,
isExpanded, isExpanded,
artistMonitored, artistMonitored,
sortKey,
sortDirection,
onSortPress,
isSmallScreen, isSmallScreen,
onTableOptionChange onTableOptionChange
} = this.props; } = this.props;
@ -171,6 +174,9 @@ class ArtistDetailsSeason extends Component {
items.length ? items.length ?
<Table <Table
columns={columns} columns={columns}
sortKey={sortKey}
sortDirection={sortDirection}
onSortPress={onSortPress}
onTableOptionChange={onTableOptionChange} onTableOptionChange={onTableOptionChange}
> >
<TableBody> <TableBody>
@ -225,6 +231,8 @@ ArtistDetailsSeason.propTypes = {
artistId: PropTypes.number.isRequired, artistId: PropTypes.number.isRequired,
name: PropTypes.string.isRequired, name: PropTypes.string.isRequired,
label: PropTypes.string.isRequired, label: PropTypes.string.isRequired,
sortKey: PropTypes.string,
sortDirection: PropTypes.oneOf(sortDirections.all),
items: PropTypes.arrayOf(PropTypes.object).isRequired, items: PropTypes.arrayOf(PropTypes.object).isRequired,
columns: PropTypes.arrayOf(PropTypes.object).isRequired, columns: PropTypes.arrayOf(PropTypes.object).isRequired,
isExpanded: PropTypes.bool, isExpanded: PropTypes.bool,
@ -232,6 +240,7 @@ ArtistDetailsSeason.propTypes = {
isSmallScreen: PropTypes.bool.isRequired, isSmallScreen: PropTypes.bool.isRequired,
onTableOptionChange: PropTypes.func.isRequired, onTableOptionChange: PropTypes.func.isRequired,
onExpandPress: PropTypes.func.isRequired, onExpandPress: PropTypes.func.isRequired,
onSortPress: PropTypes.func.isRequired,
onMonitorAlbumPress: PropTypes.func.isRequired onMonitorAlbumPress: PropTypes.func.isRequired
}; };

@ -8,7 +8,7 @@ import { findCommand } from 'Utilities/Command';
import createDimensionsSelector from 'Store/Selectors/createDimensionsSelector'; import createDimensionsSelector from 'Store/Selectors/createDimensionsSelector';
import createArtistSelector from 'Store/Selectors/createArtistSelector'; import createArtistSelector from 'Store/Selectors/createArtistSelector';
import createCommandsSelector from 'Store/Selectors/createCommandsSelector'; import createCommandsSelector from 'Store/Selectors/createCommandsSelector';
import { toggleAlbumsMonitored, setAlbumsTableOption } from 'Store/Actions/albumActions'; import { toggleAlbumsMonitored, setAlbumsTableOption, setAlbumsSort } from 'Store/Actions/albumActions';
import { executeCommand } from 'Store/Actions/commandActions'; import { executeCommand } from 'Store/Actions/commandActions';
import * as commandNames from 'Commands/commandNames'; import * as commandNames from 'Commands/commandNames';
import ArtistDetailsSeason from './ArtistDetailsSeason'; import ArtistDetailsSeason from './ArtistDetailsSeason';
@ -23,11 +23,20 @@ function createMapStateToProps() {
(label, albums, artist, commands, dimensions) => { (label, albums, artist, commands, dimensions) => {
const albumsInGroup = _.filter(albums.items, { albumType: label }); const albumsInGroup = _.filter(albums.items, { albumType: label });
const sortedAlbums = _.orderBy(albumsInGroup, 'releaseDate', 'desc');
let sortDir = 'asc';
if (albums.sortDirection === 'descending') {
sortDir = 'desc';
}
const sortedAlbums = _.orderBy(albumsInGroup, albums.sortKey, sortDir);
return { return {
items: sortedAlbums, items: sortedAlbums,
columns: albums.columns, columns: albums.columns,
sortKey: albums.sortKey,
sortDirection: albums.sortDirection,
artistMonitored: artist.monitored, artistMonitored: artist.monitored,
isSmallScreen: dimensions.isSmallScreen isSmallScreen: dimensions.isSmallScreen
}; };
@ -38,6 +47,7 @@ function createMapStateToProps() {
const mapDispatchToProps = { const mapDispatchToProps = {
toggleAlbumsMonitored, toggleAlbumsMonitored,
setAlbumsTableOption, setAlbumsTableOption,
dispatchSetAlbumSort: setAlbumsSort,
executeCommand executeCommand
}; };
@ -50,6 +60,10 @@ class ArtistDetailsSeasonConnector extends Component {
this.props.setAlbumsTableOption(payload); this.props.setAlbumsTableOption(payload);
} }
onSortPress = (sortKey) => {
this.props.dispatchSetAlbumSort({ sortKey });
}
onMonitorAlbumPress = (albumIds, monitored) => { onMonitorAlbumPress = (albumIds, monitored) => {
this.props.toggleAlbumsMonitored({ this.props.toggleAlbumsMonitored({
albumIds, albumIds,
@ -64,6 +78,7 @@ class ArtistDetailsSeasonConnector extends Component {
return ( return (
<ArtistDetailsSeason <ArtistDetailsSeason
{...this.props} {...this.props}
onSortPress={this.onSortPress}
onTableOptionChange={this.onTableOptionChange} onTableOptionChange={this.onTableOptionChange}
onMonitorAlbumPress={this.onMonitorAlbumPress} onMonitorAlbumPress={this.onMonitorAlbumPress}
/> />
@ -75,6 +90,7 @@ ArtistDetailsSeasonConnector.propTypes = {
artistId: PropTypes.number.isRequired, artistId: PropTypes.number.isRequired,
toggleAlbumsMonitored: PropTypes.func.isRequired, toggleAlbumsMonitored: PropTypes.func.isRequired,
setAlbumsTableOption: PropTypes.func.isRequired, setAlbumsTableOption: PropTypes.func.isRequired,
dispatchSetAlbumSort: PropTypes.func.isRequired,
executeCommand: PropTypes.func.isRequired executeCommand: PropTypes.func.isRequired
}; };

@ -42,16 +42,19 @@ export const defaultState = {
{ {
name: 'title', name: 'title',
label: 'Title', label: 'Title',
isSortable: true,
isVisible: true isVisible: true
}, },
{ {
name: 'releaseDate', name: 'releaseDate',
label: 'Release Date', label: 'Release Date',
isSortable: true,
isVisible: true isVisible: true
}, },
{ {
name: 'secondaryTypes', name: 'secondaryTypes',
label: 'Secondary Types', label: 'Secondary Types',
isSortable: true,
isVisible: false isVisible: false
}, },
{ {
@ -67,6 +70,7 @@ export const defaultState = {
{ {
name: 'duration', name: 'duration',
label: 'Duration', label: 'Duration',
isSortable: true,
isVisible: false isVisible: false
}, },
{ {
@ -84,6 +88,8 @@ export const defaultState = {
}; };
export const persistState = [ export const persistState = [
'albums.sortKey',
'albums.sortDirection',
'albums.columns' 'albums.columns'
]; ];
@ -223,6 +229,8 @@ export const actionHandlers = handleThunks({
export const reducers = createHandleActions({ export const reducers = createHandleActions({
[SET_ALBUMS_SORT]: createSetClientSideCollectionSortReducer(section),
[SET_ALBUMS_TABLE_OPTION]: createSetTableOptionReducer(section), [SET_ALBUMS_TABLE_OPTION]: createSetTableOptionReducer(section),
[SET_ALBUM_VALUE]: createSetSettingValueReducer(section), [SET_ALBUM_VALUE]: createSetSettingValueReducer(section),
@ -234,8 +242,6 @@ export const reducers = createHandleActions({
error: null, error: null,
items: [] items: []
}); });
}, }
[SET_ALBUMS_SORT]: createSetClientSideCollectionSortReducer(section)
}, defaultState, section); }, defaultState, section);

Loading…
Cancel
Save