duplicate view
This commit is contained in:
parent
e35ba1abc5
commit
061767103c
2 changed files with 39 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
|||
// See LICENSE.txt for license information.
|
||||
import {IBlock} from '../blocks/block'
|
||||
import {FilterGroup} from '../filterGroup'
|
||||
import {Utils} from '../utils'
|
||||
|
||||
import {MutableBlock} from './block'
|
||||
|
||||
|
@ -18,6 +19,8 @@ interface BoardView extends IBlock {
|
|||
readonly filter: FilterGroup
|
||||
readonly cardOrder: readonly string[]
|
||||
readonly columnWidths: Readonly<Record<string, number>>
|
||||
|
||||
duplicate(): MutableBoardView
|
||||
}
|
||||
|
||||
class MutableBoardView extends MutableBlock implements BoardView {
|
||||
|
@ -101,6 +104,12 @@ class MutableBoardView extends MutableBlock implements BoardView {
|
|||
this.viewType = 'board'
|
||||
}
|
||||
}
|
||||
|
||||
duplicate(): MutableBoardView {
|
||||
const view = new MutableBoardView(this)
|
||||
view.id = Utils.createGuid()
|
||||
return view
|
||||
}
|
||||
}
|
||||
|
||||
export {BoardView, MutableBoardView, IViewType, ISortOption}
|
||||
|
|
|
@ -12,6 +12,7 @@ import {BoardTree} from '../viewModel/boardTree'
|
|||
import AddIcon from '../widgets/icons/add'
|
||||
import BoardIcon from '../widgets/icons/board'
|
||||
import DeleteIcon from '../widgets/icons/delete'
|
||||
import DuplicateIcon from '../widgets/icons/duplicate'
|
||||
import TableIcon from '../widgets/icons/table'
|
||||
import Menu from '../widgets/menu'
|
||||
|
||||
|
@ -24,6 +25,27 @@ type Props = {
|
|||
}
|
||||
|
||||
export class ViewMenu extends React.PureComponent<Props> {
|
||||
private handleDuplicateView = async () => {
|
||||
const {boardTree, showView} = this.props
|
||||
Utils.log('duplicateView')
|
||||
const currentViewId = boardTree.activeView.id
|
||||
const newView = boardTree.activeView.duplicate()
|
||||
newView.title = `Copy of ${boardTree.activeView.title}`
|
||||
await mutator.insertBlock(
|
||||
newView,
|
||||
'duplicate view',
|
||||
async () => {
|
||||
// This delay is needed because OctoListener has a default 100 ms notification delay before updates
|
||||
setTimeout(() => {
|
||||
showView(newView.id)
|
||||
}, 120)
|
||||
},
|
||||
async () => {
|
||||
showView(currentViewId)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
private handleDeleteView = async () => {
|
||||
const {boardTree, showView} = this.props
|
||||
Utils.log('deleteView')
|
||||
|
@ -113,6 +135,14 @@ export class ViewMenu extends React.PureComponent<Props> {
|
|||
onClick={this.handleViewClick}
|
||||
/>))}
|
||||
<Menu.Separator/>
|
||||
{!this.props.readonly &&
|
||||
<Menu.Text
|
||||
id='__duplicateView'
|
||||
name='Duplicate View'
|
||||
icon={<DuplicateIcon/>}
|
||||
onClick={this.handleDuplicateView}
|
||||
/>
|
||||
}
|
||||
{!this.props.readonly && boardTree.views.length > 1 &&
|
||||
<Menu.Text
|
||||
id='__deleteView'
|
||||
|
|
Loading…
Reference in a new issue