2020-10-24 12:28:38 +02:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
|
|
|
//
|
|
|
|
import React, {FC} from 'react'
|
|
|
|
import {injectIntl, IntlShape} from 'react-intl'
|
2020-11-04 20:24:06 +01:00
|
|
|
|
|
|
|
import {Constants} from '../constants'
|
2020-10-24 12:28:38 +02:00
|
|
|
import mutator from '../mutator'
|
|
|
|
import {BoardTree} from '../viewModel/boardTree'
|
|
|
|
import Menu from '../widgets/menu'
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
templateId: string
|
|
|
|
boardTree: BoardTree
|
|
|
|
intl: IntlShape
|
|
|
|
}
|
|
|
|
|
|
|
|
const TableHeaderMenu: FC<Props> = (props: Props): JSX.Element => {
|
|
|
|
const {boardTree, templateId, intl} = props
|
|
|
|
const {board, activeView} = boardTree
|
|
|
|
return (
|
|
|
|
<Menu>
|
|
|
|
<Menu.Text
|
|
|
|
id='sortAscending'
|
|
|
|
name={intl.formatMessage({id: 'TableHeaderMenu.sort-ascending', defaultMessage: 'Sort ascending'})}
|
|
|
|
onClick={() => mutator.changeViewSortOptions(activeView, [{propertyId: templateId, reversed: false}])}
|
|
|
|
/>
|
|
|
|
<Menu.Text
|
|
|
|
id='sortDescending'
|
|
|
|
name={intl.formatMessage({id: 'TableHeaderMenu.sort-descending', defaultMessage: 'Sort descending'})}
|
|
|
|
onClick={() => mutator.changeViewSortOptions(activeView, [{propertyId: templateId, reversed: true}])}
|
|
|
|
/>
|
|
|
|
<Menu.Text
|
|
|
|
id='insertLeft'
|
|
|
|
name={intl.formatMessage({id: 'TableHeaderMenu.insert-left', defaultMessage: 'Insert left'})}
|
|
|
|
onClick={() => {
|
2020-11-04 20:21:09 +01:00
|
|
|
if (props.templateId === Constants.titleColumnId) {
|
2020-10-24 12:28:38 +02:00
|
|
|
// TODO: Handle name column
|
|
|
|
} else {
|
|
|
|
const index = board.cardProperties.findIndex((o) => o.id === templateId)
|
|
|
|
mutator.insertPropertyTemplate(boardTree, index)
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Menu.Text
|
|
|
|
id='insertRight'
|
|
|
|
name={intl.formatMessage({id: 'TableHeaderMenu.insert-right', defaultMessage: 'Insert right'})}
|
|
|
|
onClick={() => {
|
2020-11-04 20:21:09 +01:00
|
|
|
if (templateId === Constants.titleColumnId) {
|
|
|
|
// TODO: Handle title column
|
2020-10-24 12:28:38 +02:00
|
|
|
} else {
|
|
|
|
const index = board.cardProperties.findIndex((o) => o.id === templateId) + 1
|
|
|
|
mutator.insertPropertyTemplate(boardTree, index)
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
2020-11-04 20:21:09 +01:00
|
|
|
{props.templateId !== Constants.titleColumnId &&
|
2020-10-24 12:28:38 +02:00
|
|
|
<>
|
|
|
|
<Menu.Text
|
|
|
|
id='hide'
|
|
|
|
name={intl.formatMessage({id: 'TableHeaderMenu.hide', defaultMessage: 'Hide'})}
|
|
|
|
onClick={() => mutator.changeViewVisibleProperties(activeView, activeView.visiblePropertyIds.filter((o) => o !== templateId))}
|
|
|
|
/>
|
|
|
|
<Menu.Text
|
|
|
|
id='duplicate'
|
|
|
|
name={intl.formatMessage({id: 'TableHeaderMenu.duplicate', defaultMessage: 'Duplicate'})}
|
|
|
|
onClick={() => mutator.duplicatePropertyTemplate(boardTree, templateId)}
|
|
|
|
/>
|
|
|
|
<Menu.Text
|
|
|
|
id='delete'
|
|
|
|
name={intl.formatMessage({id: 'TableHeaderMenu.delete', defaultMessage: 'Delete'})}
|
|
|
|
onClick={() => mutator.deleteProperty(boardTree, templateId)}
|
|
|
|
/>
|
|
|
|
</>}
|
|
|
|
</Menu>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default injectIntl(TableHeaderMenu)
|