// External modules import * as React from 'react'; // Types import {IAssetItem, IAssetCallback} from '../../interfaces'; import {superdeskApi} from '../../apis'; // UI import {/* Checkbox, */ Icon, Dropdown, IconButton} from 'superdesk-ui-framework/react'; import {GridItem} from '../../ui/grid/GridItem'; import {GridItemFooter} from '../../ui/grid/GridItemFooter'; import {GridItemFooterBlock} from '../../ui/grid/GridItemFooterBlock'; import {GridItemThumb} from '../../ui/grid/GritItemThumb'; import {GridItemContent} from '../../ui/grid/GridItemContent'; import {GridItemProgressCircle} from '../../ui/grid/GridItemProgressCircle'; // Utils import { getHumanReadableFileSize, getIconTypeFromMimetype, getAssetStateLabel, } from '../../utils/ui'; import {getDropdownItemsForActions, getMimetypeHumanReadable, isAssetLocked} from '../../utils/assets'; interface IProps { asset: Partial; onClick(asset: Partial): void; onDoubleClick?(asset: Partial): void; remove?(): void; selected?: boolean; uploadProgress?: number; error?: boolean; toggleSelected?(asset: Partial): void; actions?: Array; itemSelected?: boolean; updateSelectedAssetIds?(asset: Partial): void; } export class AssetGridItem extends React.PureComponent { constructor(props: IProps) { super(props); this.onRemove = this.onRemove.bind(this); this.onItemClick = this.onItemClick.bind(this); this.onItemDoubleClick = this.onItemDoubleClick.bind(this); this.onCheckboxClick = this.onCheckboxClick.bind(this); this.toggleSelected = this.toggleSelected.bind(this); } onRemove(event: React.MouseEvent) { if (this.props.remove != null) { event.stopPropagation(); this.props.remove(); } } onItemClick() { this.props.onClick(this.props.asset); } onItemDoubleClick() { if (this.props.onDoubleClick != null) { this.props.onDoubleClick(this.props.asset); } } toggleSelected() { if (this.props.toggleSelected != null) { this.props.toggleSelected(this.props.asset); } } stopClickPropagation(e: React.MouseEvent) { e.stopPropagation(); } onCheckboxClick(e: React.MouseEvent) { if (this.props.updateSelectedAssetIds != null) { e.stopPropagation(); this.props.updateSelectedAssetIds(this.props.asset); } } render() { const {gettext, longFormatDateTime} = superdeskApi.localization; const typeIcon = getIconTypeFromMimetype( this.props.asset.mimetype ?? 'text', ); const actions = getDropdownItemsForActions(this.props.asset, this.props.actions); const mimetype = getMimetypeHumanReadable(this.props.asset.mimetype); return ( {this.props.uploadProgress && ( )} {this.props.asset._updated && ( )}

{this.props.asset.name?.substring(0, 25)}

{this.props.asset.description?.substring(0, 120)}

{gettext('Type:')} {mimetype}
{gettext('Size:')} {this.props.asset.length && getHumanReadableFileSize(this.props.asset.length)}
{this.props.asset.state && ( {getAssetStateLabel(this.props.asset.state)} )} {actions.length === 0 ? null : (
false} />
)}
); } }