mirror of
https://github.com/mattermost/focalboard.git
synced 2025-01-26 18:48:15 +02:00
Making propertyMenu a pure widget
This commit is contained in:
parent
e55e5fa2a4
commit
74de574525
@ -6,6 +6,7 @@ import {FormattedMessage, IntlShape, injectIntl} from 'react-intl'
|
|||||||
import {BlockIcons} from '../blockIcons'
|
import {BlockIcons} from '../blockIcons'
|
||||||
import {MutableTextBlock} from '../blocks/textBlock'
|
import {MutableTextBlock} from '../blocks/textBlock'
|
||||||
import {BoardTree} from '../viewModel/boardTree'
|
import {BoardTree} from '../viewModel/boardTree'
|
||||||
|
import {PropertyType} from '../blocks/board'
|
||||||
import {CardTree, MutableCardTree} from '../viewModel/cardTree'
|
import {CardTree, MutableCardTree} from '../viewModel/cardTree'
|
||||||
import mutator from '../mutator'
|
import mutator from '../mutator'
|
||||||
import {OctoListener} from '../octoListener'
|
import {OctoListener} from '../octoListener'
|
||||||
@ -163,8 +164,12 @@ class CardDetail extends React.Component<Props, State> {
|
|||||||
<MenuWrapper>
|
<MenuWrapper>
|
||||||
<div className='octo-propertyname'><Button>{propertyTemplate.name}</Button></div>
|
<div className='octo-propertyname'><Button>{propertyTemplate.name}</Button></div>
|
||||||
<PropertyMenu
|
<PropertyMenu
|
||||||
property={propertyTemplate}
|
propertyId={propertyTemplate.id}
|
||||||
boardTree={boardTree}
|
propertyName={propertyTemplate.name}
|
||||||
|
propertyType={propertyTemplate.type}
|
||||||
|
onNameChanged={(newName: string) => mutator.renameProperty(board, propertyTemplate.id, newName)}
|
||||||
|
onTypeChanged={(newType: PropertyType) => mutator.changePropertyType(boardTree, propertyTemplate, newType)}
|
||||||
|
onDelete={(id: string) => mutator.deleteProperty(boardTree, id)}
|
||||||
/>
|
/>
|
||||||
</MenuWrapper>
|
</MenuWrapper>
|
||||||
<PropertyValueElement
|
<PropertyValueElement
|
||||||
|
@ -2,25 +2,27 @@
|
|||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
import {IPropertyTemplate, PropertyType} from '../blocks/board'
|
import {PropertyType} from '../blocks/board'
|
||||||
import {BoardTree} from '../viewModel/boardTree'
|
|
||||||
import {Utils} from '../utils'
|
import {Utils} from '../utils'
|
||||||
import mutator from '../mutator'
|
|
||||||
|
|
||||||
import Menu from '../widgets/menu'
|
import Menu from '../widgets/menu'
|
||||||
|
|
||||||
import './propertyMenu.scss'
|
import './propertyMenu.scss'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
property: IPropertyTemplate
|
propertyId: string
|
||||||
boardTree: BoardTree
|
propertyName: string
|
||||||
|
propertyType: PropertyType
|
||||||
|
onNameChanged: (newName: string) => void
|
||||||
|
onTypeChanged: (newType: string) => void
|
||||||
|
onDelete: (id: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
name: string
|
name: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class PropertyMenu extends React.Component<Props, State> {
|
export default class PropertyMenu extends React.PureComponent<Props, State> {
|
||||||
private nameTextbox = React.createRef<HTMLInputElement>()
|
private nameTextbox = React.createRef<HTMLInputElement>()
|
||||||
|
|
||||||
public shouldComponentUpdate(): boolean {
|
public shouldComponentUpdate(): boolean {
|
||||||
@ -29,9 +31,7 @@ export default class PropertyMenu extends React.Component<Props, State> {
|
|||||||
|
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
this.state = {name: this.props.propertyName}
|
||||||
name: (this.props.property && this.props.property.name) || '',
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentDidMount(): void {
|
public componentDidMount(): void {
|
||||||
@ -62,16 +62,7 @@ export default class PropertyMenu extends React.Component<Props, State> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private saveName = (): void => {
|
|
||||||
if (this.state.name !== this.props.property.name) {
|
|
||||||
Utils.log('menu.onNameChanged')
|
|
||||||
mutator.renameProperty(this.props.boardTree.board, this.props.property.id, this.state.name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public render(): JSX.Element {
|
public render(): JSX.Element {
|
||||||
const {boardTree, property} = this.props
|
|
||||||
const {board} = boardTree
|
|
||||||
return (
|
return (
|
||||||
<Menu>
|
<Menu>
|
||||||
<input
|
<input
|
||||||
@ -81,48 +72,48 @@ export default class PropertyMenu extends React.Component<Props, State> {
|
|||||||
onClick={(e) => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
onChange={(e) => this.setState({name: e.target.value})}
|
onChange={(e) => this.setState({name: e.target.value})}
|
||||||
value={this.state.name}
|
value={this.state.name}
|
||||||
onBlur={this.saveName}
|
onBlur={() => this.props.onNameChanged(this.state.name)}
|
||||||
onKeyDown={(e) => {
|
onKeyDown={(e) => {
|
||||||
if (e.keyCode === 13 || e.keyCode === 27) {
|
if (e.keyCode === 13 || e.keyCode === 27) {
|
||||||
this.saveName()
|
this.props.onNameChanged(this.state.name)
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Menu.SubMenu
|
<Menu.SubMenu
|
||||||
id='type'
|
id='type'
|
||||||
name={this.typeDisplayName(this.props.property.type)}
|
name={this.typeDisplayName(this.props.propertyType)}
|
||||||
>
|
>
|
||||||
<Menu.Text
|
<Menu.Text
|
||||||
id='text'
|
id='text'
|
||||||
name='Text'
|
name='Text'
|
||||||
onClick={() => mutator.changePropertyType(boardTree, property, 'text')}
|
onClick={() => this.props.onTypeChanged('text')}
|
||||||
/>
|
/>
|
||||||
<Menu.Text
|
<Menu.Text
|
||||||
id='number'
|
id='number'
|
||||||
name='Number'
|
name='Number'
|
||||||
onClick={() => mutator.changePropertyType(boardTree, property, 'number')}
|
onClick={() => this.props.onTypeChanged('number')}
|
||||||
/>
|
/>
|
||||||
<Menu.Text
|
<Menu.Text
|
||||||
id='select'
|
id='select'
|
||||||
name='Select'
|
name='Select'
|
||||||
onClick={() => mutator.changePropertyType(boardTree, property, 'select')}
|
onClick={() => this.props.onTypeChanged('select')}
|
||||||
/>
|
/>
|
||||||
<Menu.Text
|
<Menu.Text
|
||||||
id='createdTime'
|
id='createdTime'
|
||||||
name='Created Time'
|
name='Created Time'
|
||||||
onClick={() => mutator.changePropertyType(boardTree, property, 'createdTime')}
|
onClick={() => this.props.onTypeChanged('createdTime')}
|
||||||
/>
|
/>
|
||||||
<Menu.Text
|
<Menu.Text
|
||||||
id='updatedTime'
|
id='updatedTime'
|
||||||
name='Updated Time'
|
name='Updated Time'
|
||||||
onClick={() => mutator.changePropertyType(boardTree, property, 'updatedTime')}
|
onClick={() => this.props.onTypeChanged('updatedTime')}
|
||||||
/>
|
/>
|
||||||
</Menu.SubMenu>
|
</Menu.SubMenu>
|
||||||
<Menu.Text
|
<Menu.Text
|
||||||
id='delete'
|
id='delete'
|
||||||
name='Delete'
|
name='Delete'
|
||||||
onClick={() => mutator.deleteProperty(boardTree, property.id)}
|
onClick={() => this.props.onDelete(this.props.propertyId)}
|
||||||
/>
|
/>
|
||||||
</Menu>
|
</Menu>
|
||||||
)
|
)
|
Loading…
x
Reference in New Issue
Block a user