2020-10-26 10:52:33 +01:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React from 'react'
|
|
|
|
|
2020-11-03 19:35:24 +01:00
|
|
|
import {PropertyType} from '../blocks/board'
|
2020-10-26 10:52:33 +01:00
|
|
|
import {Utils} from '../utils'
|
|
|
|
|
|
|
|
import Menu from '../widgets/menu'
|
|
|
|
|
2020-10-26 14:43:29 +01:00
|
|
|
import './propertyMenu.scss'
|
|
|
|
|
2020-10-26 10:52:33 +01:00
|
|
|
type Props = {
|
2020-11-03 19:35:24 +01:00
|
|
|
propertyId: string
|
|
|
|
propertyName: string
|
|
|
|
propertyType: PropertyType
|
|
|
|
onNameChanged: (newName: string) => void
|
2020-11-03 20:15:16 +01:00
|
|
|
onTypeChanged: (newType: PropertyType) => void
|
2020-11-03 19:35:24 +01:00
|
|
|
onDelete: (id: string) => void
|
2020-10-26 10:52:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
name: string
|
|
|
|
}
|
|
|
|
|
2020-11-03 19:35:24 +01:00
|
|
|
export default class PropertyMenu extends React.PureComponent<Props, State> {
|
2020-10-26 10:52:33 +01:00
|
|
|
private nameTextbox = React.createRef<HTMLInputElement>()
|
|
|
|
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props)
|
2020-11-03 19:35:24 +01:00
|
|
|
this.state = {name: this.props.propertyName}
|
2020-10-26 10:52:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public componentDidMount(): void {
|
2020-11-12 23:17:13 +01:00
|
|
|
this.nameTextbox.current?.focus()
|
|
|
|
document.execCommand('selectAll', false, undefined)
|
2020-10-26 10:52:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private typeDisplayName(type: PropertyType): string {
|
|
|
|
switch (type) {
|
|
|
|
case 'text': return 'Text'
|
|
|
|
case 'number': return 'Number'
|
|
|
|
case 'select': return 'Select'
|
|
|
|
case 'multiSelect': return 'Multi Select'
|
|
|
|
case 'person': return 'Person'
|
|
|
|
case 'file': return 'File or Media'
|
|
|
|
case 'checkbox': return 'Checkbox'
|
|
|
|
case 'url': return 'URL'
|
|
|
|
case 'email': return 'Email'
|
|
|
|
case 'phone': return 'Phone'
|
|
|
|
case 'createdTime': return 'Created Time'
|
|
|
|
case 'createdBy': return 'Created By'
|
|
|
|
case 'updatedTime': return 'Updated Time'
|
|
|
|
case 'updatedBy': return 'Updated By'
|
|
|
|
default: {
|
|
|
|
Utils.assertFailure(`typeDisplayName, unhandled type: ${type}`)
|
|
|
|
return type
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public render(): JSX.Element {
|
|
|
|
return (
|
|
|
|
<Menu>
|
|
|
|
<input
|
|
|
|
ref={this.nameTextbox}
|
|
|
|
type='text'
|
2020-10-26 14:43:29 +01:00
|
|
|
className='PropertyMenu menu-textbox'
|
2020-10-26 10:52:33 +01:00
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
onChange={(e) => this.setState({name: e.target.value})}
|
|
|
|
value={this.state.name}
|
2020-11-03 19:35:24 +01:00
|
|
|
onBlur={() => this.props.onNameChanged(this.state.name)}
|
2020-10-26 10:52:33 +01:00
|
|
|
onKeyDown={(e) => {
|
|
|
|
if (e.keyCode === 13 || e.keyCode === 27) {
|
2020-11-03 19:35:24 +01:00
|
|
|
this.props.onNameChanged(this.state.name)
|
2020-10-26 10:52:33 +01:00
|
|
|
e.stopPropagation()
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Menu.SubMenu
|
|
|
|
id='type'
|
2020-11-03 19:35:24 +01:00
|
|
|
name={this.typeDisplayName(this.props.propertyType)}
|
2020-10-26 10:52:33 +01:00
|
|
|
>
|
|
|
|
<Menu.Text
|
|
|
|
id='text'
|
|
|
|
name='Text'
|
2020-11-03 19:35:24 +01:00
|
|
|
onClick={() => this.props.onTypeChanged('text')}
|
2020-10-26 10:52:33 +01:00
|
|
|
/>
|
|
|
|
<Menu.Text
|
|
|
|
id='number'
|
|
|
|
name='Number'
|
2020-11-03 19:35:24 +01:00
|
|
|
onClick={() => this.props.onTypeChanged('number')}
|
2020-10-26 10:52:33 +01:00
|
|
|
/>
|
|
|
|
<Menu.Text
|
|
|
|
id='select'
|
|
|
|
name='Select'
|
2020-11-03 19:35:24 +01:00
|
|
|
onClick={() => this.props.onTypeChanged('select')}
|
2020-10-26 10:52:33 +01:00
|
|
|
/>
|
|
|
|
<Menu.Text
|
|
|
|
id='createdTime'
|
|
|
|
name='Created Time'
|
2020-11-03 19:35:24 +01:00
|
|
|
onClick={() => this.props.onTypeChanged('createdTime')}
|
2020-10-26 10:52:33 +01:00
|
|
|
/>
|
|
|
|
<Menu.Text
|
|
|
|
id='updatedTime'
|
|
|
|
name='Updated Time'
|
2020-11-03 19:35:24 +01:00
|
|
|
onClick={() => this.props.onTypeChanged('updatedTime')}
|
2020-10-26 10:52:33 +01:00
|
|
|
/>
|
|
|
|
</Menu.SubMenu>
|
|
|
|
<Menu.Text
|
|
|
|
id='delete'
|
|
|
|
name='Delete'
|
2020-11-03 19:35:24 +01:00
|
|
|
onClick={() => this.props.onDelete(this.props.propertyId)}
|
2020-10-26 10:52:33 +01:00
|
|
|
/>
|
|
|
|
</Menu>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|