// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import React from 'react' import {FormattedMessage, IntlShape, injectIntl} from 'react-intl' import {BlockIcons} from '../blockIcons' import {MutableTextBlock} from '../blocks/textBlock' import {BoardTree} from '../viewModel/boardTree' import {PropertyType} from '../blocks/board' import {CardTree} from '../viewModel/cardTree' import mutator from '../mutator' import {Utils} from '../utils' import MenuWrapper from '../widgets/menuWrapper' import Menu from '../widgets/menu' import PropertyMenu from '../widgets/propertyMenu' import Editable from '../widgets/editable' import Button from '../widgets/buttons/button' import EmojiIcon from '../widgets/icons/emoji' import {MarkdownEditor} from './markdownEditor' import ContentBlock from './contentBlock' import CommentsList from './commentsList' import BlockIconSelector from './blockIconSelector' import PropertyValueElement from './propertyValueElement' import './cardDetail.scss' type Props = { boardTree: BoardTree cardTree: CardTree intl: IntlShape readonly: boolean } type State = { title: string } class CardDetail extends React.Component { private titleRef = React.createRef() shouldComponentUpdate(): boolean { return true } componentDidMount(): void { if (!this.state.title) { this.titleRef.current?.focus() } } constructor(props: Props) { super(props) this.state = { title: props.cardTree.card.title, } } render() { const {boardTree, cardTree, intl} = this.props const {board} = boardTree if (!cardTree) { return null } const {card, comments} = cardTree let contentElements if (cardTree.contents.length > 0) { contentElements = (
{cardTree.contents.map((block) => ( ))}
) } else { contentElements = (
{!this.props.readonly && { if (text) { const block = new MutableTextBlock() block.parentId = card.id block.rootId = card.rootId block.title = text block.order = (this.props.cardTree.contents.length + 1) * 1000 mutator.insertBlock(block, 'add card text') } }} /> }
) } const icon = card.icon return ( <>
{!this.props.readonly && !icon &&
} this.setState({title})} saveOnEsc={true} onSave={() => { if (this.state.title !== this.props.cardTree.card.title) { mutator.changeTitle(card, this.state.title) } }} onCancel={() => this.setState({title: this.props.cardTree.card.title})} readonly={this.props.readonly} /> {/* Property list */}
{board.cardProperties.map((propertyTemplate) => { return (
{this.props.readonly &&
{propertyTemplate.name}
} {!this.props.readonly &&
mutator.renameProperty(board, propertyTemplate.id, newName)} onTypeChanged={(newType: PropertyType) => mutator.changePropertyType(boardTree, propertyTemplate, newType)} onDelete={(id: string) => mutator.deleteProperty(boardTree, id)} />
}
) })} {!this.props.readonly &&
}
{/* Comments */} {!this.props.readonly && <>

}
{/* Content blocks */}
{contentElements}
{!this.props.readonly &&
{ const block = new MutableTextBlock() block.parentId = card.id block.rootId = card.rootId block.order = (this.props.cardTree.contents.length + 1) * 1000 mutator.insertBlock(block, 'add text') }} /> Utils.selectLocalFile( (file) => mutator.createImageBlock(card, file, (this.props.cardTree.contents.length + 1) * 1000), '.jpg,.jpeg,.png', )} />
} ) } } export default injectIntl(CardDetail)