import React from 'react'; import { useSelector } from 'react-redux'; import { CommandBody } from 'Commands/Command'; import TableRowCell from 'Components/Table/Cells/TableRowCell'; import createMultiSeriesSelector from 'Store/Selectors/createMultiSeriesSelector'; import sortByProp from 'Utilities/Array/sortByProp'; import translate from 'Utilities/String/translate'; import styles from './QueuedTaskRowNameCell.css'; function formatTitles(titles: string[]) { if (!titles) { return null; } if (titles.length > 11) { return ( {titles.slice(0, 10).join(', ')}, {titles.length - 10} more ); } return {titles.join(', ')}; } export interface QueuedTaskRowNameCellProps { commandName: string; body: CommandBody; clientUserAgent?: string; } export default function QueuedTaskRowNameCell( props: QueuedTaskRowNameCellProps ) { const { commandName, body, clientUserAgent } = props; const seriesIds = [...(body.seriesIds ?? [])]; if (body.seriesId) { seriesIds.push(body.seriesId); } const series = useSelector(createMultiSeriesSelector(seriesIds)); const sortedSeries = series.sort(sortByProp('sortTitle')); return ( {commandName} {sortedSeries.length ? ( - {formatTitles(sortedSeries.map((s) => s.title))} ) : null} {body.seasonNumber ? ( {' '} {translate('SeasonNumberToken', { seasonNumber: body.seasonNumber, })} ) : null} {clientUserAgent ? ( {translate('From')}: {clientUserAgent} ) : null} ); }