// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import React from 'react' import {injectIntl, IntlShape} from 'react-intl' import {IPropertyTemplate} from '../blocks/board' import {Card} from '../blocks/card' import mutator from '../mutator' import IconButton from '../widgets/buttons/iconButton' import DeleteIcon from '../widgets/icons/delete' import DuplicateIcon from '../widgets/icons/duplicate' import OptionsIcon from '../widgets/icons/options' import Menu from '../widgets/menu' import MenuWrapper from '../widgets/menuWrapper' import './boardCard.scss' import PropertyValueElement from './propertyValueElement' type BoardCardProps = { card: Card visiblePropertyTemplates: IPropertyTemplate[] isSelected: boolean isDropZone?: boolean onClick?: (e: React.MouseEvent) => void onDragStart: (e: React.DragEvent) => void onDragEnd: (e: React.DragEvent) => void onDrop: (e: React.DragEvent) => void intl: IntlShape readonly: boolean } type BoardCardState = { isDragged?: boolean isDragOver?: boolean } class BoardCard extends React.Component { constructor(props: BoardCardProps) { super(props) this.state = {} } shouldComponentUpdate(): boolean { return true } render(): JSX.Element { const {card, intl} = this.props const visiblePropertyTemplates = this.props.visiblePropertyTemplates || [] let className = this.props.isSelected ? 'BoardCard selected' : 'BoardCard' if (this.props.isDropZone && this.state.isDragOver) { className += ' dragover' } const element = (
{ this.setState({isDragged: true}) this.props.onDragStart(e) }} onDragEnd={(e) => { this.setState({isDragged: false}) this.props.onDragEnd(e) }} onDragOver={() => { if (!this.state.isDragOver) { this.setState({isDragOver: true}) } }} onDragEnter={() => { if (!this.state.isDragOver) { this.setState({isDragOver: true}) } }} onDragLeave={() => { this.setState({isDragOver: false}) }} onDrop={(e) => { this.setState({isDragOver: false}) if (this.props.isDropZone) { this.props.onDrop(e) } }} > {!this.props.readonly && }/> } id='delete' name={intl.formatMessage({id: 'BoardCard.delete', defaultMessage: 'Delete'})} onClick={() => mutator.deleteBlock(card, 'delete card')} /> } id='duplicate' name={intl.formatMessage({id: 'BoardCard.duplicate', defaultMessage: 'Duplicate'})} onClick={() => { mutator.duplicateCard(card.id) }} /> }
{ card.icon ?
{card.icon}
: undefined }
{card.title || intl.formatMessage({id: 'BoardCard.untitled', defaultMessage: 'Untitled'})}
{visiblePropertyTemplates.map((template) => ( ))}
) return element } } export default injectIntl(BoardCard)