1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-24 13:43:12 +02:00

Add BlockTypes type

This commit is contained in:
Chen-I Lim 2020-11-10 11:20:43 -08:00
parent 506f2cd3bf
commit 5b07bee7ec
2 changed files with 11 additions and 6 deletions

View File

@ -2,12 +2,14 @@
// See LICENSE.txt for license information.
import {Utils} from '../utils'
type BlockTypes = 'board' | 'view' | 'card' | 'text' | 'image' | 'divider' | 'comment'
interface IBlock {
readonly id: string
readonly parentId: string
readonly schema: number
readonly type: string
readonly type: BlockTypes
readonly title?: string
readonly fields: Readonly<Record<string, any>>
@ -21,7 +23,7 @@ interface IMutableBlock extends IBlock {
parentId: string
schema: number
type: string
type: BlockTypes
title?: string
fields: Record<string, any>
@ -34,19 +36,18 @@ class MutableBlock implements IMutableBlock {
id: string = Utils.createGuid()
schema: number
parentId: string
type: string
type: BlockTypes
title: string
fields: Record<string, any> = {}
createAt: number = Date.now()
updateAt = 0
deleteAt = 0
static duplicate(block: IBlock): IBlock {
static duplicate(block: IBlock): IMutableBlock {
const now = Date.now()
const newBlock = new MutableBlock(block)
newBlock.id = Utils.createGuid()
newBlock.title = `Copy of ${block.title}`
newBlock.createAt = now
newBlock.updateAt = now
newBlock.deleteAt = 0

View File

@ -105,7 +105,11 @@ class BoardCard extends React.Component<BoardCardProps, BoardCardState> {
icon={<DuplicateIcon/>}
id='duplicate'
name={intl.formatMessage({id: 'BoardCard.duplicate', defaultMessage: 'Duplicate'})}
onClick={() => mutator.insertBlock(MutableBlock.duplicate(card), 'duplicate card')}
onClick={() => {
const newCard = MutableBlock.duplicate(card)
newCard.title = `Copy of ${card.title}`
mutator.insertBlock(newCard, 'duplicate card')
}}
/>
</Menu>
</MenuWrapper>