TagSelect field type

(cherry picked from commit 09347f79c5c486ccb88d732c1bac1cacc668536c)
This commit is contained in:
Qstick 2020-01-06 23:31:33 -05:00
parent 416104f05d
commit f8f857376a
6 changed files with 113 additions and 2 deletions

View File

@ -23,6 +23,7 @@ import QualityProfileSelectInputConnector from './QualityProfileSelectInputConne
import RootFolderSelectInputConnector from './RootFolderSelectInputConnector';
import SeriesTypeSelectInput from './SeriesTypeSelectInput';
import TagInputConnector from './TagInputConnector';
import TagSelectInputConnector from './TagSelectInputConnector';
import TextInput from './TextInput';
import TextTagInputConnector from './TextTagInputConnector';
import UMaskInput from './UMaskInput';
@ -96,6 +97,9 @@ function getComponent(type) {
case inputTypes.UMASK:
return UMaskInput;
case inputTypes.TAG_SELECT:
return TagSelectInputConnector;
default:
return TextInput;
}

View File

@ -31,6 +31,8 @@ function getType({ type, selectOptionsProviderAction }) {
return inputTypes.SELECT;
case 'tag':
return inputTypes.TEXT_TAG;
case 'tagSelect':
return inputTypes.TAG_SELECT;
case 'textbox':
return inputTypes.TEXT;
case 'oAuth':

View File

@ -0,0 +1,102 @@
import _ from 'lodash';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import TagInput from './TagInput';
function createMapStateToProps() {
return createSelector(
(state, { value }) => value,
(state, { values }) => values,
(tags, tagList) => {
const sortedTags = _.sortBy(tagList, 'value');
return {
tags: tags.reduce((acc, tag) => {
const matchingTag = _.find(tagList, { key: tag });
if (matchingTag) {
acc.push({
id: tag,
name: matchingTag.value
});
}
return acc;
}, []),
tagList: sortedTags.map(({ key: id, value: name }) => {
return {
id,
name
};
}),
allTags: sortedTags
};
}
);
}
class TagSelectInputConnector extends Component {
//
// Listeners
onTagAdd = (tag) => {
const {
name,
value,
allTags
} = this.props;
const existingTag =_.some(allTags, { key: tag.id });
const newValue = value.slice();
if (existingTag) {
newValue.push(tag.id);
}
this.props.onChange({ name, value: newValue });
}
onTagDelete = ({ index }) => {
const {
name,
value
} = this.props;
const newValue = value.slice();
newValue.splice(index, 1);
this.props.onChange({
name,
value: newValue
});
}
//
// Render
render() {
return (
<TagInput
onTagAdd={this.onTagAdd}
onTagDelete={this.onTagDelete}
{...this.props}
/>
);
}
}
TagSelectInputConnector.propTypes = {
name: PropTypes.string.isRequired,
value: PropTypes.arrayOf(PropTypes.number).isRequired,
values: PropTypes.arrayOf(PropTypes.object).isRequired,
allTags: PropTypes.arrayOf(PropTypes.object).isRequired,
onChange: PropTypes.func.isRequired
};
export default connect(createMapStateToProps)(TagSelectInputConnector);

View File

@ -18,6 +18,7 @@ export const SELECT = 'select';
export const SERIES_TYPE_SELECT = 'artistTypeSelect';
export const DYNAMIC_SELECT = 'dynamicSelect';
export const TAG = 'tag';
export const TAG_SELECT = 'tagSelect';
export const TEXT = 'text';
export const TEXT_TAG = 'textTag';
export const UMASK = 'umask';
@ -43,6 +44,7 @@ export const all = [
DYNAMIC_SELECT,
SERIES_TYPE_SELECT,
TAG,
TAG_SELECT,
TEXT,
TEXT_TAG,
UMASK

View File

@ -102,7 +102,7 @@ namespace Lidarr.Http.ClientSchema
Section = fieldAttribute.Section
};
if (fieldAttribute.Type == FieldType.Select)
if (fieldAttribute.Type == FieldType.Select || fieldAttribute.Type == FieldType.TagSelect)
{
if (fieldAttribute.SelectOptionsProviderAction.IsNotNullOrWhiteSpace())
{

View File

@ -63,7 +63,8 @@ namespace NzbDrone.Core.Annotations
Captcha,
OAuth,
Device,
Playlist
Playlist,
TagSelect
}
public enum HiddenType