New: (UI) Add filter by categories in add indexer modal

Fixes #872
Closes #1731
This commit is contained in:
Bogdan
2023-06-14 07:13:33 +03:00
parent 0155ff60fd
commit 4e03ebadc4
3 changed files with 46 additions and 6 deletions

View File

@@ -40,6 +40,7 @@
flex: 1; flex: 1;
flex-direction: column; flex-direction: column;
margin-right: 12px; margin-right: 12px;
max-width: 50%;
} }
.filterContainer:last-child { .filterContainer:last-child {

View File

@@ -2,6 +2,7 @@ import PropTypes from 'prop-types';
import React, { Component } from 'react'; import React, { Component } from 'react';
import Alert from 'Components/Alert'; import Alert from 'Components/Alert';
import EnhancedSelectInput from 'Components/Form/EnhancedSelectInput'; import EnhancedSelectInput from 'Components/Form/EnhancedSelectInput';
import NewznabCategorySelectInputConnector from 'Components/Form/NewznabCategorySelectInputConnector';
import TextInput from 'Components/Form/TextInput'; import TextInput from 'Components/Form/TextInput';
import Button from 'Components/Link/Button'; import Button from 'Components/Link/Button';
import LoadingIndicator from 'Components/Loading/LoadingIndicator'; import LoadingIndicator from 'Components/Loading/LoadingIndicator';
@@ -89,7 +90,8 @@ class AddIndexerModalContent extends Component {
filter: '', filter: '',
filterProtocols: [], filterProtocols: [],
filterLanguages: [], filterLanguages: [],
filterPrivacyLevels: [] filterPrivacyLevels: [],
filterCategories: []
}; };
} }
@@ -121,7 +123,13 @@ class AddIndexerModalContent extends Component {
.map((language) => ({ key: language, value: language })); .map((language) => ({ key: language, value: language }));
const filteredIndexers = indexers.filter((indexer) => { const filteredIndexers = indexers.filter((indexer) => {
const { filter, filterProtocols, filterLanguages, filterPrivacyLevels } = this.state; const {
filter,
filterProtocols,
filterLanguages,
filterPrivacyLevels,
filterCategories
} = this.state;
if (!indexer.name.toLowerCase().includes(filter.toLocaleLowerCase()) && !indexer.description.toLowerCase().includes(filter.toLocaleLowerCase())) { if (!indexer.name.toLowerCase().includes(filter.toLocaleLowerCase()) && !indexer.description.toLowerCase().includes(filter.toLocaleLowerCase())) {
return false; return false;
@@ -139,6 +147,18 @@ class AddIndexerModalContent extends Component {
return false; return false;
} }
if (filterCategories.length) {
const { categories = [] } = indexer.capabilities || {};
const flat = ({ id, subCategories = [] }) => [id, ...subCategories.flatMap(flat)];
const flatCategories = categories
.filter((item) => item.id < 100000)
.flatMap(flat);
if (!filterCategories.every((item) => flatCategories.includes(item))) {
return false;
}
}
return true; return true;
}); });
@@ -165,7 +185,7 @@ class AddIndexerModalContent extends Component {
<div className={styles.filterRow}> <div className={styles.filterRow}>
<div className={styles.filterContainer}> <div className={styles.filterContainer}>
<label className={styles.filterLabel}>Protocol</label> <label className={styles.filterLabel}>{translate('Protocol')}</label>
<EnhancedSelectInput <EnhancedSelectInput
name="indexerProtocols" name="indexerProtocols"
value={this.state.filterProtocols} value={this.state.filterProtocols}
@@ -175,7 +195,7 @@ class AddIndexerModalContent extends Component {
</div> </div>
<div className={styles.filterContainer}> <div className={styles.filterContainer}>
<label className={styles.filterLabel}>Language</label> <label className={styles.filterLabel}>{translate('Language')}</label>
<EnhancedSelectInput <EnhancedSelectInput
name="indexerLanguages" name="indexerLanguages"
value={this.state.filterLanguages} value={this.state.filterLanguages}
@@ -185,7 +205,7 @@ class AddIndexerModalContent extends Component {
</div> </div>
<div className={styles.filterContainer}> <div className={styles.filterContainer}>
<label className={styles.filterLabel}>Privacy</label> <label className={styles.filterLabel}>{translate('Privacy')}</label>
<EnhancedSelectInput <EnhancedSelectInput
name="indexerPrivacyLevels" name="indexerPrivacyLevels"
value={this.state.filterPrivacyLevels} value={this.state.filterPrivacyLevels}
@@ -193,6 +213,15 @@ class AddIndexerModalContent extends Component {
onChange={({ value }) => this.setState({ filterPrivacyLevels: value })} onChange={({ value }) => this.setState({ filterPrivacyLevels: value })}
/> />
</div> </div>
<div className={styles.filterContainer}>
<label className={styles.filterLabel}>{translate('Categories')}</label>
<NewznabCategorySelectInputConnector
name="indexerCategories"
value={this.state.filterCategories}
onChange={({ value }) => this.setState({ filterCategories: value })}
/>
</div>
</div> </div>
<Alert <Alert
@@ -212,7 +241,7 @@ class AddIndexerModalContent extends Component {
isFetching ? <LoadingIndicator /> : null isFetching ? <LoadingIndicator /> : null
} }
{ {
error ? <div>{errorMessage}</div> : null error ? <Alert kind={kinds.DANGER}>{errorMessage}</Alert> : null
} }
{ {
isPopulated && !!indexers.length ? isPopulated && !!indexers.length ?
@@ -237,6 +266,15 @@ class AddIndexerModalContent extends Component {
</Table> : </Table> :
null null
} }
{
isPopulated && !!indexers.length && !filteredIndexers.length ?
<Alert
kind={kinds.WARNING}
>
{translate('NoIndexersFound')}
</Alert> :
null
}
</Scroller> </Scroller>
</ModalBody> </ModalBody>

View File

@@ -277,6 +277,7 @@
"NoChange": "No Change", "NoChange": "No Change",
"NoChanges": "No Changes", "NoChanges": "No Changes",
"NoHistoryFound": "No history found", "NoHistoryFound": "No history found",
"NoIndexersFound": "No indexers found",
"NoLeaveIt": "No, Leave It", "NoLeaveIt": "No, Leave It",
"NoLinks": "No Links", "NoLinks": "No Links",
"NoLogFiles": "No log files", "NoLogFiles": "No log files",