mirror of
https://github.com/mattermost/focalboard.git
synced 2025-01-26 18:48:15 +02:00
Migrating viewHeader to functional component
This commit is contained in:
parent
5ad7ed5fc0
commit
db3dce7e58
@ -1,6 +1,6 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
import React from 'react'
|
import React, {useState} from 'react'
|
||||||
import {FormattedMessage} from 'react-intl'
|
import {FormattedMessage} from 'react-intl'
|
||||||
|
|
||||||
import ViewMenu from '../../components/viewMenu'
|
import ViewMenu from '../../components/viewMenu'
|
||||||
@ -36,133 +36,112 @@ type Props = {
|
|||||||
readonly: boolean
|
readonly: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
type State = {
|
const ViewHeader = React.memo((props: Props) => {
|
||||||
showFilter: boolean
|
const [showFilter, setShowFilter] = useState(false)
|
||||||
}
|
|
||||||
|
|
||||||
class ViewHeader extends React.Component<Props, State> {
|
const {boardTree, showView, withGroupBy} = props
|
||||||
shouldComponentUpdate(): boolean {
|
const {board, activeView} = boardTree
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(props: Props) {
|
const hasFilter = activeView.filter && activeView.filter.filters?.length > 0
|
||||||
super(props)
|
|
||||||
this.state = {showFilter: false}
|
|
||||||
}
|
|
||||||
|
|
||||||
render(): JSX.Element {
|
return (
|
||||||
const {boardTree, showView, withGroupBy} = this.props
|
<div className='ViewHeader'>
|
||||||
const {board, activeView} = boardTree
|
<Editable
|
||||||
|
style={{color: 'rgb(var(--main-fg))', fontWeight: 600}}
|
||||||
const hasFilter = activeView.filter && activeView.filter.filters?.length > 0
|
text={activeView.title}
|
||||||
|
placeholderText='Untitled View'
|
||||||
return (
|
onChanged={(text) => {
|
||||||
<div className='ViewHeader'>
|
mutator.changeTitle(activeView, text)
|
||||||
<Editable
|
}}
|
||||||
style={{color: 'rgb(var(--main-fg))', fontWeight: 600}}
|
readonly={props.readonly}
|
||||||
text={activeView.title}
|
/>
|
||||||
placeholderText='Untitled View'
|
<MenuWrapper>
|
||||||
onChanged={(text) => {
|
<IconButton icon={<DropdownIcon/>}/>
|
||||||
mutator.changeTitle(activeView, text)
|
<ViewMenu
|
||||||
}}
|
board={board}
|
||||||
readonly={this.props.readonly}
|
boardTree={boardTree}
|
||||||
|
showView={showView}
|
||||||
|
readonly={props.readonly}
|
||||||
/>
|
/>
|
||||||
<MenuWrapper>
|
</MenuWrapper>
|
||||||
<IconButton icon={<DropdownIcon/>}/>
|
|
||||||
<ViewMenu
|
<div className='octo-spacer'/>
|
||||||
board={board}
|
|
||||||
|
{!props.readonly &&
|
||||||
|
<>
|
||||||
|
{/* Card properties */}
|
||||||
|
|
||||||
|
<ViewHeaderPropertiesMenu
|
||||||
|
properties={board.cardProperties}
|
||||||
|
activeView={activeView}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Group by */}
|
||||||
|
|
||||||
|
{withGroupBy &&
|
||||||
|
<ViewHeaderGroupByMenu
|
||||||
|
properties={board.cardProperties}
|
||||||
|
activeView={activeView}
|
||||||
|
groupByPropertyName={boardTree.groupByProperty?.name}
|
||||||
|
/>}
|
||||||
|
|
||||||
|
{/* Filter */}
|
||||||
|
|
||||||
|
<ModalWrapper>
|
||||||
|
<Button
|
||||||
|
active={hasFilter}
|
||||||
|
onClick={() => setShowFilter(true)}
|
||||||
|
>
|
||||||
|
<FormattedMessage
|
||||||
|
id='ViewHeader.filter'
|
||||||
|
defaultMessage='Filter'
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
{showFilter &&
|
||||||
|
<FilterComponent
|
||||||
boardTree={boardTree}
|
boardTree={boardTree}
|
||||||
showView={showView}
|
onClose={() => setShowFilter(false)}
|
||||||
readonly={this.props.readonly}
|
/>}
|
||||||
/>
|
</ModalWrapper>
|
||||||
</MenuWrapper>
|
|
||||||
|
|
||||||
<div className='octo-spacer'/>
|
{/* Sort */}
|
||||||
|
|
||||||
{!this.props.readonly &&
|
<ViewHeaderSortMenu
|
||||||
<>
|
properties={board.cardProperties}
|
||||||
{/* Card properties */}
|
activeView={activeView}
|
||||||
|
orderedCards={boardTree.orderedCards()}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
|
||||||
<ViewHeaderPropertiesMenu
|
{/* Search */}
|
||||||
properties={boardTree.board.cardProperties}
|
|
||||||
activeView={boardTree.activeView}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Group by */}
|
<ViewHeaderSearch
|
||||||
|
boardTree={boardTree}
|
||||||
|
setSearchText={props.setSearchText}
|
||||||
|
/>
|
||||||
|
|
||||||
{withGroupBy &&
|
{/* Options menu */}
|
||||||
<ViewHeaderGroupByMenu
|
|
||||||
properties={boardTree.board.cardProperties}
|
|
||||||
activeView={boardTree.activeView}
|
|
||||||
groupByPropertyName={boardTree.groupByProperty?.name}
|
|
||||||
/>}
|
|
||||||
|
|
||||||
{/* Filter */}
|
{!props.readonly &&
|
||||||
|
<>
|
||||||
<ModalWrapper>
|
<ViewHeaderActionsMenu
|
||||||
<Button
|
boardTree={boardTree}
|
||||||
active={hasFilter}
|
|
||||||
onClick={this.showFilterDialog}
|
|
||||||
>
|
|
||||||
<FormattedMessage
|
|
||||||
id='ViewHeader.filter'
|
|
||||||
defaultMessage='Filter'
|
|
||||||
/>
|
|
||||||
</Button>
|
|
||||||
{this.state.showFilter &&
|
|
||||||
<FilterComponent
|
|
||||||
boardTree={boardTree}
|
|
||||||
onClose={this.hideFilterDialog}
|
|
||||||
/>}
|
|
||||||
</ModalWrapper>
|
|
||||||
|
|
||||||
{/* Sort */}
|
|
||||||
|
|
||||||
<ViewHeaderSortMenu
|
|
||||||
properties={boardTree.board.cardProperties}
|
|
||||||
activeView={boardTree.activeView}
|
|
||||||
orderedCards={boardTree.orderedCards()}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
|
|
||||||
{/* Search */}
|
|
||||||
|
|
||||||
<ViewHeaderSearch
|
|
||||||
boardTree={this.props.boardTree}
|
|
||||||
setSearchText={this.props.setSearchText}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Options menu */}
|
{/* New card button */}
|
||||||
|
|
||||||
{!this.props.readonly &&
|
<NewCardButton
|
||||||
<>
|
boardTree={boardTree}
|
||||||
<ViewHeaderActionsMenu
|
addCard={props.addCard}
|
||||||
boardTree={this.props.boardTree}
|
addCardFromTemplate={props.addCardFromTemplate}
|
||||||
/>
|
addCardTemplate={props.addCardTemplate}
|
||||||
|
editCardTemplate={props.editCardTemplate}
|
||||||
{/* New card button */}
|
/>
|
||||||
|
</>
|
||||||
<NewCardButton
|
}
|
||||||
boardTree={this.props.boardTree}
|
</div>
|
||||||
addCard={this.props.addCard}
|
)
|
||||||
addCardFromTemplate={this.props.addCardFromTemplate}
|
})
|
||||||
addCardTemplate={this.props.addCardTemplate}
|
|
||||||
editCardTemplate={this.props.editCardTemplate}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private showFilterDialog = () => {
|
|
||||||
this.setState({showFilter: true})
|
|
||||||
}
|
|
||||||
|
|
||||||
private hideFilterDialog = () => {
|
|
||||||
this.setState({showFilter: false})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default ViewHeader
|
export default ViewHeader
|
||||||
|
Loading…
x
Reference in New Issue
Block a user