You've already forked focalboard
mirror of
https://github.com/mattermost/focalboard.git
synced 2025-07-12 23:50:27 +02:00
Migrating viewHeader to functional component
This commit is contained in:
@ -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,22 +36,10 @@ 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 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(props: Props) {
|
|
||||||
super(props)
|
|
||||||
this.state = {showFilter: false}
|
|
||||||
}
|
|
||||||
|
|
||||||
render(): JSX.Element {
|
|
||||||
const {boardTree, showView, withGroupBy} = this.props
|
|
||||||
const {board, activeView} = boardTree
|
const {board, activeView} = boardTree
|
||||||
|
|
||||||
const hasFilter = activeView.filter && activeView.filter.filters?.length > 0
|
const hasFilter = activeView.filter && activeView.filter.filters?.length > 0
|
||||||
@ -65,7 +53,7 @@ class ViewHeader extends React.Component<Props, State> {
|
|||||||
onChanged={(text) => {
|
onChanged={(text) => {
|
||||||
mutator.changeTitle(activeView, text)
|
mutator.changeTitle(activeView, text)
|
||||||
}}
|
}}
|
||||||
readonly={this.props.readonly}
|
readonly={props.readonly}
|
||||||
/>
|
/>
|
||||||
<MenuWrapper>
|
<MenuWrapper>
|
||||||
<IconButton icon={<DropdownIcon/>}/>
|
<IconButton icon={<DropdownIcon/>}/>
|
||||||
@ -73,27 +61,27 @@ class ViewHeader extends React.Component<Props, State> {
|
|||||||
board={board}
|
board={board}
|
||||||
boardTree={boardTree}
|
boardTree={boardTree}
|
||||||
showView={showView}
|
showView={showView}
|
||||||
readonly={this.props.readonly}
|
readonly={props.readonly}
|
||||||
/>
|
/>
|
||||||
</MenuWrapper>
|
</MenuWrapper>
|
||||||
|
|
||||||
<div className='octo-spacer'/>
|
<div className='octo-spacer'/>
|
||||||
|
|
||||||
{!this.props.readonly &&
|
{!props.readonly &&
|
||||||
<>
|
<>
|
||||||
{/* Card properties */}
|
{/* Card properties */}
|
||||||
|
|
||||||
<ViewHeaderPropertiesMenu
|
<ViewHeaderPropertiesMenu
|
||||||
properties={boardTree.board.cardProperties}
|
properties={board.cardProperties}
|
||||||
activeView={boardTree.activeView}
|
activeView={activeView}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Group by */}
|
{/* Group by */}
|
||||||
|
|
||||||
{withGroupBy &&
|
{withGroupBy &&
|
||||||
<ViewHeaderGroupByMenu
|
<ViewHeaderGroupByMenu
|
||||||
properties={boardTree.board.cardProperties}
|
properties={board.cardProperties}
|
||||||
activeView={boardTree.activeView}
|
activeView={activeView}
|
||||||
groupByPropertyName={boardTree.groupByProperty?.name}
|
groupByPropertyName={boardTree.groupByProperty?.name}
|
||||||
/>}
|
/>}
|
||||||
|
|
||||||
@ -102,25 +90,25 @@ class ViewHeader extends React.Component<Props, State> {
|
|||||||
<ModalWrapper>
|
<ModalWrapper>
|
||||||
<Button
|
<Button
|
||||||
active={hasFilter}
|
active={hasFilter}
|
||||||
onClick={this.showFilterDialog}
|
onClick={() => setShowFilter(true)}
|
||||||
>
|
>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
id='ViewHeader.filter'
|
id='ViewHeader.filter'
|
||||||
defaultMessage='Filter'
|
defaultMessage='Filter'
|
||||||
/>
|
/>
|
||||||
</Button>
|
</Button>
|
||||||
{this.state.showFilter &&
|
{showFilter &&
|
||||||
<FilterComponent
|
<FilterComponent
|
||||||
boardTree={boardTree}
|
boardTree={boardTree}
|
||||||
onClose={this.hideFilterDialog}
|
onClose={() => setShowFilter(false)}
|
||||||
/>}
|
/>}
|
||||||
</ModalWrapper>
|
</ModalWrapper>
|
||||||
|
|
||||||
{/* Sort */}
|
{/* Sort */}
|
||||||
|
|
||||||
<ViewHeaderSortMenu
|
<ViewHeaderSortMenu
|
||||||
properties={boardTree.board.cardProperties}
|
properties={board.cardProperties}
|
||||||
activeView={boardTree.activeView}
|
activeView={activeView}
|
||||||
orderedCards={boardTree.orderedCards()}
|
orderedCards={boardTree.orderedCards()}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
@ -129,40 +117,31 @@ class ViewHeader extends React.Component<Props, State> {
|
|||||||
{/* Search */}
|
{/* Search */}
|
||||||
|
|
||||||
<ViewHeaderSearch
|
<ViewHeaderSearch
|
||||||
boardTree={this.props.boardTree}
|
boardTree={boardTree}
|
||||||
setSearchText={this.props.setSearchText}
|
setSearchText={props.setSearchText}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Options menu */}
|
{/* Options menu */}
|
||||||
|
|
||||||
{!this.props.readonly &&
|
{!props.readonly &&
|
||||||
<>
|
<>
|
||||||
<ViewHeaderActionsMenu
|
<ViewHeaderActionsMenu
|
||||||
boardTree={this.props.boardTree}
|
boardTree={boardTree}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* New card button */}
|
{/* New card button */}
|
||||||
|
|
||||||
<NewCardButton
|
<NewCardButton
|
||||||
boardTree={this.props.boardTree}
|
boardTree={boardTree}
|
||||||
addCard={this.props.addCard}
|
addCard={props.addCard}
|
||||||
addCardFromTemplate={this.props.addCardFromTemplate}
|
addCardFromTemplate={props.addCardFromTemplate}
|
||||||
addCardTemplate={this.props.addCardTemplate}
|
addCardTemplate={props.addCardTemplate}
|
||||||
editCardTemplate={this.props.editCardTemplate}
|
editCardTemplate={props.editCardTemplate}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
})
|
||||||
|
|
||||||
private showFilterDialog = () => {
|
|
||||||
this.setState({showFilter: true})
|
|
||||||
}
|
|
||||||
|
|
||||||
private hideFilterDialog = () => {
|
|
||||||
this.setState({showFilter: false})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default ViewHeader
|
export default ViewHeader
|
||||||
|
Reference in New Issue
Block a user