Lidarr/frontend/src/Activity/Blocklist/BlocklistRow.js

188 lines
4.5 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-10-11 22:28:32 +00:00
import TableSelectCell from 'Components/Table/Cells/TableSelectCell';
2020-09-07 01:33:10 +00:00
import TableRow from 'Components/Table/TableRow';
import { icons, kinds } from 'Helpers/Props';
2021-10-03 15:01:09 +00:00
import translate from 'Utilities/String/translate';
2021-08-19 21:35:06 +00:00
import BlocklistDetailsModal from './BlocklistDetailsModal';
import styles from './BlocklistRow.css';
2017-09-04 02:20:56 +00:00
2021-08-19 21:35:06 +00:00
class BlocklistRow extends Component {
2017-09-04 02:20:56 +00:00
//
// Lifecycle
constructor(props, context) {
super(props, context);
this.state = {
isDetailsModalOpen: false
};
}
//
// Listeners
onDetailsPress = () => {
this.setState({ isDetailsModalOpen: true });
2021-12-24 18:18:14 +00:00
};
2017-09-04 02:20:56 +00:00
onDetailsModalClose = () => {
this.setState({ isDetailsModalOpen: false });
2021-12-24 18:18:14 +00:00
};
2017-09-04 02:20:56 +00:00
//
// Render
render() {
const {
2020-10-11 22:28:32 +00:00
id,
2017-10-07 22:38:31 +00:00
artist,
2017-09-04 02:20:56 +00:00
sourceTitle,
quality,
date,
protocol,
indexer,
message,
2020-10-11 22:28:32 +00:00
isSelected,
columns,
2020-10-11 22:28:32 +00:00
onSelectedChange,
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>
2020-10-11 22:28:32 +00:00
<TableSelectCell
id={id}
isSelected={isSelected}
onSelectedChange={onSelectedChange}
/>
2017-09-04 02:20:56 +00:00
{
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
2021-10-03 15:01:09 +00:00
title={translate('RemoveFromBlocklist')}
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
})
}
2021-08-19 21:35:06 +00:00
<BlocklistDetailsModal
2017-09-04 02:20:56 +00:00
isOpen={this.state.isDetailsModalOpen}
sourceTitle={sourceTitle}
protocol={protocol}
indexer={indexer}
message={message}
onModalClose={this.onDetailsModalClose}
/>
</TableRow>
);
}
}
2021-08-19 21:35:06 +00:00
BlocklistRow.propTypes = {
2017-09-04 02:20:56 +00:00
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,
2020-10-11 22:28:32 +00:00
isSelected: PropTypes.bool.isRequired,
columns: PropTypes.arrayOf(PropTypes.object).isRequired,
2020-10-11 22:28:32 +00:00
onSelectedChange: PropTypes.func.isRequired,
onRemovePress: PropTypes.func.isRequired
2017-09-04 02:20:56 +00:00
};
2021-08-19 21:35:06 +00:00
export default BlocklistRow;