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'
|
2020-10-20 21:50:53 +02:00
|
|
|
|
2020-10-20 21:52:56 +02:00
|
|
|
import {Board} from '../blocks/board'
|
2020-10-21 03:28:55 +02:00
|
|
|
import {BoardView, MutableBoardView} from '../blocks/boardView'
|
2020-10-21 03:54:39 +02:00
|
|
|
import {BoardTree} from '../viewModel/boardTree'
|
2020-10-20 21:52:56 +02:00
|
|
|
import mutator from '../mutator'
|
|
|
|
import {Utils} from '../utils'
|
|
|
|
import Menu from '../widgets/menu'
|
2020-10-14 12:39:41 +02:00
|
|
|
|
|
|
|
type Props = {
|
2020-10-20 21:50:53 +02:00
|
|
|
boardTree?: BoardTree
|
|
|
|
board: Board,
|
|
|
|
showView: (id: string) => void
|
2020-10-14 12:39:41 +02:00
|
|
|
}
|
2020-10-14 21:39:34 +02:00
|
|
|
|
2020-10-14 12:39:41 +02:00
|
|
|
export default class ViewMenu extends React.Component<Props> {
|
2020-10-20 21:50:53 +02:00
|
|
|
handleDeleteView = async (id: string) => {
|
|
|
|
const {board, boardTree, showView} = this.props
|
|
|
|
Utils.log('deleteView')
|
|
|
|
const view = boardTree.activeView
|
|
|
|
const nextView = boardTree.views.find((o) => o !== view)
|
|
|
|
await mutator.deleteBlock(view, 'delete view')
|
|
|
|
showView(nextView.id)
|
|
|
|
}
|
2020-10-14 12:39:41 +02:00
|
|
|
|
2020-10-20 21:50:53 +02:00
|
|
|
handleViewClick = (id: string) => {
|
|
|
|
const {boardTree, showView} = this.props
|
|
|
|
Utils.log('view ' + id)
|
|
|
|
const view = boardTree.views.find((o) => o.id === id)
|
|
|
|
showView(view.id)
|
|
|
|
}
|
2020-10-14 12:39:41 +02:00
|
|
|
|
2020-10-20 21:50:53 +02:00
|
|
|
handleAddViewBoard = async (id: string) => {
|
|
|
|
const {board, boardTree, showView} = this.props
|
|
|
|
Utils.log('addview-board')
|
2020-10-21 03:28:55 +02:00
|
|
|
const view = new MutableBoardView()
|
2020-10-20 21:52:56 +02:00
|
|
|
view.title = 'Board View'
|
|
|
|
view.viewType = 'board'
|
2020-10-20 21:50:53 +02:00
|
|
|
view.parentId = board.id
|
2020-10-14 12:39:41 +02:00
|
|
|
|
2020-10-20 21:50:53 +02:00
|
|
|
const oldViewId = boardTree.activeView.id
|
2020-10-14 12:39:41 +02:00
|
|
|
|
2020-10-20 21:50:53 +02:00
|
|
|
await mutator.insertBlock(
|
|
|
|
view,
|
|
|
|
'add view',
|
|
|
|
async () => {
|
|
|
|
showView(view.id)
|
|
|
|
},
|
|
|
|
async () => {
|
|
|
|
showView(oldViewId)
|
2020-10-20 21:52:56 +02:00
|
|
|
})
|
2020-10-20 21:50:53 +02:00
|
|
|
}
|
2020-10-14 12:39:41 +02:00
|
|
|
|
2020-10-20 21:50:53 +02:00
|
|
|
handleAddViewTable = async (id: string) => {
|
|
|
|
const {board, boardTree, showView} = this.props
|
2020-10-14 12:39:41 +02:00
|
|
|
|
2020-10-20 21:50:53 +02:00
|
|
|
Utils.log('addview-table')
|
2020-10-21 03:28:55 +02:00
|
|
|
const view = new MutableBoardView()
|
2020-10-20 21:52:56 +02:00
|
|
|
view.title = 'Table View'
|
|
|
|
view.viewType = 'table'
|
2020-10-20 21:50:53 +02:00
|
|
|
view.parentId = board.id
|
|
|
|
view.visiblePropertyIds = board.cardProperties.map((o) => o.id)
|
2020-10-14 12:39:41 +02:00
|
|
|
|
2020-10-20 21:50:53 +02:00
|
|
|
const oldViewId = boardTree.activeView.id
|
2020-10-14 12:39:41 +02:00
|
|
|
|
2020-10-20 21:50:53 +02:00
|
|
|
await mutator.insertBlock(
|
|
|
|
view,
|
|
|
|
'add view',
|
|
|
|
async () => {
|
|
|
|
showView(view.id)
|
|
|
|
},
|
|
|
|
async () => {
|
|
|
|
showView(oldViewId)
|
2020-10-20 21:52:56 +02:00
|
|
|
})
|
2020-10-20 21:50:53 +02:00
|
|
|
}
|
2020-10-14 12:39:41 +02:00
|
|
|
|
2020-10-20 21:50:53 +02:00
|
|
|
render() {
|
|
|
|
const {boardTree} = this.props
|
|
|
|
return (
|
|
|
|
<Menu>
|
|
|
|
{boardTree.views.map((view) => (<Menu.Text
|
|
|
|
key={view.id}
|
|
|
|
id={view.id}
|
|
|
|
name={view.title}
|
|
|
|
onClick={this.handleViewClick}
|
|
|
|
/>))}
|
|
|
|
<Menu.Separator/>
|
|
|
|
{boardTree.views.length > 1 && <Menu.Text
|
|
|
|
id='__deleteView'
|
|
|
|
name='Delete View'
|
|
|
|
onClick={this.handleDeleteView}
|
|
|
|
/>}
|
|
|
|
<Menu.SubMenu
|
|
|
|
id='__addView'
|
|
|
|
name='Add View'
|
|
|
|
>
|
|
|
|
<Menu.Text
|
|
|
|
id='board'
|
|
|
|
name='Board'
|
|
|
|
onClick={this.handleAddViewBoard}
|
|
|
|
/>
|
|
|
|
<Menu.Text
|
|
|
|
id='table'
|
|
|
|
name='Table'
|
|
|
|
onClick={this.handleAddViewTable}
|
|
|
|
/>
|
|
|
|
</Menu.SubMenu>
|
|
|
|
</Menu>
|
|
|
|
)
|
|
|
|
}
|
2020-10-14 12:39:41 +02:00
|
|
|
}
|