2020-10-26 10:52:33 +01:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
2022-03-10 22:39:13 +01:00
|
|
|
import React from 'react'
|
2021-05-10 15:20:48 +02:00
|
|
|
import {useIntl, IntlShape} from 'react-intl'
|
2020-10-26 10:52:33 +01:00
|
|
|
|
|
|
|
import Menu from '../widgets/menu'
|
2022-08-16 18:00:43 +02:00
|
|
|
import propsRegistry from '../properties'
|
|
|
|
import {PropertyType} from '../properties/types'
|
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
|
2021-06-11 11:22:19 +02:00
|
|
|
onTypeAndNameChanged: (newType: PropertyType, newName: string) => void
|
2020-11-03 19:35:24 +01:00
|
|
|
onDelete: (id: string) => void
|
2020-10-26 10:52:33 +01:00
|
|
|
}
|
|
|
|
|
2021-03-30 13:37:47 +02:00
|
|
|
function typeMenuTitle(intl: IntlShape, type: PropertyType): string {
|
2022-08-16 18:00:43 +02:00
|
|
|
return `${intl.formatMessage({id: 'PropertyMenu.typeTitle', defaultMessage: 'Type'})}: ${type.displayName(intl)}`
|
2021-03-30 13:37:47 +02:00
|
|
|
}
|
2020-10-26 10:52:33 +01:00
|
|
|
|
2021-10-27 09:04:15 +02:00
|
|
|
type TypesProps = {
|
|
|
|
label: string
|
|
|
|
onTypeSelected: (type: PropertyType) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
export const PropertyTypes = (props: TypesProps): JSX.Element => {
|
|
|
|
const intl = useIntl()
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Menu.Label>
|
|
|
|
<b>{props.label}</b>
|
|
|
|
</Menu.Label>
|
|
|
|
|
|
|
|
<Menu.Separator/>
|
|
|
|
|
|
|
|
{
|
2022-08-16 18:00:43 +02:00
|
|
|
propsRegistry.list().map((p) => (
|
2021-10-27 09:04:15 +02:00
|
|
|
<Menu.Text
|
2022-08-16 18:00:43 +02:00
|
|
|
key={p.type}
|
|
|
|
id={p.type}
|
|
|
|
name={p.displayName(intl)}
|
|
|
|
onClick={() => props.onTypeSelected(p)}
|
2021-10-27 09:04:15 +02:00
|
|
|
/>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-02-14 21:55:13 +01:00
|
|
|
const PropertyMenu = (props: Props) => {
|
2021-05-10 15:20:48 +02:00
|
|
|
const intl = useIntl()
|
2022-07-27 21:35:36 +02:00
|
|
|
let currentPropertyName = props.propertyName
|
2020-10-26 10:52:33 +01:00
|
|
|
|
2021-03-31 22:44:02 +02:00
|
|
|
const deleteText = intl.formatMessage({
|
2021-03-31 23:19:12 +02:00
|
|
|
id: 'PropertyMenu.Delete',
|
2021-03-31 22:44:02 +02:00
|
|
|
defaultMessage: 'Delete',
|
|
|
|
})
|
|
|
|
|
2021-03-30 13:37:47 +02:00
|
|
|
return (
|
|
|
|
<Menu>
|
2022-03-10 22:39:13 +01:00
|
|
|
<Menu.TextInput
|
|
|
|
initialValue={props.propertyName}
|
2022-07-27 21:35:36 +02:00
|
|
|
onConfirmValue={(n) => {
|
|
|
|
props.onTypeAndNameChanged(props.propertyType, n)
|
|
|
|
currentPropertyName = n
|
|
|
|
}}
|
|
|
|
onValueChanged={(n) => currentPropertyName = n}
|
2021-03-30 13:37:47 +02:00
|
|
|
/>
|
|
|
|
<Menu.SubMenu
|
|
|
|
id='type'
|
|
|
|
name={typeMenuTitle(intl, props.propertyType)}
|
|
|
|
>
|
2021-10-27 09:04:15 +02:00
|
|
|
<PropertyTypes
|
|
|
|
label={intl.formatMessage({id: 'PropertyMenu.changeType', defaultMessage: 'Change property type'})}
|
2022-07-27 21:35:36 +02:00
|
|
|
onTypeSelected={(type: PropertyType) => props.onTypeAndNameChanged(type, currentPropertyName)}
|
2021-10-27 09:04:15 +02:00
|
|
|
/>
|
2021-03-30 13:37:47 +02:00
|
|
|
</Menu.SubMenu>
|
|
|
|
<Menu.Text
|
|
|
|
id='delete'
|
2021-03-31 22:44:02 +02:00
|
|
|
name={deleteText}
|
2021-03-30 13:37:47 +02:00
|
|
|
onClick={() => props.onDelete(props.propertyId)}
|
|
|
|
/>
|
|
|
|
</Menu>
|
|
|
|
)
|
2022-02-14 21:55:13 +01:00
|
|
|
}
|
2021-01-04 21:08:12 +01:00
|
|
|
|
2022-02-14 21:55:13 +01:00
|
|
|
export default React.memo(PropertyMenu)
|