/* eslint-disable react/no-multi-comp */ import React, {Fragment} from 'react'; import {get} from 'lodash'; import {OverlayTrigger, Tooltip} from 'react-bootstrap'; import {ICalendar} from '../../interfaces'; import {superdeskApi} from '../../superdeskApi'; import {getVocabularyItemFieldTranslated} from '../../utils/vocabularies'; interface IProps { item: any; calendars: Array; field?: string; language?: string; } export class calendars extends React.PureComponent { render() { const {gettext} = superdeskApi.localization; const field = this.props.field ?? 'calendars'; const qcodes: Array = (get(this.props.item, field) || []) .map((calendar) => calendar.qcode); const calendars: Array<{ qcode: string, name: string, tooltip: string, disabled: boolean, }> = []; this.props.calendars .filter((calendar) => qcodes.includes(calendar.qcode)) .forEach((calendar) => { const name = getVocabularyItemFieldTranslated( calendar, 'name', this.props.language ); calendars.push({ qcode: calendar.qcode, name: name, tooltip: calendar.is_active ? name : gettext('{{ name }} (disabled)', {name: name}), disabled: !calendar.is_active, }); }); return ( {gettext('Calendar:')} { {calendars.length > 0 ? ( {calendars.map((calendar) => (
{calendar.tooltip}
))} )} > {calendars.map((calendar, index, array) => ( {calendar.name}{index === array.length - 1 ? '' : ', '} ))}
) : ( {gettext('No calendars assigned')} )}
}
); } }