Sonarr/frontend/src/Settings/Profiles/Quality/QualityProfileItem.js

133 lines
3.2 KiB
JavaScript
Raw Normal View History

2022-05-20 04:15:43 +00:00
import classNames from 'classnames';
2018-01-13 02:01:27 +00:00
import PropTypes from 'prop-types';
import React, { Component } from 'react';
2022-05-20 04:15:43 +00:00
import CheckInput from 'Components/Form/CheckInput';
2018-01-13 02:01:27 +00:00
import Icon from 'Components/Icon';
import IconButton from 'Components/Link/IconButton';
2022-05-20 04:15:43 +00:00
import { icons } from 'Helpers/Props';
2023-07-22 19:14:33 +00:00
import translate from 'Utilities/String/translate';
2018-01-13 02:01:27 +00:00
import styles from './QualityProfileItem.css';
class QualityProfileItem extends Component {
//
// Listeners
onAllowedChange = ({ value }) => {
const {
qualityId,
onQualityProfileItemAllowedChange
} = this.props;
onQualityProfileItemAllowedChange(qualityId, value);
2022-05-20 04:15:43 +00:00
};
2018-01-13 02:01:27 +00:00
onCreateGroupPress = () => {
const {
qualityId,
onCreateGroupPress
} = this.props;
onCreateGroupPress(qualityId);
2022-05-20 04:15:43 +00:00
};
2018-01-13 02:01:27 +00:00
//
// Render
render() {
const {
editGroups,
isPreview,
groupId,
name,
allowed,
isDragging,
isOverCurrent,
connectDragSource
} = this.props;
return (
<div
className={classNames(
styles.qualityProfileItem,
isDragging && styles.isDragging,
isPreview && styles.isPreview,
isOverCurrent && styles.isOverCurrent,
groupId && styles.isInGroup
)}
>
<label
className={styles.qualityNameContainer}
>
{
editGroups && !groupId && !isPreview &&
<IconButton
className={styles.createGroupButton}
name={icons.GROUP}
2023-07-22 19:14:33 +00:00
title={translate('Group')}
2018-01-13 02:01:27 +00:00
onPress={this.onCreateGroupPress}
/>
}
{
!editGroups &&
<CheckInput
className={styles.checkInput}
containerClassName={styles.checkInputContainer}
name={name}
value={allowed}
isDisabled={!!groupId}
onChange={this.onAllowedChange}
/>
}
<div className={classNames(
styles.qualityName,
groupId && styles.isInGroup,
!allowed && styles.notAllowed
)}
>
{name}
</div>
</label>
{
connectDragSource(
<div className={styles.dragHandle}>
<Icon
className={styles.dragIcon}
2023-07-22 19:14:33 +00:00
title={translate('CreateGroup')}
2018-01-13 02:01:27 +00:00
name={icons.REORDER}
/>
</div>
)
}
</div>
);
}
}
QualityProfileItem.propTypes = {
editGroups: PropTypes.bool,
isPreview: PropTypes.bool,
groupId: PropTypes.number,
qualityId: PropTypes.number.isRequired,
name: PropTypes.string.isRequired,
allowed: PropTypes.bool.isRequired,
isDragging: PropTypes.bool.isRequired,
isOverCurrent: PropTypes.bool.isRequired,
isInGroup: PropTypes.bool,
connectDragSource: PropTypes.func,
onCreateGroupPress: PropTypes.func,
onQualityProfileItemAllowedChange: PropTypes.func
};
QualityProfileItem.defaultProps = {
isPreview: false,
isOverCurrent: false,
// The drag preview will not connect the drag handle.
connectDragSource: (node) => node
};
export default QualityProfileItem;