Lidarr/frontend/src/Activity/Blacklist/BlacklistRow.js

175 lines
4.1 KiB
JavaScript
Raw Normal View History

2017-09-04 02:20:56 +00:00
import PropTypes from 'prop-types';
import React, { Component } from 'react';
2020-09-07 01:33:10 +00:00
import TrackQuality from 'Album/TrackQuality';
import ArtistNameLink from 'Artist/ArtistNameLink';
2017-09-04 02:20:56 +00:00
import IconButton from 'Components/Link/IconButton';
import RelativeDateCellConnector from 'Components/Table/Cells/RelativeDateCellConnector';
import TableRowCell from 'Components/Table/Cells/TableRowCell';
2020-09-07 01:33:10 +00:00
import TableRow from 'Components/Table/TableRow';
import { icons, kinds } from 'Helpers/Props';
2017-09-04 02:20:56 +00:00
import BlacklistDetailsModal from './BlacklistDetailsModal';
import styles from './BlacklistRow.css';
class BlacklistRow extends Component {
//
// Lifecycle
constructor(props, context) {
super(props, context);
this.state = {
isDetailsModalOpen: false
};
}
//
// Listeners
onDetailsPress = () => {
this.setState({ isDetailsModalOpen: true });
}
onDetailsModalClose = () => {
this.setState({ isDetailsModalOpen: false });
}
//
// Render
render() {
const {
2017-10-07 22:38:31 +00:00
artist,
2017-09-04 02:20:56 +00:00
sourceTitle,
quality,
date,
protocol,
indexer,
message,
columns,
onRemovePress
2017-09-04 02:20:56 +00:00
} = this.props;
if (!artist) {
return null;
}
2017-09-04 02:20:56 +00:00
return (
<TableRow>
{
columns.map((column) => {
const {
name,
isVisible
} = column;
if (!isVisible) {
return null;
}
if (name === 'artists.sortName') {
2017-09-04 02:20:56 +00:00
return (
<TableRowCell key={name}>
<ArtistNameLink
foreignArtistId={artist.foreignArtistId}
2017-10-07 22:38:31 +00:00
artistName={artist.artistName}
2017-09-04 02:20:56 +00:00
/>
</TableRowCell>
);
}
if (name === 'sourceTitle') {
return (
<TableRowCell key={name}>
{sourceTitle}
</TableRowCell>
);
}
if (name === 'quality') {
return (
<TableRowCell
key={name}
className={styles.quality}
>
<TrackQuality
2017-09-04 02:20:56 +00:00
quality={quality}
/>
</TableRowCell>
);
}
if (name === 'date') {
return (
<RelativeDateCellConnector
key={name}
date={date}
/>
);
}
if (name === 'indexer') {
return (
<TableRowCell
key={name}
className={styles.indexer}
>
{indexer}
</TableRowCell>
);
}
if (name === 'actions') {
2017-09-04 02:20:56 +00:00
return (
<TableRowCell
key={name}
className={styles.actions}
2017-09-04 02:20:56 +00:00
>
<IconButton
name={icons.INFO}
onPress={this.onDetailsPress}
/>
<IconButton
title="Remove from blacklist"
name={icons.REMOVE}
kind={kinds.DANGER}
onPress={onRemovePress}
/>
2017-09-04 02:20:56 +00:00
</TableRowCell>
);
}
2017-10-07 06:21:06 +00:00
return null;
2017-09-04 02:20:56 +00:00
})
}
<BlacklistDetailsModal
isOpen={this.state.isDetailsModalOpen}
sourceTitle={sourceTitle}
protocol={protocol}
indexer={indexer}
message={message}
onModalClose={this.onDetailsModalClose}
/>
</TableRow>
);
}
}
BlacklistRow.propTypes = {
id: PropTypes.number.isRequired,
2017-10-07 22:38:31 +00:00
artist: PropTypes.object.isRequired,
2017-09-04 02:20:56 +00:00
sourceTitle: PropTypes.string.isRequired,
quality: PropTypes.object.isRequired,
date: PropTypes.string.isRequired,
protocol: PropTypes.string.isRequired,
indexer: PropTypes.string,
message: PropTypes.string,
columns: PropTypes.arrayOf(PropTypes.object).isRequired,
onRemovePress: PropTypes.func.isRequired
2017-09-04 02:20:56 +00:00
};
export default BlacklistRow;