Spaces:
Sleeping
Sleeping
File size: 3,992 Bytes
13555f3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
//
import React, {FC} from 'react'
import {useIntl} from 'react-intl'
import {Constants} from '../../constants'
import {Board, IPropertyTemplate} from '../../blocks/board'
import {BoardView} from '../../blocks/boardView'
import {Card} from '../../blocks/card'
import mutator from '../../mutator'
import Menu from '../../widgets/menu'
type Props = {
templateId: string
board: Board
activeView: BoardView
views: BoardView[]
cards: Card[]
}
const TableHeaderMenu: FC<Props> = (props: Props): JSX.Element => {
const {board, activeView, templateId, views, cards} = props
const intl = useIntl()
return (
<Menu>
<Menu.Text
id='sortAscending'
name={intl.formatMessage({id: 'TableHeaderMenu.sort-ascending', defaultMessage: 'Sort ascending'})}
onClick={() => mutator.changeViewSortOptions(board.id, activeView.id, activeView.fields.sortOptions, [{propertyId: templateId, reversed: false}])}
/>
<Menu.Text
id='sortDescending'
name={intl.formatMessage({id: 'TableHeaderMenu.sort-descending', defaultMessage: 'Sort descending'})}
onClick={() => mutator.changeViewSortOptions(board.id, activeView.id, activeView.fields.sortOptions, [{propertyId: templateId, reversed: true}])}
/>
<Menu.Text
id='insertLeft'
name={intl.formatMessage({id: 'TableHeaderMenu.insert-left', defaultMessage: 'Insert left'})}
onClick={() => {
if (props.templateId === Constants.titleColumnId) {
// eslint-disable-next-line no-warning-comments
// TODO: Handle name column
} else {
const index = board.cardProperties.findIndex((o: IPropertyTemplate) => o.id === templateId)
mutator.insertPropertyTemplate(board, activeView, index)
}
}}
/>
<Menu.Text
id='insertRight'
name={intl.formatMessage({id: 'TableHeaderMenu.insert-right', defaultMessage: 'Insert right'})}
onClick={() => {
if (templateId === Constants.titleColumnId) {
// eslint-disable-next-line no-warning-comments
// TODO: Handle title column
} else {
const index = board.cardProperties.findIndex((o: IPropertyTemplate) => o.id === templateId) + 1
mutator.insertPropertyTemplate(board, activeView, index)
}
}}
/>
{props.templateId !== Constants.titleColumnId &&
<>
<Menu.Text
id='hide'
name={intl.formatMessage({id: 'TableHeaderMenu.hide', defaultMessage: 'Hide'})}
onClick={() => mutator.changeViewVisibleProperties(board.id, activeView.id, activeView.fields.visiblePropertyIds, activeView.fields.visiblePropertyIds.filter((o: string) => o !== templateId))}
/>
<Menu.Text
id='duplicate'
name={intl.formatMessage({id: 'TableHeaderMenu.duplicate', defaultMessage: 'Duplicate'})}
onClick={() => mutator.duplicatePropertyTemplate(board, activeView, templateId)}
/>
<Menu.Text
id='delete'
name={intl.formatMessage({id: 'TableHeaderMenu.delete', defaultMessage: 'Delete'})}
onClick={() => mutator.deleteProperty(board, views, cards, templateId)}
/>
</>}
</Menu>
)
}
export default TableHeaderMenu
|