Show download client field only when download clients are set

pull/1763/head
Bogdan 1 year ago
parent 826828e8ec
commit 712404ddca

@ -26,6 +26,8 @@ function EditIndexerModalContent(props) {
isTesting,
saveError,
item,
hasUsenetDownloadClients,
hasTorrentDownloadClients,
onInputChange,
onFieldChange,
onModalClose,
@ -54,6 +56,7 @@ function EditIndexerModalContent(props) {
} = item;
const indexerDisplayName = implementationName === definitionName ? implementationName : `${implementationName} (${definitionName})`;
const showDownloadClientInput = downloadClientId.value > 0 || protocol.value === 'usenet' && hasUsenetDownloadClients || protocol.value === 'torrent' && hasTorrentDownloadClients;
return (
<ModalContent onModalClose={onModalClose}>
@ -158,22 +161,24 @@ function EditIndexerModalContent(props) {
/>
</FormGroup>
<FormGroup
advancedSettings={advancedSettings}
isAdvanced={true}
>
<FormLabel>{translate('DownloadClient')}</FormLabel>
{showDownloadClientInput ?
<FormGroup
advancedSettings={advancedSettings}
isAdvanced={true}
>
<FormLabel>{translate('DownloadClient')}</FormLabel>
<FormInputGroup
type={inputTypes.DOWNLOAD_CLIENT_SELECT}
name="downloadClientId"
helpText={translate('IndexerDownloadClientHelpText')}
{...downloadClientId}
includeAny={true}
protocol={protocol.value}
onChange={onInputChange}
/>
</FormGroup>
<FormInputGroup
type={inputTypes.DOWNLOAD_CLIENT_SELECT}
name="downloadClientId"
helpText={translate('IndexerDownloadClientHelpText')}
{...downloadClientId}
includeAny={true}
protocol={protocol.value}
onChange={onInputChange}
/>
</FormGroup> : null
}
<FormGroup>
<FormLabel>{translate('Tags')}</FormLabel>
@ -241,6 +246,8 @@ EditIndexerModalContent.propTypes = {
isTesting: PropTypes.bool.isRequired,
saveError: PropTypes.object,
item: PropTypes.object.isRequired,
hasUsenetDownloadClients: PropTypes.bool.isRequired,
hasTorrentDownloadClients: PropTypes.bool.isRequired,
onInputChange: PropTypes.func.isRequired,
onFieldChange: PropTypes.func.isRequired,
onModalClose: PropTypes.func.isRequired,

@ -3,17 +3,23 @@ import React, { Component } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { saveIndexer, setIndexerFieldValue, setIndexerValue, testIndexer } from 'Store/Actions/indexerActions';
import { toggleAdvancedSettings } from 'Store/Actions/settingsActions';
import { fetchDownloadClients, toggleAdvancedSettings } from 'Store/Actions/settingsActions';
import createIndexerSchemaSelector from 'Store/Selectors/createIndexerSchemaSelector';
import EditIndexerModalContent from './EditIndexerModalContent';
function createMapStateToProps() {
return createSelector(
(state) => state.settings.advancedSettings,
(state) => state.settings.downloadClients,
createIndexerSchemaSelector(),
(advancedSettings, indexer) => {
(advancedSettings, downloadClients, indexer) => {
const usenetDownloadClients = downloadClients.items.filter((downloadClient) => downloadClient.protocol === 'usenet');
const torrentDownloadClients = downloadClients.items.filter((downloadClient) => downloadClient.protocol === 'torrent');
return {
advancedSettings,
hasUsenetDownloadClients: usenetDownloadClients.length > 0,
hasTorrentDownloadClients: torrentDownloadClients.length > 0,
...indexer
};
}
@ -25,7 +31,8 @@ const mapDispatchToProps = {
setIndexerFieldValue,
saveIndexer,
testIndexer,
toggleAdvancedSettings
toggleAdvancedSettings,
dispatchFetchDownloadClients: fetchDownloadClients
};
class EditIndexerModalContentConnector extends Component {
@ -33,6 +40,10 @@ class EditIndexerModalContentConnector extends Component {
//
// Lifecycle
componentDidMount() {
this.props.dispatchFetchDownloadClients();
}
componentDidUpdate(prevProps, prevState) {
if (prevProps.isSaving && !this.props.isSaving && !this.props.saveError) {
this.props.onModalClose();
@ -90,7 +101,8 @@ EditIndexerModalContentConnector.propTypes = {
toggleAdvancedSettings: PropTypes.func.isRequired,
saveIndexer: PropTypes.func.isRequired,
testIndexer: PropTypes.func.isRequired,
onModalClose: PropTypes.func.isRequired
onModalClose: PropTypes.func.isRequired,
dispatchFetchDownloadClients: PropTypes.func.isRequired
};
export default connect(createMapStateToProps, mapDispatchToProps)(EditIndexerModalContentConnector);

Loading…
Cancel
Save