Skip to content

Commit

Permalink
New: Download Client Tags
Browse files Browse the repository at this point in the history
(cherry picked from commit f6ae9fd6c5173cbf1540341fa99d2f120be1d28e)
  • Loading branch information
Qstick authored and mynameisbogdan committed Jul 17, 2023
1 parent f436d73 commit f0f95be
Show file tree
Hide file tree
Showing 20 changed files with 210 additions and 29 deletions.
Expand Up @@ -3,6 +3,7 @@ import React, { Component } from 'react';
import Card from 'Components/Card';
import Label from 'Components/Label';
import ConfirmModal from 'Components/Modal/ConfirmModal';
import TagList from 'Components/TagList';
import { kinds } from 'Helpers/Props';
import translate from 'Utilities/String/translate';
import EditDownloadClientModalConnector from './EditDownloadClientModalConnector';
Expand Down Expand Up @@ -56,7 +57,9 @@ class DownloadClient extends Component {
id,
name,
enable,
priority
priority,
tags,
tagList
} = this.props;

return (
Expand Down Expand Up @@ -94,6 +97,11 @@ class DownloadClient extends Component {
}
</div>

<TagList
tags={tags}
tagList={tagList}
/>

<EditDownloadClientModalConnector
id={id}
isOpen={this.state.isEditDownloadClientModalOpen}
Expand All @@ -120,6 +128,8 @@ DownloadClient.propTypes = {
name: PropTypes.string.isRequired,
enable: PropTypes.bool.isRequired,
priority: PropTypes.number.isRequired,
tags: PropTypes.arrayOf(PropTypes.number).isRequired,
tagList: PropTypes.arrayOf(PropTypes.object).isRequired,
onConfirmDeleteDownloadClient: PropTypes.func.isRequired
};

Expand Down
Expand Up @@ -50,6 +50,7 @@ class DownloadClients extends Component {
const {
items,
onConfirmDeleteDownloadClient,
tagList,
...otherProps
} = this.props;

Expand All @@ -71,6 +72,7 @@ class DownloadClients extends Component {
<DownloadClient
key={item.id}
{...item}
tagList={tagList}
onConfirmDeleteDownloadClient={onConfirmDeleteDownloadClient}
/>
);
Expand Down Expand Up @@ -109,6 +111,7 @@ DownloadClients.propTypes = {
isFetching: PropTypes.bool.isRequired,
error: PropTypes.object,
items: PropTypes.arrayOf(PropTypes.object).isRequired,
tagList: PropTypes.arrayOf(PropTypes.object).isRequired,
onConfirmDeleteDownloadClient: PropTypes.func.isRequired
};

Expand Down
Expand Up @@ -4,13 +4,20 @@ import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { deleteDownloadClient, fetchDownloadClients } from 'Store/Actions/settingsActions';
import createSortedSectionSelector from 'Store/Selectors/createSortedSectionSelector';
import createTagsSelector from 'Store/Selectors/createTagsSelector';
import sortByName from 'Utilities/Array/sortByName';
import DownloadClients from './DownloadClients';

function createMapStateToProps() {
return createSelector(
createSortedSectionSelector('settings.downloadClients', sortByName),
(downloadClients) => downloadClients
createTagsSelector(),
(downloadClients, tagList) => {
return {
...downloadClients,
tagList
};
}
);
}

Expand Down
Expand Up @@ -51,6 +51,7 @@ class EditDownloadClientModalContent extends Component {
removeCompletedDownloads,
removeFailedDownloads,
fields,
tags,
message
} = item;

Expand Down Expand Up @@ -146,6 +147,18 @@ class EditDownloadClientModalContent extends Component {
/>
</FormGroup>

<FormGroup>
<FormLabel>{translate('Tags')}</FormLabel>

<FormInputGroup
type={inputTypes.TAG}
name="tags"
helpText={translate('DownloadClientTagHelpText')}
{...tags}
onChange={onInputChange}
/>
</FormGroup>

<FieldSet
size={sizes.SMALL}
legend={translate('CompletedDownloadHandling')}
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/Settings/Tags/Details/TagDetailsModalContent.js
Expand Up @@ -22,6 +22,7 @@ function TagDetailsModalContent(props) {
notifications,
releaseProfiles,
indexers,
downloadClients,
onModalClose,
onDeleteTagPress
} = props;
Expand Down Expand Up @@ -180,6 +181,22 @@ function TagDetailsModalContent(props) {
</FieldSet> :
null
}

{
downloadClients.length ?
<FieldSet legend={translate('DownloadClients')}>
{
downloadClients.map((item) => {
return (
<div key={item.id}>
{item.name}
</div>
);
})
}
</FieldSet> :
null
}
</ModalBody>

<ModalFooter>
Expand Down Expand Up @@ -214,6 +231,7 @@ TagDetailsModalContent.propTypes = {
notifications: PropTypes.arrayOf(PropTypes.object).isRequired,
releaseProfiles: PropTypes.arrayOf(PropTypes.object).isRequired,
indexers: PropTypes.arrayOf(PropTypes.object).isRequired,
downloadClients: PropTypes.arrayOf(PropTypes.object).isRequired,
onModalClose: PropTypes.func.isRequired,
onDeleteTagPress: PropTypes.func.isRequired
};
Expand Down
Expand Up @@ -77,6 +77,14 @@ function createMatchingIndexersSelector() {
);
}

function createMatchingDownloadClientsSelector() {
return createSelector(
(state, { downloadClientIds }) => downloadClientIds,
(state) => state.settings.downloadClients.items,
findMatchingItems
);
}

function createMapStateToProps() {
return createSelector(
createMatchingAuthorSelector(),
Expand All @@ -85,14 +93,16 @@ function createMapStateToProps() {
createMatchingNotificationsSelector(),
createMatchingReleaseProfilesSelector(),
createMatchingIndexersSelector(),
(author, delayProfiles, importLists, notifications, releaseProfiles, indexers) => {
createMatchingDownloadClientsSelector(),
(author, delayProfiles, importLists, notifications, releaseProfiles, indexers, downloadClients) => {
return {
author,
delayProfiles,
importLists,
notifications,
releaseProfiles,
indexers
indexers,
downloadClients
};
}
);
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/Settings/Tags/Tag.js
Expand Up @@ -58,6 +58,7 @@ class Tag extends Component {
notificationIds,
restrictionIds,
indexerIds,
downloadClientIds,
authorIds
} = this.props;

Expand All @@ -72,6 +73,7 @@ class Tag extends Component {
notificationIds.length ||
restrictionIds.length ||
indexerIds.length ||
downloadClientIds.length ||
authorIds.length
);

Expand Down Expand Up @@ -130,6 +132,14 @@ class Tag extends Component {
</div> :
null
}

{
downloadClientIds.length ?
<div>
{downloadClientIds.length} download client{indexerIds.length > 1 && 's'}
</div> :
null
}
</div>
}

Expand All @@ -149,6 +159,7 @@ class Tag extends Component {
notificationIds={notificationIds}
restrictionIds={restrictionIds}
indexerIds={indexerIds}
downloadClientIds={downloadClientIds}
isOpen={isDetailsModalOpen}
onModalClose={this.onDetailsModalClose}
onDeleteTagPress={this.onDeleteTagPress}
Expand Down Expand Up @@ -176,6 +187,7 @@ Tag.propTypes = {
notificationIds: PropTypes.arrayOf(PropTypes.number).isRequired,
restrictionIds: PropTypes.arrayOf(PropTypes.number).isRequired,
indexerIds: PropTypes.arrayOf(PropTypes.number).isRequired,
downloadClientIds: PropTypes.arrayOf(PropTypes.number).isRequired,
authorIds: PropTypes.arrayOf(PropTypes.number).isRequired,
onConfirmDeleteTag: PropTypes.func.isRequired
};
Expand All @@ -186,6 +198,7 @@ Tag.defaultProps = {
notificationIds: [],
restrictionIds: [],
indexerIds: [],
downloadClientIds: [],
authorIds: []
};

Expand Down
12 changes: 8 additions & 4 deletions frontend/src/Settings/Tags/TagsConnector.js
Expand Up @@ -2,7 +2,7 @@ import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { fetchDelayProfiles, fetchImportLists, fetchIndexers, fetchNotifications, fetchReleaseProfiles } from 'Store/Actions/settingsActions';
import { fetchDelayProfiles, fetchDownloadClients, fetchImportLists, fetchIndexers, fetchNotifications, fetchReleaseProfiles } from 'Store/Actions/settingsActions';
import { fetchTagDetails } from 'Store/Actions/tagActions';
import Tags from './Tags';

Expand Down Expand Up @@ -30,7 +30,8 @@ const mapDispatchToProps = {
dispatchFetchImportLists: fetchImportLists,
dispatchFetchNotifications: fetchNotifications,
dispatchFetchReleaseProfiles: fetchReleaseProfiles,
dispatchFetchIndexers: fetchIndexers
dispatchFetchIndexers: fetchIndexers,
dispatchFetchDownloadClients: fetchDownloadClients
};

class MetadatasConnector extends Component {
Expand All @@ -45,7 +46,8 @@ class MetadatasConnector extends Component {
dispatchFetchImportLists,
dispatchFetchNotifications,
dispatchFetchReleaseProfiles,
dispatchFetchIndexers
dispatchFetchIndexers,
dispatchFetchDownloadClients
} = this.props;

dispatchFetchTagDetails();
Expand All @@ -54,6 +56,7 @@ class MetadatasConnector extends Component {
dispatchFetchNotifications();
dispatchFetchReleaseProfiles();
dispatchFetchIndexers();
dispatchFetchDownloadClients();
}

//
Expand All @@ -74,7 +77,8 @@ MetadatasConnector.propTypes = {
dispatchFetchImportLists: PropTypes.func.isRequired,
dispatchFetchNotifications: PropTypes.func.isRequired,
dispatchFetchReleaseProfiles: PropTypes.func.isRequired,
dispatchFetchIndexers: PropTypes.func.isRequired
dispatchFetchIndexers: PropTypes.func.isRequired,
dispatchFetchDownloadClients: PropTypes.func.isRequired
};

export default connect(createMapStateToProps, mapDispatchToProps)(MetadatasConnector);
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -126,5 +127,6 @@ public class DownloadClientDefinition34
public string ConfigContract { get; set; }
public bool RemoveCompletedDownloads { get; set; }
public bool RemoveFailedDownloads { get; set; }
public List<string> Tags { get; set; }
}
}

0 comments on commit f0f95be

Please sign in to comment.