diff --git a/frontend/src/Components/Form/IndexerSelectInputConnector.js b/frontend/src/Components/Form/IndexerSelectInputConnector.js index 3efca904b..52a0e6a36 100644 --- a/frontend/src/Components/Form/IndexerSelectInputConnector.js +++ b/frontend/src/Components/Form/IndexerSelectInputConnector.js @@ -4,50 +4,59 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; import { createSelector } from 'reselect'; import sortByName from 'Utilities/Array/sortByName'; -import SelectInput from './SelectInput'; +import { fetchIndexers } from 'Store/Actions/settingsActions'; +import EnhancedSelectInput from './EnhancedSelectInput'; function createMapStateToProps() { return createSelector( (state) => state.settings.indexers, - (state, { includeNoChange }) => includeNoChange, - (state, { includeMixed }) => includeMixed, - (indexers, includeNoChange, includeMixed) => { - const values = _.map(indexers.items.sort(sortByName), (indexer) => { + (state, { includeAny }) => includeAny, + (indexers, includeAny) => { + const { + isFetching, + isPopulated, + error, + items + } = indexers; + + const values = _.map(items.sort(sortByName), (indexer) => { return { key: indexer.id, value: indexer.name }; }); - if (includeNoChange) { + if (includeAny) { values.unshift({ - key: 'noChange', - value: 'No Change', - disabled: true - }); - } - - if (includeMixed) { - values.unshift({ - key: 'mixed', - value: '(Mixed)', - disabled: true + key: 0, + value: '(Any)' }); } return { + isFetching, + isPopulated, + error, values }; } ); } +const mapDispatchToProps = { + dispatchFetchIndexers: fetchIndexers +}; + class IndexerSelectInputConnector extends Component { // // Lifecycle componentDidMount() { + if (!this.props.isPopulated) { + this.props.dispatchFetchIndexers(); + } + const { name, value, @@ -55,11 +64,7 @@ class IndexerSelectInputConnector extends Component { } = this.props; if (!value || !_.some(values, (option) => parseInt(option.key) === value)) { - const firstValue = _.find(values, (option) => !isNaN(parseInt(option.key))); - - if (firstValue) { - this.onChange({ name, value: firstValue.key }); - } + this.onChange({ name, value: 0 }); } } @@ -75,7 +80,7 @@ class IndexerSelectInputConnector extends Component { render() { return ( - @@ -84,15 +89,18 @@ class IndexerSelectInputConnector extends Component { } IndexerSelectInputConnector.propTypes = { + isFetching: PropTypes.bool.isRequired, + isPopulated: PropTypes.bool.isRequired, name: PropTypes.string.isRequired, - value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired, values: PropTypes.arrayOf(PropTypes.object).isRequired, - includeNoChange: PropTypes.bool.isRequired, - onChange: PropTypes.func.isRequired + includeAny: PropTypes.bool.isRequired, + onChange: PropTypes.func.isRequired, + dispatchFetchIndexers: PropTypes.func.isRequired }; IndexerSelectInputConnector.defaultProps = { - includeNoChange: false + includeAny: false }; -export default connect(createMapStateToProps)(IndexerSelectInputConnector); +export default connect(createMapStateToProps, mapDispatchToProps)(IndexerSelectInputConnector); diff --git a/frontend/src/Settings/Profiles/Release/EditReleaseProfileModalContent.js b/frontend/src/Settings/Profiles/Release/EditReleaseProfileModalContent.js index 28ba1e6e9..319466bd5 100644 --- a/frontend/src/Settings/Profiles/Release/EditReleaseProfileModalContent.js +++ b/frontend/src/Settings/Profiles/Release/EditReleaseProfileModalContent.js @@ -34,9 +34,9 @@ function EditReleaseProfileModalContent(props) { required, ignored, preferred, - indexerId, includePreferredWhenRenaming, - tags + tags, + indexerId } = item; return ( @@ -116,6 +116,7 @@ function EditReleaseProfileModalContent(props) { helpText="Include in {Preferred Words} renaming format" {...includePreferredWhenRenaming} onChange={onInputChange} + isDisabled={indexerId.value !== 0} /> @@ -127,6 +128,7 @@ function EditReleaseProfileModalContent(props) { name="indexerId" helpText="Specify what indexer the profile applies to" {...indexerId} + includeAny={true} onChange={onInputChange} /> diff --git a/frontend/src/Settings/Profiles/Release/EditReleaseProfileModalContentConnector.js b/frontend/src/Settings/Profiles/Release/EditReleaseProfileModalContentConnector.js index 80380dc6c..c9de8f735 100644 --- a/frontend/src/Settings/Profiles/Release/EditReleaseProfileModalContentConnector.js +++ b/frontend/src/Settings/Profiles/Release/EditReleaseProfileModalContentConnector.js @@ -8,13 +8,13 @@ import { setReleaseProfileValue, saveReleaseProfile } from 'Store/Actions/settin import EditReleaseProfileModalContent from './EditReleaseProfileModalContent'; const newReleaseProfile = { - enabled: false, + enabled: true, required: '', ignored: '', preferred: [], includePreferredWhenRenaming: false, - indexer: 0, - tags: [] + tags: [], + indexerId: 0 }; function createMapStateToProps() { diff --git a/frontend/src/Settings/Profiles/Release/ReleaseProfile.js b/frontend/src/Settings/Profiles/Release/ReleaseProfile.js index f1b03a68f..3c78a5da4 100644 --- a/frontend/src/Settings/Profiles/Release/ReleaseProfile.js +++ b/frontend/src/Settings/Profiles/Release/ReleaseProfile.js @@ -1,3 +1,4 @@ +import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import split from 'Utilities/String/split'; @@ -55,11 +56,14 @@ class ReleaseProfile extends Component { render() { const { id, + enabled, required, ignored, preferred, tags, - tagList + indexerId, + tagList, + indexerList } = this.props; const { @@ -67,6 +71,8 @@ class ReleaseProfile extends Component { isDeleteReleaseProfileModalOpen } = this.state; + const indexer = indexerId !== 0 && _.find(indexerList, { id: indexerId }); + return ( +
+ { + preferred.map((item) => { + const isPreferred = item.value >= 0; + + return ( + + ); + }) + } +
+
{ split(ignored).map((item) => { @@ -111,28 +134,33 @@ class ReleaseProfile extends Component { }
-
- { - preferred.map((item) => { - const isPreferred = item.value >= 0; - - return ( - - ); - }) - } -
- +
+ { + !enabled && + + } + + { + indexer && + + } +
+ @@ -92,6 +94,7 @@ ReleaseProfiles.propTypes = { error: PropTypes.object, items: PropTypes.arrayOf(PropTypes.object).isRequired, tagList: PropTypes.arrayOf(PropTypes.object).isRequired, + indexerList: PropTypes.arrayOf(PropTypes.object).isRequired, onConfirmDeleteReleaseProfile: PropTypes.func.isRequired }; diff --git a/frontend/src/Settings/Profiles/Release/ReleaseProfilesConnector.js b/frontend/src/Settings/Profiles/Release/ReleaseProfilesConnector.js index dd4b41171..3cca69efd 100644 --- a/frontend/src/Settings/Profiles/Release/ReleaseProfilesConnector.js +++ b/frontend/src/Settings/Profiles/Release/ReleaseProfilesConnector.js @@ -2,24 +2,28 @@ import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { connect } from 'react-redux'; import { createSelector } from 'reselect'; -import { fetchReleaseProfiles, deleteReleaseProfile } from 'Store/Actions/settingsActions'; +import { fetchReleaseProfiles, deleteReleaseProfile, fetchIndexers } from 'Store/Actions/settingsActions'; import createTagsSelector from 'Store/Selectors/createTagsSelector'; import ReleaseProfiles from './ReleaseProfiles'; function createMapStateToProps() { return createSelector( (state) => state.settings.releaseProfiles, + (state) => state.settings.indexers, createTagsSelector(), - (releaseProfiles, tagList) => { + (releaseProfiles, indexers, tagList) => { return { ...releaseProfiles, - tagList + tagList, + isIndexersPopulated: indexers.isPopulated, + indexerList: indexers.items }; } ); } const mapDispatchToProps = { + fetchIndexers, fetchReleaseProfiles, deleteReleaseProfile }; @@ -31,6 +35,9 @@ class ReleaseProfilesConnector extends Component { componentDidMount() { this.props.fetchReleaseProfiles(); + if (!this.props.isIndexersPopulated) { + this.props.fetchIndexers(); + } } // @@ -54,8 +61,10 @@ class ReleaseProfilesConnector extends Component { } ReleaseProfilesConnector.propTypes = { + isIndexersPopulated: PropTypes.bool.isRequired, fetchReleaseProfiles: PropTypes.func.isRequired, - deleteReleaseProfile: PropTypes.func.isRequired + deleteReleaseProfile: PropTypes.func.isRequired, + fetchIndexers: PropTypes.func.isRequired }; export default connect(createMapStateToProps, mapDispatchToProps)(ReleaseProfilesConnector); diff --git a/frontend/src/Store/Selectors/createIndexerSelector.js b/frontend/src/Store/Selectors/createIndexerSelector.js deleted file mode 100644 index f95eba24c..000000000 --- a/frontend/src/Store/Selectors/createIndexerSelector.js +++ /dev/null @@ -1,15 +0,0 @@ -import { createSelector } from 'reselect'; - -function createIndexerSelector() { - return createSelector( - (state, { indexerId }) => indexerId, - (state) => state.settings.indexers.items, - (indexerId, indexers) => { - return indexers.find((profile) => { - return profile.id === indexerId; - }); - } - ); -} - -export default createIndexerSelector;