focalboard/webapp/src/components/boardCard.tsx

103 lines
3.6 KiB
TypeScript
Raw Normal View History

2020-10-20 21:50:53 +02:00
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
2020-10-20 21:52:56 +02:00
import React from 'react'
import {injectIntl, IntlShape} from 'react-intl'
import {MutableBlock} from '../blocks/block'
2020-10-20 21:50:53 +02:00
2020-10-20 21:52:56 +02:00
import {IPropertyTemplate} from '../blocks/board'
import {Card} from '../blocks/card'
import mutator from '../mutator'
import MenuWrapper from '../widgets/menuWrapper'
import Menu from '../widgets/menu'
import OptionsIcon from '../widgets/icons/options'
2020-10-26 12:43:16 +01:00
import PropertyValueElement from './propertyValueElement'
import './boardCard.scss'
2020-10-08 18:21:27 +02:00
type BoardCardProps = {
2020-10-20 21:50:53 +02:00
card: Card
visiblePropertyTemplates: IPropertyTemplate[]
isSelected: boolean
2020-10-20 21:50:53 +02:00
onClick?: (e: React.MouseEvent<HTMLDivElement>) => void
onDragStart?: (e: React.DragEvent<HTMLDivElement>) => void
onDragEnd?: (e: React.DragEvent<HTMLDivElement>) => void
intl: IntlShape
2020-10-08 18:21:27 +02:00
}
type BoardCardState = {
2020-10-20 21:50:53 +02:00
isDragged?: boolean
2020-10-08 18:21:27 +02:00
}
class BoardCard extends React.Component<BoardCardProps, BoardCardState> {
2020-10-20 21:50:53 +02:00
constructor(props: BoardCardProps) {
super(props)
this.state = {}
}
2020-10-08 18:21:27 +02:00
2020-10-22 23:10:38 +02:00
shouldComponentUpdate(): boolean {
return true
}
render(): JSX.Element {
const {card, intl} = this.props
2020-10-20 21:50:53 +02:00
const visiblePropertyTemplates = this.props.visiblePropertyTemplates || []
2020-10-25 22:01:53 +01:00
const className = this.props.isSelected ? 'BoardCard selected' : 'BoardCard'
2020-10-22 23:10:38 +02:00
const element = (
<div
className={className}
2020-10-20 21:50:53 +02:00
draggable={true}
style={{opacity: this.state.isDragged ? 0.5 : 1}}
onClick={this.props.onClick}
onDragStart={(e) => {
2020-10-22 23:10:38 +02:00
this.setState({isDragged: true})
this.props.onDragStart(e)
2020-10-20 21:50:53 +02:00
}}
onDragEnd={(e) => {
2020-10-22 23:10:38 +02:00
this.setState({isDragged: false})
this.props.onDragEnd(e)
2020-10-20 21:50:53 +02:00
}}
>
2020-10-27 22:00:15 +01:00
<MenuWrapper
className='optionsMenu'
stopPropagationOnToggle={true}
>
<div className='octo-hoverbutton square'><OptionsIcon/></div>
<Menu>
<Menu.Text
id='delete'
name={intl.formatMessage({id: 'BoardCard.delete', defaultMessage: 'Delete'})}
onClick={() => mutator.deleteBlock(card, 'delete card')}
/>
<Menu.Text
id='duplicate'
name={intl.formatMessage({id: 'BoardCard.duplicate', defaultMessage: 'Duplicate'})}
onClick={() => mutator.insertBlock(MutableBlock.duplicate(card), 'duplicate card')}
/>
</Menu>
</MenuWrapper>
2020-10-08 18:21:27 +02:00
2020-10-20 21:50:53 +02:00
<div className='octo-icontitle'>
{ card.icon ? <div className='octo-icon'>{card.icon}</div> : undefined }
<div key='__title'>{card.title || intl.formatMessage({id: 'BoardCard.untitled', defaultMessage: 'Untitled'})}</div>
2020-10-20 21:50:53 +02:00
</div>
2020-10-26 12:43:16 +01:00
{visiblePropertyTemplates.map((template) => (
<PropertyValueElement
key={template.id}
readOnly={true}
card={card}
propertyTemplate={template}
emptyDisplayValue=''
/>
))}
2020-10-22 23:10:38 +02:00
</div>
)
2020-10-08 18:21:27 +02:00
2020-10-20 21:50:53 +02:00
return element
}
2020-10-08 18:21:27 +02:00
}
export default injectIntl(BoardCard)