From 5aa4a5faaadd53d5183d6f9d2f1461e886fb417c Mon Sep 17 00:00:00 2001 From: Bogdan Date: Tue, 4 Apr 2023 19:47:35 +0300 Subject: [PATCH] Fixed: (Tags) Show applications in tag details --- .../Tags/Details/TagDetailsModalContent.js | 17 ++++++++++++++++ .../TagDetailsModalContentConnector.js | 20 ++++++++++++++----- frontend/src/Settings/Tags/Tag.js | 18 ++++++++++++++--- frontend/src/Settings/Tags/TagsConnector.js | 12 +++++++---- src/NzbDrone.Core/Tags/TagDetails.cs | 9 ++------- src/NzbDrone.Core/Tags/TagService.cs | 14 ++++++++++--- .../Tags/TagDetailsResource.cs | 4 +++- 7 files changed, 71 insertions(+), 23 deletions(-) diff --git a/frontend/src/Settings/Tags/Details/TagDetailsModalContent.js b/frontend/src/Settings/Tags/Details/TagDetailsModalContent.js index dfe24646d..34d80937c 100644 --- a/frontend/src/Settings/Tags/Details/TagDetailsModalContent.js +++ b/frontend/src/Settings/Tags/Details/TagDetailsModalContent.js @@ -17,6 +17,7 @@ function TagDetailsModalContent(props) { indexers, notifications, indexerProxies, + applications, onModalClose, onDeleteTagPress } = props; @@ -79,6 +80,21 @@ function TagDetailsModalContent(props) { } } + + { + !!applications.length && +
+ { + applications.map((item) => { + return ( +
+ {item.name} +
+ ); + }) + } +
+ } @@ -110,6 +126,7 @@ TagDetailsModalContent.propTypes = { indexers: PropTypes.arrayOf(PropTypes.object).isRequired, notifications: PropTypes.arrayOf(PropTypes.object).isRequired, indexerProxies: PropTypes.arrayOf(PropTypes.object).isRequired, + applications: PropTypes.arrayOf(PropTypes.object).isRequired, onModalClose: PropTypes.func.isRequired, onDeleteTagPress: PropTypes.func.isRequired }; diff --git a/frontend/src/Settings/Tags/Details/TagDetailsModalContentConnector.js b/frontend/src/Settings/Tags/Details/TagDetailsModalContentConnector.js index 4c67407ba..56d662eb6 100644 --- a/frontend/src/Settings/Tags/Details/TagDetailsModalContentConnector.js +++ b/frontend/src/Settings/Tags/Details/TagDetailsModalContentConnector.js @@ -17,6 +17,14 @@ function createMatchingIndexersSelector() { } function createMatchingIndexerProxiesSelector() { + return createSelector( + (state, { indexerProxyIds }) => indexerProxyIds, + (state) => state.settings.indexerProxies.items, + findMatchingItems + ); +} + +function createMatchingNotificationsSelector() { return createSelector( (state, { notificationIds }) => notificationIds, (state) => state.settings.notifications.items, @@ -24,10 +32,10 @@ function createMatchingIndexerProxiesSelector() { ); } -function createMatchingNotificationsSelector() { +function createMatchingApplicationsSelector() { return createSelector( - (state, { indexerProxyIds }) => indexerProxyIds, - (state) => state.settings.indexerProxies.items, + (state, { applicationIds }) => applicationIds, + (state) => state.settings.applications.items, findMatchingItems ); } @@ -37,11 +45,13 @@ function createMapStateToProps() { createMatchingIndexersSelector(), createMatchingIndexerProxiesSelector(), createMatchingNotificationsSelector(), - (indexers, indexerProxies, notifications) => { + createMatchingApplicationsSelector(), + (indexers, indexerProxies, notifications, applications) => { return { indexers, indexerProxies, - notifications + notifications, + applications }; } ); diff --git a/frontend/src/Settings/Tags/Tag.js b/frontend/src/Settings/Tags/Tag.js index 7e9aa0991..607a67543 100644 --- a/frontend/src/Settings/Tags/Tag.js +++ b/frontend/src/Settings/Tags/Tag.js @@ -55,7 +55,8 @@ class Tag extends Component { label, notificationIds, indexerIds, - indexerProxyIds + indexerProxyIds, + applicationIds } = this.props; const { @@ -66,7 +67,8 @@ class Tag extends Component { const isTagUsed = !!( indexerIds.length || notificationIds.length || - indexerProxyIds.length + indexerProxyIds.length || + applicationIds.length ); return ( @@ -102,6 +104,13 @@ class Tag extends Component { {indexerProxyIds.length} {indexerProxyIds.length > 1 ? translate('IndexerProxies') : translate('IndexerProxy')} } + + { + !!applicationIds.length && +
+ {applicationIds.length} {applicationIds.length > 1 ? translate('Applications') : translate('Application')} +
+ } } @@ -118,6 +127,7 @@ class Tag extends Component { indexerIds={indexerIds} notificationIds={notificationIds} indexerProxyIds={indexerProxyIds} + applicationIds={applicationIds} isOpen={isDetailsModalOpen} onModalClose={this.onDetailsModalClose} onDeleteTagPress={this.onDeleteTagPress} @@ -143,13 +153,15 @@ Tag.propTypes = { notificationIds: PropTypes.arrayOf(PropTypes.number).isRequired, indexerIds: PropTypes.arrayOf(PropTypes.number).isRequired, indexerProxyIds: PropTypes.arrayOf(PropTypes.number).isRequired, + applicationIds: PropTypes.arrayOf(PropTypes.number).isRequired, onConfirmDeleteTag: PropTypes.func.isRequired }; Tag.defaultProps = { indexerIds: [], notificationIds: [], - indexerProxyIds: [] + indexerProxyIds: [], + applicationIds: [] }; export default Tag; diff --git a/frontend/src/Settings/Tags/TagsConnector.js b/frontend/src/Settings/Tags/TagsConnector.js index 374d3caa7..4f311e984 100644 --- a/frontend/src/Settings/Tags/TagsConnector.js +++ b/frontend/src/Settings/Tags/TagsConnector.js @@ -2,7 +2,7 @@ import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { connect } from 'react-redux'; import { createSelector } from 'reselect'; -import { fetchIndexerProxies, fetchNotifications } from 'Store/Actions/settingsActions'; +import { fetchApplications, fetchIndexerProxies, fetchNotifications } from 'Store/Actions/settingsActions'; import { fetchTagDetails } from 'Store/Actions/tagActions'; import Tags from './Tags'; @@ -27,7 +27,8 @@ function createMapStateToProps() { const mapDispatchToProps = { dispatchFetchTagDetails: fetchTagDetails, dispatchFetchNotifications: fetchNotifications, - dispatchFetchIndexerProxies: fetchIndexerProxies + dispatchFetchIndexerProxies: fetchIndexerProxies, + dispatchFetchApplications: fetchApplications }; class MetadatasConnector extends Component { @@ -39,12 +40,14 @@ class MetadatasConnector extends Component { const { dispatchFetchTagDetails, dispatchFetchNotifications, - dispatchFetchIndexerProxies + dispatchFetchIndexerProxies, + dispatchFetchApplications } = this.props; dispatchFetchTagDetails(); dispatchFetchNotifications(); dispatchFetchIndexerProxies(); + dispatchFetchApplications(); } // @@ -62,7 +65,8 @@ class MetadatasConnector extends Component { MetadatasConnector.propTypes = { dispatchFetchTagDetails: PropTypes.func.isRequired, dispatchFetchNotifications: PropTypes.func.isRequired, - dispatchFetchIndexerProxies: PropTypes.func.isRequired + dispatchFetchIndexerProxies: PropTypes.func.isRequired, + dispatchFetchApplications: PropTypes.func.isRequired }; export default connect(createMapStateToProps, mapDispatchToProps)(MetadatasConnector); diff --git a/src/NzbDrone.Core/Tags/TagDetails.cs b/src/NzbDrone.Core/Tags/TagDetails.cs index e0b2c018a..7cf372891 100644 --- a/src/NzbDrone.Core/Tags/TagDetails.cs +++ b/src/NzbDrone.Core/Tags/TagDetails.cs @@ -10,13 +10,8 @@ namespace NzbDrone.Core.Tags public List NotificationIds { get; set; } public List IndexerIds { get; set; } public List IndexerProxyIds { get; set; } + public List ApplicationIds { get; set; } - public bool InUse - { - get - { - return NotificationIds.Any() || IndexerIds.Any() || IndexerProxyIds.Any(); - } - } + public bool InUse => NotificationIds.Any() || IndexerIds.Any() || IndexerProxyIds.Any() || ApplicationIds.Any(); } } diff --git a/src/NzbDrone.Core/Tags/TagService.cs b/src/NzbDrone.Core/Tags/TagService.cs index 727ad88ca..9b461961a 100644 --- a/src/NzbDrone.Core/Tags/TagService.cs +++ b/src/NzbDrone.Core/Tags/TagService.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using NzbDrone.Core.Applications; using NzbDrone.Core.Datastore; using NzbDrone.Core.IndexerProxies; using NzbDrone.Core.Indexers; @@ -28,18 +29,21 @@ namespace NzbDrone.Core.Tags private readonly INotificationFactory _notificationFactory; private readonly IIndexerFactory _indexerFactory; private readonly IIndexerProxyFactory _indexerProxyFactory; + private readonly IApplicationFactory _applicationFactory; public TagService(ITagRepository repo, IEventAggregator eventAggregator, INotificationFactory notificationFactory, IIndexerFactory indexerFactory, - IIndexerProxyFactory indexerProxyFactory) + IIndexerProxyFactory indexerProxyFactory, + IApplicationFactory applicationFactory) { _repo = repo; _eventAggregator = eventAggregator; _notificationFactory = notificationFactory; _indexerFactory = indexerFactory; _indexerProxyFactory = indexerProxyFactory; + _applicationFactory = applicationFactory; } public Tag GetTag(int tagId) @@ -70,6 +74,7 @@ namespace NzbDrone.Core.Tags var notifications = _notificationFactory.AllForTag(tagId); var indexers = _indexerFactory.AllForTag(tagId); var indexerProxies = _indexerProxyFactory.AllForTag(tagId); + var applications = _applicationFactory.AllForTag(tagId); return new TagDetails { @@ -77,7 +82,8 @@ namespace NzbDrone.Core.Tags Label = tag.Label, NotificationIds = notifications.Select(c => c.Id).ToList(), IndexerIds = indexers.Select(c => c.Id).ToList(), - IndexerProxyIds = indexerProxies.Select(c => c.Id).ToList() + IndexerProxyIds = indexerProxies.Select(c => c.Id).ToList(), + ApplicationIds = applications.Select(c => c.Id).ToList() }; } @@ -87,6 +93,7 @@ namespace NzbDrone.Core.Tags var notifications = _notificationFactory.All(); var indexers = _indexerFactory.All(); var indexerProxies = _indexerProxyFactory.All(); + var applications = _applicationFactory.All(); var details = new List(); @@ -98,7 +105,8 @@ namespace NzbDrone.Core.Tags Label = tag.Label, NotificationIds = notifications.Where(c => c.Tags.Contains(tag.Id)).Select(c => c.Id).ToList(), IndexerIds = indexers.Where(c => c.Tags.Contains(tag.Id)).Select(c => c.Id).ToList(), - IndexerProxyIds = indexerProxies.Where(c => c.Tags.Contains(tag.Id)).Select(c => c.Id).ToList() + IndexerProxyIds = indexerProxies.Where(c => c.Tags.Contains(tag.Id)).Select(c => c.Id).ToList(), + ApplicationIds = applications.Where(c => c.Tags.Contains(tag.Id)).Select(c => c.Id).ToList() }); } diff --git a/src/Prowlarr.Api.V1/Tags/TagDetailsResource.cs b/src/Prowlarr.Api.V1/Tags/TagDetailsResource.cs index 2404e6857..b24d3846c 100644 --- a/src/Prowlarr.Api.V1/Tags/TagDetailsResource.cs +++ b/src/Prowlarr.Api.V1/Tags/TagDetailsResource.cs @@ -11,6 +11,7 @@ namespace Prowlarr.Api.V1.Tags public List NotificationIds { get; set; } public List IndexerIds { get; set; } public List IndexerProxyIds { get; set; } + public List ApplicationIds { get; set; } } public static class TagDetailsResourceMapper @@ -28,7 +29,8 @@ namespace Prowlarr.Api.V1.Tags Label = model.Label, NotificationIds = model.NotificationIds, IndexerIds = model.IndexerIds, - IndexerProxyIds = model.IndexerProxyIds + IndexerProxyIds = model.IndexerProxyIds, + ApplicationIds = model.ApplicationIds }; }